-
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
boards/common/atmega: initialize watchdog #9141
Conversation
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.
As per the datasheet, "the application software should always clear the WDRF and the WDE control bit in the initialization routine"and interrupt should be disabled while doing this. So I suggest 'WDTCSR |= 1 << WDCE | 1 << WDE;' and starting by irq_disable() and then irq_enable() before leaving
If I am not mistaken, interrupts are enabled for the first time only after atmega_wdog_init is being run (at the end of board_init). |
@ZetaR60 , you're right about interrupts. Any thoughts about the WDE bit ? |
@mali WDE should be cleared when all of WDTCSR is set to 0. I have an idea: What if some versions of the Arduino bootloader are clearing MCUSR / WDRF, but not WDTCSR ? The atmega_wdog_init function would do nothing (because it does not know the board was watchdog reset), but it would still have the watchdog set to reboot again. Could you try #9141 again, but with the condition removed (so that atmega_wdog_init always clears the watchdog no matter what)? |
Good idea but sorry, same result :-/ |
As there is a problem with the watchdog beeing set to the shortest time after reset in some atmega MCU the WDT has to be reseted as fast as possible. Thus in the bootloader. https://www.microchip.com/webdoc/AVRLibcReferenceManual/group__avr__watchdog.html But the application is then not able to find out the reset cause. As for the atmegas the WDT is used for softreset this can not be distinguished. So we implemented a solution for that in the Jiminy bootloader. And the atmega256rfr2 And the reboot command. My proposal would be to clear the WDT in Related arduino bootloader code shows that MCUSR gets cleared |
@Josar I am not very familiar with the section attribute and how this is modifying the startup process. Could you submit an alternate PR so that we could test the method as you intend it to be written? I think that since there is no established API for getting the reset cause it should be a secondary priority (unless a specific board needs it, like Jiminy), and the main goal should be getting all CPUs to reset properly. |
ping @Josar |
Fixed by #9866. Closing. |
This initializes the watchdog on ATmega boards if a watchdog reset occurred, preventing reboot loops when using the reboot command.
Adapted from #6837
Fixes #6836