Question
What's the bug in the code of IWDG with HAL_IWDG_RegisterCallback below? (STM32H563)
I am trying to implement an IWDG in my program, which will save the value of the specified register to EEPROM before resetting.
The STM32 I'm using is STM32H563.
But I found that my program is not working (cannot save data to EEPROM before resetting).
I politely request your help or to provide a simple example of IWDG using HAL_SWDG_Registercallbacks.
Many thanks. :)
void IWDG_EarlyWakeupCallback(IWDG_HandleTypeDef *hiwdg)
{
uint8_t arr[1] = {0xAA};
// if (imageAbortedFlag)
{
if (getCurrentRunningImage() == 0x01)
{
pRAMbootctrl->image_A_tasks_aborted_count++;
}
else if (getCurrentRunningImage() == 0x10)
{
pRAMbootctrl->image_B_tasks_aborted_count++;
}
MemoryStoreData(EEPROM_MSATABLE_UP03_INDEX, UPE6_128, 1, arr);
jump_to_IMAGE(BOOTLOADER_START_ADDRESS);
}
}
void MX_IWDG_Init(void)
{
hiwdg.Instance = IWDG;
hiwdg.Init.Prescaler = IWDG_PRESCALER_8;
hiwdg.Init.Window = IWDG_WINDOW_DISABLE;
hiwdg.Init.Reload = 0x0FFF; // ?TBD
hiwdg.Init.EWI = 0; // ?? 0x0FFE
if (HAL_IWDG_Init(&hiwdg) != HAL_OK)
{
// Error_Handler();
}
if (HAL_IWDG_RegisterCallback(&hiwdg, HAL_IWDG_EWI_CB_ID, IWDG_EarlyWakeupCallback) != HAL_OK)
{
// Error_Handler();
}
#if 0
HAL_NVIC_SetPriority(IWDG_IRQn, NVICPreemptionPriority_IWDG, NVICSubPriority_IWDG);
HAL_NVIC_EnableIRQ(IWDG_IRQn);
#endif
}
