ESP32 S3 DevKitC-1 N16R8 - using PSRAM - howto

As a long time lurker/reader/user of the content of this forum, I would like to do something back :slight_smile: And in this case I would like to share how I got an ESP32 S3 DevKitC-1 working, specifically, with PSRAM working in the N16R8 config. Hope this will help someone in the (near) future who struggles with the same issue.

This is a relative new board (with Dual USB-C), as such there are some older topics on how to get the S3 in general working, but nothing about the PSRAM. Why do you wish to have this enabled? Glad you asked! Its a much needed performance boost, needed to get for example 16 bit colors out of the ILI9xxx component and helps (I think) with boosting performance to also get the touchscreen part working on relatively large displays (4" in my case) which can often be found in combination with this board (e.g. using the XPT2046 controller).

So to start off with the actual board. Its quite a common board these days that can be found on Aliexpress and the likes. In my case it was sold as a ESP32-S3 N16R8 (indicating a flash size of 16MB and a PSRAM size of 8MB). The board itself was labeled ā€˜AI-S3ā€™ on the back, nothing more (Example here). When looking at the config and pinout, I quickly realized it followed the ESP32-S3 DevKitC-1 design. But hereā€™s the catch, when using that board designation in an ESPHOME config, PSRAM will not be enabled by default, which caused my display to be stuck in 8bit color and causing issues with wifi connectivity (which I have come to see as an issue related to reaching the limit of the board performance). When looking at the platformIO website, one can also clearly see ā€œNO PSRAMā€ stated in the name, but its not reflected in the board name you in ESPHOME.

So, the solution (for me atleast) actually turned out to be very simple, and only contains a few more lines of code:

  1. Add a few platformio_options, being
  • A build flag indicating that the build has PSRAM
  • Indicate the type of memory
  1. Indicate the flash size (as mine has 16MB, the default is 8MB).

The last one is a standard feature of ESPHOME/clearly documented on the site. The platformio options are also mentioned, but not clearly explained.

So, hereā€™s the code (sorry for all the blabbering above, I felt like explaining myself a bit):

esphome:
  name: "your project name"
  platformio_options:
    build_flags: "-DBOARD_HAS_PSRAM"
    board_build.arduino.memory_type: qio_opi
    

esp32:
  board: esp32-s3-devkitc-1
  framework:
    type: arduino
    version: latest
  flash_size: 16MB

Now in all fairness, Iā€™m not sure if the 'version: latest" is needed. I noticed it in some of the posts around the internet, so decided to try it. And ESPHOME does trigger a warning indicating that this is not recommended. Having said that, the board works now, and I did not want to fumble with it any longer :slight_smile:

Anyway, I ended up flashing this setup to the ESP using ESPHOME-web, and after that OTA can be used (and is working in my case).

As said, I hope someone finds this one day and helps them to solve there issue!

For those who find this topic because they were searching for ILI9xxx configs (in my case using a ST7796s 4" display (example here) with a XPT2046 controller, here are the remaining relevant parts of the yaml file:

spi:
  miso_pin: GPIO12
  clk_pin: GPIO13
  mosi_pin: GPIO11

touchscreen:
  platform: xpt2046
  calibration_x_min: 190 #callibration following explanation ESPHOME
  calibration_x_max: 3886
  calibration_y_min: 3929
  calibration_y_max: 261
  id: my_touchscreen
  cs_pin: 6
  on_touch: #this part is just to output coordinates in the log, useful to check if its working and for calibration (detailed on ESPHOME site)
    - lambda: |-
          ESP_LOGI("cal", "x=%d, y=%d, x_raw=%d, y_raw=%0d",
              id(my_touchscreen).x,
              id(my_touchscreen).y,
              id(my_touchscreen).x_raw,
              id(my_touchscreen).y_raw
              );

binary_sensor: #example of how one 'button' looks
  - platform: touchscreen
    name: R1C1
    x_min: 30
    x_max: 110
    y_min: 40
    y_max: 140

display:
  - platform: ili9xxx
    model: ST7796
    reset_pin: GPIO4
    cs_pin: GPIO10
    dc_pin: GPIO5
    rotation: 0
    update_interval: 5s
    lambda: |-
      //content as explained in display component on ESPHOME site
      it.printf(......);

So hope this helps someone, and if someone else finds a mistake somewhere, please do let me know :slight_smile: Iā€™m here to learn!

8 Likes

Thanks, but can you please provide a pointer to this device?

Ah yes, I was a bit hesitant to link to AliExpress as its always the question for how long the product will be sold in the given store. Regardless, I edited the post with the links, and for reference, also here:

ESP32 S3 N16R8: https://nl.aliexpress.com/item/1005006109469779.html
Display: https://nl.aliexpress.com/item/33015586094.html

Hope this does not violate any policies.

1 Like

No violation there. People frequently post Ali links.

I thought you were talking about a board with a built in touch screen.

Thanks for the links. :smile:

Cool - I have 3 of these in the parts bin just waiting for an excuse to use them.

1 Like

Thanks! This is very interesting.

There are other boards out there that use PSRAM and it would be interesting to see if they work - I have one in mind that I want to try but have a couple of questions for you since you have it working on your board.

In one article I read (ESP32 - How To Use PSRAM ā€¢ ThingPulse) it mentioned that Arduino has a flag

-mfix-esp32-psram-cache-issue

which fixes a crashing issue. Is this something youā€™ve seen, and more generally, would ESPHome be able to leverage this flag?

Second, the article has a cool code snippet (for Arduino) that dumps info about PSRAM usage - Iā€™ve only used ESPHome a couple of times, so Iā€™m not sure if this is something that can be used here. Would External Components ā€” ESPHome solve this? Is there a way that you know of in the ESPHome interface to access PSRAM?

Thanks!

I think the flag you indicate can be used. At least its used here: Starting a Diesel generator with ESPHome - #3 by alifakih1
Also including a PSRAM flag.

W.r.t. the dumping the info about PSRAM usage, in my case, the log already shows the amount of PSRAM available. If you need more, perhaps the debug component can help? Debug Component ā€” ESPHome

Iā€™m afraid Iā€™m not familiar with external components, so cannot help you there.

The -mfix-esp32-psram-cache-issue flag is only for ESP32 chips, as mentioned here; you can see the list of chips affected in the PDF linked in the paragraph.

The psram component takes care of adding flags for arduino & esp-idf as can be seen here.
It seems however to be missing the memory_type flag for arduinoā€¦
I also had to update versions; I couldnā€™t get rid of boot loop errors otherwise. I used static ones instead of latest to avoid jumping automatically in the future.
I ended up with a config like this:

esphome:
  platformio_options:
    board_build.arduino.memory_type: qio_opi
    board_upload.maximum_ram_size: 524288

esp32:
  board: esp32-s3-devkitc-1
  variant: esp32s3
  flash_size: 16MB
  partitions: "/config/esphome/custom_16MB.csv"
  framework:
    type: arduino
    version: 2.0.14
    platform_version: 6.4.0

psram:
  mode: octal
  speed: 80MHz

The custom partitions file is the default 16MB one from arduino-esp32. It fixes the core_dump errors you will get if not set.

Itā€™s quite a lot of changes in the background, but it appears to be working, as you can see in the screenshot below:

PS: In case you have a non-working RGB LED (GPIO48) with those N16R8 boards, check this out.

EDIT: A couple of days laterā€¦ I can confirm this is working just as well as the recommended version up until now! I also confirmed the PSRAM is being used by components (audio in my case), although it does seem to be a bit ā€œunderutilizedā€, probably because the codebase hasnā€™t caught up with the amounts of PSRAM available on newer boards.

3 Likes

works like a charm with a freenove esp32 s3 wroom with 8mb psram and 8mb flash size, thnxx!!!

testing now if i can record 24/7 a video stream without crashing when using the webserver option of esphome. My esp32-wrover is not stable for continuous recording.

1 Like

You can leave a comment on this issue to get esphome moving on proper (or should I say ā€œeasierā€) support for this.

Which Hardware version you are using?
Unfortunately my esp32-s3-devkitc-1 is Rev. 0.2 is not working.

I have the exact same board but I cannot seem to get it to boot with ESPHOME as you with the exact code you have shown,

Here is the log output I get once it boots, after that nothing:

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:0x44c
load:0x403c9700,len:0xbe4
load:0x403cc700,len:0x2a38
entry 0x403c98d4
E (184) esp_core_dump_flash: No core dump partition found!
E (184) esp_core_dump_flash: No core dump partition found!

Here is the ESPHOME code:

esphome:
  name: voyager
  friendly_name: voyager
  platformio_options:
    build_flags: "-DBOARD_HAS_PSRAM"
    board_build.arduino.memory_type: qio_opi

esp32:
  board: esp32-s3-devkitc-1
  flash_size: 16MB
  framework:
    type: arduino
    version: latest

# Enable logging
logger:
  level: debug

# Enable Home Assistant API
api:
  encryption:
    key: "xxxx"

ota:
  password: "xxx"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Voyager Fallback Hotspot"
    password: "xxxx"

captive_portal:

What am I doing wrong?

Have a look at post #8, this board needs some extra settings, e.g. defining the partitions and activating the PSRAM.

Here is my config:

esphome:
  name: ${device_name}
  friendly_name: ${device_name}
  comment: EPS32-S3 Testboard with RGB

  platformio_options:
    board_build.arduino.memory_type: qio_opi
    board_build.flash_mode: dio
    board_upload.maximum_ram_size: 524288

esp32:
  board: esp32-s3-devkitc-1
  variant: esp32s3
  flash_size: 16MB
  partitions: "default_16MB.csv"
  framework:
    type: arduino

psram:
  mode: octal
  speed: 80MHz

Hi

I am trying to configure an Espressif ESP32-S3-DevKit 1.0 N32R8V board

I can download the configuration via the UART connection but the devive never comes online on the ESPHome dashboard and so obviously wireless OTA updates donā€™t work

I tried some of the configurations on this thread but without success

Has any else had this network problem with this board?

Thanks

can you get logs from serial to see what is happening ? you can use https://web.esphome.io/ to view the logs over usb. once connected, with the logs window open click on the ā€˜reset deviceā€™ to see logs from boot. this may indicate what the issue is that you are facing. can you post the current config you are using ?

The following config should work if using the esp-idf framework

esphome:
  name: esp-idf
  platformio_options:
    board_build.flash_mode: dio
esp32:
  board: esp32-s3-devkitc-1
  variant: esp32s3
  framework:
    type: esp-idf
    version: recommended
    sdkconfig_options:
      CONFIG_ESP32_S3_BOX_BOARD: "y"
   
psram:
  mode: octal
  speed: 80MHz

logger:

ota:

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  
api:

1 Like

Thank you!

I tried implementing the esp-idf config you suggested

Unfortunately it is still offline after the install

Here is one of the log entries:

ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0xc (RTC_SW_CPU_RST),boot:0x8 (SPI_FAST_FLASH_BOOT)
Saved PC:0x40376290
SPIWP:0xee
Octal Flash Mode Enabled
For OPI Flash, Use Default Flash Boot Mode
mode:SLOW_RD, clock div:1
load:0x3fce3808,len:0x1658
load:0x403c9700,len:0xbc0
load:0x403cc700,len:0x2f3c
entry 0x403c9950
I (37) boot: ESP-IDF 4.4.6 2nd stage bootloader
I (37) boot: compile time 17:27:17
I (37) boot: Multicore bootloader
I (39) boot: chip revision: v0.1
I (42) boot.esp32s3: Boot SPI Speed : 80MHz
I (47) boot.esp32s3: SPI Mode       : SLOW READ
I (53) boot.esp32s3: SPI Flash Size : 4MB
I (57) boot: Enabling RNG early entropy source...
I (63) boot: Partition Table:
I (66) boot: ## Label            Usage          Type ST Offset   Length
I (74) boot:  0 otadata          OTA data         01 00 00009000 00002000
I (81) boot:  1 phy_init         RF data          01 01 0000b000 00001000
I (88) boot:  2 app0             OTA app          00 10 00010000 001c0000
I (96) boot:  3 app1             OTA app          00 11 001d0000 001c0000
I (103) boot:  4 nvs              WiFi data        01 02 00390000 0006d000
I (111) boot: End of partition table
I (115) esp_image: segment 0: paddr=00010020 vaddr=3c090020 size=23284h (144004) map
I (158) esp_image: segment 1: paddr=000332ac vaddr=3fc96880 size=03f54h ( 16212) load
I (162) esp_image: segment 2: paddr=00037208 vaddr=40374000 size=08e10h ( 36368) load
I (173) esp_image: segment 3: paddr=00040020 vaddr=42000020 size=84ad8h (543448) map
I (302) esp_image: segment 4: paddr=000c4b00 vaddr=4037ce10 size=09a6ch ( 39532) load
I (320) boot: Loaded app from partition at offset 0x10000
I (320) boot: Disabling RNG early entropy source...
I (321) cpu_start: Multicore app
I (324) opi psram: vendor id : 0x0d (AP)
I (329) opi psram: dev id    : 0x02 (generation 3)
I (334) opi psram: density   : 0x03 (64 Mbit)
I (339) opi psram: good-die  : 0x01 (Pass)
I (344) opi psram: Latency   : 0x01 (Fixed)
I (349) opi psram: VCC       : 0x00 (1.8V)
I (354) opi psram: SRF       : 0x01 (Fast Refresh)
I (359) opi psram: BurstType : 0x01 (Hybrid Wrap)
I (365) opi psram: BurstLen  : 0x01 (32 Byte)
I (370) opi psram: Readlatency  : 0x02 (10 cycles@Fixed)
I (376) opi psram: DriveStrength: 0x00 (1/1)
I (381) MSPI Timing: PSRAM timing tuning index: 5
I (386) spiram: Found 64MBit SPI RAM device
I (391) spiram: SPI RAM mode: sram 80m
I (395) spiram: PSRAM initialized, cache is in normal (1-core) mode.
I (402) cpu_start: Pro cpu up.
I (406) cpu_start: Starting app cpu, entry point is 0x40375c48

For good measure, I just tried another identical brand new board, same result

By the way, ESPHome.io seems to crash after listing a load of seemingly identical logs. Sometimes I can scroll back and download. However clicking on Reset Device causes it to hang

if the esp has 2 usb ports, try plugging into the other one and try and view logs again