baerwolf / USBaspLoader

An (V)USB bootloader firmware for AVR-MCUs emulating the popular USBasp for programming itself
Other
178 stars 146 forks source link

In all USBaspLoader version up to 0.97 exists a bug, which causes the watchdog timer to continously reboot. #12

Closed tinyusbboard closed 9 years ago

tinyusbboard commented 9 years ago

Date of discovery: 2014/11/29

Rating: High

URL: https://github.com/baerwolf/USBaspLoader

Description: In all USBaspLoader version up to 0.97 exists a bug, which causes the watchdog timer to continously reboot.

When a users firmware activates the watchdog timer, and then times out: The MCUC(S)R register then has WDRF bit to HIGH. On some ATmegas this keeps the AVRs internal hardware reset, from resetting the active watchdog (even when the WDTON fuse is unprogrammed). However the timeout period is reset anyway to minimal value of 16ms (WDP* to LOW).

In the bootloaders PROG-PIN chargeup phase, the bootloader stalls 50ms, causing the AVR to reboot.

For deactivating the watchdog timer, some AVRs need to reset the WDRF bit first. But since also the hardware reset seems to be restricted to this measure (hardware bug???), the watchdog stays on ever - even during RESET presses. This also renders the RESET pin/button effectivly useless.

ATmega8 v0.97 is NOT effected by this bug.

Patch: Upcoming asap - but still ongoing investigation

Workaround: NO software workaround known. In order to access the bootloader again, dis- and reconnect the power where possible.

On AVRs except ATmega8, it is recommended to avoid using the API (https://github.com/tinyusbboard/API) until a patch/update is provided.

cpldcpu commented 9 years ago

This confuses me a bit. The WDT is not supposed to be disabled during a watchdog timer reset. So this behavior is expected?!?

Issues with WDT, fused on or not, have been solved like this in micronucleus: https://github.com/micronucleus/micronucleus/commit/0712bc8b3fe71e923e37067242fe43978f6d7db9

baerwolf commented 9 years ago

Hi Thx for the reply.

This confuses me a bit. The WDT is not supposed to be disabled during a watchdog timer reset. So this behavior is expected?!?

No, not all of them at least. ATmega8 resets the WDT after RESET condition. And I am not sure if a WDT surviving a hard RESET is intentional at all? Perhaps someone does know an exact page of the datasheet to look for this matter?

Anyhow also micronucleus does the WDT deactivation after the bootloader condition. USBaspLoader does the same already - however that is not sufficient in some cases.

Fix is in preparation.

baerwolf commented 9 years ago

Here is my proposed fix for this annoyment: https://github.com/baerwolf/USBaspLoader/commit/1697a8814722b7eda4b10dedcac290eb97f9362e

Lets say 1 week for testing. When there are no objections until then, I will close this issue and fix the mainline.

BR Stephan

tinyusbboard commented 9 years ago

USBaspLoader v0.97.1 is available as master now.