Error: region `dram0_0_seg' overflowed by 31632 bytes

petersanch
Posts: 15
Joined: Mon Sep 10, 2018 8:58 am

Error: region `dram0_0_seg' overflowed by 31632 bytes

Postby petersanch » Mon Sep 10, 2018 9:10 am

Hi All,
I'm trying to make a global char array with size 115200. I get the following error
region `dram0_0_seg' overflowed by 31632 bytes
Someone said there could be a 96000 bytes limit even though there is lots of RAM left. Is there a way to modify the Arduino ESP32 core to increase the heap size by 32K?

I tried making a local array inside of loop() instead of global. It compiles if I do this but the processor keeps crashing on boot.
I'm only using Core 0. Can I disable Core 1 and increase the available memory like this?

Does any one have a way to go around this problem without decreasing the array size?

Cheers!

petersanch
Posts: 15
Joined: Mon Sep 10, 2018 8:58 am

Re: Error: region `dram0_0_seg' overflowed by 31632 bytes

Postby petersanch » Mon Sep 10, 2018 9:25 am

I tried a global malloc. This compiles but crashes on boot like when trying to make a local array in loop() as described in my first post.
Error message is this
Guru Meditation Error: Core 1 panic'ed (StoreProhibited). Exception was unhandled.

petersanch
Posts: 15
Joined: Mon Sep 10, 2018 8:58 am

Re: Error: region `dram0_0_seg' overflowed by 31632 bytes

Postby petersanch » Mon Sep 10, 2018 6:41 pm

I wrote a new program to make sure nothing else was causing the problem.
This is a dummy program with same array sizes and random calculation in loop(). I get the same error.

Code: Select all

uint8_t arr[115200];
float arrF[768];
uint8_t arr2[768];
uint8_t arr3[768];
uint16_t arr4[850];


void setup() {
  // put your setup code here, to run once:

}

void loop() {
  for(uint32_t i=0; i<115200;i++) {
    arr[i]=(uint8_t)i;
  }
  for(uint16_t i=0;i<768;i++) {
    arrF[i]=arr[i]*43.0;
    arr2[i]=arrF[i];
    arr3[i]=arrF[768-i];
    arr4[i]=arr2[i]*3*arr3[i];
  }

}
Error
region `dram0_0_seg' overflowed by 19584 bytes

collect2.exe: error: ld returned 1 exit status

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

Re: Error: region `dram0_0_seg' overflowed by 31632 bytes

Postby ESP_Angus » Mon Sep 10, 2018 11:21 pm

There is a limit to the amount of statically allocated RAM at compile time, due to some chip-level reasons. More memory is available as heap at runtime.

If you malloc() your largest buffer from heap, it should work. Something like:

Code: Select all

uint8_t *arr;
float arrF[768];
uint8_t arr2[768];
uint8_t arr3[768];
uint16_t arr4[850];


void setup() {
  // put your setup code here, to run once:
  arr = malloc(115200);
  assert(arr != NULL);
}

void loop() {
  for(uint32_t i=0; i<115200;i++) {
    arr[i]=(uint8_t)i;
  }
  for(uint16_t i=0;i<768;i++) {
    arrF[i]=arr[i]*43.0;
    arr2[i]=arrF[i];
    arr3[i]=arrF[768-i];
    arr4[i]=arr2[i]*3*arr3[i];
  }

}

petersanch
Posts: 15
Joined: Mon Sep 10, 2018 8:58 am

Re: Error: region `dram0_0_seg' overflowed by 31632 bytes

Postby petersanch » Tue Sep 11, 2018 4:47 am

I tried using malloc() like you suggested in setup().

Code: Select all

arr = (uint8_t*)malloc(115200);
assert(arr != NULL);
It compiled but did not show the right memory usage and the ESP32 keeps rebooting.
Sketch uses 178612 bytes (13%) of program storage space. Maximum is 1310720 bytes.
Global variables use 20200 bytes (6%) of dynamic memory, leaving 307480 bytes for local variables. Maximum is 327680 bytes.
Why is so much program storage space being used if this array is supposed to be in RAM not ROM?

Full code

Code: Select all

uint8_t *arr;
float arrF[768];
uint8_t arr2[768];
uint8_t arr3[768];
uint16_t arr4[850];


void setup() {
  // put your setup code here, to run once:
  Serial.begin(250000);
  arr = (uint8_t*)malloc(115200);
  assert(arr != NULL);
}

void loop() {
  Serial.println("cheers");
  for(uint32_t i=0; i<115200;i++) {
    arr[i]=(uint8_t)i;
  }
  for(uint16_t i=0;i<768;i++) {
    arrF[i]=arr[i]*43.0;
    arr2[i]=arrF[i];
    arr3[i]=arrF[768-i];
    arr4[i]=arr2[i]*3*arr3[i];
  }
}

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

