野路子學習esp32(五) Hello World源碼解析@a.宏萬


本示例演示如何開啟一個任務,並間隔打印 “Hello World

首次使用項目時,必須先執行 make menuconfig 后方可編譯

硬件:

  • ESP32 模組
  • USB轉TTL

軟件:

  • Cygwin + Eclipse 開發環境
  • 串口工具
/* Hello World Example

   This example code is in the Public Domain (or CC0 licensed, at your option.)

   Unless required by applicable law or agreed to in writing, this
   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
   CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include "freertos/FreeRTOS.h"    //可以看到idf是基於FreeRtos系統
#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;
    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);        //延時函數  單位ms
    }
    printf("Restarting now.\n");
    fflush(stdout);              //清除讀寫緩沖區,立即把輸出緩沖區的數據進行物理寫入
    esp_restart();               //系統重啟
}

 

野路子學習esp32(四) 燒錄固件 @a.宏萬

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM