How to use PSRAM on esp32-s3-devkitc-1 under esp-idf

I have an official s3-devkit-c1 with the n8r8 variant on it.
I have used menuconfig to add “external connected spi ram”
I have the following platformio.ini file

[env:esp32-s3-devkitc-1]
platform = espressif32
board = esp32-s3-devkitc-1
framework = espidf
monitor_speed = 115200
board_build.flash_mode = dio
build_flags =
    -DCONFIG_SPIRAM_CACHE_WORKAROUND
    -DCORE_DEBUG_LEVEL=5
    -DBOARD_HAS_PSRAM
    -mfix-esp32-psram-cache-issue
    -mfix-esp32-psram-cache-strategy=memw

I get the error

␛[0;31mE (168) psram: PSRAM ID read error: 0x00ffffff
␛[0;31mE (168) cpu_start: Failed to init external RAM!

I have read several threads, and tried many combinations of build flags, and changes to the board .json file but nothing helps.
Any ideas how I can successfully activate the psram?
thank you!

The product description says

Multiprotocol Modules SMD Module, ESP32-S3R8 with 8 MB Octal PSRAM Die, 8 MB Quad SPI flash, PCB Antenna

so, did you take care to tell the build system that you’re using an octal PSRAM and QSPI Flash?

Per

https://github.com/espressif/arduino-esp32/blob/master/tools/platformio-build-esp32s3.py#L311-L311

and available folders you should be setting

board_build.arduino.memory_type = opi_qspi

@maxgerhardt I am using esp-idf so confised why would I set Arduino build flags?
I added the line you indicated to platformio.ini and no change. Any other ideas?

also modified the board .json file to have

  "build": {
    "arduino":{
      "memory_type": "opi_qspi"
    },

but still no change

Does it work with the simplest possible Arduino sketch?

#include <Arduino.h>

void setup() {
  Serial.begin(115200);
}

void loop() {
  log_d("Total heap: %d", ESP.getHeapSize());
  log_d("Free heap: %d", ESP.getFreeHeap());
  log_d("Total PSRAM: %d", ESP.getPsramSize());
  log_d("Free PSRAM: %d", ESP.getFreePsram());
  delay(1000);
}
[env:esp32-s3-devkitc-1]
platform = espressif32
board = esp32-s3-devkitc-1
framework = arduino
monitor_speed = 115200
board_build.flash_mode = dio
board_build.arduino.memory_type = opi_qspi

I am not using arduino, i am using framework = espidf

my main.c is

#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

void app_main(void)
{
    while(1)
    {
        ESP_LOGI("memory", "Total available memory: %u bytes", heap_caps_get_total_size(MALLOC_CAP_8BIT));
        ESP_LOGI("ahh", "ok");
        vTaskDelay(1000);
    }
}

with your setup I get src/main.c:1:10: fatal error: Arduino.h: No such file or directory. Is everyone just using Arduino? I do not want to use Arduino, I have a complex sdkconfig setup in mind.

I understand your project is ESP-IDF, I’m asking you to create a new blank project with the board + Arduino as framework and use the above code as src/main.cpp. It’s just a quick check.

i see sorry.
with this setup i get E (85) cpu_start: Octal Flash option selected, but EFUSE not configured!

perhaps I have to burn the fuse for voltage using esptool? I am new to pio and to the S3

I might have confused the position of Flash and PSRAM, can you please set

board_build.arduino.memory_type = dio_opi 

I saw this in another thread and tried it already with this setup and get the very odd

ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3808,len:0x39c
load:0x403c9700,len:0x9bc
load:0x403cc700,len:0x28dc
entry 0x403c98c0

then no more logs, no loop running, but no crash either.

I have another project on this machine which uses

platform_packages =
  ;use custom patched esp-idf 5.0
  framework-espressif32 @ https://github.com/marchingband/mainframe-idf.git

I would expect this command to create a special folder inside .platformio/ somewhere, but I don’t see it. Is it possible this has corrupted my subsequent projects to use this fork of esp-idf, and is causing this issue?

There is no such package with that name. Did you mean framework-arduinoespressif32 or framework-espidf?

Weird. A way to shotgun it would be to try all memory_type configurations X_Y listed in https://github.com/espressif/arduino-esp32/tree/master/tools/sdk/esp32s3. Try to remove board_build.flash_mode = dio too.

I tried them all and none worked.
I have solved the problem for the esp-idf framework (not arduino).
No build flags are needed, nothing is needed in the board .json file.
I just needed to select OCTAL in menuconfig, it defaults to QUAD.
Thanks for indicating that my board had octal psram, that eventually led me to spot the issue.
I appreciate your support.
Let me know if I can contribute this experience back to the docs.
I also found that I need board_build.flash_mode = dio or the program crashes with the unhelpful

ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x7 (TG0WDT_SYS_RST),boot:0x8 (SPI_FAST_FLASH_BOOT)
Saved PC:0x400454d5
SPIWP:0xee
mode:QIO, clock div:1
load:0x3fce3808,len:0x164c
ets_loader.c 78 

I would have benefited from this knowledge at the start. I think all the s3 boards and modules would use the same settings, if they have psram, so there is some obvious value in publishing this info, if it is not possible to set it as the default.
I also remembered that my board was purchased around a year ago, and I believe at that time they were still marked as “engineering samples” so perhaps things have changed since then?

I also ran the same tests in a non-pio installation of esp-idf, and it gave me the very helpful error message

E (170) quad_psram: PSRAM ID read error: 0x00ffffff, PSRAM chip not found or not supported, or wrong PSRAM line mode
E (170) cpu_start: Failed to init external RAM!

I am not sure why this message doesn’t propagate through to the pio logs. It certainly cued me to look at the hardware settings more closely in menuconfig. Perhaps it is because I am using the latest idf, and pio is perhaps not yet?

Salaam

I did this and now I’m able to work with psram:

  1. Open “menuconfig”
pio run -t menuconfig
  1. Go here:
    Top → Component config → ESP32-specific

  2. Now enable “Support for external, SPI-connected RAM” by pressing space over it.

  3. Save everything (press S)

  4. Now see if you can import spi ram library:

#include "esp32/spiram.h"

Have a nice day,
Abolfazl