User Tools

Site Tools


arduino:arduino_without_a_bootloader

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
arduino:arduino_without_a_bootloader [2020/01/04 02:46]
mithat [Getting your bootloader back]
arduino:arduino_without_a_bootloader [2020/06/22 19:49] (current)
mithat old revision restored (2020/02/27 18:23)
Line 4: Line 4:
 One of the things that simplifies Arduino development is its [[https://www.arduino.cc/en/Hacking/Bootloader|bootloader]]. A bootloader is a small program that resides at the code start point of a microcontroller and manages what happens immediately on startup or reset of the device. One of the things that simplifies Arduino development is its [[https://www.arduino.cc/en/Hacking/Bootloader|bootloader]]. A bootloader is a small program that resides at the code start point of a microcontroller and manages what happens immediately on startup or reset of the device.
  
-In the case of the Arduino, the bootloader is used to let you upload new programs over a standard serial interface. This is done in conjunction with the serial-to-USB converter included on the Uno, Nano, and others, or with an external serial-to-USB converter in the case of the Pro Mini and similar. When you power up or reset one of these Arduino boards, the bootloader starts running and checks to see if a new program is coming in on the serial line. If it is, it writes the new program to the "user program" area of flash memory, that is, the area of flash not reserved for the bootloader. If no new program is incoming, it jumps execution to the start of the "user program" area.+In the case of the Arduino, the bootloader lets you upload new programs over a standard serial interface. This is done in conjunction with the serial-to-USB converter included on the Uno, Nano, and others, or with an external serial-to-USB converter in the case of the Pro Mini and similar. When you power up or reset one of these Arduino boards, the bootloader starts running and checks to see if a new program is coming in on the serial line. If it is, it writes the new program to the "user program" area of flash memory, that is, the area of flash not reserved for the bootloader. If no new program is incoming, it jumps execution to the start of the "user program" area.
  
-But a bootloader isn't the only way to program the microcontrollers on these boards. Instead, you can use an external programming device (a.k.a, //programmer//) that connects your computer to multi-function programming pins on the microcontroller. In fact, the bootloader is itself nothing more than a small program that somehow has to get itself into the microcontroller's flash storage. Programming factory-fresh ATmega microcontrollers with an Arduino bootloader is typically done with such a programmer.+But a bootloader isn't the only way to program the microcontrollers on these boards. Instead, you can use an external programming device (a.k.a, //programmer//) that connects your computer to multi-function programming pins on the microcontroller and uploads code directly into flash storage. In fact, the bootloader is itself nothing more than a small program that needs to be written into the microcontroller's flash. Programming factory-fresh ATmega microcontrollers with an Arduino bootloader is typically done with such a programmer.
  
-So while it's entirely possible to program many Arduino boards without using a bootloader, you would have to tie up one USB port on your computer for programming and another for serial communication. You would also need separate hardware for programming the board and for running serial communications. So for this and other reasons, the bootloader is a great convenience.+So while it's entirely possible to program many Arduino boards without using a bootloader, you would have to tie up one USB port on your computer for the programmer and another for serial communication (if you are using serial communication). You would also need separate hardware for both of these. So for this and other reasons, the bootloader is a great convenience.
  
 ===== Cursed is the bootloader ===== ===== Cursed is the bootloader =====
  
-There are times when you might want to bypass the convenience a bootloader offers and program your microcontroller directly. The most common reason is that you want to be able to use //all// of the available flash storage for your program. Bootloaders in ATmega chips are stored in the same flash memory as "user programs." While the amount of required memory is small---for example, the [[https://github.com/Optiboot/optiboot|Optiboot]] bootloader used in common Arduinos is a mere 512 bytes---sometimes you just need to use every last byte of flash on the micro for your program.+In spite of the convenience a bootloader offers, there are times when you might want to forego this and program microcontroller directly. The most common reason is that you want to be able to use //all// of the available flash storage for your program. Bootloaders in ATmega chips are stored in the same flash memory as "user programs." While the amount of required memory is small---for example, the [[https://github.com/Optiboot/optiboot|Optiboot]] bootloader used in common Arduinos is a mere 512 bytes---sometimes you just need to use every last byte of flash on the micro for your program.
  
-Another reason to not use a bootloader is that your project'startup time is critical. The Arduino bootloader introduces about a second and a half delay between power-up/reset and running your program. Without bootloader, your code starts running almost instantaneously.+Another reason to not use a bootloader is that the startup time is critical. The Arduino bootloader introduces about a second and a half delay between power-up/reset and running your program. Without the bootloader, your code starts running almost instantaneously.
  
 Yet another situation where you might not want a bootloader is if you have lowered or disabled the [[https://microchipdeveloper.com/8avr:bod|Brown-Out Detection]] so you can use every last ounce of battery juice in a portable application.((Disabling brown-out detection or lowering the threshold of detection involves [[arduino:atmega328p_arduinos_and_custom_fuse_settings|custom fuse settings]] and is beyond the scope of this article.)) Without brown-out detection, the erratic system behavior you can expect at very low voltages could cause a program jump to an arbitrary part of the code in flash storage. If you use a bootloader, this could be a jump into bootloader code. This then has the potential to start a cascade of events that leads to the bootloader overwriting your program code. If you're not using a bootloader, the code you have programmed can't be corrupted this way.((Not using a bootloader in this situation will keep the program memory form becoming corrupted, but EEPROM and other things can still be battered when the voltage falls below the minimum for a given clock frequency. The risks are described more completely in the [[http://ww1.microchip.com/downloads/en/Appnotes/doc1051.pdf|AVR180: External Brown-out Protection]] application note.)) Yet another situation where you might not want a bootloader is if you have lowered or disabled the [[https://microchipdeveloper.com/8avr:bod|Brown-Out Detection]] so you can use every last ounce of battery juice in a portable application.((Disabling brown-out detection or lowering the threshold of detection involves [[arduino:atmega328p_arduinos_and_custom_fuse_settings|custom fuse settings]] and is beyond the scope of this article.)) Without brown-out detection, the erratic system behavior you can expect at very low voltages could cause a program jump to an arbitrary part of the code in flash storage. If you use a bootloader, this could be a jump into bootloader code. This then has the potential to start a cascade of events that leads to the bootloader overwriting your program code. If you're not using a bootloader, the code you have programmed can't be corrupted this way.((Not using a bootloader in this situation will keep the program memory form becoming corrupted, but EEPROM and other things can still be battered when the voltage falls below the minimum for a given clock frequency. The risks are described more completely in the [[http://ww1.microchip.com/downloads/en/Appnotes/doc1051.pdf|AVR180: External Brown-out Protection]] application note.))
Line 21: Line 21:
  
 ===== Hardware ===== ===== Hardware =====
-You're going to need a device you want to program (e.g., an Arduino board) and a device with which you will do the programming (a.k.a., the programmer). You can see the complete list of programmers supported by the Arduino framework by looking at the list available under //Tools > Programmer: "xxxx"//. At the time of writing this, the available options were:+To program an ATmega328P without a bootloader, you're going to need a device you want to program (e.g., an Arduino board) and a device with which you will do the programming (i.e., the programmer). You can see the complete list of programmers supported by the Arduino framework by looking at the list available under //Tools > Programmer: "xxxx"//. At the time of writing this, the available options were:
  
 {{ :arduino:arduino-programmer-options.png?direct |}} {{ :arduino:arduino-programmer-options.png?direct |}}
Line 27: Line 27:
 That's a lot of options! That's a lot of options!
  
-Below, I cover a few cases to get you started. Most of these use the USBtinyISP.((As near as I can tell, the original source of the USBtinyISP design is Dick Streefland's [[https://dicks.home.xs4all.nl/avr/usbtiny/|USBtiny]]. Additional development and refinement leading to the [[https://learn.adafruit.com/usbtinyisp|USBtinyISP]] was done by Limor Fried. The software and hardware are open source (GPL and CC BY-SA 2.5), leading to many clones and derivatives.)) Owing to its low cost and wide availability, this is one of the most popular options. The [[https://learn.adafruit.com/usbtinyisp|original USBtinyISP]] is available sporadically through Adafruit, and clones derived from the open source design similar to [[https://www.ebay.com/itm/USBTiny-USBtinyISP-AVR-ISP-programmer-for-Arduino-bootloader-Meag2560-uno-r3/382580265905|this one]] are widely available at auction sites, Amazon, Banggood, etc. All my testing was done using USBtinyISP clones from two different suppliers.+Below, I cover a few cases to get you started. Most of these use the USBtinyISP.((As near as I can tell, the original source of the USBtinyISP design is Dick Streefland's [[https://dicks.home.xs4all.nl/avr/usbtiny/|USBtiny]]. Additional development and refinement leading to the [[https://learn.adafruit.com/usbtinyisp|USBtinyISP]] was done by Limor Fried. The software and hardware are open source (GPL and CC BY-SA 2.5), leading to many clones and derivatives.)) Owing to its low cost and wide availability, the USBtinyISP is one of the most popular options. The [[https://learn.adafruit.com/usbtinyisp|original USBtinyISP]] is available sporadically through Adafruit, and clones derived from its open source design along the lines of [[https://www.ebay.com/itm/USBTiny-USBtinyISP-AVR-ISP-programmer-for-Arduino-bootloader-Meag2560-uno-r3/382580265905|this one]] are widely available at auction sites, Amazon, Banggood, etc. All my testing was done using USBtinyISP clones from two different suppliers.
  
 The original USBtinyISP has a built-in 3x2 IDC cable that carries the signals needed for ISP (in-system programming). It also has a 5x2 IDC cable that carries the same signals but in a different layout. The original USBtinyISP has a built-in 3x2 IDC cable that carries the signals needed for ISP (in-system programming). It also has a 5x2 IDC cable that carries the same signals but in a different layout.
  
-If you are using a USBtinyISP clone, there's a good chance it has a keyed 3x2 ISP header in addition to a keyed 5x2 ISP header. The following assumes this is the case and also that you have a 3x2 keyed IDC cable. Such a cable is often included with USBtinyISP clone purchases. Finally, I'm assuming it works at 5VDC, which is the defacto standard.+If you are using a USBtinyISP clone, there's a good chance it has a keyed 3x2 ISP header in addition to a keyed 5x2 ISP header. The following assumes this is the case and that you have a 3x2 keyed IDC cable. Such a cable is often included with USBtinyISP clone purchases. Finally, I'm assuming it works at 5VDC, which is the defacto standard.
  
 Depending on the board you are programming, you may need to use Dupont wires (M to F or F to F depending on your USBtinyISP) instead of the IDC cable. Depending on the board you are programming, you may need to use Dupont wires (M to F or F to F depending on your USBtinyISP) instead of the IDC cable.
arduino/arduino_without_a_bootloader.1578105991.txt.gz · Last modified: 2020/01/04 02:46 by mithat