In previous post I have described Hello World example coming from ESP_IDF environment. Now let’s build Hello World from the scratch.
First of all let’s grab template application. It is available on GitHub under espressif project.
git clone --recursive https://github.com/espressif/esp-idf-template.git
Rename esp-idf-template directory to hello_world2.
mv esp-idf-template hello_world2
Edit Makefile and change value of PROJECT_NAME variable to hello_world2.
Main files of the projects are located in main directory, additional components will be located in components by default. So let’s got to main and remove source file main.c. This file contains example how to connect to wireless network and will be interesting in future. Create the easiest existing example hello_world2.c as below. Name of the file does not matter but one of source files must contain void app_main(void) function:
Remember to run make menuconfig to set serial flasher connection and then flash and monitor. At the end of the results you will see something like:
mode:DIO, clock div:2
ho 0 tail 12 room 4
0x40080000: _iram_start at ??:?
0x40080034: _iram_start at ??:?
It works. Now as general rule tasks should be created in form of endless loop and this peace of code hasn’t got loop. But task can delete themselves when finished. But where this task from app_main is deleted? When you quickly look into cpu_start.c file from esp-idf/components/esp32 folder you will see that right after app_main ends the task is deleted:
static void main_task(void* args)
// Now that the application is about to start, disable boot watchdogs
//Enable allocation in region where the startup stacks were located.