ESP-IDF : Using External RAM present in ESP32 WROVER module

The standard ESP32 module (ESP-WROOM-32) present in the market has 512KB SRAM. For most the applications this RAM is more than sufficient. In fact it is nearly 4 times of what we get on ESP8266. There might be cases where you need more RAM to buffer data from a server or run complex calculations on large amount data you have collected from sensors. Recently I came across a similar situation where I had to store 1 MB of data in RAM, little research showed that ESP32 supports external SPI RAM (PSRAM) of 4 MB and whats more, Espressif sells a module named WROVER with this external RAM (WROVER is basically WROOM with external RAM). The ESP-WROVER-KIT V3 has this module on board.

ESP32 WROVER KIT V3
ESP32 WROVER KIT V3 (source : esp-idf.readthedocs.io)

In this post we will see how to use/enable the external ram present in the WROVER module.

We can use the external RAM present in WROVER module in three modes.

WROVER External RAM config modes
WROVER External RAM config modes

you can select the mode of operation by using menuconfig, to start the menuconfig app run the following cmd (Refer this post if you haven’t setup ESP-IDF)

make menuconfig

WROVER External RAM
WROVER External RAM

Using external RAM with WROVER

WROVER External RAM modes
WROVER External RAM modes
mode 1

Manually allocate memory in external RAM (address starting from 0x3F800000 and up)

you need to include memory management logic in your code

choose option 1 in menuconfig SPIRAM_USE_MEMMAP to enable this mode

mode 2

Initilize and add it to capability allocator , you can get memory from external ram by using a special malloc method

heap_caps_malloc(size, MALLOC_CAP_SPIRAM)

to free the memory just call free ()

this seems best method if you are developing a new application

choose option 2 in menuconfig SPIRAM_USE_CAP_ALLOC to enable this mode

mode 3

add external ram to memory pool which can be returned by standard malloc call. this way you don’t need rewrite any old applications that use malloc call to get memory

choose option 3 in menuconfig SPIRAM_USE_MALLOC to enable this mode

You need to be careful when using the external because there are some restrictions on using the external RAM

Restrictions on usage of External RAM

stack can’t be allocated on external ram (you can add exception while compiling if you are sure that the task won’t be accessing any code in ROM)

RAM can’t be access while the cache is disabled

can’t be used for DMA transactions or buffers

for more information on support for external RAM consult this page

3 Comments

Add a Comment

Your email address will not be published. Required fields are marked *