ESP32 - Memory

ThomasESP32
Posts: 229
Joined: Thu Jul 14, 2022 5:15 am

ESP32 - Memory

Postby ThomasESP32 » Thu Jul 14, 2022 7:17 am

Good Morning,

I am a beginner in the ESP32 subject and I need to use it for my work.
I have just read the Memory part of the reference manual and I have some questions :

1) When compiling and flashing a program, where is it located exactly ? In which internal memory part ?
2) Why internal SRAM parts can be accessed by instruction bus ? Can we put instructions in these parts ?
3) Same question concerning the RTC Memory.
4) If we want to use external FLASH to put our program and that the CPU can access to it automatically using SPI, cache mecanisms and MMU, what do we have to configure exactly and how ? After that, is the instructions access totally automatic and do we have to do SPI Reads to access to the code ?
5) ROM 0 32KB can be remapped in order to access to SRAM1 => What is the point ?

Thank you for your help.
Best regards

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

Re: ESP32 - Memory

Postby ESP_Sprite » Fri Jul 15, 2022 2:06 am

ThomasESP32 wrote:
Thu Jul 14, 2022 7:17 am
1) When compiling and flashing a program, where is it located exactly ? In which internal memory part ?
It goes into flash. The bootloader then loads the various bits where they need to go: RO memory stays in flash and is mapped via the cache into CPU memory, RW data is copied to SRAM, BSS is allocated and cleared.
2) Why internal SRAM parts can be accessed by instruction bus ? Can we put instructions in these parts ?
3) Same question concerning the RTC Memory.
You answered your own question.
4) If we want to use external FLASH to put our program and that the CPU can access to it automatically using SPI, cache mecanisms and MMU, what do we have to configure exactly and how ? After that, is the instructions access totally automatic and do we have to do SPI Reads to access to the code ?
On the 2nd half of the q: SPI flash is accessed transparently through the cache and SPI peripheral; from the CPUs side it looks like the SPI flash is just another read-only memory address range.

5) ROM 0 32KB can be remapped in order to access to SRAM1 => What is the point ?
Debugging in case of a problem in ROM. It's not something we expect any user to have to do.

ThomasESP32
Posts: 229
Joined: Thu Jul 14, 2022 5:15 am

Re: ESP32 - Memory

Postby ThomasESP32 » Sun Jul 31, 2022 6:34 am

Thank you for your answer,

so, because the ROM0 is 384Kb (Accessible by Instruction Bus) and ROM1 is 64Kb (Accessible by Data Bus), does it mean that only ROM0 (384Kb) are available in order to put program/instructions ?

The same question for SRAM, SRAM0 is (192Kb) and SRAM is (128Kb) accesibles by Instruction Bus and SRAM2 is (200Kb) accessible by Data Bus, does this mean that only 128Kb are available in order to put variables/datas ?

In this case, how to increase the size available for program ? Do I have to put program into ROM0 and SRAM0 and SRAM1 ? In this case, how to put program into these 3 sections at the same time ? What is the mecanism ?
Moreover, how to increase the size available for datas ? Do I have to put variables into ROM1, SRAM2 at the same time ? In this case, how to do this ? How can I put variables into ROM0 ? (Is it for constants) ??

In order to conclude, if I need 1Mo of memory for program and 512 Ko for datas, do I need to add additional external FLASH and SRAM ?

Best regards,

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

Re: ESP32 - Memory

Postby ESP_Sprite » Sun Jul 31, 2022 1:03 pm

ThomasESP32 wrote:
Sun Jul 31, 2022 6:34 am
so, because the ROM0 is 384Kb (Accessible by Instruction Bus) and ROM1 is 64Kb (Accessible by Data Bus), does it mean that only ROM0 (384Kb) are available in order to put program/instructions ?
ROM in this case is actual ROM, as in: the contents are designed into the chip, and no one can change it after the chip designs were made. It's not where your application lives.
The same question for SRAM, SRAM0 is (192Kb) and SRAM is (128Kb) accesibles by Instruction Bus and SRAM2 is (200Kb) accessible by Data Bus, does this mean that only 128Kb are available in order to put variables/datas ?
Sorry, can't be arsed to look up the exact details, but the gist is that you have around 300'ish K of ram for your data, dependent on if you also need BT or WiFi.
In this case, how to increase the size available for program ? Do I have to put program into ROM0 and SRAM0 and SRAM1 ? In this case, how to put program into these 3 sections at the same time ? What is the mecanism ?
Moreover, how to increase the size available for datas ? Do I have to put variables into ROM1, SRAM2 at the same time ? In this case, how to do this ? How can I put variables into ROM0 ? (Is it for constants) ??

In order to conclude, if I need 1Mo of memory for program and 512 Ko for datas, do I need to add additional external FLASH and SRAM ?
You always need external flash (or an ESP32 type that has the 'external' flash die within the package). Your program more-or-less runs from this flash (through a cache). If you have 512K data, it depends... if it's read-only data, it can remain on flash (also accessed through that cache) and you don't need to allocate RAM for that. If the ESP needs to modify the data, you need to put it in RAM and as the ESP32 does not have 512K free, you'd need to add external PSRAM to the chip.

Who is online

Users browsing this forum: No registered users and 110 guests