After removing power, large program won't run until data removed & re-added

I'm running into a really strange problem with an Arduino Due. I have a rather large program (116,340 bytes program space) with about 15k of static data (bytes written to flash are 131664). If the Due has been disconnected for a while, when I try to upload the program, it uploads fine, but then it never starts.

I can upload repeatedly, and it still won't start. But if I remove a chunk of the static data, then upload, it works... And then if I re-add the same data and upload, it works fine. And from that point on, I can upload repeatedly and everything works fine. But if I disconnect the power, let it sit for a bit (30 seconds, maybe--I haven't tried shorter), and then reconnect it, the same problem happens again, even if I try to upload the exact same program.

At runtime, I still have around 70-80k of SRAM available. So while this problem seems related to the size of the program + data, it doesn't look like an out of memory issue.

I'm plugging the Due into my computer (Windows) using the USB Programming port. I'm currently running the Arduino IDE, v 1.5.5, but the same thing happens with 1.5.6-r2.

I have a variety of libraries I'm using:

  • Adafruit_9DOF
  • Adafruit_L3GD20_U
  • Adafruit_LSM303DLHC
  • Adafruit_NeoPixel
  • Adafruit_Sensor
  • libfixmath
  • libfixmatrix
  • RGBmatrixPanelDue

I have several spin-offs of this project (same libraries, similar code, similar data), and they all work fine, but this is the largest one, in terms of program + data size. It's gotten to the point where I just added a redundant block of data that I can remove and re-add when I want to start programming, to work around this problem.

If anyone has any ideas what might be wrong or what further investigation I can do, I'd really appreciate it.

I'd first double check whether you have exceeded the Flash or RAM limits of the
chip. Behaviour with RAM overflow is often erratic and mysterious, so beware
of red-herrings.

First check the chip is completely reliable with a smaller program that doesn't
risk running out of memory. Then investigate how much RAM you are using.

That sounds really ugly.

But for information: My project has a size of 165 kB and I dont have such a problem.
A hint: Take alle sources of the latest version where all did work well and do a text compare with all current files using a proper tool. Check all changes. I think, you will find the bug.

Thanks for the suggestions. Doing a diff hasn't shown anything unexpected or obviously buggy. And I've confirmed that I'm not running out of RAM.

Interestingly, it's a little bit worse than what I first described. Once I get the program uploaded and working properly, all I have to do is hit the Reset button...and it stops. And then I have to go through the same cycle again: comment out my block of extra data, upload, re-comment it, upload again. I suspect there's something wrong with the hardware I have, but I haven't been able to test on another board yet.

I have an additional idea:

If you use the 5Volt from the USB to power the Due it will work typicalle properly. But there is a problem with USB of your PC and with the voltage converter on the Due to generate the 3.3 Volt of the CPU:

The USB in you PC has a current limmiting PTC. You will not have the full 5 Volt at the Due. The voltage step down converter for the 3.3. Volt already runs at its voltage input limit. If the voltage goes significantly lower than 5 Volt, the step down converter will generate 3 Volt or lower only and the voltage is not stable.

If you are not using an external supply voltage already use one and check your system again.

I finally got a chance to check the voltage from the USB on my computer. And from the USB hub I was typically programming from. The voltage coming from the hub is only 4.3 - 4.4v. When I switch to a USB port on the computer, it's up at 5v. And the hub can be powered, in which case it's at 5v again.

Even when I've confirmed the power is 5v, I can still run into this problem. I can upload the program and it runs, but as soon as I hit the reset button in the Due, it freezes and fails to start up. Then I have to trim my program size and upload again. The only thing I've found that prevents this is keeping my program small.

I've tried this on 2 different Dues now. Both fail similarly. If anyone has any other ideas, I'm willing to try just about anything.

You may have an uninitialized variable, which would cause random symptoms.

Alright, I found a solution. I still don't know what the problem was, but upgrading to the latest Arduino IDE (1.5.7) fixed it.

Maybe it has something to do with this:

http://forum.arduino.cc/index.php?topic=256771.0

But in my case I am using 1.5.7 and such error still occurs.