Lolin D32 Pro v2 and SPIRAM access

scottkildall
Posts: 2
Joined: Fri Nov 06, 2020 7:53 pm

Lolin D32 Pro v2 and SPIRAM access

Postby scottkildall » Fri Nov 06, 2020 8:16 pm

Hi,

I'm having a heck of a time trying to figure out how to allocate SPI RAM memory with the Lolin D32 Pro v2. I can't figure out how to get SPI RAM accessed at all.

Board specs are here:
https://docs.wemos.cc/en/latest/d32/d32_pro.html

The PSRAM should actually be listed at 8mb (https://www.amazon.com/Genuine-Original ... 07QDFP3WC/), but in either case, I can't any available PSRAM memory listed.

I'm using Visual Code Studio / Platform IO.

Here is the code I've written:

Code: Select all

heap_caps_print_heap_info(MALLOC_CAP_SPIRAM);

// just to verify
multi_heap_info_t info;
heap_caps_get_info(&info, MALLOC_CAP_SPIRAM);
Serial.printf("total PSRAM size = %lu\n", info.total_free_bytes + info.total_allocated_bytes );
And the output looks like:
Heap summary for capabilities 0x00000400:
Totals:
free 0 allocated 0 min_free 0 largest_free_block 0
total PSRAM size = 0


From the notes here:
https://docs.espressif.com/projects/esp ... alloc.html
----
External SPI Memory
When external RAM is enabled, external SPI RAM under 4MiB in size can be allocated using standard malloc calls, or via heap_caps_malloc(MALLOC_CAP_SPIRAM), depending on configuration. See Configuring External RAM for more details.
---
So, it should work. Althought this is the ESP-IDF programming guide, but function calls are same as I'd use with PlatformIO.

If I allocate with heap_caps_malloc(..., MALLOC_CAP_SPIRAM), the returned pointer is NULL, as you'd expect.

I tried putting these into sdkconfig.h(temporarily) to try to solve the problem, but to no avail - based on some various research.

Code: Select all

#define CONFIG_SPIRAM_BOOT_INIT 1
#define CONFIG_ESP32_SPIRAM_SUPPORT 1
#define CONFIG_SPIRAM_IGNORE_NOTFOUND 0
#define CONFIG_SPIRAM_USE_MEMMAP 1
#define SPIRAM_USE_MALLOC 1
Any thoughts? I'm pretty stuck here.

Best,
Scott

ESP_Sprite
Posts: 9052
Joined: Thu Nov 26, 2015 4:08 am

Re: Lolin D32 Pro v2 and SPIRAM access

Postby ESP_Sprite » Sat Nov 07, 2020 3:32 am

Not sure about PlatformIO; perhaps just modifying the sdkconfig.h isn't good enough. From what I read, PlatformIO also supports menuconfig, though: 'pio run -t menuconfig'. If you modify it from there, you may have more success.

scottkildall
Posts: 2
Joined: Fri Nov 06, 2020 7:53 pm

Re: Lolin D32 Pro v2 and SPIRAM access

Postby scottkildall » Sun Nov 08, 2020 5:39 pm

Okay, I think I solved it. The menuconfig answer helped point me in the right direction.

Steps/notes for future users who are stumbling across this problem with PlatformIO, using the Arduino framework

(1) If you get stuck: try the Arduino IDE and make sure SPIRAM is working on your board. This is easy.

There is a PSRAM Enabled flag in the IDE. Turn this on and then run the code here, you should see output showing PSRAM size.

#include <Arduino.h>

Code: Select all

void setup() {
  Serial.begin(115200);
  Serial.printf("Total heap: %d\n", ESP.getHeapSize());
  Serial.printf("Free heap: %d\n", ESP.getFreeHeap());
  Serial.printf("Total PSRAM: %d\n", ESP.getPsramSize());
  Serial.printf("Free PSRAM: %d\n", ESP.getFreePsram());
   Serial.println("");
   heap_caps_print_heap_info(MALLOC_CAP_SPIRAM);

    // just to verify
     multi_heap_info_t info;
    heap_caps_get_info(&info, MALLOC_CAP_SPIRAM);
    Serial.printf("total PSRAM size = %lu\n", info.total_free_bytes + info.total_allocated_bytes );

}
(2) Back to PlatformIO with the Arduino framework. To address this *all* you should have to do is set the PlatformIO build flags for your board to:

Code: Select all

build_flags =
    -DBOARD_HAS_PSRAM
e.g. it will look something like this:

Code: Select all

[env:lolin_d32_pro]
platform = espressif32
board = lolin_d32_pro
framework = arduino
upload_speed = 460800
build_flags =
    -DBOARD_HAS_PSRAM
(3) Do not modify sdkconfig.h my modifications to it (see original post) resulted in the SPIRAM not working, even after I had set the build flags, so I only figured it out, after reverting to the original sdkconfig.h and this is where I ended up chasing my tail earlier.

(4) Note that boards.txt has these build flags in there:

Code: Select all

d32_pro.menu.PSRAM.disabled=Disabled
d32_pro.menu.PSRAM.disabled.build.defines=
d32_pro.menu.PSRAM.enabled=Enabled
d32_pro.menu.PSRAM.enabled.build.defines=-DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue
but it doesn't seem to activate the PSRAM with my Lolin D32 Pro chips

(5) Finally, just a note

Adding the build flag:

Code: Select all

-mfix-esp32-psram-cache-issue
wasn't necessary on my dev system.

(6) This doesn't address Himem, so if you want >4mb then you have to do other tricks, which I haven't yet looked at, some details here.
https://docs.espressif.com/projects/esp ... himem.html


That's what I got,
Scott

KevinA
Posts: 14
Joined: Tue Sep 20, 2016 3:09 pm

Re: Lolin D32 Pro v2 and SPIRAM access

Postby KevinA » Sat Feb 19, 2022 10:44 pm

I could not get the above to work in Arduino, had to rewrite it after I remembered how.
  1. void setup() {
  2.   Serial.begin(115200);
  3. }
  4.  
  5. void loop() {
  6.  
  7.   //Serial.printf("ESP32 Chip model = %s Rev %d\n", ESP.getChipModel(), ESP.getChipRevision());
  8.   Serial.printf("Total heap: %d\n", ESP.getHeapSize());
  9.   Serial.printf("Free heap: %d\n", ESP.getFreeHeap());
  10.   Serial.printf("Total PSRAM: %d\n", ESP.getPsramSize());
  11.   Serial.printf("Free PSRAM: %d\n", ESP.getFreePsram());
  12.   Serial.println("");
  13.   heap_caps_print_heap_info(MALLOC_CAP_SPIRAM);
  14.  
  15.   // just to verify
  16.   multi_heap_info_t info;
  17.   heap_caps_get_info(&info, MALLOC_CAP_SPIRAM);
  18.   Serial.printf("total PSRAM size = %lu\n", info.total_free_bytes + info.total_allocated_bytes );
  19.   delay(3000);
  20.  
  21. }

Who is online

Users browsing this forum: No registered users and 127 guests