I have a fairly large program running on an Atmega328P, close to 4000 lines of code, 31676 bytes (96% of capacity). Global variables use 37% of memory.
The program interfaces an SD card reader, an RTC, and a bluetooth module.
As I approached 96% of code size, I have noticed that behaviour in general has become increasingly erratic.
Specifically, I have noticed that small snippets of code, that aren't called at runtime (would only be activated by a sequence of events e.g. button presses, bluetooth commands etc.) either make or break whether or not the program executes at all. By this I mean it won't even execute the first command in setup.
Some of this behaviour seems to be related to the bluetooth (via SoftwareSerial) - behaviour stabilised somewhat when I reduced or eliminated entirely the debugging output to bluetooth.
However there is some erratic behaviour that can't be explained by that (all bluetooth output switched off).
I am using FreeRAM to monitor memory usage. As far as I can see, it isn't a problem. When I comment out bits of code that seem to make or break the execution, the FreeRAM result is the same regardless.
Posting the code isn't really viable or useful - it's almost 4000 lines and these strange problems only started happening once I approached this 95%+ size.
If I cut back the code by commenting out functions that aren't called unless a certain sequence of events occurs (i.e. only by button presses, bluetooth commands etc. they are not called at setup / loop), the program stabilises and will start (by this I mean it will run the first command in setup). I have verified that they are NOT being called. This behaviour I can't explain at all.
My question is: does a large program size cause stability issues?
Under what circumstances would code that isn't called affect whether or not the first command in setup is executed?
I can't see why it would be a problem, however I can't explain the strange behaviour of my code.
Not much to go on sorry, and I fully expect to be flamed for this because it is vague, but any suggestions very much welcome.