1 /**
2   ******************************************************************************
3   * @file    stm32wbaxx_hal_pwr_ex.h
4   * @author  MCD Application Team
5   * @brief   Header file of PWR HAL Extended module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2022 STMicroelectronics.
10   * All rights reserved.
11   *
12   * This software is licensed under terms that can be found in the LICENSE file
13   * in the root directory of this software component.
14   * If no LICENSE file comes with this software, it is provided AS-IS.
15   *
16   ******************************************************************************
17   */
18 
19 /* Define to prevent recursive inclusion -------------------------------------*/
20 #ifndef STM32WBAxx_HAL_PWR_EX_H
21 #define STM32WBAxx_HAL_PWR_EX_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif /* __cplusplus */
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32wbaxx_hal_def.h"
29 
30 /** @addtogroup STM32WBAxx_HAL_Driver
31   * @{
32   */
33 
34 /** @addtogroup PWREx
35   * @{
36   */
37 
38 /* Exported types ------------------------------------------------------------*/
39 
40 /** @defgroup PWREx_Exported_Types PWR Extended Exported Types
41   * @{
42   */
43 
44 
45 /* Exported constants --------------------------------------------------------*/
46 
47 /** @defgroup PWREx_Exported_Constants PWR Extended Exported Constants
48   * @{
49   */
50 
51 /** @defgroup PWREx_RAM_Contents_Stop_Retention PWR Extended SRAM Contents Stop Retention
52   * @{
53   */
54 /* SRAM1 pages retention defines */
55 #define PWR_SRAM1_FULL_STOP_RETENTION        PWR_CR2_SRAM1PDS1     /*!< SRAM1 full retention in Stop modes */
56 
57 /* SRAM2 pages retention defines */
58 #define PWR_SRAM2_FULL_STOP_RETENTION        PWR_CR2_SRAM2PDS1     /*!< SRAM2 full retention in Stop modes */
59 
60 /* Cache RAMs retention defines */
61 #define PWR_ICACHE_FULL_STOP_RETENTION       PWR_CR2_ICRAMPDS      /*!< ICACHE SRAM retention in Stop modes */
62 /**
63   * @}
64   */
65 
66 
67 /** @defgroup PWREx_RAM_Contents_Standby_Retention PWR Extended SRAM Contents Standby Retention
68   * @{
69   */
70 #define PWR_SRAM1_FULL_STANDBY_RETENTION        PWR_CR1_R1RSB1      /*!< SRAM1 full retention in Standby mode      */
71 
72 #define PWR_SRAM2_FULL_STANDBY_RETENTION        PWR_CR1_R2RSB1      /*!< SRAM2 full retention in Standby mode      */
73 #define PWR_RADIOSRAM_FULL_STANDBY_RETENTION    PWR_CR1_RADIORSB    /*!< 2.4GHz RADIO SRAMs (TXRX and Sequence)
74                                                                          and Sleep clock retention in Standby mode */
75 /**
76   * @}
77   */
78 
79 #if defined(PWR_CR3_REGSEL)
80 /** @defgroup PWREx_Supply_Configuration PWR Extended Supply Configuration
81   * @{
82   */
83 #define PWR_LDO_SUPPLY                      (0U)            /* LDO supply  */
84 #define PWR_SMPS_SUPPLY                     PWR_CR3_REGSEL  /* SMPS supply */
85 /**
86   * @}
87   */
88 #endif /* defined(PWR_CR3_REGSEL) */
89 
90 /** @defgroup PWREx_Regulator_Voltage_Scale PWR Extended Regulator Voltage Scale
91   * @{
92   */
93 #define PWR_REGULATOR_VOLTAGE_SCALE1     PWR_VOSR_VOS       /*!< Voltage scaling range 1 */
94 #define PWR_REGULATOR_VOLTAGE_SCALE2     (0U)               /*!< Voltage scaling range 2 */
95 /**
96   * @}
97   */
98 
99 /** @defgroup PWREx_GPIO_Port PWR Extended GPIO Port
100   * @{
101   */
102 #define PWR_GPIO_A (0x00U) /*!< GPIO port A */
103 #define PWR_GPIO_B (0x01U) /*!< GPIO port B */
104 #define PWR_GPIO_C (0x02U) /*!< GPIO port C */
105 #define PWR_GPIO_H (0x07U) /*!< GPIO port H */
106 /**
107   * @}
108   */
109 
110 /** @defgroup PWREx_GPIO_Pin_Mask PWR Extended GPIO Pin Mask
111   * @{
112   */
113 #define PWR_GPIO_BIT_0      (0x00001U) /*!< GPIO port I/O pin 0  */
114 #define PWR_GPIO_BIT_1      (0x00002U) /*!< GPIO port I/O pin 1  */
115 #define PWR_GPIO_BIT_2      (0x00004U) /*!< GPIO port I/O pin 2  */
116 #define PWR_GPIO_BIT_3      (0x00008U) /*!< GPIO port I/O pin 3  */
117 #define PWR_GPIO_BIT_4      (0x00010U) /*!< GPIO port I/O pin 4  */
118 #define PWR_GPIO_BIT_5      (0x00020U) /*!< GPIO port I/O pin 5  */
119 #define PWR_GPIO_BIT_6      (0x00040U) /*!< GPIO port I/O pin 6  */
120 #define PWR_GPIO_BIT_7      (0x00080U) /*!< GPIO port I/O pin 7  */
121 #define PWR_GPIO_BIT_8      (0x00100U) /*!< GPIO port I/O pin 8  */
122 #define PWR_GPIO_BIT_9      (0x00200U) /*!< GPIO port I/O pin 9  */
123 #define PWR_GPIO_BIT_10     (0x00400U) /*!< GPIO port I/O pin 10 */
124 #define PWR_GPIO_BIT_11     (0x00800U) /*!< GPIO port I/O pin 11 */
125 #define PWR_GPIO_BIT_12     (0x01000U) /*!< GPIO port I/O pin 12 */
126 #define PWR_GPIO_BIT_13     (0x02000U) /*!< GPIO port I/O pin 13 */
127 #define PWR_GPIO_BIT_14     (0x04000U) /*!< GPIO port I/O pin 14 */
128 #define PWR_GPIO_BIT_15     (0x08000U) /*!< GPIO port I/O pin 15 */
129 #define PWR_GPIO_PIN_MASK   (0x0FFFFU)
130 /**
131   * @}
132   */
133 
134 /** @defgroup PWREx_RADIO_Mode PWR Extended 2.4 GHz RADIO operating mode
135   * @{
136   */
137 #define PWR_RADIO_DEEPSLEEP_MODE        (0x0U)               /*!< 2.4 GHz RADIO deep sleep mode */
138 #define PWR_RADIO_SLEEP_MODE            PWR_RADIOSCR_MODE_0  /*!< 2.4 GHz RADIO sleep mode      */
139 #define PWR_RADIO_ACTIVE_MODE           PWR_RADIOSCR_MODE_1  /*!< 2.4 GHz RADIO active mode     */
140 /**
141   * @}
142   */
143 
144 /** @defgroup PWREx_RADIO_PHY_Mode PWR Extended 2.4 GHz RADIO PHY operating mode
145   * @{
146   */
147 #define PWR_RADIO_PHY_SLEEP_MODE        (0x0U)                /*!< 2.4 GHz RADIO PHY sleep mode   */
148 #define PWR_RADIO_PHY_STANDBY_MODE      PWR_RADIOSCR_PHYMODE  /*!< 2.4 GHz RADIO PHY standby mode */
149 /**
150   * @}
151   */
152 
153 /** @defgroup PWREx_RADIO_ENCODE_Mode PWR Extended 2.4 GHz RADIO encryption operating mode
154   * @{
155   */
156 #define PWR_RADIO_ENCMODE_DISABLED     (0x0U)                /*!< 2.4 GHz RADIO encryption function disabled */
157 #define PWR_RADIO_ENCMODE_ENABLED      PWR_RADIOSCR_ENCMODE  /*!< 2.4 GHz RADIO encryption function enabled */
158 /**
159   * @}
160   */
161 
162 #if defined(PWR_RADIOSCR_REGPASEL)
163 /** @defgroup PWREx_Regulator_Input_Supply_Selection PWR Extended RADIO regulator input supply selection
164   * @{
165   */
166 #define PWR_RADIO_REG_VDDRFPA           (0x0U)                /*!< VDDRFPA pin selected as regulator REG_VDDHPA input supply   */
167 #define PWR_RADIO_REG_VDDHPA_VD11       PWR_RADIOSCR_REGPASEL
168 /*!< Regulator REG_VDDHPA input supply selection between VDDRFPA
169      and VDD11 dependent on requested regulated output voltage   */
170 /**
171   * @}
172   */
173 #endif /* defined(PWR_RADIOSCR_REGPASEL) */
174 
175 /**
176   * @}
177   */
178 
179 /* Exported macros -----------------------------------------------------------*/
180 
181 /** @defgroup PWREx_Exported_Macros PWR Extended Exported Macros
182   * @{
183   */
184 
185 /**
186   * @brief Configure the main internal regulator output voltage.
187   * @note  This macro is similar to HAL_PWREx_ControlVoltageScaling() API but
188   *        doesn't check whether or not VOSRDY flag is set. User may resort
189   *        to __HAL_PWR_GET_FLAG() macro to check VOSRDY bit state.
190   * @param  __REGULATOR__ : Specifies the regulator output voltage to achieve a
191   *                         tradeoff between performance and power consumption.
192   *                         This parameter can be one of the following values :
193   *                         @arg @ref PWR_REGULATOR_VOLTAGE_SCALE1 : Regulator voltage output scale 1.
194   *                                                                  Provides a typical output voltage at 1.2 V.
195   *                                                                  It allows a system clock frequency up to 100 MHz,
196   *                                                                  and is required for any 2.4 GHz RADIO transmit and
197   *                                                                  receive operation.
198   *                         @arg @ref PWR_REGULATOR_VOLTAGE_SCALE2 : Regulator voltage output scale 2.
199   *                                                                  The system clock frequency can be up to 16 MHz.
200   *                                                                  The 2.4 GHz RADIO shall not transmit nor receive.
201   * @retval None.
202   */
203 #define __HAL_PWR_VOLTAGESCALING_CONFIG(__REGULATOR__)  \
204   do                                                      \
205   {                                                       \
206     __IO uint32_t tmpreg;                                 \
207     MODIFY_REG(PWR->VOSR, PWR_VOSR_VOS, (__REGULATOR__)); \
208     /* Delay after an RCC peripheral clock enabling */    \
209     tmpreg = READ_BIT(PWR->VOSR, PWR_VOSR_VOS);           \
210     UNUSED(tmpreg);                                       \
211   } while(0)
212 /**
213   * @}
214   */
215 
216 /* Private constants ---------------------------------------------------------*/
217 
218 /** @addtogroup PWREx_Private_Constants PWR Extended Private Constants
219   * @{
220   */
221 
222 /* All available RAM retention in Stop mode define */
223 #define PWR_ALL_RAM_STOP_RETENTION_MASK (PWR_SRAM1_FULL_STOP_RETENTION | PWR_SRAM2_FULL_STOP_RETENTION  | \
224                                          PWR_ICACHE_FULL_STOP_RETENTION )
225 /* All available RAM retention in Standby mode define */
226 #define PWR_ALL_RAM_STANDBY_RETENTION_MASK (PWR_SRAM1_FULL_STANDBY_RETENTION | PWR_SRAM2_FULL_STANDBY_RETENTION)
227 /**
228   * @}
229   */
230 
231 /* Private macros --------------------------------------------------------*/
232 
233 /** @addtogroup PWREx_Private_Macros PWR Extended Private Macros
234   * @{
235   */
236 
237 #if defined(PWR_CR3_REGSEL)
238 /* Supply selection check macro */
239 #define IS_PWR_SUPPLY(PWR_SOURCE)                (((PWR_SOURCE) == PWR_LDO_SUPPLY) ||\
240                                                   ((PWR_SOURCE) == PWR_SMPS_SUPPLY))
241 #endif /* defined(PWR_CR3_REGSEL) */
242 
243 /* Voltage scaling range check macro */
244 #define IS_PWR_VOLTAGE_SCALING_RANGE(RANGE)      (((RANGE) == PWR_REGULATOR_VOLTAGE_SCALE1)   ||\
245                                                   ((RANGE) == PWR_REGULATOR_VOLTAGE_SCALE2))
246 
247 /* GPIO port check macro */
248 #define IS_PWR_GPIO_PORT(GPIO_PORT)              (((GPIO_PORT) == PWR_GPIO_A) ||\
249                                                   ((GPIO_PORT) == PWR_GPIO_B) ||\
250                                                   ((GPIO_PORT) == PWR_GPIO_C) ||\
251                                                   ((GPIO_PORT) == PWR_GPIO_H))
252 
253 /* GPIO pin mask check macro */
254 #define IS_PWR_GPIO_PIN_MASK(BIT_MASK)           ((((BIT_MASK) & PWR_GPIO_PIN_MASK) != 0U) &&\
255                                                   ((BIT_MASK) <= PWR_GPIO_PIN_MASK))
256 
257 /* SRAM1 retention in Standby mode check macro */
258 #define IS_PWR_SRAM1_STANDBY_RETENTION(CONTENT)  ((CONTENT) == PWR_SRAM1_FULL_STANDBY_RETENTION)
259 
260 /* SRAM2 retention in Standby mode check macro */
261 #define IS_PWR_SRAM2_STANDBY_RETENTION(CONTENT)  ((CONTENT) == PWR_SRAM2_FULL_STANDBY_RETENTION)
262 
263 /* RADIO SRAM retention in Standby mode check macro */
264 #define IS_PWR_RADIOSRAM_STANDBY_RETENTION(CONTENT)  ((CONTENT) == PWR_RADIOSRAM_FULL_STANDBY_RETENTION)
265 
266 /* RAMs retention in Stop mode check macro */
267 #define IS_PWR_RAM_STOP_RETENTION(RAMCONTENT)    (((RAMCONTENT) == PWR_SRAM1_FULL_STOP_RETENTION) ||\
268                                                   ((RAMCONTENT) == PWR_SRAM2_FULL_STOP_RETENTION) ||\
269                                                   ((RAMCONTENT) == PWR_ICACHE_FULL_STOP_RETENTION))
270 /**
271   * @}
272   */
273 
274 /** @addtogroup PWREx_Exported_Functions PWR Extended Exported Functions
275   * @{
276   */
277 
278 /** @addtogroup PWREx_Exported_Functions_Group1 Power Supply Control Functions
279   * @{
280   */
281 HAL_StatusTypeDef HAL_PWREx_ControlVoltageScaling(uint32_t VoltageScaling);
282 uint32_t          HAL_PWREx_GetVoltageRange(void);
283 
284 #if defined(PWR_CR3_REGSEL)
285 HAL_StatusTypeDef HAL_PWREx_ConfigSupply(uint32_t SupplySource);
286 uint32_t          HAL_PWREx_GetSupplyConfig(void);
287 #endif /* defined(PWR_CR3_REGSEL) */
288 #if defined(PWR_CR2_FPWM)
289 void HAL_PWREx_EnableSMPSPWM(void);
290 void HAL_PWREx_DisableSMPSPWM(void);
291 #endif /* defined(PWR_CR2_FPWM) */
292 void              HAL_PWREx_EnableFastSoftStart(void);
293 void              HAL_PWREx_DisableFastSoftStart(void);
294 /**
295   * @}
296   */
297 
298 /** @addtogroup PWREx_Exported_Functions_Group2 Low Power Control Functions
299   * @{
300   */
301 void HAL_PWREx_EnableUltraLowPowerMode(void);
302 void HAL_PWREx_DisableUltraLowPowerMode(void);
303 /**
304   * @}
305   */
306 
307 /** @addtogroup PWREx_Exported_Functions_Group4 Memories Retention Functions
308   * @{
309   */
310 void              HAL_PWREx_EnableSRAM2ContentStandbyRetention(uint32_t SRAM2Pages);
311 void              HAL_PWREx_DisableSRAM2ContentStandbyRetention(void);
312 void              HAL_PWREx_EnableRadioSRAMClockStandbyRetention(uint32_t RadioSRAM);
313 void              HAL_PWREx_DisableRadioSRAMClockStandbyRetention(void);
314 void              HAL_PWREx_EnableSRAM1ContentStandbyRetention(uint32_t SRAM1Pages);
315 void              HAL_PWREx_DisableSRAM1ContentStandbyRetention(void);
316 void              HAL_PWREx_EnableRAMsContentStopRetention(uint32_t RAMSelection);
317 void              HAL_PWREx_DisableRAMsContentStopRetention(uint32_t RAMSelection);
318 void              HAL_PWREx_EnableFlashFastWakeUp(void);
319 void              HAL_PWREx_DisableFlashFastWakeUp(void);
320 /**
321   * @}
322   */
323 
324 /** @addtogroup PWREx_Exported_Functions_Group5 I/O Retention Functions
325   * @{
326   */
327 HAL_StatusTypeDef HAL_PWREx_EnableStandbyIORetention(uint32_t GPIO_Port, uint32_t GPIO_Pin);
328 HAL_StatusTypeDef HAL_PWREx_DisableStandbyIORetention(uint32_t GPIO_Port, uint32_t GPIO_Pin);
329 uint32_t          HAL_PWREx_GetStandbyIORetentionStatus(uint32_t GPIO_Port);
330 HAL_StatusTypeDef HAL_PWREx_DisableStandbyRetainedIOState(uint32_t GPIO_Port, uint32_t GPIO_Pin);
331 /**
332   * @}
333   */
334 
335 /** @addtogroup PWREx_Exported_Functions_Group6 I/O RADIO Configuration and Status Reading Functions
336   * @{
337   */
338 uint32_t HAL_PWREx_GetRADIOOperatingMode(void);
339 uint32_t HAL_PWREx_GetRADIOPHYOperatingMode(void);
340 uint32_t HAL_PWREx_GetRADIOEncryptionOperatingMode(void);
341 uint32_t HAL_PWREx_GetRFVDDHPA(void);
342 
343 #if defined(PWR_RADIOSCR_REGPASEL)
344 HAL_StatusTypeDef  HAL_PWREx_SetREGVDDHPAInputSupply(uint32_t SupplySelection);
345 uint32_t HAL_PWREx_GetREGVDDHPAInputSupply(void);
346 #endif /* defined(PWR_RADIOSCR_REGPASEL) */
347 #if defined(PWR_RADIOSCR_REGPABYPEN)
348 void HAL_PWREx_EnableREGVDDHPABypass(void);
349 void HAL_PWREx_DisableREGVDDHPABypass(void);
350 #endif /* defined(PWR_RADIOSCR_REGPABYPEN) */
351 /**
352   * @}
353   */
354 
355 /**
356   * @}
357   */
358 
359 /**
360   * @}
361   */
362 
363 /**
364   * @}
365   */
366 
367 /**
368 * @}
369 */
370 
371 #ifdef __cplusplus
372 }
373 #endif /* __cplusplus */
374 
375 
376 #endif /* STM32WBAxx_HAL_PWR_EX_H */
377 
378