Skip to content

fix: set CPU2 low power mode for STM32WBxx #87

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

Merged
merged 1 commit into from
Jan 10, 2023
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
40 changes: 37 additions & 3 deletions src/low_power.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,21 @@ void LowPower_stop(serial_t *obj)
__HAL_RCC_WAKEUPSTOP_CLK_CONFIG(RCC_STOP_WAKEUPCLOCK_HSI);
#endif
#endif

#if defined(STM32WBxx)
/* Set low-power mode of CPU2 */
/* Note: Typically, action performed by CPU2 on a dual core application.
Since this example is single core, perform it by CPU1. */
/* Note: On STM32WB, both CPU1 and CPU2 must be in low-power mode
to set the entire System in low-power mode, corresponding to
the deepest low-power mode possible.
For example, CPU1 in Stop2 mode and CPU2 in Shutdown mode
will make system enter in Stop2 mode. */
#if defined(LL_PWR_MODE_STOP2)
LL_C2_PWR_SetPowerMode(LL_PWR_MODE_STOP2);
#else
LL_C2_PWR_SetPowerMode(LL_PWR_MODE_SHUTDOWN);
#endif
#endif
/* Enter Stop mode */
#if defined(UART_WKUP_SUPPORT) && (defined(PWR_CPUCR_RETDS_CD) \
|| defined(PWR_CR1_LPMS_STOP2) || defined(PWR_LOWPOWERMODE_STOP2) \
Expand Down Expand Up @@ -528,7 +542,17 @@ void LowPower_standby()
/* Enable the fast wake up from Ultra low power mode */
HAL_PWREx_EnableFastWakeUp();
#endif

#if defined(STM32WBxx)
/* Set low-power mode of CPU2 */
/* Note: Typically, action performed by CPU2 on a dual core application.
Since this example is single core, perform it by CPU1. */
/* Note: On STM32WB, both CPU1 and CPU2 must be in low-power mode
to set the entire System in low-power mode, corresponding to
the deepest low-power mode possible.
For example, CPU1 in Stop2 mode and CPU2 in Shutdown mode
will make system enter in Stop2 mode. */
LL_C2_PWR_SetPowerMode(LL_PWR_MODE_STANDBY);
#endif
HAL_PWR_EnterSTANDBYMode();
}

Expand All @@ -550,7 +574,17 @@ void LowPower_shutdown()
#elif defined(PWR_MPUCR_CSSF)
__HAL_PWR_CLEAR_FLAG(PWR_MPUCR_CSSF);
#endif

#if defined(STM32WBxx)
/* Set low-power mode of CPU2 */
/* Note: Typically, action performed by CPU2 on a dual core application.
Since this example is single core, perform it by CPU1. */
/* Note: On STM32WB, both CPU1 and CPU2 must be in low-power mode
to set the entire System in low-power mode, corresponding to
the deepest low-power mode possible.
For example, CPU1 in Stop2 mode and CPU2 in Shutdown mode
will make system enter in Stop2 mode. */
LL_C2_PWR_SetPowerMode(LL_PWR_MODE_SHUTDOWN);
#endif
#if defined(PWR_LOWPOWERMODE_SHUTDOWN) || defined(PWR_CR1_LPMS_SHUTDOWN) || defined(LL_PWR_SHUTDOWN_MODE)
/* LSE must be on to use shutdown mode */
if (__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == SET) {
Expand Down