Arduino Forum

Using Arduino => Microcontrollers => Topic started by: sTrider_7 on Nov 26, 2012, 09:07 am

Title: Removing the Arduino Bootloader
Post by: sTrider_7 on Nov 26, 2012, 09:07 am
Hello All

I've been trying to figure this out for a couple of days now, and I think it's mostly because I don't really know what to look for.

I want to remove the Arduino bootloader on my mega board so that I can write standard AVR C code and upload it through the USB connection.

Is it possible to do this without buying a programmer? I read somewhere that I can use another Arduino as a programmer (have a spare Uno lying around), but how do I go about doing the whole thing?

The Arduino language & IDE has a bunch of annoying bugs and I'd like to just code it in plain old C. I have some experience with PIC mcus, but they're just rubbish :d

Thanks in advance
Title: Re: Removing the Arduino Bootloader
Post by: nickgammon on Nov 26, 2012, 09:23 am
The Arduino language is C++.

If you eliminate the bootloader, then you have to use a programmer. You can use another Arduino for that.
Title: Re: Removing the Arduino Bootloader
Post by: pico on Nov 26, 2012, 11:38 am

I read somewhere that I can use another Arduino as a programmer (have a spare Uno lying around), but how do I go about doing the whole thing?


If you are going to use a programmer regularly, just buy a USBasp off ebay for $5 or so. The "Uno as a programmer" is a good party trick, but a bit Rube Goldberg-ish for regular use. The USBasp will also have useful features like a slow clock generator.


The Arduino language & IDE has a bunch of annoying bugs and I'd like to just code it in plain old C. I have some experience with PIC mcus, but they're just rubbish :d


Lots of people program Arduinos without using the Arduino IDE. I myself use Emacs + makefiles, others use things like Eclipse + one of the plugins for Arduino. There are also several projects current where people are having their own crack at writing a better IDE. The thing is, it's the gnu compiler + avrdude sitting under the IDE that's really doing all the work -- the IDE just provides a simple editor and a certain amount of preprocessing of your "sketch" code into something that (hopefully) will be acceptable to the gcc compiler. What the IDE preprocessor really does isn't really that much (and it doesn't do it very well anyway, IMHO), so it's no great loss to work without it. Many (like me) see it a definite advantage, in fact.

Title: Re: Removing the Arduino Bootloader
Post by: sTrider_7 on Nov 26, 2012, 01:07 pm
I see, thanks for the advice.

If I were to erase the Arduino bootloader, is there a way to do it without purchasing another programmer?

I'll definitely get a programmer in the near future, it's just a question of finding a decent one since availability is very limited in my country.
Title: Re: Removing the Arduino Bootloader
Post by: tim7 on Nov 26, 2012, 01:24 pm
You don't need to remove the bootloader in order to upload Arduino-less code.
Title: Re: Removing the Arduino Bootloader
Post by: sTrider_7 on Nov 26, 2012, 04:02 pm

You don't need to remove the bootloader in order to upload Arduino-less code.


Wait what?
Title: Re: Removing the Arduino Bootloader
Post by: fungus on Nov 26, 2012, 04:40 pm

I'll definitely get a programmer in the near future, it's just a question of finding a decent one since availability is very limited in my country.


I got mine on eBay.
Title: Re: Removing the Arduino Bootloader
Post by: simplex on Nov 26, 2012, 05:48 pm

I want to remove the Arduino bootloader on my mega board so that I can write standard AVR C code and upload it through the USB connection.

Arduino IDE puts the compiled hex file in a directory like this:
C:\Users\Victor\AppData\Local\Temp\build1325897986179133197.tmp\Blink.cpp.hex

You have to remove that "Blink.cpp.hex" from there and replace it with the code compiled by you using another IDE, ex. Avr Studio, and then load the program into your Arduino Mega using Arduino IDE.

Title: Re: Removing the Arduino Bootloader
Post by: bperrybap on Nov 26, 2012, 08:32 pm


You don't need to remove the bootloader in order to upload Arduino-less code.


Wait what?

The bootloader is just a piece of software that is loaded in the AVR that allows
a tool (avrdude in this case) to upload code to the AVR. The bootloader itself
is totally independent of anything Arduino.

