1
\$\begingroup\$

I have a ATmega32u4 from factory with DFU inside. The HWB is pull down, and RESET pin is pull up.

The first USB plug, DFU programmer appears on my Linux box. I upload the firmware without problem. Now, every time I plug my ATmega to USB the application runs first, instead of DFU. But, when reset MCU by software, the bootloader code runs.

According to datasheet, default fuses are: BOOTRST = 1 and HWBE = 0. With this fuses and signals, the expected behaviour should be always the first one as the image shows.

Boot process datasheet

I don't know why, when reset by software, the bootloader runs.

\$\endgroup\$

2 Answers 2

1
\$\begingroup\$

After some testing, this is what happened. The startup code is:

  • At startup, check MCUSR. If reset was due to watchdog, clear corresponding flag.

  • Turn off WDT.

  • Configure WDT with desired timeout.

  • Feed the WDT when needed.

Two options are possible to start application with DFU-programmer:

  1. Start application with an internal hardware reset using watchdog.

  2. A jump at address 0x0000 without reset.

Hanging MCU later, if app was launched with option one, the application boots.

Using option two, by some reason, the bootloader runs this time.

\$\endgroup\$
1
\$\begingroup\$

I think you're asking why the ATmega32U4 first boots to the application, but boots to the bootloader when you reset it. If so, I agree this is described a little unclearly.

The key part of that diagram is the callout showing the signal timing - the initial falling edge of the RESET line is important. During initial boot (what happens when you apply power) the reset line may start high unless you have circuitry to delay it (eg. a power-on reset, POR, circuit). If no rising edge is detected, the HWBE check is not triggered.

However, if you trigger a reset while the MCU is powered, the RESET line goes low. Thus, the HWBE check is armed and the state of the HWB pin will be checked when RESET returns to high.

This is used to great effect in the Arduino Uno, where the ATmega16U2 normally boots to the application (usb-serial). But if its reset is toggled while it is powered then it boots to the bootloader (usbdfu) instead. I suspect that if a POR circuit were present, this would not be possible, but I have not confirmed.

\$\endgroup\$
2
  • \$\begingroup\$ (*Arduino Uno. *ATmega16U2. its = possessive, it's = "it is" or "it has". See, for example, this and this.) \$\endgroup\$ Commented Jan 20 at 16:57
  • \$\begingroup\$ Quite right thank you. My mistake due to haste. But your reference suggests "UNO" is correct. By sheer volume of evidence though, I think it might be wrong, so I've gone with your suggestion. Please advise further if necessary. \$\endgroup\$ Commented Jan 22 at 0:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.