Skip to main content
Graduate II
August 28, 2025
Question

Wake Up from stop mode using USART (HSI for USART Clock,System clock use MSI)

  • August 28, 2025
  • 1 reply
  • 280 views

Hi, 

I'm using STM32L0 MCU, My system uses MSI as the main system clock, but my USART is to use HSI to be able to wake up from stop mode. My system will enter stop mode for power saving. I am confused about the settings, before enter stop mode, we have to set system clock after STOP mode using HAL API:

__HAL_RCC_WAKEUPSTOP_CLK_CONFIG(RCC_STOP_WAKEUPCLOCK_MSI); // Set system clock as MSI after stop

__HAL_RCC_WAKEUPSTOP_CLK_CONFIG(RCC_STOP_WAKEUPCLOCK_HSI); // Set system clock as HSI after stop so that USART able to wake up the MCU

 

void PreSleepProcessing(uint32_t *ulExpectedIdleTime) {
	*ulExpectedIdleTime = 0; // WFI is called within next function
#ifdef TEST_LP_MODE
	HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, 0);
#endif
	if (g_diableStopModeFlags == 0) {
		while(__HAL_UART_GET_FLAG(&huart1, USART_ISR_BUSY) == SET); // Make sure that no UART transfer is on-going
		while(__HAL_UART_GET_FLAG(&huart1, USART_ISR_REACK) == RESET); // Make sure that UART is ready to receive
		HAL_UARTEx_EnableStopMode(&huart1);
		// LL_RCC_SetClkAfterWakeFromStop(RCC_STOP_WAKEUPCLOCK_MSI);
		// HAL sets STOP wakeup clock for peripherals (so UART on HSI can wake)
		__HAL_RCC_WAKEUPSTOP_CLK_CONFIG(RCC_STOP_WAKEUPCLOCK_HSI);
		HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI);
	} 
}

 

Any idea how can I maintain the system clock as MSI after stop mode at the same time USART able to wake up the system from stop mode using HSI?

    This topic has been closed for replies.

    1 reply

    ST Employee
    September 1, 2025

    Hello @chai2145

    The key point is the STOPWUCK bit. The RM states:

    "MSI or HSI16 RC oscillator are selected as system clock for Stop mode exit by configuring the STOPWUCK bit in the RCC_CFGR register" 

    SarraS_0-1756716710846.png

    Hope that helps!

     

    chai2145Author
    Graduate II
    September 8, 2025
    • Before STOP: System clock using MSI. Nothing changes yet.

    • Enter STOP → system goes into low-power mode. Configured STOPWUCK bit to use HSI 

    • Exit STOP → system will switch to HSI as the system clock. 

    After STOP exit, the system clock will change to HSI  instead of maintaining MSI as system clock source?