LUFA vs Atmel DFU bootloader startup while HWB is pressed

1,493 views
Skip to first unread message

László Monda

unread,
Apr 1, 2011, 7:59:43 PM4/1/11
to lufa-support
Hi guys,

I've observed something very interesting.

I've breadboarded an AT90USB1286 that has factory loaded Atmel DFU
bootloader. If I plug it to USB while holding the HWB button then
instead of booting to DFU mode it runs the actual firmware that has
been loaded through DFU beforehand.

I've also made a PCB centered around an ATmega8U2 to which I've loaded
the LUFA DFU bootloader through ISP and the VirtualSerial demo through
DFU. Now, if I hold down HWB and power it up through USB then it
boots into DFU mode.

I personally like the LUFA way better. Can you confirm this difference?

Thanks!

--
László Monda <http://monda.hu>

Dean Camera

unread,
Apr 3, 2011, 7:11:27 PM4/3/11
to LUFA Library Support List
László,

This is unintentional behaviour on my part - from the sounds of it,
the Atmel bootloader is checking the MCU status register on startup to
check if a reset has occurred before running. Mine doesn't do that, so
it'll run regardless of how you enter it. This is either a good thing
or a bad thing depending on what behaviour you want, although it does
make jumping to the bootloader from the application space possible.

If anyone likes the Atmel behaviour (bootloader will only run after a
physical reset with HWB pulled low) I can add in a compile time option
to the bootloader to enable this.

Cheers!
- Dean

J.C. Woltz

unread,
Apr 3, 2011, 9:46:23 PM4/3/11
to lufa-s...@googlegroups.com
I could be wrong, but am working with an atmega32u4.

This behavior can be changed by changing the fuses on the chip. That is my experience.

-J.C.
Sent from my mobile.
--
You received this message because you are subscribed to the Google Groups "LUFA Library Support List" group.
To post to this group, send email to lufa-s...@googlegroups.com.
To unsubscribe from this group, send email to lufa-support...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/lufa-support?hl=en.

Dean Camera

unread,
Apr 4, 2011, 11:08:47 PM4/4/11
to LUFA Library Support List
The BOOTRST fuse can be used to *always* enter the bootloader space
unconditionally on power on, which isn't quite the same thing; the
behaviour is a difference between the Atmel and LUFA DFU bootloader in
regards to the HWB condition. The Atmel code will have something akin
to:

if (!(MCUSR & (1 << PORF)))
Run_Application();

Which aborts the bootloader if it was a power on reset source. Other
possibilities would be to only run in response to an external reset or
to abort if the reset source was from the JTAG.

Cheers!
- Dean

László Monda

unread,
Apr 8, 2011, 6:21:45 PM4/8/11
to lufa-s...@googlegroups.com, Dean Camera
On Tue, Apr 5, 2011 at 5:08 AM, Dean Camera <abcmi...@gmail.com> wrote:
> The BOOTRST fuse can be used to *always* enter the bootloader space
> unconditionally on power on,

Let me correct you here Dean, I think this should happen on reset, not
on power on.

> which isn't quite the same thing; the
> behaviour is a difference between the Atmel and LUFA DFU bootloader in
> regards to the HWB condition. The Atmel code will have something akin
> to:
>
> if (!(MCUSR & (1 << PORF)))
>   Run_Application();
>
> Which aborts the bootloader if it was a power on reset source. Other
> possibilities would be to only run in response to an external reset or
> to abort if the reset source was from the JTAG.

I wonder whether the DFU specifcation defines the expected behaviour
regarding the HWB condition.

There's a relevant issue: I didn't touch the fuses, yet the LUFA DFU
bootloader gets activated automatically upon reset. I guess it
shouldn't happen when BOOTRST is unprogrammed.

Dean Camera

unread,
Apr 10, 2011, 3:37:21 AM4/10/11
to LUFA Library Support List
> Let me correct you here Dean, I think this should happen on reset, not
> on power on.

Actually, I'm not 100% certain about this. The datasheet says that the
fuse alters the reset vector, but also specifies the reset vector
fires after a power-on and not just when an internal or external reset
occurs. Perhaps this is special-cased for the BOOTRST fuse so that a
power on runs the application, but it may also trigger the bootloader
- I'd need to run a test on a physical device to be sure.

> I wonder whether the DFU specifcation defines the expected behaviour
> regarding the HWB condition.

I doubt it - HWB is an Atmel invention, and not part of an official
USB standard IIRC.

Cheers!
- Dean

On Apr 9, 8:21 am, László Monda <l...@monda.hu> wrote:
> > For more options, visit this group athttp://groups.google.com/group/lufa-support?hl=en.

László Monda

unread,
Apr 13, 2011, 1:23:35 PM4/13/11
to lufa-s...@googlegroups.com, Dean Camera
On Sun, Apr 10, 2011 at 9:37 AM, Dean Camera <abcmi...@gmail.com> wrote:
>> Let me correct you here Dean, I think this should happen on reset, not
>> on power on.
>
> Actually, I'm not 100% certain about this. The datasheet says that the
> fuse alters the reset vector, but also specifies the reset vector
> fires after a power-on and not just when an internal or external reset
> occurs. Perhaps this is special-cased for the BOOTRST fuse so that a
> power on runs the application, but it may also trigger the bootloader
> - I'd need to run a test on a physical device to be sure.

