espressif releases esp_idf version 5

Espessif officially released version 5 of their ESP_IDF (IoT Development Framework) on 2 December. I’ve been spending the last two days learning how to migrate from version 4.4.3 to version 5. After a few false starts I’ve discovered a workflow that works for me.

  • First thing I do is create a new work folder in which to migrate to version 5.
  • Within that folder I recursively copy the contents of a version 5 example that most closely matches what I want to port. In my case it was underneath the examples folder, examples/get-started/blink.
  • Once copied I step into the main folder and copy the main folder source contents only of the application to be ported. Adjust the CMake file in the main folder to pick up the new source files you just copied.
  • I step out of the main folder and back into the top level migration folder
  • I perform an idf.py set-target esp32s3 or esp32c3 for the hardware I need to compile for.
  • I them start to compile the code. You’re going to get errors, so you need to keep an editor open in another console tab or within a graphical editor, and fix the source that’s causing compiler errors.
  • I managed to complete the migration in no more than three steps.
  • Once compiled, then flash the new binary to the test board and see if it works. In both of my cases so far, they have.

Here’s one of the easiest of my apps to port so far.

#include <stdio.h>#include <array>#include "freertos/FreeRTOS.h"#include "freertos/task.h"#include "driver/gpio.h"#include "esp_log.h"#include "led_strip.h"#include "sdkconfig.h"// Create an array of color arrays to cycle through continuously.//using std::array;const array<array<int, 3>, 7> colors {{{32,0,0},  // red{0,32,0},  // green{0,0,32},  // blue{0,32,32}, // cyan{32,0,32}, // magenta{32,16,0}, // yellow{0,0,0}// black}};// Task 1.//static void task_blink_neo_pixel(void * pvParameters) {// Initialized the NeoPixel.//static led_strip_handle_t led_strip;led_strip_config_t strip_config = {.strip_gpio_num = CONFIG_BLINK_GPIO,.max_leds = 1, // at least one LED on board};led_strip_rmt_config_t rmt_config = {.resolution_hz = 10000000, // 10 MHz};ESP_ERROR_CHECK(led_strip_new_rmt_device(&strip_config, &rmt_config, &led_strip));// Darken NeoPixel by setting individual LED values to 0//led_strip_clear(led_strip);// Task 1 endless loop.//while(true) {for(auto color : colors) {led_strip_set_pixel(led_strip, 0, color[0], color[1], color[2]);led_strip_refresh(led_strip);vTaskDelay(500 / portTICK_PERIOD_MS);led_strip_clear(led_strip);vTaskDelay(500 / portTICK_PERIOD_MS);}}}// Task 2.//static void task_blink_led(void * pvParameters) {gpio_reset_pin(GPIO_NUM_46);// Set the GPIO as a push/pull output//gpio_set_direction(GPIO_NUM_46, GPIO_MODE_OUTPUT);// Task 2 endless loop.//while (true) {gpio_set_level(GPIO_NUM_46, true);   // LED onvTaskDelay(100 / portTICK_PERIOD_MS);gpio_set_level(GPIO_NUM_46, false);  // LED offvTaskDelay(100 / portTICK_PERIOD_MS);gpio_set_level(GPIO_NUM_46, true);   // LED onvTaskDelay(100 / portTICK_PERIOD_MS);gpio_set_level(GPIO_NUM_46, false);  // LED offvTaskDelay(2700 / portTICK_PERIOD_MS);}}// Main entry.//extern "C" void app_main(void) {static const char *TAG = "DUAL_BLINK";int core = xPortGetCoreID();ESP_LOGI(TAG, "BEGIN");ESP_LOGI(TAG, IDF_VER);ESP_LOGI(TAG, "APP_MAIN CORE %i", core);// Create task 1.//TaskHandle_t xHandle1 = NULL;static uint8_t ucParameterToPass1 = 1;xTaskCreate(task_blink_neo_pixel,"BlinkNeoPixel",// human readable task name.2048,   // stack size in bytes.&ucParameterToPass1,tskIDLE_PRIORITY,&xHandle1);configASSERT(xHandle1);// Create task 2.//TaskHandle_t xHandle2 = NULL;static uint8_t ucParameterToPass2 = 1;xTaskCreate(task_blink_led,"BlinkLED", // human-readable task name.2048,   // stack size in bytes.&ucParameterToPass2,tskIDLE_PRIORITY,&xHandle2);configASSERT(xHandle2);// Stay in an endless loop. Don't return from this task.//while (true) {vTaskDelay(5000 / portTICK_PERIOD_MS); // 5 second period}}

The solidly highlighted section above shows what had to be changed. It looks like a lot, but it’s not. The functionality is still the same as it was in older versions, it’s how that functionality is invoked that’s changed. What I found more interesting is that none of the multitasking functionality changed. I wasn’t sure what to expect, but the changes to using the NeoPixel are rather minor, all things considered. What I’m looking forward to is if I can use the external PSRAM on all the boards. Currently I can’t with ESP_IDF 4.x.

There’s also a problem compiling Micropython with version 5. I’ve already checked and there is no support in Micropython 1.19.1 for ESP_IDF 5. I found an closed ticket in the Micropython forums talking about this and asking if anyone wanted to step forward and work on this.

Micropython Issue 8607: https://github.com/micropython/micropython/issues/8607