-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
atmega328p/startup.c: Clear watchdog flag #6837
Conversation
When the atmega328p is restarted by the watchdog, the WDRF bit in the MCUSR register will also set the WDE bit, enabling the watchdog. Since we use the watchdog for reboot (see cpu/atmega_common/periph/pm.c), this means that the CPU will just loop-reboot when a reboot is issued. From the Atmel documentation about WDE in WDTCSR: "WDE is overridden by WDRF in MCUSR. This means that WDE is always set when WDRF is set. To clear WDE, WDRF must be cleared first. This feature ensures multiple resets during conditions causing failure, and a safe start-up after the failure."
I need to investigate more, because I can't reproduce the issue described in #6836. |
That is strange, I'm still seeing this. And the documentation seems to indicate that the patch is needed. Might it be a revision thing? |
..one thing just hit me. Are you running it with or without the Arduino bootloader? I'm running without it, so it might be that it clears the bit if the board was reset using the watchdog. |
@zqad : Yes I'm using arduino bootloader, indeed, that should be related. |
For now I'm unable to build Riot due to obsolete gcc toolchain. I'm waiting for the new debian stable which should be there soon. |
Ok, so here are the results of my tests.
|
Got something to track down, I've found this piece of code in arduino bootloader which can explain why the board go in loop-reboot
But this said, I should have had hand on board while pressing reset button which was not the case ... |
any news on this? |
The ATmega1284P has this reboot-loop issue as well. Tested on BOARD=mega-xplained. Placing the watchdog reset code at the beginning of board_init in boards/common/atmega/board.c fixes the reboot-loops. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other ATmegas have the reboot-loop issue. I suggest moving this to boards/common/atmega/board.c
Ping @zqad |
Updated PR that fixes all ATmega boards: #9141 |
@PeterKietzmann It should be okay to close. #9141 is not perfect (does not work on the Duemilanove, for unknown reasons), but it is a more comprehensive fix than this PR. Closing. |
When the atmega328p is restarted by the watchdog, the WDRF bit in
the MCUSR register will also set the WDE bit, enabling the
watchdog. Since we use the watchdog for reboot (see
cpu/atmega_common/periph/pm.c), this means that the CPU will just
loop-reboot when a reboot is issued.
From the Atmel documentation about WDE in WDTCSR:
"WDE is overridden by WDRF in MCUSR. This means that WDE is
always set when WDRF is set. To clear WDE, WDRF must be cleared
first. This feature ensures multiple resets during conditions
causing failure, and a safe start-up after the failure."