Search code examples
memoryesp32esp-idfi2s

ESP-ADF I2S Recording choppy with PSRAM enabled


First of all; I'm using ESP-IDF 4.2 with the ESP-ADF and have two CMM4030D microphones connected to an ESP32-WROVER-E on a custom board. These microphones should record a wav file to an SPI-Connected SD card.

And that works flawless! But not when PSRAM is enabled, should initialize on boot (which it does) and is allocatable using heap_caps_alloc(). The frequency of PSRAM, as wel as that of the SPI Flash, is set at 80MHz and there isn't anything connected to pins 16 and 17.

The SDK-Configuration most likely isn't the issue, as I took the configuration for wifi-ble coexistence example as base.

So, to conclude; when PSRAM is enabled (boots on startup and is allocatable using heap_caps_alloc), the recording is choppy, but when it's disabled (but still running the same code) it works fine... What on earth could be the cause of this issue?

Kind regards,

A confused Jochem


Solution

  • I've managed to implement a workaround for this problem that consists of disabling initialization of PSRAM on boot. One can then initialize the PSRAM first thing in the main with the following function.

    static void psram_init(){
        esp_spiram_init();
        esp_spiram_init_cache();
        esp_spiram_test();
        esp_spiram_add_to_heapalloc();
    }
    

    One prevents the ESP-ADF from using PSRAM for allocation of buffers by disabling the initialize on boot option in the sdk config. This of course results in less memory being available (which is undesired), but it at least enables me to work towards an MVP.

    One can take a look at the issue on GitHub for more details.

    Kind regards,

    Jochem