Skip to content

Commit 61b4c21

Browse files
ABOSTMfpistm
authored andcommitted
feat(C0): Add C0 LowPower support
Signed-off-by: Alexandre Bourdiol <[email protected]>
1 parent 35e3307 commit 61b4c21

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

Diff for: src/STM32LowPower.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,12 @@ void STM32LowPower::sleep(uint32_t ms)
8282
if ((ms != 0) || _rtc_wakeup) {
8383
programRtcWakeUp(ms, SLEEP_MODE);
8484
}
85+
#if defined(PWR_LOWPOWERREGULATOR_ON)
8586
LowPower_sleep(PWR_LOWPOWERREGULATOR_ON);
87+
#else
88+
LowPower_sleep(PWR_MAINREGULATOR_ON);
89+
#endif
90+
8691
}
8792

8893
/**

Diff for: src/low_power.c

+11-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,11 @@ void LowPower_init()
6060
/* Enable Power Clock */
6161
__HAL_RCC_PWR_CLK_ENABLE();
6262
#endif
63+
64+
#if defined(PWR_CR_DBP) || defined(PWR_CR1_DBP) || defined(PWR_DBPR_DBP)
6365
/* Allow access to Backup domain */
6466
HAL_PWR_EnableBkUpAccess();
67+
#endif
6568

6669
#ifdef __HAL_RCC_WAKEUPSTOP_CLK_CONFIG
6770
/* Ensure that HSI is wake-up system clock */
@@ -385,7 +388,8 @@ void SystemClock_Decrease(void)
385388
void LowPower_sleep(uint32_t regulator)
386389
{
387390

388-
#if defined(PWR_CSR_REGLPF) || defined(PWR_SR2_REGLPF)
391+
#if defined(PWR_LOWPOWERREGULATOR_ON) && \
392+
(defined(PWR_CSR_REGLPF) || defined(PWR_SR2_REGLPF))
389393
// When LowPower regulator sleep mode is used, it is necessary to decrease CPU Frequency
390394
if (regulator == PWR_LOWPOWERREGULATOR_ON) {
391395
SystemClock_Decrease();
@@ -402,7 +406,8 @@ void LowPower_sleep(uint32_t regulator)
402406
/* Enter Sleep Mode , wake up is done once User push-button is pressed */
403407
HAL_PWR_EnterSLEEPMode(regulator, PWR_SLEEPENTRY_WFI);
404408

405-
#if defined(PWR_CSR_REGLPF) || defined(PWR_SR2_REGLPF)
409+
#if defined(PWR_LOWPOWERREGULATOR_ON) && \
410+
(defined(PWR_CSR_REGLPF) || defined(PWR_SR2_REGLPF))
406411
// In case of LowPower Regulator used for sleep, restore Main regulator on exit
407412
if (regulator == PWR_LOWPOWERREGULATOR_ON) {
408413
#if defined(__HAL_RCC_PWR_CLK_ENABLE)
@@ -492,7 +497,11 @@ void LowPower_stop(serial_t *obj)
492497
} else
493498
#endif
494499
{
500+
#if defined(PWR_LOWPOWERREGULATOR_ON)
495501
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
502+
#else
503+
HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI);
504+
#endif
496505
}
497506

498507
/* Exit Stop mode reset clocks */

0 commit comments

Comments
 (0)