2017-01-09 22:39:46 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2016 Kaspar Schleiser <kaspar@schleiser.de>
|
2017-01-09 23:33:16 +01:00
|
|
|
* 2015 Freie Universität Berlin
|
2017-01-09 22:39:46 +01:00
|
|
|
* 2015 Engineering-Spirit
|
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2017-10-01 21:55:59 +02:00
|
|
|
* @ingroup cpu_stm32_common
|
2017-06-22 15:43:17 +02:00
|
|
|
* @ingroup drivers_periph_pm
|
2017-01-09 22:39:46 +01:00
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @brief Implementation of the kernels power management interface
|
|
|
|
*
|
|
|
|
* @author Nick v. IJzendoorn <nijzndoorn@engineering-spirit.nl>
|
|
|
|
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
2017-01-09 23:33:16 +01:00
|
|
|
* @author Fabian Nack <nack@inf.fu-berlin.de>
|
2017-01-09 22:39:46 +01:00
|
|
|
*
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2017-01-09 23:33:16 +01:00
|
|
|
#include "irq.h"
|
2017-01-09 22:39:46 +01:00
|
|
|
#include "periph/pm.h"
|
2017-07-06 17:17:42 +02:00
|
|
|
#if defined(CPU_FAM_STM32F1) || defined(CPU_FAM_STM32F2) || \
|
2019-03-12 09:37:58 +01:00
|
|
|
defined(CPU_FAM_STM32F4) || defined(CPU_FAM_STM32L0) || \
|
|
|
|
defined(CPU_FAM_STM32L1)
|
2017-07-19 11:50:01 +02:00
|
|
|
#include "stmclk.h"
|
|
|
|
#endif
|
2017-01-09 22:39:46 +01:00
|
|
|
|
2017-05-15 16:37:55 +02:00
|
|
|
#define ENABLE_DEBUG (0)
|
2017-01-09 22:39:46 +01:00
|
|
|
#include "debug.h"
|
|
|
|
|
2017-07-19 11:50:01 +02:00
|
|
|
#ifndef PM_STOP_CONFIG
|
|
|
|
/**
|
|
|
|
* @brief Define config flags for stop mode
|
|
|
|
*
|
|
|
|
* Available values can be found in reference manual, PWR section, register CR.
|
|
|
|
*/
|
|
|
|
#define PM_STOP_CONFIG (PWR_CR_LPDS | PWR_CR_FPDS)
|
|
|
|
#endif
|
|
|
|
|
2017-01-09 22:39:46 +01:00
|
|
|
void pm_set(unsigned mode)
|
|
|
|
{
|
2017-03-28 20:00:03 +02:00
|
|
|
int deep = 0;
|
|
|
|
|
2017-01-09 23:33:16 +01:00
|
|
|
/* I just copied it from stm32f1/2/4, but I suppose it would work for the
|
|
|
|
* others... /KS */
|
2017-07-06 17:17:42 +02:00
|
|
|
#if defined(CPU_FAM_STM32F1) || defined(CPU_FAM_STM32F2) || \
|
2019-03-12 09:37:58 +01:00
|
|
|
defined(CPU_FAM_STM32F4) || defined(CPU_FAM_STM32L0) || \
|
|
|
|
defined(CPU_FAM_STM32L1)
|
2017-01-09 22:39:46 +01:00
|
|
|
switch (mode) {
|
2017-10-23 11:36:18 +02:00
|
|
|
case STM32_PM_STANDBY:
|
2017-01-09 23:33:16 +01:00
|
|
|
/* 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 */
|
2019-03-12 09:37:58 +01:00
|
|
|
#if defined(CPU_FAM_STM32L0) || defined(CPU_FAM_STM32L1)
|
|
|
|
/* Enable Ultra Low Power mode */
|
2019-03-12 12:18:36 +01:00
|
|
|
PWR->CR |= PWR_CR_ULP;
|
2019-03-12 09:37:58 +01:00
|
|
|
|
2019-03-12 16:26:34 +01:00
|
|
|
PWR->CSR |= PWR_CSR_EWUP1;
|
2018-07-09 11:49:09 +02:00
|
|
|
#if !defined(CPU_LINE_STM32L053xx)
|
2017-07-06 17:17:42 +02:00
|
|
|
/* STM32L053 only have 2 wake pins */
|
|
|
|
PWR->CSR |= PWR_CSR_EWUP3;
|
|
|
|
#endif
|
|
|
|
#else
|
2017-01-09 23:33:16 +01:00
|
|
|
PWR->CSR |= PWR_CSR_EWUP;
|
2017-07-06 17:17:42 +02:00
|
|
|
#endif
|
2017-01-09 23:33:16 +01:00
|
|
|
/* Set SLEEPDEEP bit of system control block */
|
2017-03-28 20:00:03 +02:00
|
|
|
deep = 1;
|
2017-01-09 22:39:46 +01:00
|
|
|
break;
|
2017-10-23 11:36:18 +02:00
|
|
|
case STM32_PM_STOP:
|
2019-03-12 09:37:58 +01:00
|
|
|
#if defined(CPU_FAM_STM32L0) || defined(CPU_FAM_STM32L1)
|
|
|
|
/* Clear Wakeup flag */
|
|
|
|
PWR->CR |= PWR_CR_CWUF;
|
2019-03-12 12:18:36 +01:00
|
|
|
/* Clear PDDS to enter stop mode on */
|
2017-07-06 17:17:42 +02:00
|
|
|
PWR->CR &= ~(PWR_CR_PDDS);
|
2019-03-12 09:37:58 +01:00
|
|
|
/* Regulator in LP mode */
|
2019-03-12 12:18:36 +01:00
|
|
|
PWR->CR |= PWR_CR_LPSDSR;
|
2019-03-12 09:37:58 +01:00
|
|
|
|
|
|
|
/* Enable Ultra Low Power mode*/
|
2019-03-12 12:18:36 +01:00
|
|
|
PWR->CR |= PWR_CR_ULP;
|
2017-07-06 17:17:42 +02:00
|
|
|
#else
|
2017-01-09 22:39:46 +01:00
|
|
|
/* Clear PDDS and LPDS bits to enter stop mode on */
|
|
|
|
/* deepsleep with voltage regulator on */
|
|
|
|
PWR->CR &= ~(PWR_CR_PDDS | PWR_CR_LPDS);
|
2017-07-19 11:50:01 +02:00
|
|
|
PWR->CR |= PM_STOP_CONFIG;
|
2017-07-06 17:17:42 +02:00
|
|
|
#endif
|
2017-01-09 22:39:46 +01:00
|
|
|
/* Set SLEEPDEEP bit of system control block */
|
2017-03-28 20:00:03 +02:00
|
|
|
deep = 1;
|
2017-01-09 23:33:16 +01:00
|
|
|
break;
|
2017-01-09 22:39:46 +01:00
|
|
|
}
|
build: fix unused parameter errors
cpu, sam0_common: fix unused parameter in periph/spi
cpu, kinetis_common: fix unused parameter in periph/spi
cpu, cc2538: fix unused param in periph/i2c
cpu, cc2538: fix unused param in periph/spi
cpu, sam3: fix unused param in periph/spi
cpu, stm32_common: fix unused param in periph/pm
cpu, stm32f3: fix unused params in periph/i2c
cpu, nrf5x_common: fix unused param in periph/gpio
cpu, nrf5x_common: fix unused param in periph/spi
cpu, lpc2387: fix unused params in periph/spi
cpu, cc2538: fix unused params in radio/netdev
cpu, cc2650: fix unused params in periph/uart
cpu, lm4f120: fix unused param in periph/spi
cpu, lm4f120: fix unused params in periph/timer
cpu, lm4f120: fix unused params in periph/uart
cpu, stm32_common: fix unused params in periph/dac
cpu, stm32l0: fix unused params in periph/i2c
cpu, msp430fxyz: fix unused params in periph/uart
cpu, mips: fix unused params
cpu, cc430: fix unused-params in periph/timer
cpu, msp430fxyz: fix unused params in periph/spi
drivers, cc2420: fix unused param
cpu, mips32r2_common: fix unused params in periph/timer
cpu, cc2538: fix unused-param in periph/i2c
cpu, mips32r2_common: fix unused-param in periph/timer
cpu, msp430fxyz: fix unused params in periph/timer
cpu, atmega_common: fix unused params in periph/spi
driver, nrfmin: fix unused params
cpu, cc2538_rf: fix unused params
driver, netdev_ieee802514: fix unused param
cpu, mip_pic32m: fix unused params
cpu, lpc2387: fix unused params in periph/pwm
tests/driver_sdcard_spi: fix unused params
cpu, sam3: fix unused param in periph/pwm
tests/driver_dynamixel: fix unused params, and style issues
cpu, cc430: fix unused param in periph/rtc
cpu, atmega_common: fix unused params in periph/i2c
2017-10-31 12:09:11 +01:00
|
|
|
#else
|
|
|
|
(void) mode;
|
2017-01-09 23:33:16 +01:00
|
|
|
#endif
|
2017-01-09 22:39:46 +01:00
|
|
|
|
2017-03-28 20:00:03 +02:00
|
|
|
cortexm_sleep(deep);
|
2017-07-19 11:50:01 +02:00
|
|
|
|
2017-07-06 17:17:42 +02:00
|
|
|
#if defined(CPU_FAM_STM32F1) || defined(CPU_FAM_STM32F2) || \
|
2019-03-12 09:37:58 +01:00
|
|
|
defined(CPU_FAM_STM32F4) || defined(CPU_FAM_STM32L0) || \
|
|
|
|
defined(CPU_FAM_STM32L1)
|
2017-07-19 11:50:01 +02:00
|
|
|
if (deep) {
|
|
|
|
/* Re-init clock after STOP */
|
|
|
|
stmclk_init_sysclk();
|
|
|
|
}
|
|
|
|
#endif
|
2017-01-09 22:39:46 +01:00
|
|
|
}
|
|
|
|
|
2017-07-06 17:17:42 +02:00
|
|
|
#if defined(CPU_FAM_STM32F1) || defined(CPU_FAM_STM32F2) || \
|
2019-03-12 09:37:58 +01:00
|
|
|
defined(CPU_FAM_STM32F4) || defined(CPU_FAM_STM32L0) || \
|
|
|
|
defined(CPU_FAM_STM32L1)
|
2017-01-09 22:39:46 +01:00
|
|
|
void pm_off(void)
|
|
|
|
{
|
2017-01-09 23:33:16 +01:00
|
|
|
irq_disable();
|
|
|
|
pm_set(0);
|
2017-01-09 22:39:46 +01:00
|
|
|
}
|
2017-01-09 23:33:16 +01:00
|
|
|
#endif
|