I've faced the problem with WWDG on STM32F405 (the same problem described here, but with no no solution): After enabling WWDG interrupt occurs immediately, despite the fact, that counter is far from the value 0x3F and I update counter before it is enabled. My initialization:
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_WWDG);
LL_WWDG_SetPrescaler(WWDG, LL_WWDG_PRESCALER_8);
LL_WWDG_SetWindow(WWDG, 0x7e);
LL_WWDG_EnableIT_EWKUP(WWDG);
LL_WWDG_ClearFlag_EWKUP(WWDG);
NVIC_ClearPendingIRQ(WWDG_IRQn);
NVIC_EnableIRQ(WWDG_IRQn);
LL_WWDG_SetCounter(WWDG, 0x7d);
LL_WWDG_Enable(WWDG);
I deliberately set counter value less than window value to have possibility update timer any time. So does anyone know why interrupt occurs immediately after enabling?