As shipped the AVR fuses are set to create two sections in the FLASH. Bootloader and application.
The "Arduino" bootloader is small piece of code in the AVR that uses the serial port to update the flash
with the user application (code/program/sketch).
The bootloader runs at reset/powerup if there is no attempt to upload anything, the bootloader
will start the application code.
The application code can be written using any toolset you prefer. The Arduino tools are just one option.

avrdude is a tool that is used upload code into the flash.
avrdude can be used with an ISP programmer to upload code to the flash
avrdude can also use other mechanisms like a serial port that talks to a serial based programmer or to a bootloader.
The Arduino IDE uses avrdude to talk over a serial port to a pre-installed bootloader in the AVR chip.
The newer IDE can also use an ISP progammer to upload code. When an ISP programmer is used,
a bootloader is not used so the flash space used by the bootloader code frees up and can be used
by the application code.

If you don't want to use a bootloader, you will need some sort of ISP programmer.
Like Pico, I recommend getting a USBasp programmer off ebay.
I like the USBasp kk multicopter programmers (about $5-$10 USD) because they come with a 6 pin ISP
cable instead of 10 pin so no adapter is needed.

--- bill
Title: Re: Removing the Arduino Bootloader
Post by: nickgammon on Nov 26, 2012, 09:15 pm

If I were to erase the Arduino bootloader, is there a way to do it without purchasing another programmer?

I'll definitely get a programmer in the near future, it's just a question of finding a decent one since availability is very limited in my country.


You need a programmer if you aren't going to use the bootloader. You can use an Arduino as a programmer as I describe here:

http://www.gammon.com.au/forum/?id=11638

Also the "Arduino as ISP" method lets you upload from the IDE using another Arduino.

Quote
I'd like to just code it in plain old C ...


As I said in my earlier response you can code in "plain old C" if you want to. Make a tab in the IDE called xxxx.c and put your code into it.
Title: Re: Removing the Arduino Bootloader
Post by: Coding Badly on Nov 26, 2012, 10:27 pm
The "Uno as a programmer" is a good party trick, but a bit Rube Goldberg-ish for regular use.


Works well for me.  Despite owning a Pololu AVR Programmer (http://www.pololu.com/catalog/product/1300) (which is a very nice programmer; currently only $10!) I've only used an Uno or Teensy for the last several months.

Quote
The USBasp will also have useful features like a slow clock generator.


Also available with an Uno / Teensy programmer.
Title: Re: Removing the Arduino Bootloader
Post by: bperrybap on Nov 27, 2012, 12:04 am

Pololu AVR Programmer[/url] (which is a very nice programmer; currently only $10!)

$10 for the pololu programmer is a bargain.
Particularly since it comes with the 6 pin header and can also work as a serial port.

Coding..., out of curiosity why would you resort to using an Uno when you have a pololu programmer?
Teensy I understand as it should be faster because of the native USB support, but why use Uno?

--- bill
Title: Re: Removing the Arduino Bootloader
Post by: Coding Badly on Nov 27, 2012, 01:17 am
$10 for the pololu programmer is a bargain.


Got that right!

Quote
Coding..., out of curiosity why would you resort to using an Uno when you have a pololu programmer?
Teensy I understand as it should be faster because of the native USB support, but why use Uno?


Upload performance from fastest to slowest...

• Uno with a 250K baud bootloader

• Pololu (very close to the same speed as above)

• Teensy running TinyISP

• Uno running TinyISP

• Teensy running ArduinoISP

• Uno running ArduinoISP (very slow)


The first two are very close to the programming time listed in the Atmel datasheet and are essentially the fastest possible method using SPI.  (Again, I highly recommend the Pololu AVR Programmer.  It was worth the $20 I paid for it (now just $10).)

TinyISP on either hardware is not as fast by a noticeable amount but is still fast enough to fall within the "two second" rule1.

ArduinoISP is just abysmal.


I use the Uno or Teensy because of the amenities that I've added to the Arduino ISP sketch (TinyISP is available here (https://github.com/Coding-Badly/TinyISP)).  It makes a "good enough" programmer with some very basic debugging tools.

I like the Teensy because, inserted in a breadboard, it makes a very nice "project board".  Breadboard + programmer + basic debugging for ~$30.  What's not to like?

I like the Uno because it's easier to move from one project to another.  Getting the Teensy out of a breadboard is a little annoying.


1 Humans perceive a computer response within two seconds to be reasonable.  At five seconds, humans tend to get impatient and annoyed.  At ten seconds, they tend to get angry.  Past that, the monitor gets a fist, a boot, or a bullet.
Title: Re: Removing the Arduino Bootloader
Post by: westfw on Nov 27, 2012, 01:37 am
Quote
why would you resort to using an Uno when you have a pololu programmer?

It's possible to  fix the programmer-side firmware when it doesn't work :-)
Title: Re: Removing the Arduino Bootloader
Post by: nickgammon on Nov 27, 2012, 01:38 am
@Coding Badly: What are the actual speeds you get? (roughly)

