C++ error: Guru Meditation Error: Core 0 panic'ed (InstructionFetchError). Exception was unhandled

rmendes
Posts: 2
Joined: Mon Oct 10, 2022 11:36 am

C++ error: Guru Meditation Error: Core 0 panic'ed (InstructionFetchError). Exception was unhandled

Postby rmendes » Mon Mar 20, 2023 5:03 pm

I'm buiding a simple task project with C++, with the following code:

Code: Select all

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

static const char *TAG = "main";


void task(void *params)
{
    while (true)
    {
        ESP_LOGD(TAG, "Tick...");
        vTaskDelay(1000);
    }
}

extern "C" void app_main(void)
{
    ESP_LOGI(TAG, "Starting the scheduler...");
    xTaskCreate(&task, "Test Task", 10000, NULL, 1, NULL);
    vTaskStartScheduler();

    while (true)
    {
        ESP_LOGE(TAG, "Problem with heap memory...");
    }
}
My root CMakeLists.txt:

# For more information about build system see
# https://docs.espressif.com/projects/esp ... ystem.html
# The following five lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.16)
set(CMAKE_CXX_STANDARD 17)
set(EXTRA_COMPONENT_DIRS components)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(test)

When running on the device I'm getting the following error in a loop:

Code: Select all

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, 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:6944
load:0x40078000,len:15500
load:0x40080400,len:3844
0x40080400: _init at ??:?

entry 0x4008064c
I (27) boot: ESP-IDF v5.0.1-dirty 2nd stage bootloader
I (27) boot: compile time 17:58:32
I (27) boot: chip revision: v1.0
I (31) boot.esp32: SPI Speed      : 40MHz
I (35) boot.esp32: SPI Mode       : DIO
I (40) boot.esp32: SPI Flash Size : 4MB
I (44) boot: Enabling RNG early entropy source...
I (50) boot: Partition Table:
I (53) boot: ## Label            Usage          Type ST Offset   Length
I (61) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (68) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (76) boot:  2 factory          factory app      00 00 00010000 00100000
I (83) boot: End of partition table
I (87) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=0861ch ( 34332) map
I (108) esp_image: segment 1: paddr=00018644 vaddr=3ffb0000 size=01e8ch (  7820) load
I (112) esp_image: segment 2: paddr=0001a4d8 vaddr=40080000 size=05b40h ( 23360) load
I (124) esp_image: segment 3: paddr=00020020 vaddr=400d0020 size=166e0h ( 91872) map
I (158) esp_image: segment 4: paddr=00036708 vaddr=40085b40 size=05dc0h ( 24000) load
I (174) boot: Loaded app from partition at offset 0x10000
I (174) boot: Disabling RNG early entropy source...
I (185) cpu_start: Pro cpu up.
I (186) cpu_start: Starting app cpu, entry point is 0x40081130
0x40081130: call_start_cpu1 at /Users/renato/esp/esp-idf/components/esp_system/port/cpu_start.c:142

I (173) cpu_start: App cpu up.
I (200) cpu_start: Pro cpu start user code
I (200) cpu_start: cpu freq: 240000000 Hz
I (200) cpu_start: Application information:
I (205) cpu_start: Project name:     iotedge
I (210) cpu_start: App version:      3.0.0
I (215) cpu_start: Compile time:     Mar 20 2023 11:57:08
I (221) cpu_start: ELF file SHA256:  ddd323987fb1409c...
I (227) cpu_start: ESP-IDF:          v5.0.1-dirty
I (232) cpu_start: Min chip rev:     v0.0
I (237) cpu_start: Max chip rev:     v3.99 
I (242) cpu_start: Chip rev:         v1.0
I (246) heap_init: Initializing. RAM available for dynamic allocation:
I (254) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (260) heap_init: At 3FFB27B8 len 0002D848 (182 KiB): DRAM
I (266) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (272) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (279) heap_init: At 4008B900 len 00014700 (81 KiB): IRAM
I (286) spi_flash: detected chip: generic
I (289) spi_flash: flash io: dio
I (294) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (304) main: Starting the scheduler...
Guru Meditation Error: Core  0 panic'ed (InstructionFetchError). Exception was unhandled.

Core  0 register dump:
PC      : 0x3ffb8ea8  PS      : 0x00050833  A0      : 0x3ffb8ea8  A1      : 0x3ffb4a40  
A2      : 0x3ffb88a4  A3      : 0x3ffb8ea8  A4      : 0x3ffaff34  A5      : 0x3f40403c  
A6      : 0x00000130  A7      : 0x3f402c84  A8      : 0x0000cdcd  A9      : 0x80088154  
A10     : 0x3ffb4ab0  A11     : 0x00000003  A12     : 0x00000001  A13     : 0x7fffffff  
A14     : 0x00000000  A15     : 0x00000000  SAR     : 0x00000000  EXCCAUSE: 0x00000002  





