REFRESHING A BOOTLOADER

INTRODUCTION

Programmer

The Arduino Micro uses a single ATMega32u4 chip that manages USB communications and executes sketch code. The memory is split into two partitions, one for the bootloader software and the remainder for the sketch. It appears that, for a variety of reasons, the bootloader memory can become corrupt and the symptom is that it does not respond when connected to a PC or it continually changes USB COM port number. When it is not recognised at all, Windows PCs show the "USB device not recognized" error and set the device as "unknown". Using the lsusb command in Linux shows that nothing appears to be connected. However, the Micro may continue to run whatever sketch is loaded, but new sketches cannot be downloaded. Problem!

RESOLVING THE PROBLEM

Programmer

The only way to rectify this problem is to reload the bootloader software but as the Micro is no longer able to communicate using USB, that has to be done using the In-Circuit Serial Programming (ICSP) pins and a separate programmer. You can buy separate programmers on the Internet but a better solution for me was to use another Arduino, in this case an Uno. The steps you need to follow are laid out briefly here and in more detail in the next section:

  1. Connect the Micro to the Uno and the Uno to your PC
  2. Use the Arduino IDE to compile and load the ArduinoISP sketch
  3. Set the IDE settings for the Uno and compile the sketch
  4. Set the IDE settings for the Micro
  5. Download the bootloader program

STEP BY STEP

The procedure below applies specifically to using an Uno as a bootloader program to fix a broken Micro. Since the Micro and Leonardo are very similar it may work for the Leonardo too. If you have different combinations of boards, the process will be similar but please refer to the documentation for your board and remember to set the board parameters accordingly.


Step 1

Connecting up

Connect the Micro to the Uno and the Uno to your PC as shown here. Do not connect the USB on the Micro to your PC, it will be powered by the Uno.


Step 2

Locating the ArduinoISP sketch

Open the ArduinoISP sketch from the Examples that are provided with the IDE.


Step 3

Compiling the bootloader sketch ArduinoISP

Change the settings in the IDE as shown here: you are programming the Uno with the bootloader sketch and using the ArduinoISP to load it. Your COM port will most likely be different. Compile and upload the sketch.


Step 4

Getting ready to burn the bootloader

Change the settings in the IDE as shown here: you are now targetting the Micro so you need to specify which bootloader file the IDE should pass to the Uno in order to load into the Micro. The Arduino is the programmer so set it to Arduino as ISP.


Step 5

Burning the bootloader

Now, under Tools, click Burn bootloader. This will take a while, perhaps 90s or so. The RX and TX LEDs will show the data transfer activity and when the transfer has finished the LED on the Micro should be blinking slowly and the message "Done burning bootloader." will be displayed in the IDE.

Success message


The process is now complete and you can disconnect and use your Micro again.


NOTES

If you wish to keep the Uno as a permanent rescue device, you can fix future Micro problems by connecting up and starting at Step 4.

The bootloader sketch, as provided, has some additional features that you might find useful. By connecting three LEDs with suitable resistors (something like 330Ω or 470Ω) to pins 7, 8 and 9 the sketch will show when the Uno is communicating with the Micro, an error condition and a heartbeat to show the programmer is running. This is all documented in the sketch's source code.

Most AVR chip models can reserve a bootloader region, of perhaps 256B to 4KB, where this re-programming code can reside. When the processor is reset, the bootloader runs first and checks whether to download a new sketch from the IDE and replace the current sketch or to jump to the main sketch that is already programmed.

If you buy blank ATMEGA32u4 processors then these will really be blank and you will need to load a bootloader program before you can use them with the Arduino IDE; just follow the steps above but you will need to put the processor in a suitable DIL socket and wire it up correctly or put it in an Arduino Uno or some other board with a DIL socket.

ARDUINO IDE SETTINGS

Arduino BoardProgrammer
Arduino/Genuino UnoArduinoISP
Arduino/Genuino MicroAVR ISP
3rd party "Micro" or "Nano" using CH340 and ATmega328PAVRISP mkII