Go Down

Topic: Reclaiming some Program Memory from the bootloader (Read 1 time) previous topic - next topic

rj77

Hi, I have a project that uses an Atmega328P. I am rapidly running out of program memory (maximum reported is 30720) however I only ever program using my USBAsp via the Arduino interface.

Am I right in thinking that I can steal some of the bootloader space since I only ever use the USBAsp and then approach the maximum hex size of 32kb?

If so, is it possible to make modify my Arduino IDE install such that when I go to Sketch, Upload Using Programmer that it sets up avrdude correctly?

Hope the question makes sense...

Thanks for any assistance

Delta_G

If you're going to use a programmer like that then you don't need any part of the bootloader.  You can have the entire flash space for your code.
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

rj77

If you're going to use a programmer like that then you don't need any part of the bootloader.  You can have the entire flash space for your code.
Great! Do you know if there is a step-by-step for technically challenged people like myself to follow anywhere?

pert

Yes, it's unfortunate that the Arduino IDE does not adjust the program storage space calculation depending on the upload method. This has nothing to do with AVRDUDE, the IDE does a check before uploading but it always assumes that the space for the bootloader must be preserved even when you're not using a bootloader.

The most simple solution is:
  • Open the boards.txt associated with the board you are using with a text editor. You can find the location of this file by opening one of the SPI library examples, doing Sketch > Show Sketch Folder, then navigating up 4 folder levels.
  • Change the upload.maximum_size value from 30720 to 32768.
  • Save the file.
  • Restart the Arduino IDE if it's running.


The problem with the above is that you will need to redo that change every time you update to a new version of the hardware package (or IDE if the package is Arduino AVR Boards). The better solution is to create a custom hardware package so that you will only need to ever make the change once. Since you don't need a bootloader this package will consist of only a boards.txt file, everything else can be referenced from Arduino AVR Boards. If this is something you would like to do I can provide instructions.

rj77

Yes, it's unfortunate that the Arduino IDE does not adjust the program storage space calculation depending on the upload method. This has nothing to do with AVRDUDE, the IDE does a check before uploading but it always assumes that the space for the bootloader must be preserved even when you're not using a bootloader.

The most simple solution is:
  • Open the boards.txt associated with the board you are using with a text editor. You can find the location of this file by opening one of the SPI library examples, doing Sketch > Show Sketch Folder, then navigating up 4 folder levels.
  • Change the upload.maximum_size value from 30720 to 32768.
  • Save the file.
  • Restart the Arduino IDE if it's running.


The problem with the above is that you will need to redo that change every time you update to a new version of the hardware package (or IDE if the package is Arduino AVR Boards). The better solution is to create a custom hardware package so that you will only need to ever make the change once. Since you don't need a bootloader this package will consist of only a boards.txt file, everything else can be referenced from Arduino AVR Boards. If this is something you would like to do I can provide instructions.
Thanks so much - some instructions would be great if you don't mind. So I don't need to change any fuse settings or anything - are they done automatically when choosing "Upload Using Programmer"?

pert

Actually I remembered that someone already made a hardware package for this so it's even easier:
  • File > Preferences > Additional Boards Manager URLs > https://raw.githubusercontent.com/carlosefr/atmega/master/package_carlosefr_atmega_index.json > OK
  • Tools > Board > Boards Manager
  • Wait for downloads to finish.
  • Scroll down to the Barebones ATmega Chips (no bootloader) entry. Click on it.
  • Click "Install"
  • Wait for installation to finish.
  • Click "Close"
  • Tools > Board > ATmega328/328p
  • Tools > Processor > ATmega328p
  • Tools > Clock > select the clock speed of your board


The other useful thing about this hardware package is that it will automatically do an "Upload Using Programmer" style upload when you click the standard Upload button.


rj77

Actually I remembered that someone already made a hardware package for this so it's even easier:
  • File > Preferences > Additional Boards Manager URLs > https://raw.githubusercontent.com/carlosefr/atmega/master/package_carlosefr_atmega_index.json > OK
  • Tools > Board > Boards Manager
  • Wait for downloads to finish.
  • Scroll down to the Barebones ATmega Chips (no bootloader) entry. Click on it.
  • Click "Install"
  • Wait for installation to finish.
  • Click "Close"
  • Tools > Board > ATmega328/328p
  • Tools > Processor > ATmega328p
  • Tools > Clock > select the clock speed of your board


The other useful thing about this hardware package is that it will automatically do an "Upload Using Programmer" style upload when you click the standard Upload button.


Perfect, thank you very much, that's a huge help!

DrAzzy

Does MiniCore not provide non-bootloader board defs?
ATTinyCore for x4/x5/x61/x7/x8/x41/1634/828/x313 megaTinyCore for the megaavr ATtinies - Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

pert

No, it doesn't. That would be a useful improvement though.

rj77

#9
Aug 09, 2017, 07:35 am Last Edit: Aug 09, 2017, 11:51 am by rj77 Reason: http active
Sorry this is somewhat of a crosspost but relevant to both this topic and:

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



After I changed my code to the following, I have found that it starts to behave badly (sometimes starts, sometimes doesn't) when the sketch length exceeds 30720.

I have used the pin to watch when it starts properly and when it doesn't.


Is there any way that I can use >30720 with stability?

Thanks very much




Code: [Select]


void setup() {
  pinMode(9, OUTPUT);
  digitalWrite(9,HIGH);
  delay(3000);
  digitalWrite(9,LOW);
  delay(3000);
  digitalWrite(9,HIGH);
  delay(3000);
  digitalWrite(9,LOW);

  // now copy paste delay(3000); until the sketch length approaches 100%
  delay(3000); // hundreds of times
}
  
void loop() {

}
 

rj77

I should add that the code verifies correctly up to 100% of size 32768

rj77

OK, worked it out, used the AVR fuse calculator and set the BOOTRST.

Thanks to everyone for help!

Go Up