EXCVADDR: 0x3ffb8ea8  LBEG    : 0x00000000  LEND    : 0x00060f23  LCOUNT  : 0x00000000  


Backtrace: 0x3ffb8ea5:0x3ffb4a40 |<-CORRUPTED




ELF file SHA256: ddd323987fb1409c

Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, 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:6944
load:0x40078000,len:15500
load:0x40080400,len:3844
0x40080400: _init at ??:?

entry 0x4008064c
I (27) boot: ESP-IDF v5.0.1-dirty 2nd stage bootloader
I (27) boot: compile time 17:58:32
I (27) boot: chip revision: v1.0
I (31) boot.esp32: SPI Speed      : 40MHz
I (35) boot.esp32: SPI Mode       : DIO
I (40) boot.esp32: SPI Flash Size : 4MB
I (44) boot: Enabling RNG early entropy source...
I (50) boot: Partition Table:
I (53) boot: ## Label            Usage          Type ST Offset   Length
I (61) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (68) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (76) boot:  2 factory          factory app      00 00 00010000 00100000
I (83) boot: End of partition table
I (87) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=0861ch ( 34332) map
I (108) esp_image: segment 1: paddr=00018644 vaddr=3ffb0000 size=01e8ch (  7820) load
I (112) esp_image: segment 2: paddr=0001a4d8 vaddr=40080000 size=05b40h ( 23360) load
I (124) esp_image: segment 3: paddr=00020020 vaddr=400d0020 size=166e0h ( 91872) map
I (158) esp_image: segment 4: paddr=00036708 vaddr=40085b40 size=05dc0h ( 24000) load
I (174) boot: Loaded app from partition at offset 0x10000
I (174) boot: Disabling RNG early entropy source...
I (185) cpu_start: Pro cpu up.
I (186) cpu_start: Starting app cpu, entry point is 0x40081130
0x40081130: call_start_cpu1 at /Users/renato/esp/esp-idf/components/esp_system/port/cpu_start.c:142

I (173) cpu_start: App cpu up.
I (200) cpu_start: Pro cpu start user code
I (200) cpu_start: cpu freq: 240000000 Hz
I (200) cpu_start: Application information:
I (205) cpu_start: Project name:     iotedge
I (210) cpu_start: App version:      3.0.0
I (215) cpu_start: Compile time:     Mar 20 2023 11:57:08
I (221) cpu_start: ELF file SHA256:  ddd323987fb1409c...
I (227) cpu_start: ESP-IDF:          v5.0.1-dirty
I (232) cpu_start: Min chip rev:     v0.0
I (237) cpu_start: Max chip rev:     v3.99 
I (242) cpu_start: Chip rev:         v1.0
I (246) heap_init: Initializing. RAM available for dynamic allocation:
I (254) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (260) heap_init: At 3FFB27B8 len 0002D848 (182 KiB): DRAM
I (266) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (272) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (279) heap_init: At 4008B900 len 00014700 (81 KiB): IRAM
I (286) spi_flash: detected chip: generic
I (289) spi_flash: flash io: dio
I (294) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (304) main: Starting the scheduler...
Guru Meditation Error: Core  0 panic'ed (InstructionFetchError). Exception was unhandled.

Core  0 register dump:
PC      : 0x3ffb8ea8  PS      : 0x00050833  A0      : 0x3ffb8ea8  A1      : 0x3ffb4a40  
A2      : 0x3ffb88a4  A3      : 0x3ffb8ea8  A4      : 0x3ffaff34  A5      : 0x3f40403c  
A6      : 0x00000130  A7      : 0x3f402c84  A8      : 0x0000cdcd  A9      : 0x80088154  
A10     : 0x3ffb4ab0  A11     : 0x00000003  A12     : 0x00000001  A13     : 0x7fffffff  
A14     : 0x00000000  A15     : 0x00000000  SAR     : 0x00000000  EXCCAUSE: 0x00000002  
EXCVADDR: 0x3ffb8ea8  LBEG    : 0x00000000  LEND    : 0x00060f23  LCOUNT  : 0x00000000  


Backtrace: 0x3ffb8ea5:0x3ffb4a40 |<-CORRUPTED




ELF file SHA256: ddd323987fb1409c

Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, 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:6944
load:0x40078000,len:15500
load:0x40080400,len:3844
0x40080400: _init at ??:?

