Skip to content

Commit

Permalink
feat(u0): add STM32U0xx LowPower support
Browse files Browse the repository at this point in the history
Signed-off-by: Frederic Pillon <[email protected]>
  • Loading branch information
fpistm committed Sep 5, 2024
1 parent 3924ac1 commit 9942c29
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/low_power.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ void SystemClock_Decrease(void)
}
}

#elif defined(STM32G0xx) || defined(STM32G4xx)
#elif defined(STM32G0xx) || defined(STM32G4xx) || defined(STM32U0xx)
/**
* @brief For STM32G0 and STM32G4
* running in LowPower Sleep requires to slow down frequency to 2MHz max.
Expand Down Expand Up @@ -366,7 +366,7 @@ void SystemClock_Decrease(void)
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
| RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
#elif defined(STM32G0xx)
#elif defined(STM32G0xx) || defined(STM32U0xx)
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
| RCC_CLOCKTYPE_PCLK1;
#endif
Expand Down Expand Up @@ -447,7 +447,7 @@ void LowPower_stop(serial_t *obj)
/* Enable Ultra low power mode */
HAL_PWREx_EnableUltraLowPower();
#endif
#if defined(PWR_CR1_ULPMEN) || defined(PWR_CR3_ULPMEN)
#if defined(PWR_CR1_ULPMEN) || defined(PWR_CR3_ULPMEN) || defined(PWR_CR3_ENULP)
/* Enable Ultra low power mode */
HAL_PWREx_EnableUltraLowPowerMode();
#endif
Expand Down Expand Up @@ -481,11 +481,14 @@ void LowPower_stop(serial_t *obj)
/* Enter Stop mode */
#if defined(UART_WKUP_SUPPORT) && (defined(PWR_CPUCR_RETDS_CD) \
|| defined(PWR_CR1_LPMS_STOP2) || defined(PWR_LOWPOWERMODE_STOP2) \
|| defined(LL_PWR_STOP2_MODE))
|| defined(LL_PWR_STOP2_MODE) || defined(PWR_CR1_LPMS_1))
if ((WakeUpUart == NULL)
|| (WakeUpUart->Instance == (USART_TypeDef *)LPUART1_BASE)
#ifdef LPUART2_BASE
|| (WakeUpUart->Instance == (USART_TypeDef *)LPUART2_BASE)
#endif
#ifdef LPUART3_BASE
|| (WakeUpUart->Instance == (USART_TypeDef *)LPUART3_BASE)
#endif
) {
#if defined(PWR_CR1_RRSTP)
Expand Down Expand Up @@ -596,7 +599,11 @@ void LowPower_shutdown(bool isRTC)
#if defined(LL_PWR_SHUTDOWN_MODE) || defined(LL_PWR_MODE_SHUTDOWN)
/* LSE must be on to use shutdown mode within RTC else fallback to standby */
if ((!isRTC) || (__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == SET)) {
#if defined(STM32U0xx)
HAL_PWR_EnterSHUTDOWNMode();
#else
HAL_PWREx_EnterSHUTDOWNMode();
#endif
} else
#else
UNUSED(isRTC);
Expand Down

0 comments on commit 9942c29

Please sign in to comment.