arch/arm/src/stm32f7: Port the low-level PM functions to STM32F7.
This commit is contained in:
parent
b7bec7f064
commit
069e9b899c
@ -125,10 +125,7 @@ int stm32_pmstandby(void);
|
||||
* - false: SLEEPONEXIT bit is cleared, the MCU enters Sleep mode
|
||||
* as soon as WFI or WFE instruction is executed.
|
||||
* Returned Value:
|
||||
* Zero means that the STOP was successfully entered and the system has
|
||||
* been re-awakened. The internal voltage regulator is back to its
|
||||
* original state. Otherwise, STOP mode did not occur and a negated
|
||||
* errno value is returned to indicate the cause of the failure.
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
@ -77,10 +77,7 @@
|
||||
* - false: SLEEPONEXIT bit is cleared, the MCU enters Sleep mode
|
||||
* as soon as WFI or WFE instruction is executed.
|
||||
* Returned Value:
|
||||
* Zero means that the STOP was successfully entered and the system has
|
||||
* been re-awakened. The internal volatage regulator is back to its
|
||||
* original state. Otherwise, STOP mode did not occur and a negated
|
||||
* errno value is returned to indicate the cause of the failure.
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
@ -134,6 +134,13 @@ ifeq ($(CONFIG_STM32F7_DMA),y)
|
||||
CHIP_CSRCS += stm32_dma.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_PM),y)
|
||||
CHIP_CSRCS += stm32_pmstandby.c stm32_pmstop.c stm32_pmsleep.c
|
||||
ifneq ($(CONFIG_ARCH_CUSTOM_PMINIT),y)
|
||||
CHIP_CSRCS += stm32_pminitialize.c
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_STM32F7_PWR),y)
|
||||
CHIP_CSRCS += stm32_pwr.c stm32_exti_pwr.c
|
||||
endif
|
||||
|
122
arch/arm/src/stm32f7/stm32_pm.h
Normal file
122
arch/arm/src/stm32f7/stm32_pm.h
Normal file
@ -0,0 +1,122 @@
|
||||
/************************************************************************************
|
||||
* arch/arm/src/stm32f7/stm32_pm.h
|
||||
*
|
||||
* Copyright (C) 2018 Haltian Ltd. All rights reserved.
|
||||
* Author: Juha Niskanen <juha.niskanen@haltian.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
#ifndef __ARCH_ARM_SRC_STM32F7_STM32_PM_H
|
||||
#define __ARCH_ARM_SRC_STM32F7_STM32_PM_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "chip.h"
|
||||
#include "up_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_pmstop
|
||||
*
|
||||
* Description:
|
||||
* Enter STOP mode.
|
||||
*
|
||||
* Input Parameters:
|
||||
* lpds - true: To further reduce power consumption in Stop mode, put the
|
||||
* internal voltage regulator in low-power under-drive mode using the
|
||||
* LPDS and LPUDS bits of the Power control register (PWR_CR1).
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void stm32_pmstop(bool lpds);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_pmstandby
|
||||
*
|
||||
* Description:
|
||||
* Enter STANDBY mode.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void stm32_pmstandby(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_pmsleep
|
||||
*
|
||||
* Description:
|
||||
* Enter SLEEP mode.
|
||||
*
|
||||
* Input Parameters:
|
||||
* sleeponexit - true: SLEEPONEXIT bit is set when the WFI instruction is
|
||||
* executed, the MCU enters Sleep mode as soon as it
|
||||
* exits the lowest priority ISR.
|
||||
* - false: SLEEPONEXIT bit is cleared, the MCU enters Sleep mode
|
||||
* as soon as WFI or WFE instruction is executed.
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void stm32_pmsleep(bool sleeponexit);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __ASSEMBLY__ */
|
||||
|
||||
#endif /* __ARCH_ARM_SRC_STM32F7_STM32_PM_H */
|
78
arch/arm/src/stm32f7/stm32_pminitialize.c
Normal file
78
arch/arm/src/stm32f7/stm32_pminitialize.c
Normal file
@ -0,0 +1,78 @@
|
||||
/****************************************************************************
|
||||
* arch/arm/src/stm32f7/stm32_pminitialize.c
|
||||
*
|
||||
* Copyright (C) 2012, 2017 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <nuttx/power/pm.h>
|
||||
|
||||
#include "up_internal.h"
|
||||
#include "stm32_pm.h"
|
||||
|
||||
#ifdef CONFIG_PM
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_pminitialize
|
||||
*
|
||||
* Description:
|
||||
* This function is called by MCU-specific logic at power-on reset in
|
||||
* order to provide one-time initialization the power management subystem.
|
||||
* This function must be called *very* early in the initialization sequence
|
||||
* *before* any other device drivers are initialized (since they may
|
||||
* attempt to register with the power management subsystem).
|
||||
*
|
||||
* Input Parameters:
|
||||
* None.
|
||||
*
|
||||
* Returned Value:
|
||||
* None.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void up_pminitialize(void)
|
||||
{
|
||||
/* Then initialize the NuttX power management subsystem proper */
|
||||
|
||||
pm_initialize();
|
||||
}
|
||||
|
||||
#endif /* CONFIG_PM */
|
101
arch/arm/src/stm32f7/stm32_pmsleep.c
Normal file
101
arch/arm/src/stm32f7/stm32_pmsleep.c
Normal file
@ -0,0 +1,101 @@
|
||||
/****************************************************************************
|
||||
* arch/arm/src/stm32f7/stm32_pmsleep.c
|
||||
*
|
||||
* Copyright (C) 2012, 2017 Gregory Nutt. All rights reserved.
|
||||
* Authors: Gregory Nutt <gnutt@nuttx.org>
|
||||
* Diego Sanchez <dsanchez@nx-engineering.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "up_arch.h"
|
||||
#include "nvic.h"
|
||||
#include "stm32_pwr.h"
|
||||
#include "stm32_pm.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_pmsleep
|
||||
*
|
||||
* Description:
|
||||
* Enter SLEEP mode.
|
||||
*
|
||||
* Input Parameters:
|
||||
* sleeponexit - true: SLEEPONEXIT bit is set when the WFI instruction is
|
||||
* executed, the MCU enters Sleep mode as soon as it
|
||||
* exits the lowest priority ISR.
|
||||
* - false: SLEEPONEXIT bit is cleared, the MCU enters Sleep mode
|
||||
* as soon as WFI or WFE instruction is executed.
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void stm32_pmsleep(bool sleeponexit)
|
||||
{
|
||||
uint32_t regval;
|
||||
|
||||
/* Clear SLEEPDEEP bit of Cortex System Control Register */
|
||||
|
||||
regval = getreg32(NVIC_SYSCON);
|
||||
regval &= ~NVIC_SYSCON_SLEEPDEEP;
|
||||
if (sleeponexit)
|
||||
{
|
||||
regval |= NVIC_SYSCON_SLEEPONEXIT;
|
||||
}
|
||||
else
|
||||
{
|
||||
regval &= ~NVIC_SYSCON_SLEEPONEXIT;
|
||||
}
|
||||
|
||||
putreg32(regval, NVIC_SYSCON);
|
||||
|
||||
/* Sleep until the wakeup interrupt or event occurs */
|
||||
|
||||
#ifdef CONFIG_PM_WFE
|
||||
/* Mode: SLEEP + Entry with WFE */
|
||||
|
||||
asm("wfe");
|
||||
#else
|
||||
/* Mode: SLEEP + Entry with WFI */
|
||||
|
||||
asm("wfi");
|
||||
#endif
|
||||
}
|
96
arch/arm/src/stm32f7/stm32_pmstandby.c
Normal file
96
arch/arm/src/stm32f7/stm32_pmstandby.c
Normal file
@ -0,0 +1,96 @@
|
||||
/****************************************************************************
|
||||
* arch/arm/src/stm32f7/stm32_pmstandby.c
|
||||
*
|
||||
* Copyright (C) 2018 Haltian Ltd. All rights reserved.
|
||||
* Author: Juha Niskanen <juha.niskanen@haltian.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "up_arch.h"
|
||||
#include "nvic.h"
|
||||
#include "stm32_rcc.h"
|
||||
#include "stm32_pwr.h"
|
||||
#include "stm32_pm.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_pmstandby
|
||||
*
|
||||
* Description:
|
||||
* Enter STANDBY mode.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void stm32_pmstandby(void)
|
||||
{
|
||||
uint32_t regval;
|
||||
|
||||
/* Clear the wake-up flags before reseting. */
|
||||
|
||||
modifyreg32(STM32_PWR_CR1, 0, PWR_CR1_CSBF);
|
||||
modifyreg32(STM32_PWR_CR2, 0, PWR_CR2_CWUPF1 | PWR_CR2_CWUPF2 |
|
||||
PWR_CR2_CWUPF3 | PWR_CR2_CWUPF4 |
|
||||
PWR_CR2_CWUPF5 | PWR_CR2_CWUPF6);
|
||||
|
||||
/* Clear reset flags. */
|
||||
|
||||
modifyreg32(STM32_RCC_CSR, 0, RCC_CSR_RMVF);
|
||||
|
||||
/* Set the Power Down Deep Sleep (PDDS) bit in the power control register. */
|
||||
|
||||
modifyreg32(STM32_PWR_CR1, 0, PWR_CR1_PDDS);
|
||||
|
||||
/* Set SLEEPDEEP bit of Cortex System Control Register */
|
||||
|
||||
regval = getreg32(NVIC_SYSCON);
|
||||
regval |= NVIC_SYSCON_SLEEPDEEP;
|
||||
putreg32(regval, NVIC_SYSCON);
|
||||
|
||||
/* Sleep until the wakeup reset occurs */
|
||||
|
||||
asm("wfi");
|
||||
}
|
129
arch/arm/src/stm32f7/stm32_pmstop.c
Normal file
129
arch/arm/src/stm32f7/stm32_pmstop.c
Normal file
@ -0,0 +1,129 @@
|
||||
/****************************************************************************
|
||||
* arch/arm/src/stm32f7/stm32_pmstop.c
|
||||
*
|
||||
* Copyright (C) 2018 Haltian Ltd. All rights reserved.
|
||||
* Author: Juha Niskanen <juha.niskanen@haltian.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "up_arch.h"
|
||||
#include "nvic.h"
|
||||
#include "stm32_pwr.h"
|
||||
#include "stm32_pm.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_pmstop
|
||||
*
|
||||
* Description:
|
||||
* Enter STOP mode.
|
||||
*
|
||||
* Input Parameters:
|
||||
* lpds - true: To further reduce power consumption in Stop mode, put the
|
||||
* internal voltage regulator in low-power under-drive mode using the
|
||||
* LPDS and LPUDS bits of the Power control register (PWR_CR1).
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void stm32_pmstop(bool lpds)
|
||||
{
|
||||
uint32_t regval;
|
||||
|
||||
/* Clear the Power Down Deep Sleep (PDDS), the Low Power Deep Sleep
|
||||
* (LPDS), Under-Drive Enable in Stop Mode (UDEN), Flash Power Down in Stop
|
||||
* Mode (FPDS), Main Regulator in Deepsleep Under-Drive Mode (MRUDS), and
|
||||
* Low-power Regulator in Deepsleep Under-Drive Mode (LPUDS) bits in
|
||||
* the power control register.
|
||||
*/
|
||||
|
||||
regval = getreg32(STM32_PWR_CR1);
|
||||
regval &= ~(PWR_CR1_LPDS | PWR_CR1_PDDS | PWR_CR1_FPDS);
|
||||
regval &= ~(PWR_CR1_UDEN_ENABLE | PWR_CR1_MRUDS | PWR_CR1_LPUDS);
|
||||
|
||||
/* Set under-drive enabled with low-power regulator. */
|
||||
|
||||
if (lpds)
|
||||
{
|
||||
regval |= PWR_CR1_UDEN_ENABLE | PWR_CR1_LPUDS | PWR_CR1_LPDS;
|
||||
}
|
||||
|
||||
putreg32(regval, STM32_PWR_CR1);
|
||||
|
||||
/* Set SLEEPDEEP bit of Cortex System Control Register */
|
||||
|
||||
regval = getreg32(NVIC_SYSCON);
|
||||
regval |= NVIC_SYSCON_SLEEPDEEP;
|
||||
putreg32(regval, NVIC_SYSCON);
|
||||
|
||||
/* Sleep until the wakeup interrupt or event occurs */
|
||||
|
||||
#ifdef CONFIG_PM_WFE
|
||||
/* Mode: SLEEP + Entry with WFE */
|
||||
|
||||
asm volatile ("wfe");
|
||||
#else
|
||||
/* Mode: SLEEP + Entry with WFI */
|
||||
|
||||
asm volatile ("wfi");
|
||||
#endif
|
||||
|
||||
/* Clear deep sleep bits, so that MCU does not go into deep sleep in idle. */
|
||||
|
||||
/* Clear the Power Down Deep Sleep (PDDS), the Low Power Deep Sleep
|
||||
* (LPDS) bits, Under-Drive Enable in Stop Mode (UDEN), Main Regulator in
|
||||
* Deepsleep Under-Drive Mode (MRUDS), and Low-power Regulator in Deepsleep
|
||||
* Under-Drive Mode (LPUDS) in the power control register.
|
||||
*/
|
||||
|
||||
regval = getreg32(STM32_PWR_CR1);
|
||||
regval &= ~(PWR_CR1_LPDS | PWR_CR1_PDDS);
|
||||
regval &= ~(PWR_CR1_UDEN_ENABLE | PWR_CR1_MRUDS | PWR_CR1_LPUDS);
|
||||
putreg32(regval, STM32_PWR_CR1);
|
||||
|
||||
/* Clear SLEEPDEEP bit of Cortex System Control Register */
|
||||
|
||||
regval = getreg32(NVIC_SYSCON);
|
||||
regval &= ~NVIC_SYSCON_SLEEPDEEP;
|
||||
putreg32(regval, NVIC_SYSCON);
|
||||
}
|
@ -131,10 +131,7 @@ int stm32l4_pmstandby(void);
|
||||
* - false: SLEEPONEXIT bit is cleared, the MCU enters Sleep mode
|
||||
* as soon as WFI or WFE instruction is executed.
|
||||
* Returned Value:
|
||||
* Zero means that the STOP was successfully entered and the system has
|
||||
* been re-awakened. The internal volatage regulator is back to its
|
||||
* original state. Otherwise, STOP mode did not occur and a negated
|
||||
* errno value is returned to indicate the cause of the failure.
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
@ -64,10 +64,7 @@
|
||||
* - false: SLEEPONEXIT bit is cleared, the MCU enters Sleep mode
|
||||
* as soon as WFI or WFE instruction is executed.
|
||||
* Returned Value:
|
||||
* Zero means that the STOP was successfully entered and the system has
|
||||
* been re-awakened. The internal volatage regulator is back to its
|
||||
* original state. Otherwise, STOP mode did not occur and a negated
|
||||
* errno value is returned to indicate the cause of the failure.
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user