Cannot declare array into the External PSRAM?

The_YongGrand
Posts: 19
Joined: Fri Nov 04, 2016 1:14 am

Cannot declare array into the External PSRAM?

Postby The_YongGrand » Tue Jan 01, 2019 4:17 am

Hello there and Happy New Year to all the ESP32 crew!

I have a program that I'm porting as an experiment, and found out that it doesn't fit the memory, so I tried to move some of the declarations into the external PSRAM (I have the WROVER).

My attempts:
1.) Menuconfig -> I have set this -
* SPI RAM access Method: Integrate RAM into ESP32 memory map
* Allow .bss segment placed in external memory

2.) In the code -

Code: Select all

static uint32_t bigArray[......] EXT_RAM_ATTR;
But all it does is this:
c:/msys32/opt/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/5.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: <elf name> section `.dram0.bss' will not fit in region `dram0_0_seg'
c:/msys32/opt/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/5.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: DRAM segment data does not fit.
c:/msys32/opt/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/5.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: region `dram0_0_seg' overflowed by 240344 bytes
collect2.exe: error: ld returned 1 exit status
I checked the *.map file, but it doesn't allocate anything to the external RAM. What have I missed out?

The ESP32-IDF I'm using is obtained at November 2018.

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: Cannot declare array into the External PSRAM?

Postby fly135 » Tue Jan 01, 2019 3:36 pm

Allocate your array dynamically...

heap_caps_malloc(size, MALLOC_CAP_SPIRAM)

But yeah, it does seem that the docs say what you are doing should work. Try making it a small array and see if that works. The error message does say that it won't fit.

fivdiAtESP32
Posts: 47
Joined: Thu Dec 20, 2018 9:47 am

Re: Cannot declare array into the External PSRAM?

Postby fivdiAtESP32 » Tue Jan 01, 2019 4:30 pm

Does the file defining bigArray directly or indiectly include "sdkconfig.h"?

If "sdkconfig.h" (which contains the define for CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY) is not directly or indirectly included then EXT_RAM_ATTR will be defined as the empty string here and an error message similar to what you are seeing will be shown.

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: Cannot declare array into the External PSRAM?

Postby ESP_Angus » Wed Jan 02, 2019 6:05 am

Fivdi is right, and this is a bug (esp_attr.h should include sdkconfig.h itself, but does not). Will fix, in the meantime ensuring there's an #include "sdkconfig.h" line above "#include esp_attr.h" in the source file is a workaround.

The_YongGrand
Posts: 19
Joined: Fri Nov 04, 2016 1:14 am

Re: Cannot declare array into the External PSRAM?

Postby The_YongGrand » Wed Jan 02, 2019 1:43 pm

ESP_Angus wrote:
Wed Jan 02, 2019 6:05 am
Fivdi is right, and this is a bug (esp_attr.h should include sdkconfig.h itself, but does not). Will fix, in the meantime ensuring there's an #include "sdkconfig.h" line above "#include esp_attr.h" in the source file is a workaround.
Thanks! It compiles successfully now! :)

Who is online

Users browsing this forum: Baidu [Spider], dzungpv, jimmy98035@gmail.com and 68 guests