I'm working on a project where I have to upload via ISP (not bootloader) and I am uploading a sketch of 9308 bytes (program memory) or 26208 bytes (hex file size) in 11 seconds, using the Arduino via SD card system I devised.

http://www.gammon.com.au/forum/?id=11638

I don't feel particularly annoyed at waiting that long. That time includes reading the file from SD and checking its integrity, uploading and then verifying the upload. There is an additional overhead of a few seconds to move the SD card from the Mac to the card reader.
Title: Re: Removing the Arduino Bootloader
Post by: Coding Badly on Nov 27, 2012, 04:16 am
@Coding Badly: What are the actual speeds you get? (roughly)


Arduino 1.0.1-rc2
avrdude 5.11

Times are reported by avrdude.  Rate is bytes per second for a write then verify.

Breadboard Uno running 250K baud Optiboot 4.4 with the Pololu programmer as the USB-to-serial converter: 5313.9

Pololu to an ATmega328P running at 16MHz (2M SPI): 4573.5

Teensy 1 running TinyISP to an ATtiny85: 1628.6

Uno running TinyISP to an ATtiny85: 1481.4

Uno running the stock ArduinoISP to an ATtiny85: 352.4

Quote
I'm working on a project where I have to upload via ISP (not bootloader) and I am uploading a sketch of 9308 bytes (program memory) or 26208 bytes (hex file size) in 11 seconds, using the Arduino via SD card system I devised.


846.2 bytes per second. 

Quote
http://www.gammon.com.au/forum/?id=11638


pollUntilReady ... that and fixing heartbeat makes the biggest difference to ArduinoISP.

Quote
I don't feel particularly annoyed at waiting that long. That time includes reading the file from SD and checking its integrity, uploading and then verifying the upload. There is an additional overhead of a few seconds to move the SD card from the Mac to the card reader.


Dude.  You need a programmer.   ;)
Title: Re: Removing the Arduino Bootloader
Post by: nickgammon on Nov 27, 2012, 04:32 am

Dude.  You need a programmer.   ;)


OK, well I plugged in my USBtinyISP into the board under test. It has an Atmega32U4 on it, although it isn't a Leonardo. Since that is the same chip as the Leonardo I selected Leonardo in the Boards menu. (It's actually uploading using ICSP not the bootloader / USB interface).

My time to upload and verify was 45 seconds, compared to 11 seconds using my programmer. Maybe the configuration (in boards.txt) can be improved, but so far that is a lot slower. Using USBtinyISP that was only 215 bytes per second uploaded, whereas with my Uno as a programmer it was 879 bytes per second.

Quote
pollUntilReady ... that and fixing heartbeat makes the biggest difference to ArduinoISP.


Are you suggesting a fixed delay?
Title: Re: Removing the Arduino Bootloader
Post by: Coding Badly on Nov 27, 2012, 04:35 am
Quote
pollUntilReady ... that and fixing heartbeat makes the biggest difference to ArduinoISP.


Are you suggesting a fixed delay?


No no.  The fixed delay is horrible.  The Atmel specification calls for a very conservative (read that as "way too long") delay.  Polling (when the target supports it) is most definitely the way to go.

ArduinoISP uses a fixed delay which is one of the reasons it's so slow.
Title: Re: Removing the Arduino Bootloader
Post by: Coding Badly on Nov 27, 2012, 04:36 am


Dude.  You need a programmer.   ;)


My time to upload and verify was 45 seconds... Using USBtinyISP that was only 215 bytes per second uploaded...


Ouch!  Dude.  You need a better programmer.   :D
Title: Re: Removing the Arduino Bootloader
Post by: sTrider_7 on Nov 27, 2012, 03:43 pm



You don't need to remove the bootloader in order to upload Arduino-less code.


Wait what?

The bootloader is just a piece of software that is loaded in the AVR that allows
a tool (avrdude in this case) to upload code to the AVR. The bootloader itself
is totally independent of anything Arduino.

