STM32F4: WWDG interrumpe los incendios tan pronto como está habilitado

Estoy codificando un poco en una placa STM32F411, usé las bibliotecas CubeMX y HAL por pereza.

Estoy tratando de poner en funcionamiento el perro guardián de ventana (WWDG), y hacer que la versión muy básica (sin interrupción) funcione como se esperaba usando esta secuencia de configuración (directamente desde HAL/CubeMX):

/* Reset of all peripherals, Initialises the Flash interface and the Systick. */
HAL_Init();

/* Configure the system clock */
SystemClock_Config();

/* Initialise all configured peripherals */
MX_GPIO_Init();
MX_ADC1_Init();
MX_I2C1_Init();
MX_IWDG_Init();
MX_TIM1_Init();
MX_USART6_UART_Init(); 
MX_USB_OTG_FS_USB_Init();

MX_WWDG_Init(); // Window == count == 0x7F
HAL_WWDG_Refresh(&hwwdg, 0x7F);
HAL_WWDG_Start(&hwwdg);

while(1)
{
    //main loop stuff
}

Esto funciona como se esperaba (reduciré la ventana más adelante), pero si cambio el código para usar la función de interrupción de "despertar temprano" (EWIF), nuevamente, todo generado automáticamente desde CubeMX, dispara instantáneamente la interrupción:

/* Reset of all peripherals, Initialises the Flash interface and the Systick. */
HAL_Init();

/* Configure the system clock */
SystemClock_Config();

/* Initialise all configured peripherals */
MX_GPIO_Init();
MX_ADC1_Init();
MX_I2C1_Init();
MX_IWDG_Init();
MX_TIM1_Init();
MX_USART6_UART_Init(); 
MX_USB_OTG_FS_USB_Init();

MX_WWDG_Init(); // Window == count == 0x7F
HAL_WWDG_Refresh(&hwwdg, 0x7F);
HAL_WWDG_Start_IT(&hwwdg);

while(1)
{
    //main loop stuff
}

La MX_WWDG_Init();llamada en este caso incluye las líneas para configurar NVIC/habilitar IRQ, pero por lo demás es idéntica:

void HAL_WWDG_MspInit(WWDG_HandleTypeDef* hwwdg)
{

  if(hwwdg->Instance==WWDG)
  {
  /* USER CODE BEGIN WWDG_MspInit 0 */

  /* USER CODE END WWDG_MspInit 0 */
    /* Peripheral clock enable */
    __HAL_RCC_WWDG_CLK_ENABLE();

    /* Peripheral interrupt init */
   HAL_NVIC_SetPriority(WWDG_IRQn, 0, 0);
   HAL_NVIC_EnableIRQ(WWDG_IRQn);
  /* USER CODE BEGIN WWDG_MspInit 1 */

  /* USER CODE END WWDG_MspInit 1 */
  }
}

Intenté agregar __HAL_WWDG_CLEAR_FLAG(hwwdg, WWDG_FLAG_EWIF);justo antes de la __HAL_WWDG_ENABLE_IT(hwwdg, WWDG_IT_EWI);llamada, HAL_WWDG_Start_IT(&hwwdg);pero no hace ninguna diferencia.

¿Qué me he perdido aquí?

Respuestas (2)

Debe borrar el indicador pendiente de IWDG_SR.EWIF y NVIC para la interrupción de IWDG antes de habilitarlo:

WWDG->SR = 0;
NVIC_ClearPendingIRQ(WWDG_IRQn);
NVIC_EnableIRQ(WWDG_IRQn);

Incluso he trabajado tanto en IWDG como en WWDG de STM32F407 BOARD. Le sugiero que use el temporizador de vigilancia independiente (IWDG) en lugar de WWDG ... El tiempo de espera de IWDG es más, y puede configurar el preescalar de IWDG para obtener el tiempo de espera deseado ... Tiene un reloj separado.

¿Responde esto a la pregunta?
Solo si "no use esa función" es una respuesta razonable a "¿cómo uso esa función?"
Pero IWDG no se puede deshabilitar. Eso significa que si tienes tiempos de sueño de horas, IWDG te despertará cada cierto tiempo.