upper limit on sketch size for Uno

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
botbilder
 
Posts: 18
Joined: Thu Dec 09, 2010 2:07 am

upper limit on sketch size for Uno

Post by botbilder »

I think I just hit the wall on flash memory with my Wave shield project, when I thought I still had several K remaining.

My Arduino v.22 sketch worked fine compiling and uploading to my Uno at this size:

Code: Select all

Binary sketch size: 28032 bytes (of a 32256 byte maximum)
But when I added a few more functions and debugging strings it got up to 29142 bytes, at which point the sketch took way too long to upload, and finally Arduino printed some red error messages (which I didn't save). I had to trim my code back under 29K before it started working again.

Have others experienced a similar limitation, below 32K?

Any thoughts on what's stealing my last few K -- is it the bootloader, or my program data, or what? I do use PSTR() a lot.

Isn't it a bug that the Arduino environment reports the incorrect maximum sketch size?

User avatar
adafruit_support_bill
 
Posts: 88154
Joined: Sat Feb 07, 2009 10:11 am

Re: upper limit on sketch size for Uno

Post by adafruit_support_bill »

Some space is taken up by the bootloader.

User avatar
westfw
 
Posts: 2010
Joined: Fri Apr 27, 2007 1:01 pm

Re: upper limit on sketch size for Uno

Post by westfw »

In theory, the bootloader occupies 512 bytes, and your sketch can can be up to 32256 bytes long.
In reality, the current bootloader shipped with Uno has a bug that prevents it from being able to load any sketch that exceeds approximately 30k. See http://code.google.com/p/arduino/issues/detail?id=380

User avatar
botbilder
 
Posts: 18
Joined: Thu Dec 09, 2010 2:07 am

Re: upper limit on sketch size for Uno

Post by botbilder »

Good to know, thanks for the pointer!

How easy would it be for me to build/install a patched bootloader in my Uno? I'm using Arduino 0022.

User avatar
westfw
 
Posts: 2010
Joined: Fri Apr 27, 2007 1:01 pm

Re: upper limit on sketch size for Uno

Post by westfw »


User avatar
botbilder
 
Posts: 18
Joined: Thu Dec 09, 2010 2:07 am

Re: upper limit on sketch size for Uno

Post by botbilder »

Fantastic! Thanks for putting together this solution.

I verified that I can now build and upload sketches past the 30K limit. In my case the limit was even lower, around 28700 bytes -- maybe because I use a lot of PROGMEM strings (PSTR) to conserve RAM.

Here are the steps I took to fix it in case other people have the same problem.

First I had to get a new Uno (which happens to be the SMD version) to use as a programmer for my old Uno. I built and uploaded the "optifix" sketch from this thread to the new Uno. Then I unplugged it (powered off) and hooked up the pins between the new Uno and the old Uno with breadboard wire as shown in this diagram. After triple-checking my wiring I plugged the new Uno back into the computer, opened the Arduino serial monitor (which you might have to switch to 19200 if you're normally at 9600 baud), and saw that as soon as the "new Uno" reset it recognized the attached "old Uno" and burned the new bootloader into it. You can also type a "G" into the serial monitor to force another upload. Then I unplugged the new Uno from the computer (powered off), took out all the breadboard pins, and verified that my old Uno still worked -- but now had about 3K more of program memory to fill up!

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”