Go Down

Topic: Made My Own Arduino Board - ATMEGA32U4 - Bootloader Questions (Read 25774 times) previous topic - next topic


Fm, can you advise of a suitable programmer for the ATMEGA32U4 chip (assuming no bootloader)?
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics


Sep 28, 2012, 12:48 am Last Edit: Sep 28, 2012, 12:49 am by fm Reason: 1
Sorry to answer so later, its been a looong day. For that board and layout you should be more than fine downloading the Leonardo bootloader. If you use the Arduino IDE it will write the fuses for you.
Let me know if it worked.
@Nick - I recomend the AVR ISP MkII from Atmel and any old Arduino should do the trick too. The moded AVR ISP mkIi is the one I use to flash the Leonardo bootloader to all the vinciDuinos. If you order from Digikey as part of something else you save on shipping costs.


Thanks, fm, for the encouraging remarks. I actually have an AVR ISP MkII to hand, but hadn't got it to work as a PDI programmer before. After downloading the (fairly hefty) Atmel Studio 6, I got it to work on my Leonardo.

@MrBEEF: Below is the firmware from my Leonardo. Unfortunately Atmel Studio writes out 16-byte lines (they start with hex 10) and the firmware on the page below is in 32-byte lines (they start with hex 20):

However a few spot checks at addresses above 0x7000 appear to indicate the code is the same (I only checked a few bytes but you could do a more rigorous check).



My firmware:


The first part will definitely be different as I have one of my sketches loaded on it, but the part past 0x7000 should be the bootloader.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics


Hey Everyone,

So here is the scenario for everyone's benefit:


1) download winavr
2) edit and compile the caterina bootloder files in the arduino directory, using the makefile, and editing the .h and .cpp to your own custom needs, use winavr to compile and generate the .hex for your bootloader.
3) using an isp such as JTAGICE MKII or a different ISP, use Atmel studio to program your .hex file into your device, using jtag or the SPI

4) Use fuse and circuit reference :

fuse references:


circuit for isp:

Device programming can be found under the tools menu in AVR studio. Interface is pretty self explanatory. Change fuses, remove lock bits, go to the memories section browse for .hex that one generates using the caterina files and WinAVR. Edit the .cpp and .h, and the USB driver .inf for leonardo(if you have ATMEGA32U4), so it doesnt say leonardo and so on.








Hi Nick,

However, all those use SPI programming, whereas your chip uses PDI. Now I don't have a hardware PDI programmer, and although I have an AVR Dragon this model doesn't (seem to) support the PDI interface.

I attempted to make a PDI programmer using a Uno, but the documentation for the protocol is somewhat sparse, and I haven't succeeded yet.

I had a look in the data sheet, if I interprete things right, PDI is just a term used in the data sheet for ICSP. But it uses plain SPI underneath: see the block diagram of the chip: port B is connected to the spi block which in turn is connected to the programming logic.
The data sheet uses PDI and PDO as signal names because not on all packages they are on the same pins as the MOSI and MISO signals used when not in programming mode. (but on the atmega32u4 they are)

If I had one, I could download the firmware from my Leonardo, and confirm whether or not it agrees with the hex file we were discussing.

Seen the above, you can just connect an arduino running ArduinoISP, to the atmega32u4 and download it as follows:

    avrdude -P/dev/ttyUSB0 -b9600 -cavrisp -pm32u4 -U flash:r:leo.hex:i

I tried it (my leo serving as atmega32u4), it results indeed in a hex file of 76KB.

That is why fm suggested you can use any "old" arduino as programmer. BTW, in mean time you can also use a "new" arduino: the leonardo (so probably also a vinciduino).


Hmm. The datasheet for the ATmega32U4 says (page 360):

Both the Flash and EEPROM memory arrays can be programmed using a serial programming bus while /RESET is pulled to GND. The serial programming interface consists of pins SCK, PDI (input) and PDO (output). After /RESET is set low, the Programming Enable instruction needs to be executed first before program/erase operations can be executed.

If it used SPI it would mention MOSI, MISO, SCK.

Mind you, the documentation is a bit obscure on this point. I had been looking at the ATxmega32A4U which has this note about programming:


The XMEGA doesn't have the SPI based In-System Programming (ISP) interface for external programming, which has been used for megaAVR. Nor does it have the debugWIRE interface. These have been replaced by a two wire "Programming and Debugging Interface" (PDI). This interface can, as the name indicates, be used for both programming and debugging.

That appears to suggest that SPI and PDI programming are different.

However the documentation for the ATmega32U4 does seem to be closer to the SPI programming model.

A bit more testing reveals that despite labelling the pins as SCK, PDI, PDO, the chip can indeed be programmed using SPI as you said. Ah well, you learn something new every day. I've amended my "chip detector" and "hex uploader" sketches to handle the signature for that chip.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics



I haven't read that page in a while - does the hex uploader set the fuses for a '328P to an Uno-like state if uploading to a totally blank chip?
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.


If you upload a file, which appears to be a bootloader (judging by the address) it sets the fuse for the bootloader size, and sets the "boot into bootloader" fuse bit. Otherwise it clears the "boot into bootloader" fuse bit. The other fuses are unchanged, however there is a "F" (fuse) action which lets you set any of the fuses to any value you choose.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics


Now that I look at the app note for the AtXmega again, they are doing a different thing than with the Atmega. The PDI interface is 2-wire, not 3-wire.

They have PDI_DATA and PDI_CLK instead of SCK, PDI and PDO.

On those chips PDI_DATA is a bi-directional interface, connected via a couple of resistors. See the app note AVR1612 (doc8282.pdf) which mentions connecting TxD and RxD both to the PDI_DATA pin via a 220R resistor in series (each). Like this:

Clearly this is different to the normal SPI interface.

It's a rather confusing naming of two different interfaces with the same name "PDI".
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics


I simply use arduinoISP to burn a custom leonardo bootloader, its really no different then bootloading any other Arduino.
You can also use DFU if it hasnt been overwritten. For reference Caterina contains the Blink sketch as well, this makes sure the Leonardo shows up as its designated PID instead of the sketch load PID, and is why it seems like a rather large bootloader file.

Go Up