Skip to content

5inch_P4_IDF_01_Print_Hello_World: ESP32-P4 Serial Print Hello World

1. Course Introduction

In this lesson, we use the ESP-IDF framework to run the first program on the ESP32-P4. Through the FreeRTOS main task, the program prints an incrementing counter line to the serial port once per second. After the program is flashed and the development board is powered on and reset, the serial monitor first outputs the ESP-IDF startup information, then prints a line such as Hello world: 0, Hello world: 1… once per second, with the counter continuously incrementing. Learners only need to connect a USB data cable, complete the ESP-IDF environment setup, compile, and flash in order to see the serial port output continuously.

This lesson is the first in the entire ESP32-P4 curriculum series. It does not involve any peripheral drivers; the focus is on verifying whether the development environment and the communication link with the development board are working properly. Through this experiment, learners will complete the full introductory chain of opening an ESP-IDF project, setting the target chip, compiling, flashing, and monitoring the serial port, laying the environmental foundation for subsequent lessons such as lighting up an LED and driving a screen.

2. Learning Objectives

  • Be able to open the Lesson01 project in the ESP-IDF environment and set the target chip to esp32p4.
  • Be able to explain the timing of app_main as the default task entry point in ESP-IDF, and the role of vTaskDelay within the loop.
  • Be able to complete project compilation and flashing, and open the serial monitor to observe the Hello world counter output.
  • Be able to determine whether the development environment and communication link are working properly based on whether the serial port continuously prints an incrementing counter.

3. Preparations

  • Applicable development board: CrowPanel Advanced 5-inch ESP32-P4 HMI AI Display Development Board.
  • Software: VS Code, ESP-IDF Extension (ESP-IDF and its toolchain installed; v5.4 or later recommended). This lesson uses v5.5.4.
  • Project dependencies: Keep the CMakeLists.txt and main/hello_world_main.c files under the Lesson01-Print_Hello_World directory. No additional components need to be installed for this lesson.
  • Configuration: target chip esp32p4.

Code download link:

https://github.com/Elecrow-RD/-CrowPanel-Advanced-5inch-ESP32-P4-HMI-AI-Display-800x480-IPS-Touch-Screen/tree/master/example/V1.0

4. Software Operation Steps

Open the ESP-IDF Extension panel in VS Code, click Open ESP-IDF Project, and select the Lesson01-Print_Hello_World folder. If you need to create a project from a template, you can fill in the project name, target chip, and serial port in the ESP-IDF panel and then select a template.

You can also right-click the lesson directory in File Explorer and choose to open it with VS Code.

Open lesson directory in File Explorer

After opening, the Explorer on the left should display project files such as main and CMakeLists.txt.

Open main/hello_world_main.c and confirm that the app_main, printf, and vTaskDelay code is complete.

View lesson project structure

First, select the code runtime environment ESP-IDF v5.5.4.

For installation steps, refer to: Get Started with ESP IDF - Elecrow Wiki

Then set the flashing method to UART.

Next, select the serial port that actually corresponds to the development board.

In the ESP-IDF Extension panel, click Set Espressif Device Target, and select esp32p4 from the target list that pops up. After the setting is complete, the target chip in the status bar should display ESP32-P4.

Confirm ESP-IDF, UART, serial port, and target chip

Click SDK Configuration Editor in the VS Code bottom status bar or the ESP-IDF extension panel, and wait for the configuration page to finish loading completely before modifying any parameters. If the page is still loading, wait for it to finish first.

Open SDK Configuration Editor

View SDK configuration page

Enter flash in the search box and ensure the following: Flash SPI mode: QIO; Flash Sampling Mode: STR Mode; Flash SPI speed: 80 MHz; Flash size: 16 MB. These parameters should match the on-board Flash of the Advance-P4.

Configure Flash parameters

This lesson does not require enabling any additional components; keep the remaining SDK options at their project default values. After verifying that the Flash parameters above are correct, click Save in the top-right corner, and compile only after the save succeeds.

Then click Full Clean to clear previous compilation caches, which does not affect the compilation of the new code.

Execute Full Clean

Click the Build button and wait for compilation to complete. On success, the end of the output window should display Project build complete with no error messages.

Execute Full Clean

After confirming that the development board is connected to the computer via a USB data cable, click Select Port to Use and select the corresponding serial port (subject to the port actually recognized by the system).

Then click the Flash button. During flashing, the output window shows progress, and upon completion prompts Hash of data verified and Hard resetting....

Compile project and confirm success

After flashing is complete, click the Monitor button to open the serial monitor; the default baud rate is 115200. Once the monitor opens, it should first display the ESP-IDF startup information, then continuously print the Hello world counter. Press Ctrl + ] to exit the monitor.

View firmware flashing completion message

Finally, we introduce a one-click operation button that can sequentially complete compilation, flashing, and opening the serial monitor. Use it only after the project configuration and serial port have both been confirmed correct.

Select serial port and flash

5. Hardware Operation Steps

Use a USB Type-C data cable that supports data transfer to connect the ESP32-P4 development board's UART0 interface to the computer. After connection, the development board's power indicator should light up.

Configure Flash parameters

After flashing is complete and the board is reset, observe whether the development board starts up normally. If the serial monitor is already open, you should be able to see the ESP-IDF startup information, including the chip model ESP32-P4 and the reset reason.

Observe whether the serial monitor prints a line Hello world: N once per second, where N starts from 0 and increments continuously, with no restart or freeze occurring. The serial output should be consistent with the loop and delay logic in the main program.

View Hello World serial output

6. Key Code Explanation

void app_main(void)
{
    int i = 0;
    while (1) {
        printf("Hello world: %d\n", i++);
        vTaskDelay(1000 / portTICK_PERIOD_MS);
    }
}

app_main() is the ESP-IDF application entry point. The local variable i starts at 0, printf() outputs the current value and then increments it, and the infinite loop keeps the message running continuously. vTaskDelay(1000 / portTICK_PERIOD_MS) suspends the current FreeRTOS task for approximately one second, so the serial monitor receives one new line per second. Removing the delay makes the loop print as quickly as the CPU and serial port allow.

7. Experimental Observations

After the program is flashed and the board is reset, the serial monitor first outputs the ESP-IDF startup information, including the chip model ESP32-P4, CPU frequency, reset reason, and so on. It then enters the user program and begins incrementing from Hello world: 0, printing one line per second:

Open lesson directory in File Explorer

The printing should continue, with the counter incrementing continuously, and the development board should not restart, freeze, or experience prolonged output loss. If the serial port produces no output at all, you should first check whether the serial port is correctly selected, whether the baud rate is 115200, and whether the target chip is esp32p4; if garbled characters appear, it is most often caused by a baud rate mismatch.