/* Hello World examplethis example code is in the public domain (or cc0 licensed, at your option .) unless required by applicable law or agreed to in writing, thissoftware is distributed on an "as is" basis, without warranties orconditions of any kind, either express or implied. */# include <stdio. h> # include "freertos/freertos. H "# include" freertos/task. H "# include" esp_system.h "# include" esp_spi_flash.h "Void app_main () {printf (" Hello world! \ N ");/* print chip information */esp_chip_info_t chip_info; // This structure indicates information about the chip. esp_chip_info (& chip_info ); printf ("this is esp32 chip with % d CPU cores, WiFi % S % s,", chip_info.cores, (chip_info.features & chip_feature_bt )? "/BT": "", (chip_info.features & chip_feature_ble )? "/Ble": ""); printf ("Silicon revision % d,", chip_info.revision); printf ("% DMB % s Flash \ n", spi_flash_get_chip_size () /(1024*1024), (chip_info.features & chip_feature_emb_flash )? "Embedded": "external"); For (INT I = 10; I> = 0; I --) {printf ("Restarting in % d seconds... \ n ", I); vtaskdelay( 1000/porttick_period_ms);} printf (" Restarting now. \ n "); fflush (stdout); esp_restart ();}
Void esp_chip_info (esp_chip_info_t * out_info) fills in the esp_chip_info_t structure with information about the chip. Parameter out_info: structures structure to be filled: esp_chip_info_t this structure represents information about the chip. Public Member esp_chip_model_t model chip model, bit mask uint8_t corescpu core quantity uint8_t revision chip revision number of uint8_t, one of esp_chip_model_t, featureschip_feature_x feature
Size_t spi_flash_get_chip_size () to obtain the size of the flash chip, as set in the binary image header. Note that this value does not necessarily match the actual flash size. Returns the size of the flash memory chip, in bytes.
void vTaskDelay(const TickType_t xTicksToDelay)Delay a task for a given number of ticks.The actual time that the task remains blocked depends on the tick rate. The constant portTICK_PERIOD_MS can be used to calculate real time from the tick rate - with the resolution of one tick period.INCLUDE_vTaskDelay must be defined as 1 for this function to be available. See the configuration section for more information.vTaskDelay() specifies a time at which the task wishes to unblock relative to the time at which vTaskDelay() is called. For example, specifying a block period of 100 ticks will cause the task to unblock 100 ticks after vTaskDelay() is called. vTaskDelay() does not therefore provide a good method of controlling the frequency of a periodic task as the path taken through the code, as well as other task and interrupt activity, will effect the frequency at which vTaskDelay() gets called and therefore the time at which the task next executes. See vTaskDelayUntil() for an alternative API function designed to facilitate fixed frequency execution. It does this by specifying an absolute time (rather than a relative time) at which the calling task should unblock.Example usage:void vTaskFunction( void * pvParameters ){// Block for 500ms.const TickType_t xDelay = 500 / portTICK_PERIOD_MS; for( ;; ) { // Simply toggle the LED every 500ms, blocking between each toggle. vToggleLED(); vTaskDelay( xDelay ); }}ParametersxTicksToDelay: The amount of time, in tick periods, that the calling task should block.
After reading hello_world, you always have to learn something:
1. # include <stdio. h> it can be seen that the SDK depends on the Standard C library.
2. # include "freertos/freertos. H". We can see that this SDK is defined as a freertos system, namely, an embedded real-time operating system (RTOs ).
# Include "freertos/task. H"
3. Void app_main () {}we can see that app_main is the program entry function, which is also called the main function.
4. vtaskdelay (1000/porttick_period_ms) is a common latency function in freertos. This function has some research value and will be discussed later.
5. The use of fflush (stdout) is very careful, and the lexin code level is still good.
Analyze the usage of fflush (stdout:
Printf is a row buffer function. It is written to the buffer zone first. After the conditions are met, the buffer zone is flushed to the corresponding file. The conditions for flushing the buffer zone are as follows:
1) buffer Filling
2) The written characters include '\ n'
3) Call fflush to manually refresh the buffer
4) When scanf is called to read data from the buffer, it also refreshes the data in the buffer.
Someone asked why I can print the program smoothly without adding '\ n', because your printf is not in a loop and won't involve any problems, because even after printf is executed, the content is only sent to the buffer zone, but when you reach the end of the program, the buffer will be refreshed, and you will see that you have expected something to appear on the screen, of course, after testing, this is also related to the compiler, but the use of printf in while is similar to the previous sentence fflush (stdout) is an insurance practice. manually refresh the buffer to avoid unnecessary bugs.
Finally, this code is analyzed here and you can try to run your first hello_world demo.
[Embedded hardware esp32] (1) Routine Hello world example Annotation