Entering low power mode on STM32L0 to use USART1
I want to use as little power as possible by reading USART1 at 300 baud. 40 bytes. There are many other peripherals out there, but they don't need to run - all that needs to be run is RTC in parallel. The peripherals must be frozen and the RAM must be the same.
As I see it, the low power mode is the optimal mode (please correct me if I'm wrong here):
void HAL_PWREx_EnableLowPowerRunMode(void)
{
/* Enters the Low Power Run mode */
SET_BIT(PWR->CR, PWR_CR_LPSDSR);
SET_BIT(PWR->CR, PWR_CR_LPRUN);
}
Now the clock configuration is currently
- System Clock Source = PLL (HSI)
- SYSCLK (Hz) = 32000000
- HCLK (Hz) = 32000000
- AHB Prescaler = 1
- APB1 Prescaler = 1
- APB2 Prescaler = 1
- HSI frequency (Hz) = 16000000
- PLLMUL = 6
- PLLDIV = 3
- Flash Delay (WS) = 1
- Power regulator voltage = SCALE 1
How can I enter this mode and restore it?
// Init?
HAL_PWREx_EnableLowPowerRunMode();
HAL_PWREx_DisableLowPowerRunMode();
// Deinit?
My attempt at initialization, what am I missing here?
void init_clock(){
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_PeriphCLKInitTypeDef PeriphClkInit;
/**Initializes the CPU, AHB and APB busses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_MSI;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
{
Error_Handler();
}
/**Configure the main internal regulator output voltage
*/
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);
/**Initializes the CPU, AHB and APB busses clocks
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_MSI;
RCC_OscInitStruct.HSIState = RCC_HSI_DIV4;
RCC_OscInitStruct.HSICalibrationValue = 16;
RCC_OscInitStruct.MSIState = RCC_MSI_ON;
RCC_OscInitStruct.MSICalibrationValue = 0;
RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_0;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1;
PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_SYSCLK;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
Error_Handler();
}
}
- Deinit = Same as inital init clock config
+3
source to share
1 answer
USART1 can receive a byte in stop mode and can also wake up.
The procedure for reaching low power is to use LSE for USART1 and wake up from stop mode on RXNE.
UART_WakeUpTypeDef wakeup;
wakeup.WakeUpEvent=UART_WAKEUP_ON_READDATA_NONEMPTY;
HAL_UARTEx_StopModeWakeUpSourceConfig(&huart1,wakeup);
HAL_UARTEx_EnableStopMode(&huart1);
It is easier and equal, if not better than BAM with DMA and Low Power Sleep.
0
source to share