How to flash Arduino UNO bootloader

Post Reply
User avatar
SevenZero
Major
Major
Posts: 263
Joined: Sun Nov 01, 2009 8:37 pm

How to flash Arduino UNO bootloader

Post by SevenZero » Thu Jan 03, 2013 12:02 am

This guide is for programming the Arduino UNO bootloader through Atmel ICSP USB programmer. If you have a diffrent programmer such as STK500, that only requires a different interfacing.

It is a known fact that it is a bit tricky to program the Arduino bootloader. But if you follow these instructions correctly, it will become a piece of cake. It's always easy when you know it.

I assume that you have Atmega328P-PU (or even the AU SMT version) with 16MHz crystal.

First of all, download the Optiboot which is a special efficient variant of Arduino bootloader from http://code.google.com/p/optiboot/. When I'm writing this article, the latest version is 4.4. There are so many advantageous in using this bootloader. One of the most interesting thing is that it only consume 2KB on your flash space leaving more room for your sketches.
  1. Connect the Arduino board to your ICSP programmer.
  2. On some ICSP programmers such as STK500, the communication rate must be set to less than 1/4 of the chip's running frequency.
  3. Read the signature of the chip and confirm it to be Atmega328p [0x1E 0x95 0x0F]
  4. Once signature is read, erase the chip. This clears out the flash area and clears out the Fuse and Lock bits
  5. Read the ‘Lock’ bits. It should read 0xFF. Note that it has also been noted that these bits can be 0x3F. That is because the upper 2 bits do not exists and are treated as ’1?. Hence the bit combination would be 1111 1111 => 0xFF. NOTE: Never try to mess with the lower 2 bits (bits 1 & 0). These bits LB2, LB1 can actually lock out the programming of the Flash and the eeprom memory, ‘bricking’ the chip!!. They are used for production to prevent you from accessing the firmware. They should be left as 11
  6. Burn the ‘optiboot_atmega328.hex’ downloaded from above link. Read back and verify
  7. Now the lock bits. set them to 0x0F (which means BLB12, BLB11 or lock[5:4] = 00. This will prevent bootloader to be modified by itself using SPM). Burn the lock bits. Read back. They would be 0xCF. That is because the upper 2 bits are always 1.
  8. Fuse bits settings
    • Extended Fuse byte
      Only bits [2:0] define the BOD. All others are ’1?. So if no BOD is needed, this can be 0xFF
    • High fuse byte
      SPIEN(bit 5) = 0, BOOTRST(bit 0) = 0, BOOTSZ1, BOOTSZ0 (bits 2,1) are 11 which gives 256words for the bootloader. That is 256words * 2 = 512bytes for the bootloader (because the flash memory organization is x16 not x8). That should correctly fit the optiboot bootloader which is 512 bytes!.All other bits are 1 . So the High fuse byte = 0xDE
    • Low fuse byte
      CKDIV8(bit 7) = 1, For ceramic resonator SUT[1:0] = 01 and CKSEL[3:0] = 0110. All other bits are 1. So Low fuse = 0xD6
    • So your fuse settings are 0xFF 0xDE 0xD6. Burn them. Read back and verify
You now have the Optiboot bootloader on your Atmega328p. Download the latest Arduino binaries, select the board as ‘Uno’, select the correct COM port and you should be good to go!
Post Reply

Return to “Arduino”