ezieragabriel / arduino

Automatically exported from code.google.com/p/arduino
Other
0 stars 0 forks source link

Sketch with progmem Data >64kb won't run on Mega2560 #1067

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.Create any Sketch that uses progmem Data greater 64kB.
2.Compile & Download it using Arduino1.0.1 (Does all without any Error)
3.The Sketch crashes immediately after Reseting the Board.

What is the expected output? What do you see instead?

I expectet at least that the Sketch starts to run, but no Line of Code is ever 
executed. It stucks immediately after Reset altough Compiling and Downloading 
worked without any Error, so no debugging is possible!!

What version of the Arduino software are you using? On what operating
system?  Which Arduino board are you using?

Arduino1.0.1 Version of May 12/2012 on Windows 7 32Bit.
Board: Arduino Mega2560.

Please provide any additional information below.

I checked out different AVR-Toolchains including the newest one, but that 
didn't solved the Issue. (But created other ones ;O( )
I use the lates Bootloader available here
https://github.com/arduino/Arduino-stk500v2-bootloader

You can use this Sketch to test the Issue:
https://github.com/arduino/Arduino-stk500v2-bootloader/tree/master/test/bigprogr
am

Original issue reported on code.google.com by tombroe...@gmail.com on 9 Oct 2012 at 11:13

GoogleCodeExporter commented 9 years ago
PROGMEM indeed supports only the first 64k of flash. This is not fixed until 
avr-gcc 4.7 which is not yet anywhere near ready for production use. (avr-gcc 
4.7 adds memory spaces for AVR which allows additional 64k blocks beyond the 
first one.)

Should be documented somewhere in the Arduino docs about using PROGMEM that 
this limitation applies.

Original comment by david.s....@gmail.com on 9 Oct 2012 at 6:18

GoogleCodeExporter commented 9 years ago
It's not quite as dire as David says, but it's not good, and there are many 
things wrong with the example sketch that would prevent it from working.  There 
is some summary explanation here: 
http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=93874&highligh
t=remarks

1) you definitely need to use pgm_read_byte_far() instead of pgm_read_byte()
2) All pointers in avr-gcc are only 16bits, so to access more than 16bits you 
need to use other data types, and can no longer use pointer-like constructs (&, 
[]) for accessing the data.
3) GET_FAR_ADDRESS() needs to be added and used to load those non-pointer types 
from C symbol names.

I've attached an attempt at corrected code.  I don't actually have a MEGA to 
try it on, but it does compile...

Original comment by wes...@gmail.com on 10 Oct 2012 at 12:25

Attachments:

GoogleCodeExporter commented 9 years ago
Hmm.  On further analysis, it looks like the version of g++ used by Arduino 
will fail whenever the global constructors get pushed beyond the 64k limit, 
because the global constructor table is only 16bits wide and the code uses ijmp 
to access it.  This is somewhat related to the bug that used to keep 64k+ 
programs from working when compiled under linux, but not quite the same 
(http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=97077 ) (I 
did theorize there that all version of g++ were broken for large programs; I 
guess I was right.)

Having a lot of PROGMEM data is one thing that will push the constructors past 
64k.

Original comment by wes...@gmail.com on 10 Oct 2012 at 6:30