Pages: [1]   Go Down
Author Topic: Reduce bootloader size  (Read 1705 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I'm looking forward to reduce the size of the standard serial bootloader in order to make some room for a custom calibration routine. Is there any thing that may be removed/commented from the standard source file without altering the normal use of the bootloader? This is for a custom Atmega328p board running from the internal RC oscilator. Hence my wish to do some calibrations from the bootloader.

Thanks in advance!

Daniel.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17259
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I'm looking forward to reduce the size of the standard serial bootloader in order to make some room for a custom calibration routine. Is there any thing that may be removed/commented from the standard source file without altering the normal use of the bootloader? This is for a custom Atmega328p board running from the internal RC oscilator. Hence my wish to do some calibrations from the bootloader.

Thanks in advance!

Daniel.


Well I think there is little point in your request. As I understand it the current Uno bootloader already fits inside the smallest flash chunk size the AVR hardware can reserve for a protected bootloader space. I will let ours confirm that statement. If that is indeed the case, making the object size of the bootloader any smaller would not free up any available flash space for you users sketch. I seem to recall reading posted here that the current uno bootloader leaves only 3 bytes free from the size limit it uses for the smallest possible flash memory bootloader reserved area.

Or are you wishing to add your calibration function to the bootloader such that it runs only when the chip is first powered up or upon a hardware reset? If that is the case you could possibly add it to the existing bootloader source code, recompile it and then burn this new bootloading/self-calibrating program into the chip using the next larger size reserved bootloader section of the flash memory. The fuse settings tell the chip what size bootloader area to save and I think the choices are 256, 512, and 1024 bytes, but check the 328p datasheet to confirm that, as I'm pretty old and the old memory can play tricks on me.  smiley-wink

I don't see an advantage to having your calibration function run inside a bootloader area, as just running it from the setup function of your sketch would accomplish the same thing, to be run just once at power up or reset time. But perhaps I'm not fully understanding your requirements?

Lefty
« Last Edit: August 31, 2012, 10:21:52 am by retrolefty » Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Lefty,

I'm using the old 2KB bootloader, with support for the WDT, since I was unable to make optiboot work on my board.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17259
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Lefty,

I'm using the old 2KB bootloader, with support for the WDT, since I was unable to make optiboot work on my board.


I'm pretty sure the uno bootloader for the 328p handles WDT correctly. Probably you should try and figure out why you can't burn and run optiboot on your 328p chip rather then trying to add a function to your old bootloader. And again why not just run your calibration function inside the setup function in your sketch?
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm pretty sure the uno bootloader for the 328p handles WDT correctly. Probably you should try and figure out why you can't burn and run optiboot on your 328p chip rather then trying to add a function to your old bootloader.

Not sure why but the bootloader didn't like running at 8MHz, at least from the internal RC oscillator. I even posted a question some time ago but nobody seemed to be using those settings with optiboot.

Quote
And again why not just run your calibration function inside the setup function in your sketch?

This is how I'm running it right now. I just wondered if running the calibration tasks from the bootloader was something possible, mainly because I wanted to run them before comms start.

Thanks again!

Daniel.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17259
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm pretty sure the uno bootloader for the 328p handles WDT correctly. Probably you should try and figure out why you can't burn and run optiboot on your 328p chip rather then trying to add a function to your old bootloader.

Not sure why but the bootloader didn't like running at 8MHz, at least from the internal RC oscillator. I even posted a question some time ago but nobody seemed to be using those settings with optiboot.

That is a problem, as the standard arduino optiboot is hard coded to run at 16mhz, so the baudrate would be wrong if you run it at 8mhz. You would need a modified optiboot recompiled to run at 8mhz.

Quote
And again why not just run your calibration function inside the setup function in your sketch?

This is how I'm running it right now. I just wondered if running the calibration tasks from the bootloader was something possible, mainly because I wanted to run them before comms start.

Well just place your calibrate function inside your setup function before the comm statements, even add a delay if you wish or need before you execute the comm start statements. You are making a problem where one does not exist I think.  smiley-wink

Thanks again!

Daniel.
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You're right, that was not a problem. Just looking forward to do it a bit smarter  smiley-grin

As for optiboot, I remember having tried to hack it for 8MHz but no luck. I should maybe look into this again.

Thank you very much!
Logged

Leeds, UK
Offline Offline
Edison Member
*
Karma: 78
Posts: 1719
Once the magic blue smoke is released, it won't go back in!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Here you go, optiboot for 8MHz for the 328p. It uses 115200Baud

You just need to set the fuses for a 512byte boot partition. I believe the fuse settings should be:
Low = 0xE2
High = 0xD4
Extended = 0xFE

* optiboot_atmega328_pro_8MHz.hex (1.35 KB - downloaded 12 times.)
Logged

~Tom~

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 518
Posts: 26344
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Can also upload your code with an ISP programmer,
File:Upload Using Programmer
and take all the bootload space back.

Still too big? Time to move up to a bigger chip such as '1284. 16K SRAM, 128K Flash.
Examples at my signature link with 1284 Mini's and '1284 style duemilanove style PCBs available to purchase.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Rapa Nui
Offline Offline
Edison Member
*
Karma: 60
Posts: 2061
Pukao hats cleaning services
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here you go, optiboot for 8MHz for the 328p. It uses 115200Baud
Does the 115k2 uart run reliably at 8MHz ?? There is 7.8% error, though..
Logged

Leeds, UK
Offline Offline
Edison Member
*
Karma: 78
Posts: 1719
Once the magic blue smoke is released, it won't go back in!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I haven't tried it, but that is the bootloader file for the Sparkfun pro mini.
Logged

~Tom~

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Finally got to make optiboot work on my custom board. The problem was in that I was incorrectly defining the board in boards.txt. This time I copied the UNO definition and changed f_cpu to 8000000L. Well, now I have enough room to add my calibration routine in the bootloader itself.

Thanks guys for your help!

Daniel.
Logged

Pages: [1]   Go Up
Jump to: