Pseudostatic Ram (PSRAM)

 

Just got me a second LOLIN D32 Pro v.2, this time with the newer ESP32-WROVER-B module on board. For just € 1,- extra, it has 4x more RAM and 2x more PSRAM. But what is this PSRAM, and could I use it for memory-hungry sketches, like the ones where AI or pathfinding algorithms are involved?

Searching the Internet gave me a first idea of what it is, but more important: I found out how to use it, which luckily turned out to be remarkably simple.

Below is a simple demo sketch that shows how to address PSRAM. It allocates a 1 MB buffer in PSRAM and then starts writing random integers at random positions, reading them back again for control. Make sure that PSRAM is enabled when you compile it, otherwise the ESP32 will panic! (it’s an option in the Tools menu of the Arduino IDE after a WROVER based ESP32 board has been selected).

[edit: a more useful application can be found in this later post]

Note that GPIO pins 16 and 17 are used for communication between ESP32 and PSRAM, so WROVER-based boards will not have these pins broken out.

Also note that content in PSRAM will be lost after the ESP32 loses power (still have to figure out what happens during deep sleep).

My search for information on PSRAM triggered a more general interest in the chip’s architecture. Espressif’s documentation has been very helpful.