Hi, this is related to another post on this forum Is there a 128k limit on Mega 2560? - Programming Questions - Arduino Forum
Here's the edited, highlights....
My project has been growing over the months, (both in functionality and size), over the last couple of weeks it's slowly expanded to the point where it now it compiles to just over 128 kBytes on a Mega 2560 (not sure if this is relevant)
During this period I noticed what started as an occasional bug, the code would compile and upload as normal without error. But when run I would just get a seemingly random string of about 100 numerals and then nothing further. (exactly the same string every time -see the above post for details)
Initially I took this as an occasional glitch, and discovered that I could get around it simply by compiling and uploading an unrelated sketch onto the board instead, and then re-compiling and loading my project (sometimes I would have to repeat this process several times to get it to work). This was initially a very occasional error, but as time progressed (and the project got bigger) the problem was occurring more frequently, and my work-around was having to be run more times to get the project to work.
I've made a few more changes to the code, and seem to have reached the point where the error always occurs, and the work-around never works!
ok, now for the really annoying bit. Every time I've built the project I've backed up all my libraries (all my .cpp and .h files) , so getting it working again ought to be just be a matter of restoring the last working set of files and re-compiling. However, for reasons that baffle me, I've had to go back 14 versions (nearly 3 weeks ago) to find a version that will work.
So, ignoring the actual problem with the project, my question is - why won't code that worked yesterday work today????
So far my research has suggested that the problem may be down to where in memory the compiler chooses to put objects (in particular PROGMEM strings) - (does this sound plausible? please comment) I've also learnt that a compiler won't always put the same object in the same location (does anyone know why? I thought a computer working on exactly the same data should do exactly the same thing every time)
Bearing this in mind, my current conclusion is that for the last few weeks the compiler has (through chance only) being putting objects in the right place, and has recently started putting objects in the wrong place (again through luck only). does this sound plausible? I'll admit I'm just guessing.
The following facts may also be relevant...
I'm compiling to a Mega 2560 using version 1.0
There are NO compilation errors - this is just about run-time problems.
All the individual libraries compile and run without problems. I only get a problem when I build the whole project and the sketch compiles to around 128k
There's not been one big change (I haven't even added any new libraries) I've just been adding a few lines every day over the last few weeks.
The project includes about 800 progmem constants totaling about 28k.
I get the same error on three different Mega 2560s
I've tried loading the progmem constants into higher memory using ''attribute((section(".fini7")))" instead of "PROGMEM" but this made no difference.
all comments appreciated!