ESP32 crashes when try to execute code from IRAM
Posted: Sun May 26, 2019 5:26 pm
I am trying to find a way to execute code (for exemple, load a code from SD card to RAM) without re-flashing esp32. I know ESP32 can execute instructions from IRAM, but when I try to do it, esp32 crashes.
This is the code (the compiled binary) I am trying to execute from IRAM. I am compiling it with the following linker script:
I compile the code using
This is the output binary:
The code I am using on ESP32:
I put the compiled binary on IRAM using IRAM_ATTR. This code basically tryies to execute the compiled binary from IRAM, but when I call f() esp32 crashes.
What am I doing wrong?
* Sorry for my english. I speak portuguese. This is the first time I use this forum.
Code: Select all
int main()
{
int c = 0;
for (int i = 0; i < 1000; i ++)
{
for (int j = 0; j < 1000; j ++)
{
c++;
}
}
}
Code: Select all
SECTIONS
{
.literal : {*(.literal)}
.text : {*(.text)}
}
Code: Select all
xtensa-esp32-elf-gcc.exe -Xlinker -T link.ld -std=c99 -Os -nostdlib -c main.c -o out/main.o
xtensa-esp32-elf-objcopy -O binary out/main.o out/APP.bin
Code: Select all
0x36, 0x41, 0x00, 0x0C, 0x02, 0x1D, 0xF0
Code: Select all
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_attr.h"
#define SIZE 7
IRAM_ATTR uint32_t PROGRAM[SIZE] = {
0x36, 0x41, 0x00, 0x0C, 0x02, 0x1D, 0xF0
};
const void* PTR = (void*)PROGRAM;
void exec_bin()
{
typedef void func(void);
func* f = (func*)(PTR);
printf("\nIT'S NOW ...\n");
f(); // ESP32 CRASHES HERE <<---
}
void app_main()
{
printf("\n\nGoint to exec code ...\n\n");
vTaskDelay(1000 / portTICK_RATE_MS);
exec_bin();
printf("Done");
}
Code: Select all
Guru Meditation Error: Core 0 panic'ed (Unhandled debug exception)
Debug exception reason: BREAK instr
* Sorry for my english. I speak portuguese. This is the first time I use this forum.