@PaulStoffregen (@all) - looking at CrashReport - playing with recent topic on Stack overflow
Caused a CrashReport for killing the Stack:
Code:
T:\T_Drive\tCode\sketch_jul14a\sketch_jul14a.ino Jul 15 2023 22:57:32
CrashReport:
A problem occurred at (system time) 22:58:9
Code was executing from address 0x2F84
CFSR: 82
(DACCVIOL) Data Access Violation
(MMARVALID) Accessed Address: 0x2006FB80 (Stack problem)
Check for stack overflows, array bounds, etc.
Temperature inside the chip was 47.90 °C
Startup CPU clock speed is 600MHz
Reboot was caused by software write to SCB_AIRCR or CPU lockup
hello world before buffer clear
It was Causing an INSTANT restart so made me wonder if CrashReport uses more stack variables and crashing causes it to crash.
Wondering if any variable in CrashReportClass:
rintTo(Print& p) should be made static?
> and in unused_interrupt_vector()? :: It recorded this crash correctly - AFAIK
Also noticed that none of the strings are F("inflash") so even though the code is in FLASH - the many strings are in RAM1?
So then I tried some extra strings to WATCH them appear in FLASH :: Please read and explain if this is going wrong?
In above :
rintTo building with the following extra strings causes this memory size change from the first to ...?
Code:
p.println("CrashReport:");
Memory Usage on Teensy 4.1:
FLASH: code:38100, data:8168, headers:9024 free for files:8071172
RAM1: variables:457600, code:33360, padding:32176 free for local variables:1152
RAM2: variables:486272 free for malloc/new:38016
To this - where is seems the added string went to FLASH 'data' and RAM1/DTCM reducing 'free for local variables'?:
Code:
p.println("CrashReport:");
p.println("Cr1shReport12345678:abcdefghijklmnopqrstuvwxyz1234CrashReport12345678:abcdefghijklmnopqrstuvwxyz1234");
p.println("Cr2shReport12345678:abcdefghijklmnopqrstuvwxyz1234CrashReport12345678:abcdefghijklmnopqrstuvwxyz1234");
p.println("Cr3shReport12345678:abcdefghijklmnopqrstuvwxyz1234CrashReport12345678:abcdefghijklmnopqrstuvwxyz1234");
p.println("Cr4shReport12345678:abcdefghijklmnopqrstuvwxyz1234CrashReport12345678:abcdefghijklmnopqrstuvwxyz1234");
p.println("Cr5shReport12345678:abcdefghijklmnopqrstuvwxyz1234CrashReport12345678:abcdefghijklmnopqrstuvwxyz1234");
p.println("Cr6shReport12345678:abcdefghijklmnopqrstuvwxyz1234CrashReport12345678:abcdefghijklmnopqrstuvwxyz1234");
p.println("Cr7shReport12345678:abcdefghijklmnopqrstuvwxyz1234CrashReport12345678:abcdefghijklmnopqrstuvwxyz1234");
p.println("Cr8shReport12345678:abcdefghijklmnopqrstuvwxyz1234CrashReport12345678:abcdefghijklmnopqrstuvwxyz1234");
p.println("Cr9shReport12345678:abcdefghijklmnopqrstuvwxyz1234CrashReport12345678:abcdefghijklmnopqrstuvwxyz1234");
p.println("Cr0shReport12345678:abcdefghijklmnopqrstuvwxyz1234CrashReport12345678:abcdefghijklmnopqrstuvwxyz1234");
Memory Usage on Teensy 4.1:
FLASH: code:38316, data:9192, headers:8808 free for files:8070148
RAM1: variables:458624, code:33360, padding:32176 free for local variables:128
RAM2: variables:486272 free for malloc/new:38016
And using the F("") changes nothing where the above took out 1,024 bytes of RAM for 10 strings of 101 chars - It is still 'gone'?:
Code:
p.println("CrashReport:");
p.println(F("Cr1shReport12345678:abcdefghijklmnopqrstuvwxyz1234CrashReport12345678:abcdefghijklmnopqrstuvwxyz1234"));
p.println(F("Cr2shReport12345678:abcdefghijklmnopqrstuvwxyz1234CrashReport12345678:abcdefghijklmnopqrstuvwxyz1234"));
p.println(F("Cr3shReport12345678:abcdefghijklmnopqrstuvwxyz1234CrashReport12345678:abcdefghijklmnopqrstuvwxyz1234"));
p.println(F("Cr4shReport12345678:abcdefghijklmnopqrstuvwxyz1234CrashReport12345678:abcdefghijklmnopqrstuvwxyz1234"));
p.println(F("Cr5shReport12345678:abcdefghijklmnopqrstuvwxyz1234CrashReport12345678:abcdefghijklmnopqrstuvwxyz1234"));
p.println(F("Cr6shReport12345678:abcdefghijklmnopqrstuvwxyz1234CrashReport12345678:abcdefghijklmnopqrstuvwxyz1234"));
p.println(F("Cr7shReport12345678:abcdefghijklmnopqrstuvwxyz1234CrashReport12345678:abcdefghijklmnopqrstuvwxyz1234"));
p.println(F("Cr8shReport12345678:abcdefghijklmnopqrstuvwxyz1234CrashReport12345678:abcdefghijklmnopqrstuvwxyz1234"));
p.println(F("Cr9shReport12345678:abcdefghijklmnopqrstuvwxyz1234CrashReport12345678:abcdefghijklmnopqrstuvwxyz1234"));
p.println(F("Cr0shReport12345678:abcdefghijklmnopqrstuvwxyz1234CrashReport12345678:abcdefghijklmnopqrstuvwxyz1234"));
Memory Usage on Teensy 4.1:
FLASH: code:38316, data:9192, headers:8808 free for files:8070148
RAM1: variables:458624, code:33360, padding:32176 free for local variables:128
RAM2: variables:486272 free for malloc/new:38016
And for repro this WIP that triggers this - added code and stack dropped as posted above and this happened - easy fix "uint8_t buf1[447500];", but seemed noteworthy:
Code:
extern "C" unsigned long _heap_start;
extern "C" unsigned long _heap_end;
extern "C" unsigned long _stext;
extern "C" unsigned long _etext;
uint8_t buf1[448000];
DMAMEM uint8_t buf2[480000];
uint32_t fooCnt = 0;
void setup() {
Serial.begin(9600);
while (!Serial) ; // wait for serial monitor
Serial.println("\n" __FILE__ " " __DATE__ " " __TIME__);
if ( CrashReport ) Serial.print( CrashReport );
Serial.println("hello world before buffer clear");
memset(buf1, 0x5A, sizeof(buf1));
memset(buf2, 0xA5, sizeof(buf2));
Serial.println("hello world after buffer clear");
Serial.printf( "[HeapStart 0x%X] [HeapEnd 0x%X] [SText 0x%X] [EText 0x%X]\n",
((uint32_t)&_heap_start) - 0x20200000, ((uint32_t)&_heap_end) - 0x20200000, (uint32_t)&_stext, (uint32_t)&_etext );
foo( (uint32_t)&_heap_start );
}
uint32_t foo( uint32_t stPtr ) {
uint32_t fooRet = 0;
uint32_t bar[8];
bar[0] = stPtr;
fooCnt++;
Serial.printf( "foo %u MYbar @%lu INbar %lu [HeapEnd %lu]\n", fooCnt, (uint32_t)bar, stPtr, &_heap_end );
if ( fooCnt < 3 ) fooRet = foo( (uint32_t) bar );
Serial.printf( "\tRet foo %u barRET %lu fooRet %lu [HeapEnd %lu]\n", fooCnt, fooRet, stPtr, &_heap_end );
fooCnt--;
return (uint32_t)bar;
}
void loop() {
}