Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(u0): add STM32U0xx LowPower support #113

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 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,8 @@ 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) && defined(STM32U0xx))
/* Enable Ultra low power mode */
HAL_PWREx_EnableUltraLowPowerMode();
#endif
Expand Down Expand Up @@ -479,13 +480,15 @@ void LowPower_stop(serial_t *obj)
#endif
#endif
/* 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))
#if defined(UART_WKUP_SUPPORT) && (defined(PWR_CPUCR_RETDS_CD) || \
defined(LL_PWR_MODE_STOP2))
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
Loading