Bill Greiman
Well-known member
It appears that something in an isr is clobbering two locations near the beginning of the stack. Here is a sketch that demonstrates the possible problem. This is for beta7.
This is typical output from the sketch:
The sketch then delays for a second, rechecks the stack and stores the result in check2.
The result is that two locations are overwritten after the delay. These locations seem to always have the same values.
This is far from the part of the stack that should be used.
Code:
extern unsigned long _ebss;
extern unsigned long _estack;
#include <unistd.h>
void setup() {
// fill start of stack
uint32_t* stack = (uint32_t*)sbrk(0);
for (size_t i = 0; i < 1000; i++) stack[i] = 0X55555555;
// see if all is well
bool check1 = true;
for (size_t i = 0; i < 1000; i++) {
if (stack[i] != 0X55555555) check1 = false;
}
// wait for interrupts
delay(1000);
// check again
bool check2 = true;
for (size_t i = 0; i < 1000; i++) {
if (stack[i] != 0X55555555) check2 = false;
}
Serial.begin(9600);
while(!Serial) {}
delay(2000);
Serial.print("check1 ");
Serial.println(check1, DEC);
Serial.print("check2 ");
Serial.println(check2, DEC);
// print clobbered stack locations
for (size_t i = 0; i < 1000; i++) {
if (stack[i] == 0X55555555) continue;
Serial.print((int)&stack[i], HEX);
Serial.print(' ');
Serial.println(stack[i], HEX);
}
Serial.print("&_ebss ");
Serial.println((int)&_ebss, HEX);
Serial.print("sbrk(0) ");
Serial.println((int)sbrk(0), HEX);
Serial.print("stack ");
Serial.println((int)stack, HEX);
}
void loop() {}
The sketch fills the beginning of the stack with a pattern of 0X55555555. It then checks to see if all is well and saves the result in check1.check1 1
check2 0
1FFFEC50 2580
1FFFEC54 1080000
&_ebss 1FFFEC2C
sbrk(0) 1FFFEC2C
stack 1FFFEC2C
The sketch then delays for a second, rechecks the stack and stores the result in check2.
The result is that two locations are overwritten after the delay. These locations seem to always have the same values.
This is far from the part of the stack that should be used.