Hello all, first I just wanted to ask which compiler is best? Just kidding! I actually have a bit of an odd problem that I was hoping I could get some opinions on. I've been working on a project for several months using a mega2560 as my development target (board by arduino). This project involves talking to several different devices over the UARTs and I2c bus. The project has grown in complexity and everything has been going pretty well until today.
Today I have started adding in some more functionality and now I find that my program won't run on the hardware anymore. After some debug I have found that merely declaring & initializing a a few new 8-bit variables (global or local scope) makes the difference between the program running or not. For example I can add/remove a dummy variable from the code and recompile; and the application will then run, or not, on the hardware depending on its presence. I also found that I can add/subtract characters from a string and affect the same behavior.
I'm a little bit stumped as to why that should be. I have tried to rule out a few things but first some specifics. I'm programming in C, compiled using the 8-bit GCC toolchain from Atmel Studio 6.2 (latest version available through the extension manager). I also should mention that I'm using the FreeRTOS kernel for the mega that felipu has been maintaining over on Sourceforge.
My first thought was that it might be that I have filled up the entire flash memory, but this is definitely not the case. I can change the optimization level of the compiler too -O0 (from -Os) and the size of the binary grows by 30-40%; but the behavior remains exactly the same. (avrdude tells me that it is writing ~48000 bytes to flash at the higher optimization level and ~67000 bytes at the lower, either way well below the 256k on the chip.. and programming through atmel studio yields identical behavior to avrdude).
I also thought it might be a RAM issue; but I don't think this is the case. I have done two things toward this end. First I have observed that declaring global variables will cause the behavior the same as local variables within a function called by a freeRTOS task; so it is not a stack overrun inside one of my freeRTOS processes. And in conjunction I lowered the heap size available for freeRTOS (from 4608 to 4096 bytes) to free up RAM in general, which of course did not fix anything either. My program is not a memory hog anyway, I estimate that I'm using 1.5k-2k of the 8k on the system for my code, plus whatever the overhead for FreeRTOS is.
Finally I have scoured the program for programming errors involving incorrect memory access, such as forgetting to dereference a pointer etc. I can't find anything. (Side note; as per the faq at the top of this board, no I have not tried to simulate operation)
Does anyone have any advice or nuggets of wisdom that might help? This is a program that's been working very well for several weeks at least and I don't understand why simply adding variables without even manipulating them is causing this problem. Anyway thanks for your time!