Cannot build blinky for ESP32

I’m new to RIOT, and I tried to build some examples for different platforms. I was able to build blinky for the board Re-Mote (revb) from Zolertia, but I failed for ESP32-wroom-32 (which is my current target platform).

There are several issues when compiling, so I suspect something is wrong in my installation, or I’m using a newer compiler that treats former warnings as errors.

  1. The compiler complains about implicit conversions for uint32_t to esp_log_level_t. For example, in cpu/esp32/startup.c I have to add a cast to esp_log_level_t before LOG_DEBUG (e.g. lines 243, 244).

    […]RIOT/cpu/esp32/startup.c:243:31: error: implicit conversion from ‘enum ’ to ‘esp_log_level_t’ [-Werror=enum-conversion] 243 | esp_log_level_set(“wifi”, LOG_DEBUG);

  2. The format tags in cpu/esp32/syscalls.c (lines 385, 386) do not match the type (long unsigned int)

    […]RIOT/cpu/esp32/syscalls.c:385:11: error: format ‘%x’ expects argument of type ‘unsigned int’, but argument 3 has type ‘uint32_t’ {aka ‘long unsigned int’} [-Werror=format=] 385 | DEBUG("%s TIMERG0 wdtconfig0=%08x wdtconfig1=%08x wdtconfig2=%08x "

  3. This is where I’m stuck:

    […]RIOT/build/pkg/esp32_sdk/components/esp_system/port/cpu_start.c:604:5: error: ‘memcpy’ offset [0, 23] is out of the bounds [0, 0] [-Werror=array-bounds]

    604 | memcpy(&fhdr, (void *) SOC_DROM_LOW, sizeof(fhdr));

Hi and welcome to RIOT! I don’t have this issue when building the example, what toolchain are you using?

Please post the output of make print-versions

Did you use the toolchain installation script?

I tried two environments, openSUSE Tumbleweed as the native one and Ubuntu 22.04 LTS in a VM. I observe the same behavior in both environments.

In order to build I use

[...]examples/blinky$ make BOARD=esp32-wroom-32

Operating System Environment

Operating System: "openSUSE Tumbleweed" 
Kernel: Linux 6.1.12-1-default x86_64 x86_64
System shell: GNU bash, Version 5.2.15(1)-release (x86_64-suse-linux)
make's shell: GNU bash, Version 5.2.15(1)-release (x86_64-suse-linux)

Installed compiler toolchains

native gcc: gcc (SUSE Linux) 12.2.1 20230124 [revision 193f7e62815b4089dfaed4c2bd34fd4f10209e27]
arm-none-eabi-gcc: arm-none-eabi-gcc (SUSE Linux) 13.0.1 20230127 (experimental) [revision ca8fb0096713a8477614ef874f16ba5bf16c48bc]
avr-gcc: missing
msp430-elf-gcc: missing
riscv-none-elf-gcc: missing
riscv64-unknown-elf-gcc: missing
riscv-none-embed-gcc: missing
xtensa-esp32-elf-gcc: xtensa-esp32-elf-gcc (crosstool-NG esp-2022r1) 11.2.0
xtensa-esp8266-elf-gcc: missing
clang: clang version 15.0.7

Installed compiler libs

arm-none-eabi-newlib: "4.1.0"
msp430-elf-newlib: missing
riscv-none-elf-newlib: missing
riscv64-unknown-elf-newlib: missing
riscv-none-embed-newlib: missing
xtensa-esp32-elf-newlib: "4.1.0"
xtensa-esp8266-elf-newlib: missing
avr-libc: missing (missing)

Installed development tools

ccache: missing
cmake: cmake version 3.25.2
cppcheck: missing
doxygen: missing
git: git version 2.39.2
make: GNU Make 4.4
openocd: missing
python: Python 2.7.18
python2: Python 2.7.18
python3: Python 3.10.9
flake8: error: /usr/bin/python3: No module named flake8
coccinelle: missing

Operating System Environment

Operating System: "Ubuntu" "22.04.2 LTS (Jammy Jellyfish)"
Kernel: Linux 5.19.0-32-generic x86_64 x86_64
System shell: /usr/bin/dash (probably dash)
make's shell: /usr/bin/dash (probably dash)

Installed compiler toolchains

native gcc: gcc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
arm-none-eabi-gcc: arm-none-eabi-gcc (15:10.3-2021.07-4) 10.3.1 20210621 (release)
avr-gcc: missing
msp430-elf-gcc: missing
riscv-none-elf-gcc: missing
riscv64-unknown-elf-gcc: missing
riscv-none-embed-gcc: missing
xtensa-esp32-elf-gcc: xtensa-esp32-elf-gcc (crosstool-NG esp-2022r1) 11.2.0
xtensa-esp8266-elf-gcc: missing
clang: missing

Installed compiler libs

arm-none-eabi-newlib: "3.3.0"
msp430-elf-newlib: missing
riscv-none-elf-newlib: missing
riscv64-unknown-elf-newlib: missing
riscv-none-embed-newlib: missing
xtensa-esp32-elf-newlib: "4.1.0"
xtensa-esp8266-elf-newlib: missing
avr-libc: missing (missing)

Installed development tools

ccache: missing
cmake: missing
cppcheck: missing
doxygen: missing
git: git version 2.34.1
make: GNU Make 4.3
openocd: missing
python: missing
python2: missing
python3: Python 3.10.6
flake8: error: /usr/bin/python3: No module named flake8
coccinelle: missing

Looks like your compiler is newer than what comes with IDF. Since those warnings are in our code we should eventually fix them - but best you use compiler from the esp32 setup script which is currently GGC 8.4

cpu/esp*,pkg/esp*: fix compilation with GCC 12.2.0 and newlib 4.x by maribu · Pull Request #18719 · RIOT-OS/RIOT · GitHub should fix them.

But note: I was unable to actually get working binaries with toolchains other than the one @gschorcht provides. For now I would highly recommend to either compile with BUILD_IN_DOCKER=1 or installing the toolchain @gschorcht provides e.g. via the convenience install script found here: RIOT/install.sh at master · RIOT-OS/RIOT · GitHub.

RIOT currently still uses ESP-IDF 4.4, which is only compilable with GCC 8.4. Please note that the GCC 8.4 was the officially released toolchain from Espressif until 2 weeks ago. The current toolchain GCC 12.2, released 2 weeks ago, requires ESP-IDF 5.1.

As @maribu said you could use BUILD_IN_DOCKER=1 but installing the toolchain locally as mentioned by @benpicco and described here should be just as easy. For short

cd <RIOT directory>
dist/tools/esptools/install.sh esp32
. dist/tools/esptools/export.sh esp32
make BOARD=esp32-wroom-32 -C examples/blinky

The target argument esp32 in command install.sh and setup.sh could be replaced by esp32c3, esp32s2, esp32s3 or all to install and export the toolchain for another ESP32x SoCs or just for all ESP32x SoCs.

Just to clarify, the toolchain is no longer provided by me :wink: The script pulls the official release version from Espressif’s GitHub repositories.

Thank you for the quick responses.

It’s a pity somehow that each project seems to require a separate version of compilers and libs. I’ll probably set up a separate Ubuntu guest to avoid messing up my other build environments. I’m not really a friend of Docker, actually.

That’s not complaining against you. I know how difficult it is to lift a complex project to a new tool chain. I’ll report my results later.

It’s all contained within ~/.espressif so it doesn’t clutter the system too much.

Me either. Off topic but, I use mkosi to build throw-away containers when I need to run some vendor’s install script to see what it will do to my system. Then decide if I actually want to install their stuff on my host, or setup a more permanent container instead. fakeroot is another great tool to run installers that want to be run as root, without actually giving it root access.