entry 0x4008064c
I (27) boot: ESP-IDF v5.0.1-dirty 2nd stage bootloader
I (27) boot: compile time 17:58:32
I (27) boot: chip revision: v1.0
I (31) boot.esp32: SPI Speed      : 40MHz
I (35) boot.esp32: SPI Mode       : DIO
I (40) boot.esp32: SPI Flash Size : 4MB
I (44) boot: Enabling RNG early entropy source...
I (50) boot: Partition Table:
I (53) boot: ## Label            Usage          Type ST Offset   Length
I (61) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (68) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (76) boot:  2 factory          factory app      00 00 00010000 00100000
I (83) boot: End of partition table
I (87) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=0861ch ( 34332) map
I (108) esp_image: segment 1: paddr=00018644 vaddr=3ffb0000 size=01e8ch (  7820) load
I (112) esp_image: segment 2: paddr=0001a4d8 vaddr=40080000 size=05b40h ( 23360) load
I (124) esp_image: segment 3: paddr=00020020 vaddr=400d0020 size=166e0h ( 91872) map
I (158) esp_image: segment 4: paddr=00036708 vaddr=40085b40 size=05dc0h ( 24000) load
I (174) boot: Loaded app from partition at offset 0x10000
I (174) boot: Disabling RNG early entropy source...
I (185) cpu_start: Pro cpu up.
I (186) cpu_start: Starting app cpu, entry point is 0x40081130
0x40081130: call_start_cpu1 at /Users/renato/esp/esp-idf/components/esp_system/port/cpu_start.c:142

I (173) cpu_start: App cpu up.
I (200) cpu_start: Pro cpu start user code
I (200) cpu_start: cpu freq: 240000000 Hz
I (200) cpu_start: Application information:
I (205) cpu_start: Project name:     iotedge
I (210) cpu_start: App version:      3.0.0
I (215) cpu_start: Compile time:     Mar 20 2023 11:57:08
I (221) cpu_start: ELF file SHA256:  ddd323987fb1409c...
I (227) cpu_start: ESP-IDF:          v5.0.1-dirty
I (232) cpu_start: Min chip rev:     v0.0
I (237) cpu_start: Max chip rev:     v3.99 
I (242) cpu_start: Chip rev:         v1.0
I (246) heap_init: Initializing. RAM available for dynamic allocation:
I (254) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (260) heap_init: At 3FFB27B8 len 0002D848 (182 KiB): DRAM
I (266) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (272) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (279) heap_init: At 4008B900 len 00014700 (81 KiB): IRAM
I (286) spi_flash: detected chip: generic
I (289) spi_flash: flash io: dio
I (294) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (304) main: Starting the scheduler...
Guru Meditation Error: Core  0 panic'ed (InstructionFetchError). Exception was unhandled.

Core  0 register dump:
PC      : 0x3ffb8ea8  PS      : 0x00050833  A0      : 0x3ffb8ea8  A1      : 0x3ffb4a40  
A2      : 0x3ffb88a4  A3      : 0x3ffb8ea8  A4      : 0x3ffaff34  A5      : 0x3f40403c  
A6      : 0x00000130  A7      : 0x3f402c84  A8      : 0x0000cdcd  A9      : 0x80088154  
A10     : 0x3ffb4ab0  A11     : 0x00000003  A12     : 0x00000001  A13     : 0x7fffffff  
A14     : 0x00000000  A15     : 0x00000000  SAR     : 0x00000000  EXCCAUSE: 0x00000002  
EXCVADDR: 0x3ffb8ea8  LBEG    : 0x00000000  LEND    : 0x00060f23  LCOUNT  : 0x00000000  


Backtrace: 0x3ffb8ea5:0x3ffb4a40 |<-CORRUPTED
I can't find out what is wrong or if this is something related to C++.
Help appreciated to make my code run without errors.

ESP_Sprite
Posts: 9764
Joined: Thu Nov 26, 2015 4:08 am

Re: C++ error: Guru Meditation Error: Core 0 panic'ed (InstructionFetchError). Exception was unhandled

Postby ESP_Sprite » Tue Mar 21, 2023 1:06 am

vTaskStartScheduler();
Don't do this. The scheduler already is running when the ESP32 is entering app_main.

markkuk
Posts: 38
Joined: Wed Mar 27, 2019 11:50 am

Re: C++ error: Guru Meditation Error: Core 0 panic'ed (InstructionFetchError). Exception was unhandled

Postby markkuk » Tue Mar 21, 2023 10:04 pm

rmendes wrote:
Mon Mar 20, 2023 5:03 pm

Code: Select all

    xTaskCreate(&task, "Test Task", 10000, NULL, 1, NULL);
You have extra indirection that causes the code to crash. The call should be:

Code: Select all

    xTaskCreate(task, "Test Task", 10000, NULL, 1, NULL);
See the example in the docs:
https://docs.espressif.com/projects/esp ... skHandle_t

Who is online

Users browsing this forum: atx823, brushlow18, Google [Bot] and 221 guests