I have an application that is running on an ARM9 and compiled with V3.60. It uses RL. I am having a strange problem. We are really close to the maximum amount of memory on our processor, within 2K. During development, I declared an unsigned char array of size 1056 with global scope in one of the libraries that handles data packets that are received.
#include <91x_conf.h> #include <91x_lib.H> #include <RTL.h> #include <string.h>
U8 my_buffer[1056];
I changed my implementation later and no longer needed that array.
Now, here is the strange part.
Task1 cannot handle large packets without that array declaration being present. If I comment the array declaration out or cut the size in half, the first large packet (~1076 bytes) that comes in crashes the entire application, though it works as long as the packets received over Task1's interface are small. Another weird thing is that Task2 is unable to properly receive data if I leave the array declaration in my code, yet it works if I leave the declaration out.
Task1 and Task2 both claim between 2-3K of allocated blocks of memory on the heap when they start, and those blocks are not reallocated or deallocated until the board is rebooted.
Any ideas what is going on here?
Time to check your map file. Either you have a buffer overflow somewhere that needs part of this memory. Try to fill the memory with a known value and later check if it has been touched.
Another alternative is that you have a buffer overflow or absolute address in use somewhere that overwrites something completely different, and the existence of this unused buffer affects what variable that is located where the buffer overrun happens.
A third alternative is that you have a stack overflow, and that your buffer is located so that the existence/removal of the buffer changes what will be overwritten by the stack overflow.
Buffer overruns can be evilishly hard to catch, which is a reason for always code defensively from day one. If you play with macros, you may even have to run the source code through the preprocessor just to be able to spot a source code line that may somehow change a pointer or index or in some other way result in memory addresses where none are allowed.