Burning the Optiboot Arduino bootloader into the Atmega328p

I have some arduino boards (all of them are the RBBB ones from moderndevice & Jeelabs). But rather than buying the kits with the atmega programmed with the arduino firmware, i just bought the boards and populated them. Then came the part of burning the arduino firmware (bootloader) into the atmega328p. I have an Stk500 Atmel programmer. So i figured how hard can it be. Turns out it is very confusing if not hard.

I guess the most confusing part is figuring out which bootloader to use. The latest and greates is the ‘optiboot’ that is supposed to allow faster upload speeds and occupy less space (about 2kb). So that should give more space for your applications.

So after lots of experimentation and hair-pulling, i have these steps that should get the optiboot bootloader into the arduino using your favorite burner (Stk500 in my case) and software (AVR studio4)

Assumptions:

  1. The chip used is Atmega328p
  2. You are using a 16mhz crystal or resonator
  3. Using arduino-0021 or higher
  4. You are planning on burning the Optiboot (v3 or latest) bootloader
  5. You are using an ‘unbricked’ chip. Which means that the lower 2 lock bits are ’11’

All the above should give you an arduino ‘UNO’. So here are the steps

  1. Hook up the Atmega for ISP or Parallel burning operation with your burner (STK500 supports ISP and parallel high voltage programming)
  2. Confirm your ISP settings or HVP settings. If using ISP, the frequency should be 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.  !!BIG NOTE!!. On no account 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 github. 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

And that is it!!!. 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!

Advertisements
About

I am a computer engineer living in the beautiful city of Austin,TX. While my day job is designing computer chips, I love to dabble in woodworking, metalworking, r/c and electronics.

Tagged with: , ,
Posted in Electronics

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Archives
Categories
%d bloggers like this: