DRAM segment data does not fit?

Greg Corson
Posts: 35
Joined: Sun May 20, 2018 9:16 pm

DRAM segment data does not fit?

Postby Greg Corson » Mon May 20, 2019 11:35 pm

Hi,
I have some fairly simple Arduino code that is allocating a couple of buffer structures like this:

Code: Select all

typedef struct
{
  int len;
  uint8_t buff[INTERRUPT_BUFFER_SIZE];
} Buffer, *Buffer_ptr;

Buffer
  bufferA,
  bufferB;
When INTERRUPT_BUFFER_SIZE is 42000 I get the following info from the compile which seems to be saying I have a lot of memory left.

Code: Select all

Sketch uses 700270 bytes (53%) of program storage space. Maximum is 1310720 bytes.
Global variables use 123436 bytes (37%) of dynamic memory, leaving 204244 bytes for local variables. Maximum is 327680 bytes.
When INTERRUPT_BUFFER_SIZE is 43000 I get this error.

Code: Select all

c:/users/gcorson/appdata/local/arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/1.22.0-80-g6c4433a-5.2.0/bin/../lib/gcc/xtensa-esp32-elf/5.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: C:\Users\gcorson\AppData\Local\Temp\1\arduino_build_508386/SPI_IMU_Test_Telemetry.ino.elf section `.dram0.bss' will not fit in region `dram0_0_seg'

c:/users/gcorson/appdata/local/arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/1.22.0-80-g6c4433a-5.2.0/bin/../lib/gcc/xtensa-esp32-elf/5.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: DRAM segment data does not fit.

c:/users/gcorson/appdata/local/arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/1.22.0-80-g6c4433a-5.2.0/bin/../lib/gcc/xtensa-esp32-elf/5.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: region `dram0_0_seg' overflowed by 864 bytes

collect2.exe: error: ld returned 1 exit status
I don't understand this, at 42000 it says I have 204244 bytes free, why does adding another 20k bytes make it too big? Is there a way to let me use more memory?

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

Re: DRAM segment data does not fit?

Postby ESP_Angus » Tue May 21, 2019 12:19 am

ESP-IDF currently has a statically allocated memory limit of 160KB. The remaining DRAM has to be allocated dynamically.

You can modify your code to allocate this large buffer dynamically at runtime, and it should work:

Code: Select all

Buffer *bufferA;
Buffer *bufferB;

void setup() {
  bufferA = new Buffer();
  bufferB = new Buffer();
}
... and then use "bufferA->field" anywhere you previously had "bufferA.field".

A GitHub issue was recently opened about the same underlying problem. If you have a GitHub account you can subscribe to receive an update when it's fixed: https://github.com/espressif/esp-idf/issues/3497

Greg Corson
Posts: 35
Joined: Sun May 20, 2018 9:16 pm

Re: DRAM segment data does not fit?

Postby Greg Corson » Tue May 21, 2019 5:20 pm

Thanks! I'll give this a try.

It's an easy change because these were ping-pong buffers and are already referenced through pointers everywhere else in the code.

Who is online

Users browsing this forum: Baidu [Spider] and 25 guests