Atmega32u4 bootloaders, HWB pin, USB programming - Page 1
Forum section: electronics / general

author: yeah_indeed
author_rank: Contributor
timestamp: December 10, 2016, 06:08:10 pm
content: Hello everyone,At the moment I am working on a project with the Atmega32u4. Unfortunately I am a bit confused about the programming steps and necessary voltages at certain pins. I am planning to have an ISP connector on the board to which I connect my AVR programmer to flash the hex file. But does that mean I do not need a bootloader? Also, I read that for entering the bootloader it is necessary to pull down the /HWB pin, do I have to connect the /HWB pin always to ground or have a pull up and a button to ground on that pin? Same question about /RESET. Last but not least, the Atmega32u4 supports USB natively and also programming over USB. Again; do I need a bootloader for that and could I flash that via ISP?This is all a bit new so I hope someone can help me clear up my confusion. Thank you!

author: Skashkash
author_rank: Regular Contributor
timestamp: December 10, 2016, 06:29:51 pm
content: Hi,The 32u4 ships from the factory with the DFU USB bootloader already programmed into the top pages of flash memory. The fuses are also programmed to run the USB bootloader when the HWB button is grounded at power up or reset. Be aware that you must have the correct frequency crystal connected to use the USB boot loader.You can always use the ISP connector to program the 32u4 with or without the bootloader code on the chip. But if you erase or otherwise overwrite that atmel bootloader code, then that ability is gone. You then need to always use ISP to program the chip (unless you re-program a bootloader into the chip via isp).Be sure to read up on the function of the fuses in the datasheet.Also note, finding a .hex file of the atmel usb bootloader to restore the chip to the way it came from the factory might be difficult (it used to be).

author: yeah_indeed
author_rank: Contributor
timestamp: December 10, 2016, 06:38:53 pm
content: Quote from: Skashkash on December 10, 2016, 06:29:51 pmHello and thank you. So if I pull down or ground /HWB on my board then it's OK, also if I decide to overwrite the bootloader later with ISP?

author: Skashkash
author_rank: Regular Contributor
timestamp: December 10, 2016, 07:20:09 pm
content: Quote from: yeah_indeed on December 10, 2016, 06:38:53 pmIf you ground the HWB button with the chip configured from the factory it will always run the USB bootloader on power up / reset.You can change the fuses to disable this default behavior. But unless you are very short on IO pins, it's usually best to leave this pin with just a pull up resistor so you can make use of it later. I tend to try to dual use the pin by connecting a front panel push button to it. This way if the button is held down during power up the bootloader runs, otherwise it's just a regular push button during normal operation.If you use ISP to erase the chip you will lose the USB boot loader. It's up to you and your design if that's an issue. But it can be replaced via ISP if you have a bootloader .hex file from atmel or an alternative bootloader (like lufa).You tend to want to use ISP during development because it's faster. When you ship the finished product, the builtin USB bootloader can be darned convenient.

author: yeah_indeed
author_rank: Contributor
timestamp: December 10, 2016, 07:53:19 pm
content: Quote from: Skashkash on December 10, 2016, 07:20:09 pmThanks again for the nice overview. It's not a problem if I have to continue using ISP, moreover I am completely not short on IO so I'll use a pull up on HWB and connect a grounded push button to it as you mentioned. I see Atmel makes the hex files of the DFU bootloaders available so I can try and work with that if necessary. Thank you for the explanation!

author: stj
author_rank: Super Contributor
timestamp: December 11, 2016, 01:32:28 am
content: Quote from: Skashkash on December 10, 2016, 06:29:51 pmi have that if anybody wants it.it's on Atmel's site, but took forever to find!

author: yeah_indeed
author_rank: Contributor
timestamp: December 11, 2016, 12:51:53 pm
content: Quote from: stj on December 11, 2016, 01:32:28 amWhen I searched for it yesterday I found it very easily, where did you search? For reference, it is on the product page of the 32U4 (http://www.atmel.com/devices/atmega32u4.aspx) under the PDF datasheet for the DFU bootloader where it says "Download the USB DFU bootloader hex files here."

author: stj
author_rank: Super Contributor
timestamp: December 11, 2016, 01:40:51 pm
content: i think i looked under applications or something.

author: Skashkash
author_rank: Regular Contributor
timestamp: December 11, 2016, 04:56:13 pm
content: The factory restore bootloader .hex files for some of the usb devices used to be very difficult to find. (at least as of a couple of years ago)Looks like atmel updated the support pages. That's helpful to know.

author: unixb0y
author_rank: Contributor
timestamp: March 04, 2021, 03:53:59 pm
content: Sorry for replying to an old thread, but I think it fits in here really well.So, I am also trying to program a 32U4, but it's 32U4-MU and I think it actually has no bootloader on it. I replaced it on an already existing PCB that is setup in a way that if you press a button and boot the circuit up, the micro goes into programming mode and is instantly visible as such in my operating system.Since it doesn't behave this way with the new chip, I am pretty sure there is no bootloader on it.I will need to flash the "ATMega32U4-usbdevice_dfu-1_0_0.hex" right?

author: Skashkash
author_rank: Regular Contributor
timestamp: March 06, 2021, 10:07:57 pm
content: Nothing like picking up a five year old thread like it was yesterday.No idea if Atmel stopped shipping 32u4s with the dfu bootloader installed.But you need to confirm a few things on the board you are putting the new chip onto.It's possible the orig board had a custom bootloader installed on it that replaced the factory bootloader.Can you confirm the right freq crystal is used?Can you confirm the HWB pin is being used to put the chip into bootloader mode?If that's the case, and you have access to the ISP pins then yes, you can reflash the chip with the atmel DFU bootloader.(and make sure the fuses are correct)