Re: Error: region `dram0_0_seg' overflowed by 31632 bytes

Postby ESP_Angus » Tue Sep 11, 2018 4:55 am

petersanch wrote: It compiled but did not show the right memory usage and the ESP32 keeps rebooting.
What exactly happens when it reboots? If allocating 115200 bytes fails then the assert() will fail, and the ESP32 will print an error message and reset. This means there wasn't enough free heap (in a single contiguous block) to allocate 115200 bytes. Maybe there is enough to make 2-3 smaller allocations that add up to 115200 bytes.

Or, if there's a crash somewhere else in your program then this will also make it reboot.
Why is so much program storage space being used if this array is supposed to be in RAM not ROM?
Some space is taken up by ESP-IDF and Arduino framework code.

petersanch
Posts: 15
Joined: Mon Sep 10, 2018 8:58 am

Re: Error: region `dram0_0_seg' overflowed by 31632 bytes

Postby petersanch » Tue Sep 11, 2018 5:26 am

With assert(arr != NULL); uncommented, it crashes once and halts
Serial with baud 250000
(41) boot: Assert failed in void setup(), array-test2.ino:12 (arr != NULL)
baud 115200
ets Jun 8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
ets Jun 8 2016 00:22:57

rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:952
load:0x40078000,len:6084
load:0x40080000,len:7936
entry 0x40080310
With assert(arr != NULL); commented out, it crashes and reboots forever
baud 250000
cheers
Guru Meditation Error: Core 1 panic'ed (StoreProhibited). Exception was unhandled.
Core 1 register dump:
PC : 0x400d09d2 PS : 0x00060530 A0 : 0x800e20e1 A1 : 0x3ffb1f80
A2 : 0x00000000 A3 : 0x0001c200 A4 : 0x00000000 A5 : 0x3ffc3c80
A6 : 0x00000000 A7 : 0x00000000 A8 : 0x800d09c5 A9 : 0x3ffb1f60
A10 : 0x00000008 A11 : 0x00000006 A12 : 0x0800001c A13 : 0x00000003
A14 : 0x00000001 A15 : 0x00000000 SAR : 0x0000001f EXCCAUSE: 0x0000001d
EXCVADDR: 0x00000000 LBEG : 0x400d09ce LEND : 0x400d09d7 LCOUNT : 0x0001c1ff

Backtrace: 0x400d09d2:0x3ffb1f80 0x400e20de:0x3ffb1fa0

Rebooting...
baud 115200
rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:952
load:0x40078000,len:6084
load:0x40080000,len:7936
entry 0x40080310

Code

Code: Select all

uint8_t *arr;
float arrF[768];
uint8_t arr2[768];
uint8_t arr3[768];
uint16_t arr4[850];


void setup() {
  // put your setup code here, to run once:
  Serial.begin(250000);
  arr = (uint8_t*)malloc(115200);
  assert(arr != NULL);
  Serial.println("end");
}

void loop() {
  Serial.println("cheers");
  for(uint32_t i=0; i<115200;i++) {
    arr[i]=(uint8_t)i;
  }
  for(uint16_t i=0;i<768;i++) {
    arrF[i]=arr[i]*43.0;
    arr2[i]=arrF[i];
    arr3[i]=arrF[768-i];
    arr4[i]=arr2[i]*3*arr3[i];
  }
}

petersanch
Posts: 15
Joined: Mon Sep 10, 2018 8:58 am

Re: Error: region `dram0_0_seg' overflowed by 31632 bytes

Postby petersanch » Tue Sep 11, 2018 5:52 am

Now I tried 2 arrays with half the size each in case the compiler doesnt like one large memory allocation but it doesnt compile either

Code: Select all

uint8_t arrA[57600];
uint8_t arrB[57600];

float arrF[768];
uint8_t arr2[768];
uint8_t arr3[768];
uint16_t arr4[850];


void setup() {
  Serial.begin(250000);

}

void loop() {
  Serial.println("cheers");
  for(uint32_t i=0; i<115200/2;i++) {
    arrA[i]=(uint8_t)i;
  }
  for(uint32_t i=0; i<115200/2;i++) {
    arrB[i]=(uint8_t)i;
  }
  for(uint16_t i=0;i<768;i++) {
    arrF[i]=arrA[i]*43.0;
    arr2[i]=arrF[i];
    arr3[i]=arrB[768-i];
    arr4[i]=arr2[i]*3*arr3[i];
  }
  Serial.println("end");
}
region `dram0_0_seg' overflowed by 20192 bytes

collect2.exe: error: ld returned 1 exit status

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Error: region `dram0_0_seg' overflowed by 31632 bytes

Postby WiFive » Tue Sep 11, 2018 10:12 am

He meant do 2 mallocs

petersanch
Posts: 15
Joined: Mon Sep 10, 2018 8:58 am

Re: Error: region `dram0_0_seg' overflowed by 31632 bytes

Postby petersanch » Thu Sep 13, 2018 4:43 am

ESP_Angus wrote: What exactly happens when it reboots? If allocating 115200 bytes fails then the assert() will fail, and the ESP32 will print an error message and reset. This means there wasn't enough free heap (in a single contiguous block) to allocate 115200 bytes. Maybe there is enough to make 2-3 smaller allocations that add up to 115200 bytes.

Or, if there's a crash somewhere else in your program then this will also make it reboot.
WiFive wrote:He meant do 2 mallocs
2 smaller mallocs looks like it worked. Cheers!

Who is online

Users browsing this forum: No registered users and 37 guests