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

cpu/stm32l1: add stop and standby modes, adds pm_layered #11159

Merged
merged 2 commits into from
Mar 13, 2019
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
3 changes: 2 additions & 1 deletion cpu/stm32_common/include/periph_cpu_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ extern "C" {
* @brief Number of usable low power modes
*/
#if defined(CPU_FAM_STM32F1) || defined(CPU_FAM_STM32F2) || \
defined(CPU_FAM_STM32F4) || defined(CPU_FAM_STM32L0) || defined(DOXYGEN)
defined(CPU_FAM_STM32F4) || defined(CPU_FAM_STM32L0) || \
defined(CPU_FAM_STM32L1) || defined(DOXYGEN)
#define PM_NUM_MODES (2U)

/**
Expand Down
34 changes: 21 additions & 13 deletions cpu/stm32_common/periph/pm.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
#include "irq.h"
#include "periph/pm.h"
#if defined(CPU_FAM_STM32F1) || defined(CPU_FAM_STM32F2) || \
defined(CPU_FAM_STM32F4) || defined(CPU_FAM_STM32L0)
defined(CPU_FAM_STM32F4) || defined(CPU_FAM_STM32L0) || \
defined(CPU_FAM_STM32L1)
#include "stmclk.h"
#endif

Expand All @@ -49,13 +50,17 @@ void pm_set(unsigned mode)
/* I just copied it from stm32f1/2/4, but I suppose it would work for the
* others... /KS */
#if defined(CPU_FAM_STM32F1) || defined(CPU_FAM_STM32F2) || \
defined(CPU_FAM_STM32F4) || defined(CPU_FAM_STM32L0)
defined(CPU_FAM_STM32F4) || defined(CPU_FAM_STM32L0) || \
defined(CPU_FAM_STM32L1)
switch (mode) {
case STM32_PM_STANDBY:
/* Set PDDS to enter standby mode on deepsleep and clear flags */
PWR->CR |= (PWR_CR_PDDS | PWR_CR_CWUF | PWR_CR_CSBF);
/* Enable WKUP pin to use for wakeup from standby mode */
#if defined(CPU_FAM_STM32L0)
#if defined(CPU_FAM_STM32L0) || defined(CPU_FAM_STM32L1)
/* Enable Ultra Low Power mode */
PWR->CR |= PWR_CR_ULP;

PWR->CSR |= PWR_CSR_EWUP1;
#if !defined(CPU_LINE_STM32L053xx)
/* STM32L053 only have 2 wake pins */
Expand All @@ -68,15 +73,16 @@ void pm_set(unsigned mode)
deep = 1;
break;
case STM32_PM_STOP:
#if defined(CPU_FAM_STM32L0)
/* Clear PDDS to enter stop mode on */
/*
* Regarding LPSDSR, it's up to the user to configure it :
* 0: Voltage regulator on during Deepsleep/Sleep/Low-power run mode
* 1: Voltage regulator in low-power mode during
* Deepsleep/Sleep/Low-power run mode
*/
#if defined(CPU_FAM_STM32L0) || defined(CPU_FAM_STM32L1)
/* Clear Wakeup flag */
PWR->CR |= PWR_CR_CWUF;
/* Clear PDDS to enter stop mode on */
PWR->CR &= ~(PWR_CR_PDDS);
/* Regulator in LP mode */
PWR->CR |= PWR_CR_LPSDSR;

/* Enable Ultra Low Power mode*/
PWR->CR |= PWR_CR_ULP;
#else
/* Clear PDDS and LPDS bits to enter stop mode on */
/* deepsleep with voltage regulator on */
Expand All @@ -94,7 +100,8 @@ void pm_set(unsigned mode)
cortexm_sleep(deep);

#if defined(CPU_FAM_STM32F1) || defined(CPU_FAM_STM32F2) || \
defined(CPU_FAM_STM32F4) || defined(CPU_FAM_STM32L0)
defined(CPU_FAM_STM32F4) || defined(CPU_FAM_STM32L0) || \
defined(CPU_FAM_STM32L1)
if (deep) {
/* Re-init clock after STOP */
stmclk_init_sysclk();
Expand All @@ -103,7 +110,8 @@ void pm_set(unsigned mode)
}

#if defined(CPU_FAM_STM32F1) || defined(CPU_FAM_STM32F2) || \
defined(CPU_FAM_STM32F4) || defined(CPU_FAM_STM32L0)
defined(CPU_FAM_STM32F4) || defined(CPU_FAM_STM32L0) || \
defined(CPU_FAM_STM32L1)
void pm_off(void)
{
irq_disable();
Expand Down
2 changes: 2 additions & 0 deletions cpu/stm32l1/Makefile.include
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export CPU_ARCH = cortex-m3
export CPU_FAM = stm32l1

USEMODULE += pm_layered

include $(RIOTCPU)/stm32_common/Makefile.include
include $(RIOTMAKE)/arch/cortexm.inc.mk