hello_world: Erstellen eines ESP-IDF Projekts
Das hello_world kommt ohne besonderen IO aus. Man muss also keine besonderen Initialisierungen durchführten. Deswegen eignet es sich gerade im Embedded Bereich, um die Funktionalität der Toolchain zu testen.
Die ESP32-IDE ist so nett und erzeugt die Applikation selber. Es gibt sie aber auch schon im Repository (siehe Tutorial). Hier will ich aber einmal zeigen, wie so ein Projekt mit der IDE erstellt wird.
In der IDE wählt man zuerst File->New->Espressif IDF Project. Im nachfolgenden Dialog unter Template Selection checkt man "Create a project using one of the tamplates" und wählt hello_world als template aus. Falls hello_world aus dem Tutorial dort schon existiert muss man den Projektnamen ändern (Vorschlag hello_world_new).
Der Vorgang wird mit Finish abgeschlossen und das Projekt wird erstellt.
/*
* SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: CC0-1.0
*/
#include <stdio.h>
#include <inttypes.h>
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_chip_info.h"
#include "esp_flash.h"
#include "esp_system.h"
void app_main(void)
{
printf("Hello world!\n");
/* Print chip information */
esp_chip_info_t chip_info;
uint32_t flash_size;
esp_chip_info(&chip_info);
printf("This is %s chip with %d CPU core(s), %s%s%s%s, ",
CONFIG_IDF_TARGET,
chip_info.cores,
(chip_info.features & CHIP_FEATURE_WIFI_BGN) ? "WiFi/" : "",
(chip_info.features & CHIP_FEATURE_BT) ? "BT" : "",
(chip_info.features & CHIP_FEATURE_BLE) ? "BLE" : "",
(chip_info.features & CHIP_FEATURE_IEEE802154) ? ", 802.15.4 (Zigbee/Thread)" : "");
unsigned major_rev = chip_info.revision / 100;
unsigned minor_rev = chip_info.revision % 100;
printf("silicon revision v%d.%d, ", major_rev, minor_rev);
if(esp_flash_get_size(NULL, &flash_size) != ESP_OK) {
printf("Get flash size failed");
return;
}
printf("%" PRIu32 "MB %s flash\n", flash_size / (uint32_t)(1024 * 1024),
(chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external");
printf("Minimum free heap size: %" PRIu32 " bytes\n", esp_get_minimum_free_heap_size());
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();
}
AXP2101
Nahdem wir den ESP32 neu programmiert haben, wird der Power-Controller AXP2101 beim nächsten Neustart ohne Konfiguration starten und somit kämen wir nicht mehr an das FPGA ran.
Deswegen gibt es die IDF-Komponente PowerLIb, die diesen Chip konfiguriert und in allen ESP32-IDF Applikationen eingebunden wird. Somit wird einmal beim Booten der Controller initialisiert.
Wenn man die hello_world aus dem Tutorial verwendet, dann ist dieser Schritt schon gemacht.
