ESP32 study notes (3) running multitasking

After the tossing of the first two posts, the basic development environment has been set up! We can finally write code and tune sensors happily now! !
Because the younger brother is using the official Espressif original SDK, I can only find the SDK package with freertos on the official website, so based on this original SDK, I will share with you the process of esp32 running multitasking (LED flashing + serial port) Print)


First, we copy the example program of the LED light flashing in esp/esp-idf/examples.
          Here is a small detail, because the official blink program selects the pins through the SDK setting tool menuconfig, so you can use the SDK configuration tool to directly select the pins you need to control, or you can use the program to select the pins, Below I will use the SDK configuration tool, which is menuconfig, to configure the pins.

Enter the esp directory and copy the program
   cd esp
   cp -r /esp/esp-idf/examples/get-started/blink . (Be careful not to miss it. This means copying to this directory)

Use vim to watch the code writing

   sudo vim main.c (first enter the blink/main directory, and then run this statement) the



code probably means to set the GPIO level to achieve the effect of LED blinking, and then the main function creates a task.

Then I first test the effect of the program.

Execute the
make menuconfig     

up and down keys to select the fifth option.





This option is the pin selection tool for the routine, and we press Enter.





Here is the selection of the io pin, I choose pin 5, which is the GPIO5 on the board, save and exit

Compile and download the program
su
make flash

and wait for the board to finish programming, and connect the LED to GPIO5 with a Dupont wire, you can see the LED flashing.

After the LED flashing test is completed, we continue to add a task. I directly refer to the official example program to create a serial port output task.





Then create a new task in the main function.




Note that the priority must be modified, otherwise it will be stuck in a task, because we are using the blocking delay, so the priority needs to be modified. I changed it to 5.
(If you don’t understand here, please refer to the relevant information of freertos, which has nothing to do with esp32)

Then compile and download

su 
make flash and

wait for the download to complete. Open the serial port assistant

sudo cutecom

and stare at the LED and the serial port software is








OK. The LED flashes and the serial port output is correct.

enjoy yourself!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324846939&siteId=291194637