Implement a secure ICS protocol targeting LoRa Node151 microcontroller for controlling irrigation.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

431 lines
16 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_hal_pwr.h
  4. * @author MCD Application Team
  5. * @brief Header file of PWR HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification,
  12. * are permitted provided that the following conditions are met:
  13. * 1. Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  28. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. ******************************************************************************
  34. */
  35. /* Define to prevent recursive inclusion -------------------------------------*/
  36. #ifndef __STM32L4xx_HAL_PWR_H
  37. #define __STM32L4xx_HAL_PWR_H
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /* Includes ------------------------------------------------------------------*/
  42. #include "stm32l4xx_hal_def.h"
  43. /** @addtogroup STM32L4xx_HAL_Driver
  44. * @{
  45. */
  46. /** @addtogroup PWR
  47. * @{
  48. */
  49. /* Exported types ------------------------------------------------------------*/
  50. /** @defgroup PWR_Exported_Types PWR Exported Types
  51. * @{
  52. */
  53. /**
  54. * @brief PWR PVD configuration structure definition
  55. */
  56. typedef struct
  57. {
  58. uint32_t PVDLevel; /*!< PVDLevel: Specifies the PVD detection level.
  59. This parameter can be a value of @ref PWR_PVD_detection_level. */
  60. uint32_t Mode; /*!< Mode: Specifies the operating mode for the selected pins.
  61. This parameter can be a value of @ref PWR_PVD_Mode. */
  62. }PWR_PVDTypeDef;
  63. /**
  64. * @}
  65. */
  66. /* Exported constants --------------------------------------------------------*/
  67. /** @defgroup PWR_Exported_Constants PWR Exported Constants
  68. * @{
  69. */
  70. /** @defgroup PWR_PVD_detection_level Programmable Voltage Detection levels
  71. * @{
  72. */
  73. #define PWR_PVDLEVEL_0 PWR_CR2_PLS_LEV0 /*!< PVD threshold around 2.0 V */
  74. #define PWR_PVDLEVEL_1 PWR_CR2_PLS_LEV1 /*!< PVD threshold around 2.2 V */
  75. #define PWR_PVDLEVEL_2 PWR_CR2_PLS_LEV2 /*!< PVD threshold around 2.4 V */
  76. #define PWR_PVDLEVEL_3 PWR_CR2_PLS_LEV3 /*!< PVD threshold around 2.5 V */
  77. #define PWR_PVDLEVEL_4 PWR_CR2_PLS_LEV4 /*!< PVD threshold around 2.6 V */
  78. #define PWR_PVDLEVEL_5 PWR_CR2_PLS_LEV5 /*!< PVD threshold around 2.8 V */
  79. #define PWR_PVDLEVEL_6 PWR_CR2_PLS_LEV6 /*!< PVD threshold around 2.9 V */
  80. #define PWR_PVDLEVEL_7 PWR_CR2_PLS_LEV7 /*!< External input analog voltage (compared internally to VREFINT) */
  81. /**
  82. * @}
  83. */
  84. /** @defgroup PWR_PVD_Mode PWR PVD interrupt and event mode
  85. * @{
  86. */
  87. #define PWR_PVD_MODE_NORMAL ((uint32_t)0x00000000) /*!< Basic mode is used */
  88. #define PWR_PVD_MODE_IT_RISING ((uint32_t)0x00010001) /*!< External Interrupt Mode with Rising edge trigger detection */
  89. #define PWR_PVD_MODE_IT_FALLING ((uint32_t)0x00010002) /*!< External Interrupt Mode with Falling edge trigger detection */
  90. #define PWR_PVD_MODE_IT_RISING_FALLING ((uint32_t)0x00010003) /*!< External Interrupt Mode with Rising/Falling edge trigger detection */
  91. #define PWR_PVD_MODE_EVENT_RISING ((uint32_t)0x00020001) /*!< Event Mode with Rising edge trigger detection */
  92. #define PWR_PVD_MODE_EVENT_FALLING ((uint32_t)0x00020002) /*!< Event Mode with Falling edge trigger detection */
  93. #define PWR_PVD_MODE_EVENT_RISING_FALLING ((uint32_t)0x00020003) /*!< Event Mode with Rising/Falling edge trigger detection */
  94. /**
  95. * @}
  96. */
  97. /** @defgroup PWR_Regulator_state_in_SLEEP_STOP_mode PWR regulator mode
  98. * @{
  99. */
  100. #define PWR_MAINREGULATOR_ON ((uint32_t)0x00000000) /*!< Regulator in main mode */
  101. #define PWR_LOWPOWERREGULATOR_ON PWR_CR1_LPR /*!< Regulator in low-power mode */
  102. /**
  103. * @}
  104. */
  105. /** @defgroup PWR_SLEEP_mode_entry PWR SLEEP mode entry
  106. * @{
  107. */
  108. #define PWR_SLEEPENTRY_WFI ((uint8_t)0x01) /*!< Wait For Interruption instruction to enter Sleep mode */
  109. #define PWR_SLEEPENTRY_WFE ((uint8_t)0x02) /*!< Wait For Event instruction to enter Sleep mode */
  110. /**
  111. * @}
  112. */
  113. /** @defgroup PWR_STOP_mode_entry PWR STOP mode entry
  114. * @{
  115. */
  116. #define PWR_STOPENTRY_WFI ((uint8_t)0x01) /*!< Wait For Interruption instruction to enter Stop mode */
  117. #define PWR_STOPENTRY_WFE ((uint8_t)0x02) /*!< Wait For Event instruction to enter Stop mode */
  118. /**
  119. * @}
  120. */
  121. /** @defgroup PWR_PVD_EXTI_LINE PWR PVD external interrupt line
  122. * @{
  123. */
  124. #define PWR_EXTI_LINE_PVD ((uint32_t)0x00010000) /*!< External interrupt line 16 Connected to the PVD EXTI Line */
  125. /**
  126. * @}
  127. */
  128. /** @defgroup PWR_PVD_EVENT_LINE PWR PVD event line
  129. * @{
  130. */
  131. #define PWR_EVENT_LINE_PVD ((uint32_t)0x00010000) /*!< Event line 16 Connected to the PVD Event Line */
  132. /**
  133. * @}
  134. */
  135. /**
  136. * @}
  137. */
  138. /* Exported macros -----------------------------------------------------------*/
  139. /** @defgroup PWR_Exported_Macros PWR Exported Macros
  140. * @{
  141. */
  142. /** @brief Check whether or not a specific PWR flag is set.
  143. * @param __FLAG__: specifies the flag to check.
  144. * This parameter can be one of the following values:
  145. * @arg @ref PWR_FLAG_WUF1 Wake Up Flag 1. Indicates that a wakeup event
  146. * was received from the WKUP pin 1.
  147. * @arg @ref PWR_FLAG_WUF2 Wake Up Flag 2. Indicates that a wakeup event
  148. * was received from the WKUP pin 2.
  149. * @arg @ref PWR_FLAG_WUF3 Wake Up Flag 3. Indicates that a wakeup event
  150. * was received from the WKUP pin 3.
  151. * @arg @ref PWR_FLAG_WUF4 Wake Up Flag 4. Indicates that a wakeup event
  152. * was received from the WKUP pin 4.
  153. * @arg @ref PWR_FLAG_WUF5 Wake Up Flag 5. Indicates that a wakeup event
  154. * was received from the WKUP pin 5.
  155. * @arg @ref PWR_FLAG_SB StandBy Flag. Indicates that the system
  156. * entered StandBy mode.
  157. * @arg @ref PWR_FLAG_EXT_SMPS External SMPS Ready Flag. When available on device, indicates
  158. * that external switch can be closed to connect to the external SMPS, when the Range 2
  159. * of internal regulator is ready.
  160. * @arg @ref PWR_FLAG_WUFI Wake-Up Flag Internal. Set when a wakeup is detected on
  161. * the internal wakeup line.
  162. * @arg @ref PWR_FLAG_REGLPS Low Power Regulator Started. Indicates whether or not the
  163. * low-power regulator is ready.
  164. * @arg @ref PWR_FLAG_REGLPF Low Power Regulator Flag. Indicates whether the
  165. * regulator is ready in main mode or is in low-power mode.
  166. * @arg @ref PWR_FLAG_VOSF Voltage Scaling Flag. Indicates whether the regulator is ready
  167. * in the selected voltage range or is still changing to the required voltage level.
  168. * @arg @ref PWR_FLAG_PVDO Power Voltage Detector Output. Indicates whether VDD voltage is
  169. * below or above the selected PVD threshold.
  170. * @arg @ref PWR_FLAG_PVMO1 Peripheral Voltage Monitoring Output 1. Indicates whether VDDUSB voltage is
  171. * is below or above PVM1 threshold (applicable when USB feature is supported).
  172. @if STM32L486xx
  173. * @arg @ref PWR_FLAG_PVMO2 Peripheral Voltage Monitoring Output 2. Indicates whether VDDIO2 voltage is
  174. * is below or above PVM2 threshold (applicable when VDDIO2 is present on device).
  175. @endif
  176. * @arg @ref PWR_FLAG_PVMO3 Peripheral Voltage Monitoring Output 3. Indicates whether VDDA voltage is
  177. * is below or above PVM3 threshold.
  178. * @arg @ref PWR_FLAG_PVMO4 Peripheral Voltage Monitoring Output 4. Indicates whether VDDA voltage is
  179. * is below or above PVM4 threshold.
  180. *
  181. * @retval The new state of __FLAG__ (TRUE or FALSE).
  182. */
  183. #define __HAL_PWR_GET_FLAG(__FLAG__) ( ((((uint8_t)(__FLAG__)) >> 5U) == 1) ?\
  184. (PWR->SR1 & (1U << ((__FLAG__) & 31U))) :\
  185. (PWR->SR2 & (1U << ((__FLAG__) & 31U))) )
  186. /** @brief Clear a specific PWR flag.
  187. * @param __FLAG__: specifies the flag to clear.
  188. * This parameter can be one of the following values:
  189. * @arg @ref PWR_FLAG_WUF1 Wake Up Flag 1. Indicates that a wakeup event
  190. * was received from the WKUP pin 1.
  191. * @arg @ref PWR_FLAG_WUF2 Wake Up Flag 2. Indicates that a wakeup event
  192. * was received from the WKUP pin 2.
  193. * @arg @ref PWR_FLAG_WUF3 Wake Up Flag 3. Indicates that a wakeup event
  194. * was received from the WKUP pin 3.
  195. * @arg @ref PWR_FLAG_WUF4 Wake Up Flag 4. Indicates that a wakeup event
  196. * was received from the WKUP pin 4.
  197. * @arg @ref PWR_FLAG_WUF5 Wake Up Flag 5. Indicates that a wakeup event
  198. * was received from the WKUP pin 5.
  199. * @arg @ref PWR_FLAG_WU Encompasses all five Wake Up Flags.
  200. * @arg @ref PWR_FLAG_SB Standby Flag. Indicates that the system
  201. * entered Standby mode.
  202. * @retval None
  203. */
  204. #define __HAL_PWR_CLEAR_FLAG(__FLAG__) ( (((uint8_t)(__FLAG__)) == PWR_FLAG_WU) ?\
  205. (PWR->SCR = (__FLAG__)) :\
  206. (PWR->SCR = (1U << ((__FLAG__) & 31U))) )
  207. /**
  208. * @brief Enable the PVD Extended Interrupt Line.
  209. * @retval None
  210. */
  211. #define __HAL_PWR_PVD_EXTI_ENABLE_IT() SET_BIT(EXTI->IMR1, PWR_EXTI_LINE_PVD)
  212. /**
  213. * @brief Disable the PVD Extended Interrupt Line.
  214. * @retval None
  215. */
  216. #define __HAL_PWR_PVD_EXTI_DISABLE_IT() CLEAR_BIT(EXTI->IMR1, PWR_EXTI_LINE_PVD)
  217. /**
  218. * @brief Enable the PVD Event Line.
  219. * @retval None
  220. */
  221. #define __HAL_PWR_PVD_EXTI_ENABLE_EVENT() SET_BIT(EXTI->EMR1, PWR_EVENT_LINE_PVD)
  222. /**
  223. * @brief Disable the PVD Event Line.
  224. * @retval None
  225. */
  226. #define __HAL_PWR_PVD_EXTI_DISABLE_EVENT() CLEAR_BIT(EXTI->EMR1, PWR_EVENT_LINE_PVD)
  227. /**
  228. * @brief Enable the PVD Extended Interrupt Rising Trigger.
  229. * @retval None
  230. */
  231. #define __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE() SET_BIT(EXTI->RTSR1, PWR_EXTI_LINE_PVD)
  232. /**
  233. * @brief Disable the PVD Extended Interrupt Rising Trigger.
  234. * @retval None
  235. */
  236. #define __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE() CLEAR_BIT(EXTI->RTSR1, PWR_EXTI_LINE_PVD)
  237. /**
  238. * @brief Enable the PVD Extended Interrupt Falling Trigger.
  239. * @retval None
  240. */
  241. #define __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE() SET_BIT(EXTI->FTSR1, PWR_EXTI_LINE_PVD)
  242. /**
  243. * @brief Disable the PVD Extended Interrupt Falling Trigger.
  244. * @retval None
  245. */
  246. #define __HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE() CLEAR_BIT(EXTI->FTSR1, PWR_EXTI_LINE_PVD)
  247. /**
  248. * @brief Enable the PVD Extended Interrupt Rising & Falling Trigger.
  249. * @retval None
  250. */
  251. #define __HAL_PWR_PVD_EXTI_ENABLE_RISING_FALLING_EDGE() \
  252. do { \
  253. __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE(); \
  254. __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE(); \
  255. } while(0)
  256. /**
  257. * @brief Disable the PVD Extended Interrupt Rising & Falling Trigger.
  258. * @retval None
  259. */
  260. #define __HAL_PWR_PVD_EXTI_DISABLE_RISING_FALLING_EDGE() \
  261. do { \
  262. __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE(); \
  263. __HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE(); \
  264. } while(0)
  265. /**
  266. * @brief Generate a Software interrupt on selected EXTI line.
  267. * @retval None
  268. */
  269. #define __HAL_PWR_PVD_EXTI_GENERATE_SWIT() SET_BIT(EXTI->SWIER1, PWR_EXTI_LINE_PVD)
  270. /**
  271. * @brief Check whether or not the PVD EXTI interrupt flag is set.
  272. * @retval EXTI PVD Line Status.
  273. */
  274. #define __HAL_PWR_PVD_EXTI_GET_FLAG() (EXTI->PR1 & PWR_EXTI_LINE_PVD)
  275. /**
  276. * @brief Clear the PVD EXTI interrupt flag.
  277. * @retval None
  278. */
  279. #define __HAL_PWR_PVD_EXTI_CLEAR_FLAG() WRITE_REG(EXTI->PR1, PWR_EXTI_LINE_PVD)
  280. /**
  281. * @}
  282. */
  283. /* Private macros --------------------------------------------------------*/
  284. /** @addtogroup PWR_Private_Macros PWR Private Macros
  285. * @{
  286. */
  287. #define IS_PWR_PVD_LEVEL(LEVEL) (((LEVEL) == PWR_PVDLEVEL_0) || ((LEVEL) == PWR_PVDLEVEL_1)|| \
  288. ((LEVEL) == PWR_PVDLEVEL_2) || ((LEVEL) == PWR_PVDLEVEL_3)|| \
  289. ((LEVEL) == PWR_PVDLEVEL_4) || ((LEVEL) == PWR_PVDLEVEL_5)|| \
  290. ((LEVEL) == PWR_PVDLEVEL_6) || ((LEVEL) == PWR_PVDLEVEL_7))
  291. #define IS_PWR_PVD_MODE(MODE) (((MODE) == PWR_PVD_MODE_NORMAL) ||\
  292. ((MODE) == PWR_PVD_MODE_IT_RISING) ||\
  293. ((MODE) == PWR_PVD_MODE_IT_FALLING) ||\
  294. ((MODE) == PWR_PVD_MODE_IT_RISING_FALLING) ||\
  295. ((MODE) == PWR_PVD_MODE_EVENT_RISING) ||\
  296. ((MODE) == PWR_PVD_MODE_EVENT_FALLING) ||\
  297. ((MODE) == PWR_PVD_MODE_EVENT_RISING_FALLING))
  298. #define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_MAINREGULATOR_ON) || \
  299. ((REGULATOR) == PWR_LOWPOWERREGULATOR_ON))
  300. #define IS_PWR_SLEEP_ENTRY(ENTRY) (((ENTRY) == PWR_SLEEPENTRY_WFI) || ((ENTRY) == PWR_SLEEPENTRY_WFE))
  301. #define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPENTRY_WFI) || ((ENTRY) == PWR_STOPENTRY_WFE) )
  302. /**
  303. * @}
  304. */
  305. /* Include PWR HAL Extended module */
  306. #include "stm32l4xx_hal_pwr_ex.h"
  307. /* Exported functions --------------------------------------------------------*/
  308. /** @addtogroup PWR_Exported_Functions PWR Exported Functions
  309. * @{
  310. */
  311. /** @addtogroup PWR_Exported_Functions_Group1 Initialization and de-initialization functions
  312. * @{
  313. */
  314. /* Initialization and de-initialization functions *******************************/
  315. void HAL_PWR_DeInit(void);
  316. void HAL_PWR_EnableBkUpAccess(void);
  317. void HAL_PWR_DisableBkUpAccess(void);
  318. /**
  319. * @}
  320. */
  321. /** @addtogroup PWR_Exported_Functions_Group2 Peripheral Control functions
  322. * @{
  323. */
  324. /* Peripheral Control functions ************************************************/
  325. HAL_StatusTypeDef HAL_PWR_ConfigPVD(PWR_PVDTypeDef *sConfigPVD);
  326. void HAL_PWR_EnablePVD(void);
  327. void HAL_PWR_DisablePVD(void);
  328. /* WakeUp pins configuration functions ****************************************/
  329. void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinPolarity);
  330. void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx);
  331. /* Low Power modes configuration functions ************************************/
  332. void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry);
  333. void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry);
  334. void HAL_PWR_EnterSTANDBYMode(void);
  335. void HAL_PWR_EnableSleepOnExit(void);
  336. void HAL_PWR_DisableSleepOnExit(void);
  337. void HAL_PWR_EnableSEVOnPend(void);
  338. void HAL_PWR_DisableSEVOnPend(void);
  339. void HAL_PWR_PVDCallback(void);
  340. /**
  341. * @}
  342. */
  343. /**
  344. * @}
  345. */
  346. /**
  347. * @}
  348. */
  349. /**
  350. * @}
  351. */
  352. #ifdef __cplusplus
  353. }
  354. #endif
  355. #endif /* __STM32L4xx_HAL_PWR_H */
  356. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/