Page 1 of 1

Cannot declare array into the External PSRAM?

Posted: Tue Jan 01, 2019 4:17 am
by The_YongGrand
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.

Re: Cannot declare array into the External PSRAM?

Posted: Tue Jan 01, 2019 3:36 pm
by fly135
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.

Re: Cannot declare array into the External PSRAM?

Posted: Tue Jan 01, 2019 4:30 pm
by fivdiAtESP32
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.

Re: Cannot declare array into the External PSRAM?

Posted: Wed Jan 02, 2019 6:05 am
by ESP_Angus
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.

Re: Cannot declare array into the External PSRAM?

Posted: Wed Jan 02, 2019 1:43 pm
by The_YongGrand
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! :)