Archive

Archive for January, 2013

Burning Arduino Bootloader

January 11, 2013 1 comment

EDIT: I had written this a while back but never published. There must’ve been more things I wanted to write, but it’s been over a year and I simply forgot what I wanted to add. So here you go…

 

If you bought one of many Arduino clones out there, chances are, the bootloader is not burned into the chip. If that’s the case, you can’t use it out of the box with the Arduino IDE and you won’t be able to upload those sketches. Now, you can only burn the bootloader firmware using the ICSP programmer such as avrispmkII.

It was a bit of a pain to get it working. In the end, I had to drive the avrispmkII from linux machine using the Makefile provided with the latest Arduino v1.0 download. Under the directory hardware/arduino/bootloaders/atmega, I had to make some minor changes to the source code ATmegaBOOT_168.c.

The changes required in this file can be found at this following url: http://code.google.com/p/arduino/issues/detail?id=152. Basically, you modify the #if defined preprocessor directive to use the macros that are defined.

Once the source is modified, just run “make atmega328_isp“, which will compile the bootloader source code, create the hex, and then proceed to upload the .hex file into atmega328 chip using the ICSP programmer. The Makefile issues these avrdude commands to setup the fuse bits and then upload the hex.

# fuse settings
avrdude -c stk500v2 -p atmega328p -P usb -b 115200 -e -u -U lock:w:0x3f:m -U efuse:w:0x05:m -U hfuse:w:0xDA:m -U lfuse:w:0xFF:m

# burns the bootloader and then locks it
avrdude -c stk500v2 -p atmega328p -P usb -b 115200 -U flash:w:ATmegaBOOT_168_atmega328.hex -U lock:w:0x0f:m

The second command takes a while to run. And it also complains with errors like:

avrdude: stk500v2_recv_mk2: error in USB receive

You just have to wait and let it finish.

Once that’s done, you’ll have the bootloader burned onto the atmega328p chip, and will be able to use the Arduino IDE to upload the sketches onto it.

Categories: Uncategorized