Getting a 32u4 back into DFU. Doable as designed?

Go To Last Post
12 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Folks,

 

My apologies for the newbie question, and if this isn't quite the right forum. 

 

I have a custom-designed board based on an ATmega32u4. When plugged in, it initially shows up as ATmega32u4DFU.  I specified a driver, uploaded a program using FLIP, and it runs... but now it shows up as an Arduino Leonardo, and I can't upload code anymore using FLIP or dfu-programmer. I'm assuming that if I want this to be anything but a brick running Blink code, that I need to get it back into DFU mode.

 

One possible issue is that HWB is tied directly to ground on this board. See the attached partial schematic. My limited understanding (and maybe wrong) is that HWB has to be pulled high during reset to bring it back to DFU.

 

My question is, is there any way to get this back into DFU mode, or any way to replace the code on the board?  Alternatively, is there a way to avoid doing what I've managed to do? I'm hesitant to repeat myself with my two remaining prototypes until I have a better handle on what I've done and how to manage it. 

 

Partial schematic

 

~ A

<p>~ Athyrio</p>

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You are right about HWB (assuming the fuse is activated) it is the pin that says "start in the boot loader " (DFU) rather than "start app". It was a very unwise decision to hardwire the HWB pin if that fuse is activated. Alternative might be to use JTAG/ISP to reprogram the fuses so BOOTRST is active so it starts into DFU every time.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I suppose I could do that... if they had designed in a header. Crap!

 

So, if I'm understanding correctly, what I have here is a an embedded device that can be programmed once. After that, SOL?

 

A commonly asked question, but one where I've seen no clear or consistent answer:  Is there no way to get this thing to play nicely with Arduino IDE, as a convenience, as a real Leonardo does?

 

~ A

<p>~ Athyrio</p>

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No the idea of the HWB fuse and pin is that you activate the fuse then in the electronic design you put a normally open tact switch (could be a jumper) on the HWB pin. 99.9% of the time you want the AVR to power up and enumerate as whatever class the application performs (HID, CDC, MIDI, MSD, printer, whatever). In fact you very specifically DON'T want it to enumerate as DFU as that would just "get in the way" and the majority of the time you'd want it to immediately terminate DFU operation then restart as the application device. So HWB facilitates this. Only on the very rare occasion you do want to reprogram with DFU+Flip do you power on woth the HWB button held (or jumper made). This time the chip powers on into the bootloader not the app where it enumerates as DFU and then it can be reprogrammed. Like I say, if you want you could set BOOTRST and get DFU at every power on but then you need something to say "but I don't want bootloading this time" (maybe an EEPROM flag?)
.
PS like so many threads like this I do wonder how people get as far as committed hardware layouts before they've actually read about and understood the operation of the chip. This programming/startup thing is probably something you should have prototyped first (which is why eval boards are often a good place to start)

Last Edited: Tue. Aug 14, 2018 - 05:50 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Athyrio wrote:
Is there no way to get this thing to play nicely with Arduino IDE, as a convenience, as a real Leonardo does?
Yes over USB CDC with the bootloader as a variant of Dean Camera's LUFA USB CDC bootloader.

https://github.com/arduino/ArduinoCore-avr/blob/master/bootloaders/caterina/Caterina-Leonardo.txt

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

also over USB HID with the Arduino IDE variant Teensyduino via the 0.5KB PJRC HalfKay bootloader :

PJRC

PJRC Store

Pre-programmed ATMEGA32U4 Chip for DIY Teensy Projects

https://www.pjrc.com/store/ic_atmega32u4_tqfp.html

 

not Arduino : there's another 0.5KB mega32U4 bootloader with a Python loader :

https://github.com/rrevans/ubaboot

USB bootloader for atmega32u4 in 512 bytes

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If it’s really behaving like a Leonardo, it should show up as a com port, and reset back to the bootloader if you set the com port to 1200bps.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Indeed. I flashed it with the SparkFun Leonardo bootloader using dfu-programmer (having trouble getting avrdude to talk to libusb on my Mac). OSX sees the board.  Arduino IDE sees it.  If I try to upload code directly from Arduino IDE:

...

Sketch uses 4606 bytes (16%) of program storage space. Maximum is 28672 bytes.
Global variables use 165 bytes (6%) of dynamic memory, leaving 2395 bytes for local variables. Maximum is 2560 bytes.
Forcing reset using 1200bps open/close on port /dev/cu.usbmodemFD121
PORTS {/dev/cu.Bluetooth-Incoming-Port, /dev/cu.usbmodemFD121, /dev/cu.WillsiPhone5S-Wirelessi, /dev/tty.Bluetooth-Incoming-Port, /dev/tty.usbmodemFD121, /dev/tty.WillsiPhone5S-Wirelessi, } / {/dev/cu.Bluetooth-Incoming-Port, /dev/cu.WillsiPhone5S-Wirelessi, /dev/tty.Bluetooth-Incoming-Port, /dev/tty.WillsiPhone5S-Wirelessi, } => {}
PORTS {/dev/cu.Bluetooth-Incoming-Port, /dev/cu.WillsiPhone5S-Wirelessi,...

 

...and so on.  The board vanishes right after the 1200bps, and stays that way until I unplug it. 

<p>~ Athyrio</p>

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
PS like so many threads like this I do wonder how people get as far as committed hardware layouts before they've actually read about and understood the operation of the chip. This programming/startup thing is probably something you should have prototyped first (which is why eval boards are often a good place to start)

 

That's what I got for asking an electrical engineer to do the board design for me. ;-)  Now I'm just trying to make it work. 

 

I could have swore that I posted this earlier, but it's not appearing:  I found that I could get the board back into DFU by pulling the RESET pin LOW.  I thought I had to also pull HWB HIGH, but apparently not.  It's a pain in the arse, requiring a fine probe, but it can be done.  At least now I can get on with other testing. 

 

Would be great to have it behave like a stock Arduino, though!  Still struggling to get that right. I'm assuming that it has to do with the fuses, but I don't want to muck with those until I have avrdude working, and reach a better understanding of how they should be set. 

<p>~ Athyrio</p>

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It's both. You have to hold HWB the right way then reset or power on the chip because it is as it comes out of reset that HWB is sensed.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Note that the Leonardo was problematic. I think anything other than win xp had problems with it.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have more problems with my "native USB" SAM boards than I do with the Leonardo clone I have.

(Which is "interesting": they have essentially the same "I'm a system"/"oops, now I'm a bootloader" logical problem; they should behave ... more alike.)