I stand corrected. It's definitely not a major issue.

>> I wonder whether the DFU specifcation defines the expected behaviour
>> regarding the HWB condition.
>
> I doubt it - HWB is an Atmel invention, and not part of an official
> USB standard IIRC.

Ah, so it's a de-facto thing. Ok then.

What about the last issue that I've mentionied? (Let me quote that again.)

> For more options, visit this group at http://groups.google.com/group/lufa-support?hl=en.

Dean Camera

unread,
Apr 15, 2011, 12:36:47 AM4/15/11
to LUFA Library Support List
> What about the last issue that I've mentionied? (Let me quote that again.)
>
> "I didn't touch the fuses, yet the LUFA DFU bootloader gets activated
> automatically upon reset. I guess it shouldn't happen when BOOTRST is
> unprogrammed."

Do you mean that the bootloader is getting activated without manually
pulling down HWB on power on? This isn't happening for me on my
USBKEY, but it may be an issue on other boards depending on what's
connected to the HWB line. If you're referring to the bootloader being
activated while manually pulling down the HWB line on poweron, you can
use the code I posted earlier to abort if the bootloader starts
without an external physical reset.

Cheers!
- Dean

On Apr 14, 3:23 am, László Monda <l...@monda.hu> wrote:

László Monda

unread,
Apr 15, 2011, 6:16:43 AM4/15/11
to lufa-s...@googlegroups.com, Dean Camera
On Fri, Apr 15, 2011 at 6:36 AM, Dean Camera <abcmi...@gmail.com> wrote:
>> What about the last issue that I've mentionied?  (Let me quote that again.)
>>
>> "I didn't touch the fuses, yet the LUFA DFU bootloader gets activated
>> automatically upon reset.  I guess it shouldn't happen when BOOTRST is
>> unprogrammed."
>
> Do you mean that the bootloader is getting activated without manually
> pulling down HWB on power on?

Yes, exactly.

> This isn't happening for me on my
> USBKEY, but it may be an issue on other boards depending on what's
> connected to the HWB line. If you're referring to the bootloader being
> activated while manually pulling down the HWB line on poweron, you can
> use the code I posted earlier to abort if the bootloader starts
> without an external physical reset.

Thanks for the advice! I'll look into this issue whether it happens
with the next version of my board.

> For more options, visit this group at http://groups.google.com/group/lufa-support?hl=en.

Mark

unread,
Apr 20, 2011, 12:47:52 AM4/20/11
to lufa-s...@googlegroups.com, Dean Camera
I just skimmed over this thread, however it seems similar to issues I was having a few months ago so I figured I'd throw in my two cents.

I use an ATmega32U4 on a custom board.  I use the Atmel bootloader and LUFA CDC class as my running program.  By default on power up, the MCU always runs my program.  I have tried to enter the bootloader via software however never got it to work.  You can use the combination reset/HWB to manually enter the bootloader (specs in the datasheet on clock timing) without having to set any fuses.  Therefore, the reset button resets the program, the combination enters the bootloader.  

If I am to understand correctly, the LUFA bootloader works a little differently.

Dean Camera

unread,
Apr 20, 2011, 1:50:02 AM4/20/11
to LUFA Library Support List
You should be able to enter the bootloader via software (LUFA, not
Atmel) by performing a software jump to the bootloader start - that
can be achieved via a function pointer in the C language. I've put
some example code in the LUFA manual for a software bootloader jump,
which uses the watchdog, a NOINIT static variable as a key, and a
special initialisation function which performs the jump after a reset
if the key is correct.

Cheers!
- Dean

Xulio Coira

unread,
Sep 15, 2013, 11:05:32 AM9/15/13
to lufa-s...@googlegroups.com, jwo...@gmail.com
Hi people!

I've just "discovered" that attaching a 1uF capacitor from RESET pin to GND (and 10K to VCC) I can enter DFU mode in default Atmel bootloader, plugging the USB connector while holding down HWB. This way RESET switch is not needed.

This is very good for me because I wanted not to do ICSP for updating bootloader in production.

I guess this is a timings stuff that I cant explain. Maybe some of you can. Does this math with Dean explanation about status register?

Regards,

Xulio.

Dean Camera

unread,
Sep 29, 2013, 7:24:32 AM9/29/13
to lufa-s...@googlegroups.com
Xulio,

That makes sense (to me at least) - the capacitor on RESET means that
the device will sense an external reset startup rather than a normal
Power on Reset startup (due to slow rise of /RESET line on powerup),
which causes the device and bootloader to do its HWB checks. A normal
POR will not activate the HWB detection logic.

Cheers!
- Dean
> <javascript:>.
> To unsubscribe from this group, send email to
> lufa-support...@googlegroups.com <javascript:>.
> For more options, visit this group at
> http://groups.google.com/group/lufa-support?hl=en
> <http://groups.google.com/group/lufa-support?hl=en>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "LUFA Library Support List" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to lufa-support...@googlegroups.com.
> To post to this group, send email to lufa-s...@googlegroups.com.
> Visit this group at http://groups.google.com/group/lufa-support.
> For more options, visit https://groups.google.com/groups/opt_out.
Reply all
Reply to author
Forward
0 new messages