ESP32 Wroom with SPIRAM support

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
cristian
Posts: 1
Joined: Wed Feb 26, 2020 12:21 pm

ESP32 Wroom with SPIRAM support

Post by cristian » Wed Feb 26, 2020 1:01 pm

Good day everybody.

First of all let me say that I am a beginner with micropython and with python in general. I tested micropython with an ESP8266 and I was really amazed how fast you can develop software so, I am thinking to skip Arduino for my future projects. Since I was not satisfied with my ESP8266 experience because of the lack of RAM I am thinking to start using ESP32.
Because I am manufacturing my own boards I want to use an ESP32 WROOVER module with 8Mb of SPI RAM and 16Mb of flash. But before buying the modules I want to make myself some things clear:

1. I saw that in firmware builds page it is stated that: .....
whereas SPIRAM enabled firmware will only work on boards with
4MiB of external pSRAM.
Will the current "GENERIC-SPIRAM" firmware built work with my module?

2. If this firmware will work and SPIRAM will be used how this will affect the speed execution of code?

Thank you in advance for your answer!

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: ESP32 Wroom with SPIRAM support

Post by jimmo » Wed Feb 26, 2020 1:51 pm

The startup code (ports/esp32/main.c) does the following:

Code: Select all

    switch (esp_spiram_get_chip_size()) {
        case ESP_SPIRAM_SIZE_16MBITS:
            mp_task_heap_size = 2 * 1024 * 1024;
            break;
        case ESP_SPIRAM_SIZE_32MBITS:
        case ESP_SPIRAM_SIZE_64MBITS:
            mp_task_heap_size = 4 * 1024 * 1024;
            break;
        default:
            // No SPIRAM, fallback to normal allocation
            mp_task_heap_size = heap_caps_get_largest_free_block(MALLOC_CAP_8BIT);
            mp_task_heap = malloc(mp_task_heap_size);
            break;
    }
So it looks like with your 8MiB spiram (i.e. 64Mib), you'll get 4MiB of usable heap, and this will work with the generic-spiram firmware.

See https://github.com/micropython/micropython/issues/5428 for why only the low 4MiB gets used.
cristian wrote:
Wed Feb 26, 2020 1:01 pm
f this firmware will work and SPIRAM will be used how this will affect the speed execution of code?
My experience has been that there are so many other things that affect speed on the ESP32 that the SPIRAM doesn't change it very much -- other than that more heap means less frequent garbage collection, although the garbage collection takes a lot longer when it does run.

seonr
Posts: 43
Joined: Mon Sep 10, 2018 6:54 am

Re: ESP32 Wroom with SPIRAM support

Post by seonr » Mon Mar 23, 2020 1:04 am

Actually, the SPIRAM use will dramatically effect the speed of execution if you fill the cache. The current (Non ESP32-S2) chips use a shared cache with Flash and PSRAM, and if you fill the cache with PSRAM stuff and it needs to be flushed, all flash is removed, and then needs to get reloaded again.

It's why using PSRAM for large buffers for stuff like image data (re cameras etc) is not really viable as you are constantly filling and flushing and reloading the cache, between Flash and Ram. I probably didn't explain this too well, but it's a real and documented issue.

That said, this has been improved (speed wise) with silicon changes in the new ECO3 revision ESP32 chips (I think only the PICO-D4 and one variant of the non SIP chips), and the new S2 (and future Sx) versions have 2 dedicated caches now, one for Flash and one for RAM, so it never has to unload and reload in the flash if you fill your RAM cache.

Cheers,
Seon
Unexpected Maker

Post Reply