Migrating ESP32-S3 VEE Port to ESP-IDF 5.4.x, 5.5.x and 6.0.x

This guide explains how to solve issues when migrating the VEEPort-Espressif-ESP32-S3-DevKitC-1-N8R8 to ESP-IDF versions 5.4.x, 5.5.x and 6.0.x. Since our example on GitHub is compatible with ESP-IDF version 5.0.1, the fixes below are not included.

Migrating to ESP-IDF version 5.4.x or 5.5.x

When migrating to ESP-IDF version 5.4.x or 5.5.x, you might get a LoadStoreError hardfault when the MicroEJ runtime is initialized.

This is due to the execution of the script rename-sections.py, which silently fails during the link phase (you might see warnings about orphaned sections in your logs, but the firmware build is successful). This script allows you to place the MicroEJ memory sections in external RAM for BSS sections and in internal RAM for rodata sections. Without proper execution, the MicroEJ runtime fails to initialize because it attempts to write to read-only memory.

In ESP-IDF versions 5.4.x and 5.5.x, the binutils version is 2.43.1. With this version, the xtensa-esp32s3-elf-objcopy fails to rename the microejapp.o sections. The solution is to use an older (2.35.1) or newer (2.44) version of binutils.
The easiest way to fix this is to modify the CMake command that calls the rename-sections.py script and replace ${CMAKE_OBJCOPY} with the path to an older or newer version of xtensa-esp32s3-elf-objcopy, for example, $ENV{USERPROFILE}/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20230928/xtensa-esp-elf/bin/xtensa-esp32s3-elf-objcopy.exe

Migrating to ESP-IDF version 6.0.x

The above-described issue with ESP-IDF version 5.4.x and 5.5.x is no longer present in version 6.0.x. But when migrating to ESP-IDF version 6.0.x, you might encounter the following error at build time:

pyparsing.exceptions.ParseException: Parsing sections info for library <path_to_VEE_Port>/P0286_ESP32-S3-DevKitC-1/bsp/projects/microej/platform/lib/microejapp.o failed. Expected 'In archive'  (at char 0), (line:1, col:1)

This error is due to the fact that, starting from version 6.0.x, the linker from ESP-IDF only accepts *.a format.
The solution is to convert microejapp.o in microejapp.a by modifying these lines:

    add_custom_command(TARGET ${COMPONENT_LIB} PRE_LINK
                COMMAND python ${CMAKE_CURRENT_LIST_DIR}/rename-sections.py ${CMAKE_OBJCOPY} ${CMAKE_CURRENT_LIST_DIR}/../platform/lib/microejapp.o)

    add_prebuilt_library(microejruntime "../platform/lib/microejruntime.a")
    add_prebuilt_library(microejapp "../platform/lib/microejapp.o")

With the following:

    add_custom_command(TARGET ${COMPONENT_LIB} PRE_BUILD
                COMMAND python ${CMAKE_CURRENT_LIST_DIR}/rename-sections.py ${CMAKE_OBJCOPY} ${CMAKE_CURRENT_LIST_DIR}/../platform/lib/microejapp.o)
                
    add_custom_command(TARGET ${COMPONENT_LIB} PRE_BUILD
                COMMAND ${CMAKE_AR} rcs ${CMAKE_CURRENT_LIST_DIR}/../platform/lib/microejapp.a ${CMAKE_CURRENT_LIST_DIR}/../platform/lib/microejapp.o)

    add_prebuilt_library(microejruntime "../platform/lib/microejruntime.a")
    add_prebuilt_library(microejapp "../platform/lib/microejapp.a")

Clotilde for MicroEJ