As shipped the AVR fuses are set to create two sections in the FLASH. Bootloader and application.
The "Arduino" bootloader is small piece of code in the AVR that uses the serial port to update the flash
with the user application (code/program/sketch).
The bootloader runs at reset/powerup if there is no attempt to upload anything, the bootloader
will start the application code.
The application code can be written using any toolset you prefer. The Arduino tools are just one option.

avrdude is a tool that is used upload code into the flash.
avrdude can be used with an ISP programmer to upload code to the flash
avrdude can also use other mechanisms like a serial port that talks to a serial based programmer or to a bootloader.
The Arduino IDE uses avrdude to talk over a serial port to a pre-installed bootloader in the AVR chip.
The newer IDE can also use an ISP progammer to upload code. When an ISP programmer is used,
a bootloader is not used so the flash space used by the bootloader code frees up and can be used
by the application code.

If you don't want to use a bootloader, you will need some sort of ISP programmer.
Like Pico, I recommend getting a USBasp programmer off ebay.
I like the USBasp kk multicopter programmers (about $5-$10 USD) because they come with a 6 pin ISP
cable instead of 10 pin so no adapter is needed.

--- bill


This cleared up a lot of things, thank you Bill.
Title: Re: Removing the Arduino Bootloader
Post by: sTrider_7 on Nov 27, 2012, 03:44 pm

$10 for the pololu programmer is a bargain.


Got that right!

Quote
Coding..., out of curiosity why would you resort to using an Uno when you have a pololu programmer?
Teensy I understand as it should be faster because of the native USB support, but why use Uno?


Upload performance from fastest to slowest...

• Uno with a 250K baud bootloader

• Pololu (very close to the same speed as above)

• Teensy running TinyISP

• Uno running TinyISP

• Teensy running ArduinoISP

• Uno running ArduinoISP (very slow)


The first two are very close to the programming time listed in the Atmel datasheet and are essentially the fastest possible method using SPI.  (Again, I highly recommend the Pololu AVR Programmer.  It was worth the $20 I paid for it (now just $10).)

TinyISP on either hardware is not as fast by a noticeable amount but is still fast enough to fall within the "two second" rule1.

ArduinoISP is just abysmal.


I use the Uno or Teensy because of the amenities that I've added to the Arduino ISP sketch (TinyISP is available here (https://github.com/Coding-Badly/TinyISP)).  It makes a "good enough" programmer with some very basic debugging tools.

I like the Teensy because, inserted in a breadboard, it makes a very nice "project board".  Breadboard + programmer + basic debugging for ~$30.  What's not to like?

I like the Uno because it's easier to move from one project to another.  Getting the Teensy out of a breadboard is a little annoying.


1 Humans perceive a computer response within two seconds to be reasonable.  At five seconds, humans tend to get impatient and annoyed.  At ten seconds, they tend to get angry.  Past that, the monitor gets a fist, a boot, or a bullet.



What bootloader is that exactly, that allows the fast baud rate when using the UNO as ISP?
Title: Re: Removing the Arduino Bootloader
Post by: Coding Badly on Nov 27, 2012, 07:54 pm
What bootloader is that exactly, that allows the fast baud rate when using the UNO as ISP?


The context of your question is difficult to divine from the way you quote.  I assume you are referring to this...

Quote
• Uno running TinyISP


If that is the subject matter then the bootloader is irrelevant.
Title: Re: Removing the Arduino Bootloader
Post by: pico on Nov 28, 2012, 02:00 am

What bootloader is that exactly, that allows the fast baud rate when using the UNO as ISP?


The context of your question is difficult to divine from the way you quote.  I assume you are referring to this...

Quote
• Uno running TinyISP


If that is the subject matter then the bootloader is irrelevant.


I suspect sTrider_7 is actually referring to this

Quote
• Uno with a 250K baud bootloader


which, given the topic context, he think is using the Uno as an ISP and programming w/o a bootloader (rather than comparing the performance of a fast bootloader on the Uno with various ISP programmers.)

Title: Re: Removing the Arduino Bootloader
Post by: cyclegadget on Nov 28, 2012, 10:08 pm

Quote
• Uno with a 250K baud bootloader


Is this a optiboot that is not currently supplied with the Arduino IDE? Is there a link the code for this?


By the way Coded Badly, thanks for the break down of programmer speeds!

