annotate Common/Drivers/STM32F4xx_HAL_DRIVER_v120/Src/stm32f4xx_hal_pwr_ex.c @ 75:2b3f8ed4a0b8

Update version info
author Ideenmodellierer
date Thu, 04 Oct 2018 20:41:21 +0200
parents 5f11787b4f42
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3 * @file stm32f4xx_hal_pwr_ex.c
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
4 * @author MCD Application Team
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
5 * @version V1.2.0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
6 * @date 26-December-2014
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
7 * @brief Extended PWR HAL module driver.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
8 * This file provides firmware functions to manage the following
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
9 * functionalities of PWR extension peripheral:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
10 * + Peripheral Extended features functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
11 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
12 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
13 * @attention
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
14 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
15 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
16 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
17 * Redistribution and use in source and binary forms, with or without modification,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
18 * are permitted provided that the following conditions are met:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
19 * 1. Redistributions of source code must retain the above copyright notice,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
20 * this list of conditions and the following disclaimer.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
21 * 2. Redistributions in binary form must reproduce the above copyright notice,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
22 * this list of conditions and the following disclaimer in the documentation
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
23 * and/or other materials provided with the distribution.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
24 * 3. Neither the name of STMicroelectronics nor the names of its contributors
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
25 * may be used to endorse or promote products derived from this software
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
26 * without specific prior written permission.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
27 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
29 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
31 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
34 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
36 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
37 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
38 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
39 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
40 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
41
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
42 /* Includes ------------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
43 #include "stm32f4xx_hal.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
44
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
45 /** @addtogroup STM32F4xx_HAL_Driver
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
46 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
47 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
48
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
49 /** @defgroup PWREx PWREx
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
50 * @brief PWR HAL module driver
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
51 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
52 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
53
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
54 #ifdef HAL_PWR_MODULE_ENABLED
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
55
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
56 /* Private typedef -----------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
57 /* Private define ------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
58 /** @addtogroup PWREx_Private_Constants
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
59 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
60 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
61 #define PWR_OVERDRIVE_TIMEOUT_VALUE 1000
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
62 #define PWR_UDERDRIVE_TIMEOUT_VALUE 1000
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
63 #define PWR_BKPREG_TIMEOUT_VALUE 1000
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
64 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
65 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
66 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
67
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
68 /* Private macro -------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
69 /* Private variables ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
70 /* Private function prototypes -----------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
71 /* Private functions ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
72 /** @defgroup PWREx_Exported_Functions PWREx Exported Functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
73 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
74 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
75
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
76 /** @defgroup PWREx_Exported_Functions_Group1 Peripheral Extended features functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
77 * @brief Peripheral Extended features functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
78 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
79 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
80
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
81 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
82 ##### Peripheral extended features functions #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
83 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
84
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
85 *** Main and Backup Regulators configuration ***
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
86 ================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
87 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
88 (+) The backup domain includes 4 Kbytes of backup SRAM accessible only from
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
89 the CPU, and address in 32-bit, 16-bit or 8-bit mode. Its content is
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
90 retained even in Standby or VBAT mode when the low power backup regulator
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
91 is enabled. It can be considered as an internal EEPROM when VBAT is
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
92 always present. You can use the HAL_PWREx_EnableBkUpReg() function to
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
93 enable the low power backup regulator.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
94
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
95 (+) When the backup domain is supplied by VDD (analog switch connected to VDD)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
96 the backup SRAM is powered from VDD which replaces the VBAT power supply to
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
97 save battery life.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
98
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
99 (+) The backup SRAM is not mass erased by a tamper event. It is read
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
100 protected to prevent confidential data, such as cryptographic private
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
101 key, from being accessed. The backup SRAM can be erased only through
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
102 the Flash interface when a protection level change from level 1 to
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
103 level 0 is requested.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
104 -@- Refer to the description of Read protection (RDP) in the Flash
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
105 programming manual.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
106
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
107 (+) The main internal regulator can be configured to have a tradeoff between
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
108 performance and power consumption when the device does not operate at
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
109 the maximum frequency. This is done through __HAL_PWR_MAINREGULATORMODE_CONFIG()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
110 macro which configure VOS bit in PWR_CR register
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
111
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
112 Refer to the product datasheets for more details.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
113
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
114 *** FLASH Power Down configuration ****
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
115 =======================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
116 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
117 (+) By setting the FPDS bit in the PWR_CR register by using the
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
118 HAL_PWREx_EnableFlashPowerDown() function, the Flash memory also enters power
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
119 down mode when the device enters Stop mode. When the Flash memory
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
120 is in power down mode, an additional startup delay is incurred when
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
121 waking up from Stop mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
122
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
123 (+) For STM32F42xxx/43xxx Devices, the scale can be modified only when the PLL
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
124 is OFF and the HSI or HSE clock source is selected as system clock.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
125 The new value programmed is active only when the PLL is ON.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
126 When the PLL is OFF, the voltage scale 3 is automatically selected.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
127 Refer to the datasheets for more details.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
128
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
129 *** Over-Drive and Under-Drive configuration ****
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
130 =================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
131 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
132 (+) For STM32F42xxx/43xxx Devices, in Run mode: the main regulator has
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
133 2 operating modes available:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
134 (++) Normal mode: The CPU and core logic operate at maximum frequency at a given
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
135 voltage scaling (scale 1, scale 2 or scale 3)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
136 (++) Over-drive mode: This mode allows the CPU and the core logic to operate at a
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
137 higher frequency than the normal mode for a given voltage scaling (scale 1,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
138 scale 2 or scale 3). This mode is enabled through HAL_PWREx_EnableOverDrive() function and
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
139 disabled by HAL_PWREx_DisableOverDrive() function, to enter or exit from Over-drive mode please follow
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
140 the sequence described in Reference manual.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
141
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
142 (+) For STM32F42xxx/43xxx Devices, in Stop mode: the main regulator or low power regulator
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
143 supplies a low power voltage to the 1.2V domain, thus preserving the content of registers
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
144 and internal SRAM. 2 operating modes are available:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
145 (++) Normal mode: the 1.2V domain is preserved in nominal leakage mode. This mode is only
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
146 available when the main regulator or the low power regulator is used in Scale 3 or
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
147 low voltage mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
148 (++) Under-drive mode: the 1.2V domain is preserved in reduced leakage mode. This mode is only
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
149 available when the main regulator or the low power regulator is in low voltage mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
150
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
151 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
152 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
153 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
154
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
155 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
156 * @brief Enables the Backup Regulator.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
157 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
158 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
159 HAL_StatusTypeDef HAL_PWREx_EnableBkUpReg(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
160 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
161 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
162
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
163 *(__IO uint32_t *) CSR_BRE_BB = (uint32_t)ENABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
164
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
165 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
166 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
167
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
168 /* Wait till Backup regulator ready flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
169 while(__HAL_PWR_GET_FLAG(PWR_FLAG_BRR) == RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
170 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
171 if((HAL_GetTick() - tickstart ) > PWR_BKPREG_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
172 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
173 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
174 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
175 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
176 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
177 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
178
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
179 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
180 * @brief Disables the Backup Regulator.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
181 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
182 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
183 HAL_StatusTypeDef HAL_PWREx_DisableBkUpReg(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
184 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
185 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
186
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
187 *(__IO uint32_t *) CSR_BRE_BB = (uint32_t)DISABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
188
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
189 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
190 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
191
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
192 /* Wait till Backup regulator ready flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
193 while(__HAL_PWR_GET_FLAG(PWR_FLAG_BRR) != RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
194 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
195 if((HAL_GetTick() - tickstart ) > PWR_BKPREG_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
196 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
197 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
198 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
199 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
200 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
201 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
202
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
203 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
204 * @brief Enables the Flash Power Down in Stop mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
205 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
206 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
207 void HAL_PWREx_EnableFlashPowerDown(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
208 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
209 *(__IO uint32_t *) CR_FPDS_BB = (uint32_t)ENABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
210 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
211
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
212 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
213 * @brief Disables the Flash Power Down in Stop mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
214 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
215 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
216 void HAL_PWREx_DisableFlashPowerDown(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
217 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
218 *(__IO uint32_t *) CR_FPDS_BB = (uint32_t)DISABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
219 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
220
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
221 #if defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F411xE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
222 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
223 * @brief Enables Main Regulator low voltage mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
224 * @note This mode is only available for STM32F401xx/STM32F411xx devices.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
225 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
226 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
227 void HAL_PWREx_EnableMainRegulatorLowVoltage(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
228 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
229 *(__IO uint32_t *) CR_MRLVDS_BB = (uint32_t)ENABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
230 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
231
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
232 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
233 * @brief Disables Main Regulator low voltage mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
234 * @note This mode is only available for STM32F401xx/STM32F411xx devices.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
235 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
236 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
237 void HAL_PWREx_DisableMainRegulatorLowVoltage(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
238 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
239 *(__IO uint32_t *) CR_MRLVDS_BB = (uint32_t)DISABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
240 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
241
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
242 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
243 * @brief Enables Low Power Regulator low voltage mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
244 * @note This mode is only available for STM32F401xx/STM32F411xx devices.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
245 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
246 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
247 void HAL_PWREx_EnableLowRegulatorLowVoltage(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
248 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
249 *(__IO uint32_t *) CR_LPLVDS_BB = (uint32_t)ENABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
250 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
251
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
252 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
253 * @brief Disables Low Power Regulator low voltage mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
254 * @note This mode is only available for STM32F401xx/STM32F411xx devices.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
255 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
256 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
257 void HAL_PWREx_DisableLowRegulatorLowVoltage(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
258 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
259 *(__IO uint32_t *) CR_LPLVDS_BB = (uint32_t)DISABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
260 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
261
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
262 #endif /* STM32F401xC || STM32F401xE || STM32F411xE */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
263
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
264 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
265 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
266 * @brief Activates the Over-Drive mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
267 * @note This function can be used only for STM32F42xx/STM32F43xx devices.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
268 * This mode allows the CPU and the core logic to operate at a higher frequency
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
269 * than the normal mode for a given voltage scaling (scale 1, scale 2 or scale 3).
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
270 * @note It is recommended to enter or exit Over-drive mode when the application is not running
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
271 * critical tasks and when the system clock source is either HSI or HSE.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
272 * During the Over-drive switch activation, no peripheral clocks should be enabled.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
273 * The peripheral clocks must be enabled once the Over-drive mode is activated.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
274 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
275 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
276 HAL_StatusTypeDef HAL_PWREx_EnableOverDrive(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
277 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
278 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
279
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
280 __HAL_RCC_PWR_CLK_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
281
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
282 /* Enable the Over-drive to extend the clock frequency to 180 Mhz */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
283 __HAL_PWR_OVERDRIVE_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
284
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
285 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
286 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
287
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
288 while(!__HAL_PWR_GET_FLAG(PWR_FLAG_ODRDY))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
289 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
290 if((HAL_GetTick() - tickstart ) > PWR_OVERDRIVE_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
291 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
292 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
293 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
294 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
295
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
296 /* Enable the Over-drive switch */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
297 __HAL_PWR_OVERDRIVESWITCHING_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
298
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
299 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
300 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
301
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
302 while(!__HAL_PWR_GET_FLAG(PWR_FLAG_ODSWRDY))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
303 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
304 if((HAL_GetTick() - tickstart ) > PWR_OVERDRIVE_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
305 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
306 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
307 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
308 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
309 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
310 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
311
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
312 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
313 * @brief Deactivates the Over-Drive mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
314 * @note This function can be used only for STM32F42xx/STM32F43xx devices.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
315 * This mode allows the CPU and the core logic to operate at a higher frequency
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
316 * than the normal mode for a given voltage scaling (scale 1, scale 2 or scale 3).
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
317 * @note It is recommended to enter or exit Over-drive mode when the application is not running
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
318 * critical tasks and when the system clock source is either HSI or HSE.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
319 * During the Over-drive switch activation, no peripheral clocks should be enabled.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
320 * The peripheral clocks must be enabled once the Over-drive mode is activated.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
321 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
322 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
323 HAL_StatusTypeDef HAL_PWREx_DisableOverDrive(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
324 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
325 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
326
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
327 __HAL_RCC_PWR_CLK_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
328
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
329 /* Disable the Over-drive switch */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
330 __HAL_PWR_OVERDRIVESWITCHING_DISABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
331
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
332 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
333 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
334
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
335 while(__HAL_PWR_GET_FLAG(PWR_FLAG_ODSWRDY))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
336 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
337 if((HAL_GetTick() - tickstart ) > PWR_OVERDRIVE_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
338 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
339 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
340 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
341 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
342
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
343 /* Disable the Over-drive */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
344 __HAL_PWR_OVERDRIVE_DISABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
345
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
346 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
347 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
348
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
349 while(__HAL_PWR_GET_FLAG(PWR_FLAG_ODRDY))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
350 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
351 if((HAL_GetTick() - tickstart ) > PWR_OVERDRIVE_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
352 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
353 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
354 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
355 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
356
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
357 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
358 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
359
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
360 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
361 * @brief Enters in Under-Drive STOP mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
362 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
363 * @note This mode is only available for STM32F42xxx/STM324F3xxx devices.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
364 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
365 * @note This mode can be selected only when the Under-Drive is already active
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
366 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
367 * @note This mode is enabled only with STOP low power mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
368 * In this mode, the 1.2V domain is preserved in reduced leakage mode. This
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
369 * mode is only available when the main regulator or the low power regulator
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
370 * is in low voltage mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
371 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
372 * @note If the Under-drive mode was enabled, it is automatically disabled after
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
373 * exiting Stop mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
374 * When the voltage regulator operates in Under-drive mode, an additional
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
375 * startup delay is induced when waking up from Stop mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
376 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
377 * @note In Stop mode, all I/O pins keep the same state as in Run mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
378 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
379 * @note When exiting Stop mode by issuing an interrupt or a wake-up event,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
380 * the HSI RC oscillator is selected as system clock.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
381 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
382 * @note When the voltage regulator operates in low power mode, an additional
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
383 * startup delay is incurred when waking up from Stop mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
384 * By keeping the internal regulator ON during Stop mode, the consumption
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
385 * is higher although the startup time is reduced.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
386 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
387 * @param Regulator: specifies the regulator state in STOP mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
388 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
389 * @arg PWR_MAINREGULATOR_UNDERDRIVE_ON: Main Regulator in under-drive mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
390 * and Flash memory in power-down when the device is in Stop under-drive mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
391 * @arg PWR_LOWPOWERREGULATOR_UNDERDRIVE_ON: Low Power Regulator in under-drive mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
392 * and Flash memory in power-down when the device is in Stop under-drive mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
393 * @param STOPEntry: specifies if STOP mode in entered with WFI or WFE instruction.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
394 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
395 * @arg PWR_SLEEPENTRY_WFI: enter STOP mode with WFI instruction
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
396 * @arg PWR_SLEEPENTRY_WFE: enter STOP mode with WFE instruction
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
397 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
398 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
399 HAL_StatusTypeDef HAL_PWREx_EnterUnderDriveSTOPMode(uint32_t Regulator, uint8_t STOPEntry)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
400 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
401 uint32_t tmpreg = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
402 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
403
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
404 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
405 assert_param(IS_PWR_REGULATOR_UNDERDRIVE(Regulator));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
406 assert_param(IS_PWR_STOP_ENTRY(STOPEntry));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
407
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
408 /* Enable Power ctrl clock */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
409 __HAL_RCC_PWR_CLK_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
410 /* Enable the Under-drive Mode ---------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
411 /* Clear Under-drive flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
412 __HAL_PWR_CLEAR_ODRUDR_FLAG();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
413
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
414 /* Enable the Under-drive */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
415 __HAL_PWR_UNDERDRIVE_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
416
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
417 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
418 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
419
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
420 /* Wait for UnderDrive mode is ready */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
421 while(__HAL_PWR_GET_FLAG(PWR_FLAG_UDRDY))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
422 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
423 if((HAL_GetTick() - tickstart ) > PWR_UDERDRIVE_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
424 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
425 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
426 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
427 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
428
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
429 /* Select the regulator state in STOP mode ---------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
430 tmpreg = PWR->CR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
431 /* Clear PDDS, LPDS, MRLUDS and LPLUDS bits */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
432 tmpreg &= (uint32_t)~(PWR_CR_PDDS | PWR_CR_LPDS | PWR_CR_LPUDS | PWR_CR_MRUDS);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
433
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
434 /* Set LPDS, MRLUDS and LPLUDS bits according to PWR_Regulator value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
435 tmpreg |= Regulator;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
436
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
437 /* Store the new value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
438 PWR->CR = tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
439
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
440 /* Set SLEEPDEEP bit of Cortex System Control Register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
441 SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
442
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
443 /* Select STOP mode entry --------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
444 if(STOPEntry == PWR_SLEEPENTRY_WFI)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
445 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
446 /* Request Wait For Interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
447 __WFI();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
448 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
449 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
450 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
451 /* Request Wait For Event */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
452 __WFE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
453 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
454 /* Reset SLEEPDEEP bit of Cortex System Control Register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
455 SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
456
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
457 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
458 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
459
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
460 #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
461 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
462 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
463 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
464
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
465 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
466 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
467 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
468
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
469 #endif /* HAL_PWR_MODULE_ENABLED */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
470 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
471 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
472 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
473
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
474 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
475 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
476 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
477
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
478 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/