art Number: TMS320F28069M
Hello,
Sometimes when I use too many printf instructions, trying to run my code (from RAM) results in illegal ISR or the debugger halting in a memory location that doesn't belong to any source file (before even reaching the START symbol). I thought it may be caused by exceeding stack range - and indeed, increasing stack size usually helps. But methods of detecting stack overflow don't reveal anything wrong here!
1) First, I find the STACK_END size in memory browser when the problem occurs, but there is still plenty of empty space available (filled with 0xDEAD in linker file). Very often the whole .stack section seems to be untouched.
Does it mean I can be sure that the stack didn't get corrupted?
2) Next, I decided to implement a method described in Online Stack Overflow Detection (spra820) document. I implemented the exemplary source code so that no error is returned and then added the interrupt routine as simple as it can be:
extern interrupt void Stackmonitor_ovfISR(void)
{
asm(" ESTOP0");
}
...which I linked to PIE in HAL_initIntVectorTable() function:
pie->RTOSINT = &Stackmonitor_ovfISR;
The funny thing is, after implementing this feature the problem changed: debugger properly stops at the START symbol and the vulnerable code executes. However, it halts at some other part of the code (after a few seconds of normal execution) with a note that ' No source available for "0x3ff4fa" '. I commented my changes trying to evoke the initial situation once again, but this time the code run properly - until it started to restart over and over again.
What may cause such behavior? Increasing heap size doesn't change anything, but increasing stack makes the program run alright.
3) To make sure that the interrupt triggers properly, I redu the stack size trying to enforce its overflow. But using any value below default 0x1000 results in the following problem: the debugger doesn't even start properly with the "suspend" button grayed out and most of the views staying blank (registers, memory browser, etc).
How can I test this functionality to make sure that the interrupt will trigger to save the stack?
4) And I have one more bonus question. In the memory browser I can see two symbols existing: "_stack" and "_STACK_END". But I cannot find them anywhere in my project (definitely not in a linker file)! They only exist in a map file under "global data symbols" (double underscore).
Where are they defined?
5) Some additional information:
- I am developing the code basing on one of the motorWare labs examples, currently in RAM version only.
- The stack size that I'm using is 0x1000 and heap is 0x400. Trying to solve the problems by changing my code (using less printf) instead of blindly increasing the stack each time they occur.
- The command linker file that I use is attached here (I have STACK_END_X defined to differentiate it from already existing STACK_END): https://ufile.io/kl6g5