-
Notifications
You must be signed in to change notification settings - Fork 372
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
WDIE is wronly cleared on interrupt in Interrupt Mode #456
Comments
Hi @WGH- I have applied your fix suggestion to my simavr fork and now I can use WDT and Arduino_freeRTOS without any problems. |
@lcgamboa just to clarify, Arduino_freeRTOS depends on the correct behaviour of |
Yes, I tested some examples from the Arduino_freeRTOS library and they all worked after the fix you suggested. |
WDIE must be automatically cleared only in "Interrupt and System Reset Mode" (where it's used to transition to "System Reset Mode"). In other modes, watchdog interrupt must not clear WDIE. Strictly speaking, the modified condition also clears it in "System Reset Mode" as well, but the system is reset on interrupt anyway, so it doesn't matter. See buserror#456
I was having issues with the watchdog timer interrupts and I'm glad to find this issue. Here's a simple example code for testing purposes. it uses the watchdog timer to blink an LED. The watchdog timer interrupt only works once and then stops. I updated the interrupt clearing line with the following line of code as an interim solution. Current: #include <avr/io.h>
#include <avr/wdt.h>
#include <avr/interrupt.h>
ISR(WDT_vect)
{
// Clear interrupt flag by writing 1 to it.
WDTCSR |= (1 << WDIF);
// Toggle LED.
PORTB ^= _BV(PB5);
}
int main()
{
// Set LED as output.
DDRB |= _BV(DDB5);
// Enable watchdog timer.
WDTCSR |= (1 << WDCE) | (1 << WDE);
WDTCSR = (1 << WDIE);
// Toggle LED.
PORTB ^= _BV(PB5);
// Enable global interrupts.
sei();
// Loop forever.
while (1)
{
_NOP();
}
} |
I had the same issue, @itopaloglu83 your workaround by setting |
WDIE
should be only cleared in "Interrupt and System Reset Mode".The fix is to add
&& avr_regbit_get(avr, p->wde)
condition.simavr/simavr/sim/avr_watchdog.c
Lines 172 to 188 in a56b550
I think I'll submit a PR (unless someone does that first) once I get access to hardware to double-check the tests on.
The text was updated successfully, but these errors were encountered: