cancel
Showing results for 
Search instead for 
Did you mean: 

WWDG on HSE not stopping when enter STOP mode.

phuocly
Associate II

Dear,

Recently, when working with STM32U575 and using WWDG, I've encountered an unclear behavior when I set the controller to STOP mode by using HSE or HSI clock source.

By using HSI and LSE clock source (See below code), when enter STOP mode, WWDG is also stop counting since it's pre-scaled from APB clock, so this is quite normal from what I expected.

 

void SystemClock_Config(void)
{
    RCC_OscInitTypeDef RCC_OscInitStruct = {0};
    RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

    /* Configure the main internal regulator output voltage */
    INIT_HAL_CHECK(HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1));

    /** Configure LSE Drive Capability
     */
    HAL_PWR_EnableBkUpAccess();
    __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
 
    /** Initializes the CPU, AHB and APB buses clocks
     */
    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_LSE;
    RCC_OscInitStruct.LSEState = RCC_LSE_ON;
    RCC_OscInitStruct.HSIState = RCC_HSI_ON;
    RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
    RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
    RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
    RCC_OscInitStruct.PLL.PLLMBOOST = RCC_PLLMBOOST_DIV4;
    RCC_OscInitStruct.PLL.PLLM = 1;
    RCC_OscInitStruct.PLL.PLLN = 10;
    RCC_OscInitStruct.PLL.PLLP = 2;
    RCC_OscInitStruct.PLL.PLLQ = 1;
    RCC_OscInitStruct.PLL.PLLR = 1;
    RCC_OscInitStruct.PLL.PLLRGE = RCC_PLLVCIRANGE_1;
    RCC_OscInitStruct.PLL.PLLFRACN = 0;
    INIT_HAL_CHECK(HAL_RCC_OscConfig(&RCC_OscInitStruct));

    /** Initializes the CPU, AHB and APB buses clocks
     */
    RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2 | RCC_CLOCKTYPE_PCLK3;
    RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
    RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
    RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
    RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
    RCC_ClkInitStruct.APB3CLKDivider = RCC_HCLK_DIV1;
    INIT_HAL_CHECK(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4));
}
 
However, when switching to HSE and LSE combination, as soon as the controller went to STOP mode, WWDG will trigger a reset, which appear a little unclear to me since I was expecting "All clocks in the VCORE domain are stopped. The PLL, the MSI (MSIS and MSIK) RC, the HSI16 RC and the HSE crystal oscillators are disabled." according to HAL_PWR_EnterSTOPMode note.
void SystemClock_Config(void)
{
    RCC_OscInitTypeDef RCC_OscInitStruct = {0};
    RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

    /* Configure the main internal regulator output voltage */
    INIT_HAL_CHECK(HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1));

    /** Configure LSE Drive Capability
     */
    HAL_PWR_EnableBkUpAccess();
    __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
 
    /** Initializes the CPU, AHB and APB buses clocks
     */
    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE | RCC_OSCILLATORTYPE_LSE;
    RCC_OscInitStruct.HSEState = RCC_HSE_ON;
    RCC_OscInitStruct.LSEState = RCC_LSE_ON;
    RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
    RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
    RCC_OscInitStruct.PLL.PLLMBOOST = RCC_PLLMBOOST_DIV1;
    RCC_OscInitStruct.PLL.PLLM = 1;
    RCC_OscInitStruct.PLL.PLLN = 20;
    RCC_OscInitStruct.PLL.PLLP = 2;
    RCC_OscInitStruct.PLL.PLLQ = 1;
    RCC_OscInitStruct.PLL.PLLR = 1;
    RCC_OscInitStruct.PLL.PLLRGE = RCC_PLLVCIRANGE_1;
    RCC_OscInitStruct.PLL.PLLFRACN = 0;
    INIT_HAL_CHECK(HAL_RCC_OscConfig(&RCC_OscInitStruct));

    /** Initializes the CPU, AHB and APB buses clocks
     */
    RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2 | RCC_CLOCKTYPE_PCLK3;
    RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
    RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
    RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
    RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
    RCC_ClkInitStruct.APB3CLKDivider = RCC_HCLK_DIV1;

    INIT_HAL_CHECK(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4));
}
 
The way I have worked around this is to call __HAL_RCC_WWDG_CLK_SLEEP_DISABLE() which will CLEAR_BIT(RCC->APB1SMENR1, RCC_APB1SMENR1_WWDGSMEN). and __HAL_RCC_WWDG_CLK_SLEEP_ENABLE() after waking up. According to RM0456 11.8.41, WWDGSMEN: Window watchdog clock enable during Sleep and Stop modes, but I don't see this is used anywhere in the driver. I also make sure to have WWDG Software in all use cases.
phuocly_0-1737453257195.png

 

 
My question is that would there be a different between using HSI or HSE to drive the ABP and WWDG as describe above (when using HSE an explicit disable action has to be made to the RCC)? Appreciate any insight about this topic. 
 
Best regards,
Phuoc
2 REPLIES 2
Sarra.S
ST Employee

Hello @phuocly

When using HSE and LSE, it is unexpected that the WWDG triggers a reset in STOP mode. This might be due to the fact that the HSE oscillator is disabled in STOP mode, but the WWDG clock enable during STOP mode (WWDGSMEN) might still be active, causing the WWDG to reset the system

Any updates on this? 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hi Sarra,

Thank you for the response, so far we are just moving on by manually using  __HAL_RCC_WWDG_CLK_SLEEP_DISABLE before sleep and __HAL_RCC_WWDG_CLK_SLEEP_ENABLE after wakeup. This at least solves the issue.

I see your point but isn't WWDG must be clocked from the main clock sources (HSE / HSI / etc), which are all disabled when entering STOP mode? Perhaps this is because of the RCC generator or I might have missed something here?