cancel
Showing results for 
Search instead for 
Did you mean: 

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

chai2145
Senior

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?

0 REPLIES 0