ESP32 PSRAM support
Posted: Fri Jun 02, 2017 12:03 pm
TL;DR: We just released a *beta version* of esp-idf with support for external PSRAM. If you hook up the correct chip, it should give you 4MiB more RAM than a plain ESP32 has.
So, it's been in the datasheet forever, some people actually were lucky enough to receive some chips and it some companies already use it in private: the ESP32 has support for 4MiB of external RAM which it can use in (almost) the same way as the internal RAM. Today, we have released the toolchain and SDK you need to make use of it.
For this to work, you need an ESP32-module or board that has a V1 ESP32 and uses 1.8V flash. (The ESP32-D2WD with internal memory may work, but it's untested as of now.) You also need an ESP-PSRAM32 chip, as that's the only external memory chip supported for now. The connections that are needed essentially are: wire the RAM chip in parallel with the existing flash chip except for CLK and CS. Route CLK to GPIO17 and CS to GPIO16 instead. Alternatively, get yourself an ESP32-WROVER module; that essentially is similar to an ESP32-WROOM module but with PSRAM built-in.
You can download the beta esp-idf and the toolchain from the usual spots (https://github.com/espressif/esp-idf and https://github.com/espressif/crosstool-NG) but be sure to switch to the psram-compatible branches. For esp-idf, the branch is called 'feature/psram_malloc', for the toolchain it is called 'xtensa-1.22.x-ext_ram_patch'. Note that there are no binaries available for the toolchain, you will need to build it from source. For the different OSses, this is documented here: Linux Mac (Sorry, no Windows support for this yet.). Note: In order to get the psram version, in the instructions at the 'git clone' command, replace 'xtensa-1.22.x' with 'xtensa-1.22.x-ext_ram_patch'. For esp-idf, just clone esp-idf as usual, then do 'git checkout feature/psram_malloc'.
FAQ: (Well, questions no one asked yet but which we think you may want to ask)
How do we get the PSRAM chips / Wrover modules?
At the moment, the only place you can get them is sales@espressif.com. Be aware that due to the beta status of this thing, they do not have too many items in stock, so do not be surprised it you cannot get one immediately.
Why did this take so long?
As you may know, the V0 ESP32 had a bug in it that stopped psram from working at all. V1 mostly solved this bug, but not entirely: some instruction sequences, sometimes only in combination with an interrupt at a very specific time, could cause data corruption. We spent a fair amount of time characterizing and tracing back the origin of this bug before formulating a feasible workaround. This is also why you need to grab a new toolchain: it doesn't emit the instruction sequences that have a potential for errors.
Workaround? What consequences does this have?
For a normal user, mostly that all code will run somewhat slower. We haven't characterized the slowdown yet, but it's depending on the application and we estimate it in the range of 10-20%.
Is there documentation for all this?
We'll be uploading an updated ECO with the PSRAM cache details shortly. Datasheets for the ESP
Can I read more about the esp-idf implementation of psram support?
Sure! In the feature/psram_malloc branch, you can find docs/api-guides/external-ram.rst giving some more info.
What if I find a bug?
Feel free to post those either here if you're not entirely sure if it's a bug, or on Github as an esp-idf issue if you are. Be sure to mention PSRAM somewhere in the title if you post it on Github so we know it's about that specific branch.
I have another question
Feel free to ask it in this thread.
So, it's been in the datasheet forever, some people actually were lucky enough to receive some chips and it some companies already use it in private: the ESP32 has support for 4MiB of external RAM which it can use in (almost) the same way as the internal RAM. Today, we have released the toolchain and SDK you need to make use of it.
For this to work, you need an ESP32-module or board that has a V1 ESP32 and uses 1.8V flash. (The ESP32-D2WD with internal memory may work, but it's untested as of now.) You also need an ESP-PSRAM32 chip, as that's the only external memory chip supported for now. The connections that are needed essentially are: wire the RAM chip in parallel with the existing flash chip except for CLK and CS. Route CLK to GPIO17 and CS to GPIO16 instead. Alternatively, get yourself an ESP32-WROVER module; that essentially is similar to an ESP32-WROOM module but with PSRAM built-in.
You can download the beta esp-idf and the toolchain from the usual spots (https://github.com/espressif/esp-idf and https://github.com/espressif/crosstool-NG) but be sure to switch to the psram-compatible branches. For esp-idf, the branch is called 'feature/psram_malloc', for the toolchain it is called 'xtensa-1.22.x-ext_ram_patch'. Note that there are no binaries available for the toolchain, you will need to build it from source. For the different OSses, this is documented here: Linux Mac (Sorry, no Windows support for this yet.). Note: In order to get the psram version, in the instructions at the 'git clone' command, replace 'xtensa-1.22.x' with 'xtensa-1.22.x-ext_ram_patch'. For esp-idf, just clone esp-idf as usual, then do 'git checkout feature/psram_malloc'.
FAQ: (Well, questions no one asked yet but which we think you may want to ask)
How do we get the PSRAM chips / Wrover modules?
At the moment, the only place you can get them is sales@espressif.com. Be aware that due to the beta status of this thing, they do not have too many items in stock, so do not be surprised it you cannot get one immediately.
Why did this take so long?
As you may know, the V0 ESP32 had a bug in it that stopped psram from working at all. V1 mostly solved this bug, but not entirely: some instruction sequences, sometimes only in combination with an interrupt at a very specific time, could cause data corruption. We spent a fair amount of time characterizing and tracing back the origin of this bug before formulating a feasible workaround. This is also why you need to grab a new toolchain: it doesn't emit the instruction sequences that have a potential for errors.
Workaround? What consequences does this have?
For a normal user, mostly that all code will run somewhat slower. We haven't characterized the slowdown yet, but it's depending on the application and we estimate it in the range of 10-20%.
Is there documentation for all this?
We'll be uploading an updated ECO with the PSRAM cache details shortly. Datasheets for the ESP
Can I read more about the esp-idf implementation of psram support?
Sure! In the feature/psram_malloc branch, you can find docs/api-guides/external-ram.rst giving some more info.
What if I find a bug?
Feel free to post those either here if you're not entirely sure if it's a bug, or on Github as an esp-idf issue if you are. Be sure to mention PSRAM somewhere in the title if you post it on Github so we know it's about that specific branch.
I have another question
Feel free to ask it in this thread.