Skip to content

feat(C0): Add C0 LowPower support #88

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 23, 2023
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions src/STM32LowPower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ void STM32LowPower::sleep(uint32_t ms)
if ((ms != 0) || _rtc_wakeup) {
programRtcWakeUp(ms, SLEEP_MODE);
}
#if defined(PWR_LOWPOWERREGULATOR_ON)
LowPower_sleep(PWR_LOWPOWERREGULATOR_ON);
#else
LowPower_sleep(PWR_MAINREGULATOR_ON);
#endif

}

/**
Expand Down
13 changes: 11 additions & 2 deletions src/low_power.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ void LowPower_init()
/* Enable Power Clock */
__HAL_RCC_PWR_CLK_ENABLE();
#endif

#if defined(PWR_CR_DBP) || defined(PWR_CR1_DBP) || defined(PWR_DBPR_DBP)
/* Allow access to Backup domain */
HAL_PWR_EnableBkUpAccess();
#endif

#ifdef __HAL_RCC_WAKEUPSTOP_CLK_CONFIG
/* Ensure that HSI is wake-up system clock */
Expand Down Expand Up @@ -385,7 +388,8 @@ void SystemClock_Decrease(void)
void LowPower_sleep(uint32_t regulator)
{

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

#if defined(PWR_CSR_REGLPF) || defined(PWR_SR2_REGLPF)
#if defined(PWR_LOWPOWERREGULATOR_ON) && \
(defined(PWR_CSR_REGLPF) || defined(PWR_SR2_REGLPF))
// In case of LowPower Regulator used for sleep, restore Main regulator on exit
if (regulator == PWR_LOWPOWERREGULATOR_ON) {
#if defined(__HAL_RCC_PWR_CLK_ENABLE)
Expand Down Expand Up @@ -492,7 +497,11 @@ void LowPower_stop(serial_t *obj)
} else
#endif
{
#if defined(PWR_LOWPOWERREGULATOR_ON)
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
#else
HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI);
#endif
}

/* Exit Stop mode reset clocks */
Expand Down