#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h" //IDF框架是基于FreeRTOS的
#include "esp_system.h" //esp32 系统操作库
#include "esp_spi_flash.h" //闪存读写库
void app_main()
app_main 为整个程序入口,系统会自动查找 app_main 函数,并从此函数开始执行(类似于 C 语言中的 main 函数)
在此函数中,可以初始化一些应用,比如创建其他 task,app_main 函数不能返回,否则会删除 main task 导致 crash
{
printf("Hello world!\n");
/* Print chip information */
esp_chip_info_t chip_info;
esp_chip_info_t有4个成员,分别是:
.model 芯片类型:ESP32
.features 芯片特性:嵌入式闪存/2.4G WiFi/低功耗蓝牙/经典蓝牙
.cores 核心数:单核/双核
.revision 版本号
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");
以 esp 开头的函数均为乐鑫提供的接口,上述代码主要打印芯片信息,esp_chip_info() 函数在 esp_system.h 中定义,作用是获取芯片的信息,以 esp_chip_info_t 返回,其中包含 CPU 核数,芯片版本号等信息, spi_flash_get_chip_size() 函数在 esp_spi_flash.h 中定义,作用是获取 flash 的大小
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();
}
循环 10 次,每隔 1s 打印一次消息,循环结束后,打印并立即输出所有缓存数据,然后调用 esp_restart() 重启,其中 esp_restart()在 esp_system.h 中定义,对芯片进行软重启
文章参考:https://blog.csdn.net/espressif/article/details/85799241