[ESP32] FreeRTOS Unicore Mode Assertion Failure

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
AwesomeCronk
Posts: 33
Joined: Fri Oct 11, 2019 1:24 am

[ESP32] FreeRTOS Unicore Mode Assertion Failure

Post by AwesomeCronk » Wed Feb 23, 2022 8:58 pm

I am trying to make a board definition for the ESP32 port that works on single-core ESP32 modules, such as the ESP32-MINI-1 (core CPU is ESP32-U4WDH). I have a created a board definition that is a copy of GENERIC, except with names changed and a file called sdkconfig.board:

Code: Select all

CONFIG_FREERTOS_UNICORE=y
This is how I compiled and uploaded:

Code: Select all

ports/esp32 $ make BOARD=GENERIC_UNICORE
ports/esp32 $ python3 -m esptool --chip esp32 --port /dev/ttyUSB0 write_flash -z 0x1000 build-GENERIC_UNICORE/bootloader/bootloader.bin 0x8000 build-GENERIC_UNICORE/partition_table/partition-table.bin 0x10000 build-GENERIC_UNICORE/micropython.bin
Firmware flashes, I reboot the ESP32 in SPI flash mode and the ESP32 boot-loops, printing:

Code: Select all

ets Jul 29 2019 12:21:46

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 188777542, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:4540
ho 0 tail 12 room 4
load:0x40078000,len:12364
load:0x40080400,len:4140
entry 0x40080680
/usr/local/bin/esp-idf/components/freertos/tasks.c:1070 (prvAddNewTaskToReadyList)- assert failed!

abort() was called at PC 0x40094482 on core 0

Backtrace:0x4009357e:0x3ffb71d0 0x40093c21:0x3ffb71f0 0x400975fa:0x3ffb7210 0x40094482:0x3ffb7280 0x40094621:0x3ffb72a0 0x400d4bc2:0x3ffb72e0 0x400d350f:0x3ffb7310


ELF file SHA256: 33ea2d6c4c0ba2c3

Rebooting...
I searched Google with the terms "esp32 esp-idf/components/freertos/tasks.c:1070 (prvAddNewTaskToReadyList)- assert failed!" and got
this page, which indicates that the poster's issue was due to FreeRTOS unicore mode being enabled when they tried to start a task in Core 1. Is this potentially what is happening here too? What might I need to do to find the root cause of this issue?

Here is my board definition: https://github.com/AwesomeCronk/micropy ... IC_UNICORE

AwesomeCronk
Posts: 33
Joined: Fri Oct 11, 2019 1:24 am

Re: [ESP32] FreeRTOS Unicore Mode Assertion Failure

Post by AwesomeCronk » Sat Feb 26, 2022 3:19 am

Here's the line in tasks.c that's failing the assertion:

Code: Select all

/* Assure that xCoreID is valid or we'll have an out-of-bounds on pxCurrentTCB
   You will assert here if e.g. you only have one CPU enabled in menuconfig and
   are trying to start a task on core 1. */
configASSERT( xCoreID == tskNO_AFFINITY || xCoreID < portNUM_PROCESSORS);
So yeah, something in MicroPython is trying to start a task on Core 1 and it's not working. :? What might be doing that? I'm afraid I know next to little about debugging ESP32 applications, but if anyone could at least tell me where in MicroPython source the issue is, I could work towards fixing it.

AwesomeCronk
Posts: 33
Joined: Fri Oct 11, 2019 1:24 am

Re: [ESP32] FreeRTOS Unicore Mode Assertion Failure

Post by AwesomeCronk » Sun Feb 27, 2022 1:31 pm

I finally found a way to trace the code. I ran this command on the backtrace addresses:

Code: Select all

$ addr2line -e build-GENERIC_UNICORE/micropython.elf -pfiaC 0x40094482 0x4009357e:0x3ffb71d0 0x40093c21:0x3ffb71f0 0x400975fa:0x3ffb7210 0x40094482:0x3ffb7280 0x40094621:0x3ffb72a0 0x400d4bc2:0x3ffb72e0 0x400d350f:0x3ffb7310
0x40094482: prvAddNewTaskToReadyList at /usr/local/bin/esp-idf/components/freertos/tasks.c:1070
0x4009357e: panic_abort at /usr/local/bin/esp-idf/components/esp_system/panic.c:353
0x40093c21: esp_system_abort at /usr/local/bin/esp-idf/components/esp_system/system_api.c:106
0x400975fa: abort at /usr/local/bin/esp-idf/components/newlib/abort.c:46
0x40094482: prvAddNewTaskToReadyList at /usr/local/bin/esp-idf/components/freertos/tasks.c:1070
0x40094621: xTaskCreatePinnedToCore at /usr/local/bin/esp-idf/components/freertos/tasks.c:843
0x400d4bc2: app_main at /home/aweso/Source/C/micropython/ports/esp32/build-GENERIC_UNICORE/../main.c:226
0x400d350f: main_task at /usr/local/bin/esp-idf/components/esp32/cpu_start.c:609
Upon further inspection, MP_TASK_COREID is being defined somewhere and it's being set to 1. So, MicroPython seems to be intentionally pinning the WiFi task to Core 1 (ports/esp32/mphalport.h) for IDF 4.2.0+. Now that I've found that, I guess I have to find how to change this...

AwesomeCronk
Posts: 33
Joined: Fri Oct 11, 2019 1:24 am

Re: [ESP32] FreeRTOS Unicore Mode Assertion Failure

Post by AwesomeCronk » Mon Feb 28, 2022 4:23 am

Got it, finally! I added a #if to ports/esp32/mphalport.h and a MICROPY_UNICORE definition in /ports/esp32/boards/GENERIC_UNICORE/mpconfigboard.h.

Post Reply