Page 1 of 1

Executing code on stack. Writing to IRAM. Possible?

Posted: Fri Apr 04, 2025 8:21 am
by vvb333007
Hello,

I am trying to find bits of information on MMU & memory usage on ESP32. In particular: how we can (can we?) execute code, which is located on stack? Or code must be located in IRAM?

Is it possible to disable write-protection for the IRAM so I can modify some code, invalidate icache and jump to that code?

Thanks!

Re: Executing code on stack. Writing to IRAM. Possible?

Posted: Sat Apr 05, 2025 3:28 am
by Sprite
The (original) ESP32 can only execute code in IRAM, not in DRAM. Since the stack tends to be in DRAM you cannot execute code from there. You can allocate a chunk of IRAM using heap_malloc_caps(), put your code in there, then jump to it or call into it. I don't think the (original) ESP32 has write protection in place for IRAM, but later chips (ESP32-Sx, ESP32-Cx, ...) may have.

Re: Executing code on stack. Writing to IRAM. Possible?

Posted: Mon Apr 07, 2025 3:39 pm
by vvb333007
Thank you for the reply!
Now I see why there is a problem with C trampolines.