Skip to content

Commit ee9a8e6

Browse files
committed
fix(WB): set CPU2 low power mode
Fixes #85 Typically, action performed by CPU2 on a dual core application. Since this example is single core, perform it by CPU1. 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. Signed-off-by: Frederic Pillon <[email protected]>
1 parent 638ae13 commit ee9a8e6

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

src/low_power.c

+37-3
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,21 @@ void LowPower_stop(serial_t *obj)
459459
__HAL_RCC_WAKEUPSTOP_CLK_CONFIG(RCC_STOP_WAKEUPCLOCK_HSI);
460460
#endif
461461
#endif
462-
462+
#if defined(STM32WBxx)
463+
/* Set low-power mode of CPU2 */
464+
/* Note: Typically, action performed by CPU2 on a dual core application.
465+
Since this example is single core, perform it by CPU1. */
466+
/* Note: On STM32WB, both CPU1 and CPU2 must be in low-power mode
467+
to set the entire System in low-power mode, corresponding to
468+
the deepest low-power mode possible.
469+
For example, CPU1 in Stop2 mode and CPU2 in Shutdown mode
470+
will make system enter in Stop2 mode. */
471+
#if defined(LL_PWR_MODE_STOP2)
472+
LL_C2_PWR_SetPowerMode(LL_PWR_MODE_STOP2);
473+
#else
474+
LL_C2_PWR_SetPowerMode(LL_PWR_MODE_SHUTDOWN);
475+
#endif
476+
#endif
463477
/* Enter Stop mode */
464478
#if defined(UART_WKUP_SUPPORT) && (defined(PWR_CPUCR_RETDS_CD) \
465479
|| defined(PWR_CR1_LPMS_STOP2) || defined(PWR_LOWPOWERMODE_STOP2) \
@@ -528,7 +542,17 @@ void LowPower_standby()
528542
/* Enable the fast wake up from Ultra low power mode */
529543
HAL_PWREx_EnableFastWakeUp();
530544
#endif
531-
545+
#if defined(STM32WBxx)
546+
/* Set low-power mode of CPU2 */
547+
/* Note: Typically, action performed by CPU2 on a dual core application.
548+
Since this example is single core, perform it by CPU1. */
549+
/* Note: On STM32WB, both CPU1 and CPU2 must be in low-power mode
550+
to set the entire System in low-power mode, corresponding to
551+
the deepest low-power mode possible.
552+
For example, CPU1 in Stop2 mode and CPU2 in Shutdown mode
553+
will make system enter in Stop2 mode. */
554+
LL_C2_PWR_SetPowerMode(LL_PWR_MODE_STANDBY);
555+
#endif
532556
HAL_PWR_EnterSTANDBYMode();
533557
}
534558

@@ -550,7 +574,17 @@ void LowPower_shutdown()
550574
#elif defined(PWR_MPUCR_CSSF)
551575
__HAL_PWR_CLEAR_FLAG(PWR_MPUCR_CSSF);
552576
#endif
553-
577+
#if defined(STM32WBxx)
578+
/* Set low-power mode of CPU2 */
579+
/* Note: Typically, action performed by CPU2 on a dual core application.
580+
Since this example is single core, perform it by CPU1. */
581+
/* Note: On STM32WB, both CPU1 and CPU2 must be in low-power mode
582+
to set the entire System in low-power mode, corresponding to
583+
the deepest low-power mode possible.
584+
For example, CPU1 in Stop2 mode and CPU2 in Shutdown mode
585+
will make system enter in Stop2 mode. */
586+
LL_C2_PWR_SetPowerMode(LL_PWR_MODE_SHUTDOWN);
587+
#endif
554588
#if defined(PWR_LOWPOWERMODE_SHUTDOWN) || defined(PWR_CR1_LPMS_SHUTDOWN) || defined(LL_PWR_SHUTDOWN_MODE)
555589
/* LSE must be on to use shutdown mode */
556590
if (__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == SET) {

0 commit comments

Comments
 (0)