Title: Re: Removing the Arduino Bootloader
Post by: john1993 on Nov 29, 2012, 02:29 am
im also fascinated by relative speed of various programming methods. of the half dozen ive tried bootloader beats others hands down. lpt 4 wire slowest (probably due to 1us pc in/out penalty. however unlike coding i notice no difference between 115k and 230k. it would be interesting to see how those baud rates fit in with maximum theoretical atmel burn time. ie is there really any room for improvement over 115kb download of a hex file. btw i never verify because imo theres no point.
Title: Re: Removing the Arduino Bootloader
Post by: Coding Badly on Nov 29, 2012, 03:34 am

Quote
• Uno with a 250K baud bootloader

Is this a optiboot that is not currently supplied with the Arduino IDE?


Yes.  It is not supplied with the Arduino IDE.  The one that comes with the IDE is configured for 115200 baud.


Quote
Is there a link the code for this?


Unfortunately, no.  I don't think I even kept a copy of it.  I built it solely to answer two questions, "Does baud rate make a significant difference?" and "Is 250000 baud reliable?"


The answer to the second question is "yes", 250K baud is reliable.  I suspect 500K is also reliable but I have not performed any testing.


The answer to the first question...

Arduino 1.0.1-rc2, Avrdude 5.11

#1: Uno, Optiboot 3.3, 115200 baud: 2821.8

#2: m328p on a breadboard w/ Pololu as converter, Optiboot 4.4, 115200 baud: 3403.1

#3: m328p on a breadboard w/ Pololu as converter, Optiboot 4.4, 250000 baud: 5313.9


The serial converter makes a difference (#1 versus #2).  The Pololu appears to be a more efficient converter.

The baud rate makes a big difference (especially on the verify pass) (#2 versus #3).


Quote
By the way Coded Badly, thanks for the break down of programmer speeds!


You are welcome.  If I ever have time, I'll write-up the details (and try to remember to post a link here).
Title: Re: Removing the Arduino Bootloader
Post by: sTrider_7 on Nov 29, 2012, 03:44 pm
Thanks for the info Coding Badly :)
Title: Re: Removing the Arduino Bootloader
Post by: Coding Badly on Dec 07, 2012, 08:33 pm

More details and Optiboot compiled for higher baud rates...
http://zygomorphic.com/arduino-tiny/?page_id=249
Title: Re: Removing the Arduino Bootloader
Post by: cyclegadget on Dec 08, 2012, 12:31 am


More details and Optiboot compiled for higher baud rates...
http://zygomorphic.com/arduino-tiny/?page_id=249



Thanks for the link! It is a good read but, it seems that the link for the bootloader files is no longer active. It leads to a page related to signing up to Rowdy Dog Software for information???
Title: Re: Removing the Arduino Bootloader
Post by: Coding Badly on Dec 08, 2012, 01:32 am

Ouch.  Sorry about that.  I'll get it fixed in a minute...

Fixed.
Title: Re: Removing the Arduino Bootloader
Post by: john1993 on Dec 08, 2012, 01:47 am
thanks for that link coding badly. i found it very informative. it explains why i didnt see a huge difference between 115k and 230k. at least not like the 100x-200x usbasp speed improvement i got with the version of avrdude bill perry built for me.

ps too bad he didnt include 57k. that might have been interesting too.
Title: Re: Removing the Arduino Bootloader
Post by: Coding Badly on Dec 08, 2012, 01:52 am
thanks for that link coding badly.


You are welcome.

Quote
it explains why i didnt see a huge difference between 115k and 230k.


Should have seen some improvement (up to 24%).

Quote
at least not like the 100x-200x usbasp speed improvement i got with the version of avrdude bill perry built for me.


Skipping FFs?
Title: Re: Removing the Arduino Bootloader
Post by: john1993 on Dec 08, 2012, 01:57 am
yeah. it has already saved me literally man-days of staring at that cursed progress bar.

as far as the baud rate, more like 20% in my case. the difference between 5sec and 6sec is not noticeable to me.
Title: Re: Removing the Arduino Bootloader
Post by: cyclegadget on Dec 08, 2012, 03:15 am

Thanks Coded Badly!

   I installed the 500,000 baud bootloader on two Uno's. The bootload went perfectly, and I couldn't be happier!  I loaded the blink without delay sketch in a couple seconds! I know that is a small sketch but, it did seem to load a lot faster.  If one's and zero's made noise, the best way to describe it was WAAAMMM done!