PlatformIO Community

PlatformIO Support for ESP32 Coredump

I’m trying to compile ESP insights with Coredump enabled code in PlatformIO. But it gives me below errors:

"/Users/sduddell/workplace/esp_insights/src/esp_insights_cbor_encoder.h:27:42: error: unknown type name ‘esp_core_dump_summary_t’

  • void esp_insights_cbor_encode_diag_crash(esp_core_dump_summary_t summary);"

"/Users/sduddell/workplace/esp_insights/src/esp_insights_encoder.c:98:5: error: unknown type name ‘esp_core_dump_summary_t’

  • esp_core_dump_summary_t *summary = malloc(sizeof(esp_core_dump_summary_t));"*
    

On debugging, I understood that version 4.4 of ESP IDF(https://github.com/espressif/esp-idf/blob/release/v4.4/components/espcoredump/include/esp_core_dump.h) has this core dump code enabled whereas latest ESP IDF version integrated in platformIO is still 4.3.1 ( https://github.com/platformio/platform-espressif32/releases )

Can you please tell when the latest version of ESP IDF(v4.4) will be integrated to platformIO, also in the meanwhile is there any workaround I can follow to resolve this issue and build my code successfully.

Thanks!!

Per https://github.com/espressif/esp-idf/releases the latest official version is 4.4-beta1, and it’s PlatformIO policy to only support stable versions – meaning with the current used 4.3.1 version, PlatformIO is still lagging behind the most recent v4.3.2 version from 6 days ago.

However, PlatformIO is adaptive. Through a platform_packages directive you can arbitrarily modify the source of the package framework-espidf, to e.g. point at a specific repository with ESP-IDF v4.4-beta1 with the PlatformIO-specific package.json file. With some luck then, the current builder script logic in espidf.py still works for the newer ESP-IDF version. (If not, things get interesting and more complicated…)

I’ve tested this out practically by creating https://github.com/maxgerhardt/esp-idf/tree/release/v4.4, which is really just the base repo plus a package.json in the release/v4.4 branch and creating a project that uses it. Additionally, since PlatformIO currently uses version 8.4.0+2021r1 of the XTensa-GCC toolchain, but current ESP-IDF requires the 2021r2 version, an extra directive regarding this has to be added in platform_packages, too.

After then activating the needed coredump configs through menuconfig → Component Config → Core dump, code like

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "sdkconfig.h"
#include "esp_core_dump.h"

void app_main()
{
        printf("Hello, world!\n");

        esp_core_dump_init();
        esp_core_dump_summary_t *summary = malloc(sizeof(esp_core_dump_summary_t));
        if (summary) {
                esp_err_t err = esp_core_dump_get_summary(summary);
                if (err == ESP_OK) {
                        printf("Getting core dump summary ok.");
                } else {
                        printf("Getting core dump summary not ok. Error: %d\n", (int) err);
                        printf("Probably no coredump present yet.\n");
                        printf("esp_core_dump_image_check() = %d\n", esp_core_dump_image_check());
                }
                free(summary);
        }

    while(1) {
                vTaskDelay(1000 / portTICK_PERIOD_MS);
                printf("Doing nothing...\n");
    }
}

the source file compiles fine, but linking fails at a later step.

ld.exe: cannot open linker script file esp32.peripherals.ld: No such file or directory

So I’m stuck for the moment here and opened an issue at https://github.com/platformio/platform-espressif32/issues/695 – maybe someone else can complete this.

Thanks Max for your quick reply and help!! will follow-up this linker error from the issue you have opened.

Thanks to a comment in the issue I got a working builder script.

I’ve tested the crashdump feature and it works fine.

The example app (https://github.com/maxgerhardt/pio-espidf-4.4-test) retrieves the coredump at boot (if present) and then does

Crashing in 3 seconds..
Crashing in 2 seconds..
Crashing in 1 seconds..
Crashing in 0 seconds..
Crashing..
Guru Meditation Error: Core  0 panic'ed (StoreProhibited). Exception was unhandled.

Core  0 register dump:
PC      : 0x400d0f57  PS      : 0x00060630  A0      : 0x800d0feb  A1      : 0x3ffb88b0
A2      : 0x00000064  A3      : 0x3ffb1138  A4      : 0x3ffaf988  A5      : 0x00000001
A6      : 0x3f410000  A7      : 0x3ffaf988  A8      : 0x00000000  A9      : 0x01234567
A10     : 0x00000000  A11     : 0x0000021e  A12     : 0x3ffb4e10  A13     : 0x3ffb8780
A14     : 0x00000018  A15     : 0x3ffb8780  SAR     : 0x00000009  EXCCAUSE: 0x0000001d
EXCVADDR: 0x00000000  LBEG    : 0x400014fd  LEND    : 0x4000150d  LCOUNT  : 0xfffffffd


Backtrace:0x400d0f54:0x3ffb88b00x400d0fe8:0x3ffb88d0 0x400e7150:0x3ffb88f0 0x400882c9:0x3ffb8910




ELF file SHA256: 8309f0727b020b98

I (6205) esp_core_dump_flash: Save core dump to flash...
...

and at the next reboot, this data is retrieved…

Retrieving core dump summary..
D (822) esp_core_dump_elf: ELF ident 7f E L F
D (826) esp_core_dump_elf: Ph_num 14 offset 34
D (830) esp_core_dump_elf: PHDR type 4 off 1f4 vaddr 0 paddr 0 filesz e40 memsz e40 flags 6 align 0
D (840) esp_core_dump_elf: Note NameSZ 8 DescSZ 24c Type 1 name CORE
D (846) esp_core_dump_elf: Note NameSZ 8 DescSZ 24c Type 1 name CORE
D (852) esp_core_dump_elf: Note NameSZ 8 DescSZ 24c Type 1 name CORE
D (859) esp_core_dump_elf: Note NameSZ 8 DescSZ 24c Type 1 name CORE
D (865) esp_core_dump_elf: Note NameSZ 8 DescSZ 24c Type 1 name CORE
D (872) esp_core_dump_elf: Note NameSZ 8 DescSZ 24c Type 1 name CORE
D (878) esp_core_dump_elf: PHDR type 1 off 1034 vaddr 3ffb899c paddr 3ffb899c filesz 158 memsz 158 flags 6 align 0
D (889) esp_core_dump_elf: PHDR type 1 off 118c vaddr 3ffb87f0 paddr 3ffb87f0 filesz 1a4 memsz 1a4 flags 6 align 0
D (899) esp_core_dump_elf: PHDR type 1 off 1330 vaddr 3ffb8af8 paddr 3ffb8af8 filesz 158 memsz 158 flags 6 align 0
D (909) esp_core_dump_elf: PHDR type 1 off 1488 vaddr 3ffb90b0 paddr 3ffb90b0 filesz 1a0 memsz 1a0 flags 6 align 0
D (920) esp_core_dump_elf: PHDR type 1 off 1628 vaddr 3ffb9258 paddr 3ffb9258 filesz 158 memsz 158 flags 6 align 0
D (930) esp_core_dump_elf: PHDR type 1 off 1780 vaddr 3ffb9810 paddr 3ffb9810 filesz 1a0 memsz 1a0 flags 6 align 0
D (941) esp_core_dump_elf: PHDR type 1 off 1920 vaddr 3ffafdd4 paddr 3ffafdd4 filesz 158 memsz 158 flags 6 align 0
D (951) esp_core_dump_elf: PHDR type 1 off 1a78 vaddr 3ffb5dc0 paddr 3ffb5dc0 filesz 1c0 memsz 1c0 flags 6 align 0
D (961) esp_core_dump_elf: PHDR type 1 off 1c38 vaddr 3ffb7744 paddr 3ffb7744 filesz 158 memsz 158 flags 6 align 0
D (972) esp_core_dump_elf: PHDR type 1 off 1d90 vaddr 3ffb7580 paddr 3ffb7580 filesz 1bc memsz 1bc flags 6 align 0
D (982) esp_core_dump_elf: PHDR type 1 off 1f4c vaddr 3ffb65e4 paddr 3ffb65e4 filesz 158 memsz 158 flags 6 align 0
D (993) esp_core_dump_elf: PHDR type 1 off 20a4 vaddr 3ffb6430 paddr 3ffb6430 filesz 1ac memsz 1ac flags 6 align 0
D (1003) esp_core_dump_elf: PHDR type 4 off 2250 vaddr 0 paddr 0 filesz 114 memsz 114 flags 6 align 0
D (1012) esp_core_dump_elf: Note NameSZ 14 DescSZ 48 Type 204a name ESP_CORE_DUMP_INFO
D (1020) esp_core_dump_elf: Core dump version 0x100
D (1025) esp_core_dump_elf: App ELF SHA2 8309f0727b020b98
D (1031) esp_core_dump_elf: Note NameSZ c DescSZ 94 Type 2a5 name EXTRA_INFO
D (1038) esp_core_dump_port: Crash TCB 0x3ffb899c
D (1043) esp_core_dump_port: excvaddr 0x0
D (1047) esp_core_dump_port: exccause 0x1d
D (1051) esp_core_dump_elf: Crashing task main
D (1055) esp_core_dump_port: Crashing PC 0x400d0f54
D (1060) esp_core_dump_port: A[0] 0x800d0feb
D (1065) esp_core_dump_port: A[1] 0x3ffb88b0
D (1069) esp_core_dump_port: A[2] 0x64
D (1073) esp_core_dump_port: A[3] 0x3ffb1138
D (1077) esp_core_dump_port: A[4] 0x3ffaf988
D (1082) esp_core_dump_port: A[5] 0x1
D (1085) esp_core_dump_port: A[6] 0x3f410000
D (1090) esp_core_dump_port: A[7] 0x3ffaf988
D (1094) esp_core_dump_port: A[8] 0x0
D (1098) esp_core_dump_port: A[9] 0x1234567
D (1102) esp_core_dump_port: A[10] 0x0
D (1106) esp_core_dump_port: A[11] 0x21e
D (1110) esp_core_dump_port: A[12] 0x3ffb4e10
D (1114) esp_core_dump_port: A[13] 0x3ffb8780
D (1119) esp_core_dump_port: A[14] 0x18
D (1123) esp_core_dump_port: A[15] 0x3ffb8780
D (1127) esp_core_dump_port: Crash Backtrace
D (1131) esp_core_dump_port:  0x400d0f54
D (1135) esp_core_dump_port:  0x400d0fe8
D (1139) esp_core_dump_port:  0x400e7150
D (1143) esp_core_dump_port:  0x400882c9
Getting core dump summary ok.

If you tried a previous version of this example, make sure to delete C:\Users\<user>\.platformio\platforms\espressif32* to force a download of the fixed platform version.

Hi Max, I tried this change, but I end up in some other error.

I made changes in platformio.ini to include:
platform_packages =
framework-espidf@https://github.com/maxgerhardt/esp-idf.git#release/v4.4
espressif/toolchain-xtensa-esp32@8.4.0+2021r2

I pulled in the change espidf.py from https://github.com/platformio/platform-espressif32/pull/693/files

Now, I get below error:

usage: ldgen.py [-h] [--input INPUT] [--fragments FRAGMENTS [FRAGMENTS ...]]
                [--libraries-file LIBRARIES_FILE] [--output OUTPUT]
                [--config CONFIG] [--kconfig KCONFIG] [--check-mapping]
                [--check-mapping-exceptions CHECK_MAPPING_EXCEPTIONS]
                [--env NAME=VAL] [--env-file ENV_FILE] [--objdump OBJDUMP]
ldgen.py: error: unrecognized arguments: --fragments-list /Users/sduddell/.platformio/packages/framework-espidf@src-98347c2f74f997bae9c72daf5a46798a/components/esp_phy/linker.lf;/Users/sduddell/.platformio/packages/framework-espidf@src-98347c2f74f997bae9c72daf5a46798a/components/xtensa/linker.lf;/Users/sduddell/.platformio/packages/framework-espidf@src-98347c2f74f997bae9c72daf5a46798a/components/espcoredump/linker.lf;/Users/sduddell/.platformio/packages/framework-espidf@src-98347c2f74f997bae9c72daf5a46798a/components/esp_hw_support/linker.lf;/Users/sduddell/.platformio/packages/framework-espidf@src-98347c2f74f997bae9c72daf5a46798a/components/hal/linker.lf;/Users/sduddell/.platformio/packages/framework-espidf@src-98347c2f74f997bae9c72daf5a46798a/components/driver/linker.lf;/Users/sduddell/.platformio/packages/framework-espidf@src-98347c2f74f997bae9c72daf5a46798a/components/lwip/linker.lf;/Users/sduddell/.platformio/packages/framework-espidf@src-98347c2f74f997bae9c72daf5a46798a/components/soc/linker.lf;/Users/sduddell/.platformio/packages/framework-espidf@src-98347c2f74f997bae9c72daf5a46798a/components/esp_system/linker.lf;/Users/sduddell/.platformio/packages/framework-espidf@src-98347c2f74f997bae9c72daf5a46798a/components/esp_event/linker.lf;/Users/sduddell/.platformio/packages/framework-espidf@src-98347c2f74f997bae9c72daf5a46798a/components/freertos/linker.lf;/Users/sduddell/.platformio/packages/framework-espidf@src-98347c2f74f997bae9c72daf5a46798a/components/esp_pm/linker.lf;/Users/sduddell/.platformio/packages/framework-espidf@src-98347c2f74f997bae9c72daf5a46798a/components/heap/linker.lf;/Users/sduddell/.platformio/packages/framework-espidf@src-98347c2f74f997bae9c72daf5a46798a/components/bt/linker.lf;/Users/sduddell/.platformio/packages/framework-espidf@src-98347c2f74f997bae9c72daf5a46798a/components/esp_ringbuf/linker.lf;/Users/sduddell/.platformio/packages/framework-espidf@src-98347c2f74f997bae9c72daf5a46798a/components/esp_gdbstub/linker.lf;/Users/sduddell/.platformio/packages/framework-espidf@src-98347c2f74f997bae9c72daf5a46798a/components/log/linker.lf;/Users/sduddell/.platformio/packages/framework-espidf@src-98347c2f74f997bae9c72daf5a46798a/components/spi_flash/linker.lf;/Users/sduddell/.platformio/packages/framework-espidf@src-98347c2f74f997bae9c72daf5a46798a/components/esp_wifi/linker.lf;/Users/sduddell/.platformio/packages/framework-espidf@src-98347c2f74f997bae9c72daf5a46798a/components/app_trace/linker.lf;/Users/sduddell/.platformio/packages/framework-espidf@src-98347c2f74f997bae9c72daf5a46798a/components/esp_common/common.lf;/Users/sduddell/.platformio/packages/framework-espidf@src-98347c2f74f997bae9c72daf5a46798a/components/esp_common/soc.lf;/Users/sduddell/.platformio/packages/framework-espidf@src-98347c2f74f997bae9c72daf5a46798a/components/esp_system/app.lf;/Users/sduddell/.platformio/packages/framework-espidf@src-98347c2f74f997bae9c72daf5a46798a/components/newlib/newlib.lf;/Users/sduddell/.platformio/packages/framework-espidf@src-98347c2f74f997bae9c72daf5a46798a/components/newlib/system_libs.lf
Compiling .pio/build/m5stack-timer-cam/bootloader/bootloader_support/src/bootloader_init.o
*** [.pio/build/m5stack-timer-cam/sections.ld] Error 2

No, that file does not work correctly, I had to adapt it espidf.py.

You should not be copying files manually. If you’re using the reference project, just

and then do a build, it should pull all the right versions and build without any intervention. It references the correct

with a few other option such as a partition table and a sdkconfig.esp32dev with the activated options regarding coredump to flash in ELF format, log level set to verbose and a reference to the partition table.

Thanks a lot, it worked for me now.
Closing this issue now.