Go Down

Topic: Problem of boot loading of large program for Mega2560 board (Read 842 times) previous topic - next topic


Apr 02, 2013, 12:04 pm Last Edit: Apr 02, 2013, 12:18 pm by StanleyAudio Reason: 1
I have been working with my Mega 2560 board for few weeks without problem.
Now my program together with some audio data stored as constant table in the program memory has exceeded 80 kB.
When I downloaded the program to my Mega2560 board, it seemed that the downloading was successfully completed, but when the program run, it just crashed.

I was wondering around for sometimes and tried reducing the program size. The magic boundary of the program size is about 75kB, below that it works, above that can't..

Two questions:

1. Is there any limit in program size for the boot loading of Mega2560, which has indicated a maximum size of 258,048 bytes? The program crashed just after loaded, even the very first line code was not executed. So I guess the jump vector to the start of program code may be incorrect.
2. I declared an unsigned char array[] PROGMEM for storing audio samples. Although each array size is less than 64kB, I have a few audio clips (tables) so the total size may exceed 64kB. The compiler doesn't complaint about this. So would that be the source of problem? I tried to move the tables in various positions of the program code, it’s still the same.




There have been various posts about the Mega. It appears that the code generated by the compiler may not always be correct.

In particular, large arrays may cause problems. I think the compiler may assume that arrays can fit into 64 Kb boundaries. Try searching for this issue on this forum. There was a fairly lengthy discussion about this not that long ago.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics


You can move around with some data.

You could use more 'F()' macros with the print() and write(). That can be with the Serial.print() but also with other library functions that use the stream class.

Are you very sure that the arrays are in flash ?
Can you show your code for the arrays and variables ?
If they happen to be placed in ram, you have ram overflow.

You could implement the function for available ram, http://playground.arduino.cc/Code/AvailableMemory

Version 1.0.4 and 1.5.2 of the Arduino IDE have improved code for the bootloader. You could rewrite the bootloader with a programmer or another Arduino (Arduino as ISP).

If you don't use too many libraries, and you upload or send me the code, I could try to make it work. I have already the newest bootloader on my Mega.


Hi Erdin,

Thanks for the information.
Actually,I followed the suggestions from an old thread and made it works now.

The download and crash problem is avoided by moving all other data out of the first 64kb page. Perhaps there are better methods, for the now it works for me.
I can now access all my voice data within the 256kB of program memory by using the GET_FAR_ADDRESS macro and pgm_read_byte_far().


Go Up