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.

stm32l1xx_hal_cortex.h 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. /**
  2. ******************************************************************************
  3. * @file stm32l1xx_hal_cortex.h
  4. * @author MCD Application Team
  5. * @brief Header file of CORTEX HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. /* Define to prevent recursive inclusion -------------------------------------*/
  20. #ifndef __STM32L1xx_HAL_CORTEX_H
  21. #define __STM32L1xx_HAL_CORTEX_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32l1xx_hal_def.h"
  27. /** @addtogroup STM32L1xx_HAL_Driver
  28. * @{
  29. */
  30. /** @addtogroup CORTEX
  31. * @{
  32. */
  33. /* Exported types ------------------------------------------------------------*/
  34. /** @defgroup CORTEX_Exported_Types Cortex Exported Types
  35. * @{
  36. */
  37. #if (__MPU_PRESENT == 1)
  38. /** @defgroup CORTEX_MPU_Region_Initialization_Structure_definition MPU Region Initialization Structure Definition
  39. * @brief MPU Region initialization structure
  40. * @{
  41. */
  42. typedef struct
  43. {
  44. uint8_t Enable; /*!< Specifies the status of the region.
  45. This parameter can be a value of @ref CORTEX_MPU_Region_Enable */
  46. uint8_t Number; /*!< Specifies the number of the region to protect.
  47. This parameter can be a value of @ref CORTEX_MPU_Region_Number */
  48. uint32_t BaseAddress; /*!< Specifies the base address of the region to protect. */
  49. uint8_t Size; /*!< Specifies the size of the region to protect.
  50. This parameter can be a value of @ref CORTEX_MPU_Region_Size */
  51. uint8_t SubRegionDisable; /*!< Specifies the number of the subregion protection to disable.
  52. This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFF */
  53. uint8_t TypeExtField; /*!< Specifies the TEX field level.
  54. This parameter can be a value of @ref CORTEX_MPU_TEX_Levels */
  55. uint8_t AccessPermission; /*!< Specifies the region access permission type.
  56. This parameter can be a value of @ref CORTEX_MPU_Region_Permission_Attributes */
  57. uint8_t DisableExec; /*!< Specifies the instruction access status.
  58. This parameter can be a value of @ref CORTEX_MPU_Instruction_Access */
  59. uint8_t IsShareable; /*!< Specifies the shareability status of the protected region.
  60. This parameter can be a value of @ref CORTEX_MPU_Access_Shareable */
  61. uint8_t IsCacheable; /*!< Specifies the cacheable status of the region protected.
  62. This parameter can be a value of @ref CORTEX_MPU_Access_Cacheable */
  63. uint8_t IsBufferable; /*!< Specifies the bufferable status of the protected region.
  64. This parameter can be a value of @ref CORTEX_MPU_Access_Bufferable */
  65. }MPU_Region_InitTypeDef;
  66. /**
  67. * @}
  68. */
  69. #endif /* __MPU_PRESENT */
  70. /**
  71. * @}
  72. */
  73. /* Exported constants --------------------------------------------------------*/
  74. /** @defgroup CORTEX_Exported_Constants CORTEX Exported Constants
  75. * @{
  76. */
  77. /** @defgroup CORTEX_Preemption_Priority_Group CORTEX Preemption Priority Group
  78. * @{
  79. */
  80. #define NVIC_PRIORITYGROUP_0 (0x00000007U) /*!< 0 bits for pre-emption priority
  81. 4 bits for subpriority */
  82. #define NVIC_PRIORITYGROUP_1 (0x00000006U) /*!< 1 bits for pre-emption priority
  83. 3 bits for subpriority */
  84. #define NVIC_PRIORITYGROUP_2 (0x00000005U) /*!< 2 bits for pre-emption priority
  85. 2 bits for subpriority */
  86. #define NVIC_PRIORITYGROUP_3 (0x00000004U) /*!< 3 bits for pre-emption priority
  87. 1 bits for subpriority */
  88. #define NVIC_PRIORITYGROUP_4 (0x00000003U) /*!< 4 bits for pre-emption priority
  89. 0 bits for subpriority */
  90. /**
  91. * @}
  92. */
  93. /** @defgroup CORTEX_SysTick_clock_source CORTEX SysTick clock source
  94. * @{
  95. */
  96. #define SYSTICK_CLKSOURCE_HCLK_DIV8 (0x00000000U)
  97. #define SYSTICK_CLKSOURCE_HCLK (0x00000004U)
  98. /**
  99. * @}
  100. */
  101. #if (__MPU_PRESENT == 1)
  102. /** @defgroup CORTEX_MPU_HFNMI_PRIVDEF_Control MPU HFNMI and PRIVILEGED Access control
  103. * @{
  104. */
  105. #define MPU_HFNMI_PRIVDEF_NONE (0x00000000U)
  106. #define MPU_HARDFAULT_NMI (MPU_CTRL_HFNMIENA_Msk)
  107. #define MPU_PRIVILEGED_DEFAULT (MPU_CTRL_PRIVDEFENA_Msk)
  108. #define MPU_HFNMI_PRIVDEF (MPU_CTRL_HFNMIENA_Msk | MPU_CTRL_PRIVDEFENA_Msk)
  109. /**
  110. * @}
  111. */
  112. /** @defgroup CORTEX_MPU_Region_Enable CORTEX MPU Region Enable
  113. * @{
  114. */
  115. #define MPU_REGION_ENABLE ((uint8_t)0x01)
  116. #define MPU_REGION_DISABLE ((uint8_t)0x00)
  117. /**
  118. * @}
  119. */
  120. /** @defgroup CORTEX_MPU_Instruction_Access CORTEX MPU Instruction Access
  121. * @{
  122. */
  123. #define MPU_INSTRUCTION_ACCESS_ENABLE ((uint8_t)0x00)
  124. #define MPU_INSTRUCTION_ACCESS_DISABLE ((uint8_t)0x01)
  125. /**
  126. * @}
  127. */
  128. /** @defgroup CORTEX_MPU_Access_Shareable CORTEX MPU Instruction Access Shareable
  129. * @{
  130. */
  131. #define MPU_ACCESS_SHAREABLE ((uint8_t)0x01)
  132. #define MPU_ACCESS_NOT_SHAREABLE ((uint8_t)0x00)
  133. /**
  134. * @}
  135. */
  136. /** @defgroup CORTEX_MPU_Access_Cacheable CORTEX MPU Instruction Access Cacheable
  137. * @{
  138. */
  139. #define MPU_ACCESS_CACHEABLE ((uint8_t)0x01)
  140. #define MPU_ACCESS_NOT_CACHEABLE ((uint8_t)0x00)
  141. /**
  142. * @}
  143. */
  144. /** @defgroup CORTEX_MPU_Access_Bufferable CORTEX MPU Instruction Access Bufferable
  145. * @{
  146. */
  147. #define MPU_ACCESS_BUFFERABLE ((uint8_t)0x01)
  148. #define MPU_ACCESS_NOT_BUFFERABLE ((uint8_t)0x00)
  149. /**
  150. * @}
  151. */
  152. /** @defgroup CORTEX_MPU_TEX_Levels MPU TEX Levels
  153. * @{
  154. */
  155. #define MPU_TEX_LEVEL0 ((uint8_t)0x00)
  156. #define MPU_TEX_LEVEL1 ((uint8_t)0x01)
  157. #define MPU_TEX_LEVEL2 ((uint8_t)0x02)
  158. /**
  159. * @}
  160. */
  161. /** @defgroup CORTEX_MPU_Region_Size CORTEX MPU Region Size
  162. * @{
  163. */
  164. #define MPU_REGION_SIZE_32B ((uint8_t)0x04)
  165. #define MPU_REGION_SIZE_64B ((uint8_t)0x05)
  166. #define MPU_REGION_SIZE_128B ((uint8_t)0x06)
  167. #define MPU_REGION_SIZE_256B ((uint8_t)0x07)
  168. #define MPU_REGION_SIZE_512B ((uint8_t)0x08)
  169. #define MPU_REGION_SIZE_1KB ((uint8_t)0x09)
  170. #define MPU_REGION_SIZE_2KB ((uint8_t)0x0A)
  171. #define MPU_REGION_SIZE_4KB ((uint8_t)0x0B)
  172. #define MPU_REGION_SIZE_8KB ((uint8_t)0x0C)
  173. #define MPU_REGION_SIZE_16KB ((uint8_t)0x0D)
  174. #define MPU_REGION_SIZE_32KB ((uint8_t)0x0E)
  175. #define MPU_REGION_SIZE_64KB ((uint8_t)0x0F)
  176. #define MPU_REGION_SIZE_128KB ((uint8_t)0x10)
  177. #define MPU_REGION_SIZE_256KB ((uint8_t)0x11)
  178. #define MPU_REGION_SIZE_512KB ((uint8_t)0x12)
  179. #define MPU_REGION_SIZE_1MB ((uint8_t)0x13)
  180. #define MPU_REGION_SIZE_2MB ((uint8_t)0x14)
  181. #define MPU_REGION_SIZE_4MB ((uint8_t)0x15)
  182. #define MPU_REGION_SIZE_8MB ((uint8_t)0x16)
  183. #define MPU_REGION_SIZE_16MB ((uint8_t)0x17)
  184. #define MPU_REGION_SIZE_32MB ((uint8_t)0x18)
  185. #define MPU_REGION_SIZE_64MB ((uint8_t)0x19)
  186. #define MPU_REGION_SIZE_128MB ((uint8_t)0x1A)
  187. #define MPU_REGION_SIZE_256MB ((uint8_t)0x1B)
  188. #define MPU_REGION_SIZE_512MB ((uint8_t)0x1C)
  189. #define MPU_REGION_SIZE_1GB ((uint8_t)0x1D)
  190. #define MPU_REGION_SIZE_2GB ((uint8_t)0x1E)
  191. #define MPU_REGION_SIZE_4GB ((uint8_t)0x1F)
  192. /**
  193. * @}
  194. */
  195. /** @defgroup CORTEX_MPU_Region_Permission_Attributes CORTEX MPU Region Permission Attributes
  196. * @{
  197. */
  198. #define MPU_REGION_NO_ACCESS ((uint8_t)0x00)
  199. #define MPU_REGION_PRIV_RW ((uint8_t)0x01)
  200. #define MPU_REGION_PRIV_RW_URO ((uint8_t)0x02)
  201. #define MPU_REGION_FULL_ACCESS ((uint8_t)0x03)
  202. #define MPU_REGION_PRIV_RO ((uint8_t)0x05)
  203. #define MPU_REGION_PRIV_RO_URO ((uint8_t)0x06)
  204. /**
  205. * @}
  206. */
  207. /** @defgroup CORTEX_MPU_Region_Number CORTEX MPU Region Number
  208. * @{
  209. */
  210. #define MPU_REGION_NUMBER0 ((uint8_t)0x00)
  211. #define MPU_REGION_NUMBER1 ((uint8_t)0x01)
  212. #define MPU_REGION_NUMBER2 ((uint8_t)0x02)
  213. #define MPU_REGION_NUMBER3 ((uint8_t)0x03)
  214. #define MPU_REGION_NUMBER4 ((uint8_t)0x04)
  215. #define MPU_REGION_NUMBER5 ((uint8_t)0x05)
  216. #define MPU_REGION_NUMBER6 ((uint8_t)0x06)
  217. #define MPU_REGION_NUMBER7 ((uint8_t)0x07)
  218. /**
  219. * @}
  220. */
  221. #endif /* __MPU_PRESENT */
  222. /**
  223. * @}
  224. */
  225. /* Exported Macros -----------------------------------------------------------*/
  226. /** @defgroup CORTEX_Exported_Macros CORTEX Exported Macros
  227. * @{
  228. */
  229. /** @defgroup CORTEX_Preemption_Priority_Group_Macro CORTEX Preemption Priority Group
  230. * @{
  231. */
  232. #define IS_NVIC_PRIORITY_GROUP(GROUP) (((GROUP) == NVIC_PRIORITYGROUP_0) || \
  233. ((GROUP) == NVIC_PRIORITYGROUP_1) || \
  234. ((GROUP) == NVIC_PRIORITYGROUP_2) || \
  235. ((GROUP) == NVIC_PRIORITYGROUP_3) || \
  236. ((GROUP) == NVIC_PRIORITYGROUP_4))
  237. #define IS_NVIC_PREEMPTION_PRIORITY(PRIORITY) ((PRIORITY) < 0x10)
  238. #define IS_NVIC_SUB_PRIORITY(PRIORITY) ((PRIORITY) < 0x10)
  239. #define IS_NVIC_DEVICE_IRQ(IRQ) ((IRQ) >= 0x00)
  240. /**
  241. * @}
  242. */
  243. /**
  244. * @}
  245. */
  246. /* Private macro -------------------------------------------------------------*/
  247. /** @defgroup CORTEX_Private_Macros CORTEX Private Macros
  248. * @{
  249. */
  250. /** @defgroup CORTEX_SysTick_clock_source_Macro_Private CORTEX SysTick clock source
  251. * @{
  252. */
  253. #define IS_SYSTICK_CLK_SOURCE(SOURCE) (((SOURCE) == SYSTICK_CLKSOURCE_HCLK) || \
  254. ((SOURCE) == SYSTICK_CLKSOURCE_HCLK_DIV8))
  255. /**
  256. * @}
  257. */
  258. #if (__MPU_PRESENT == 1)
  259. #define IS_MPU_REGION_ENABLE(STATE) (((STATE) == MPU_REGION_ENABLE) || \
  260. ((STATE) == MPU_REGION_DISABLE))
  261. #define IS_MPU_INSTRUCTION_ACCESS(STATE) (((STATE) == MPU_INSTRUCTION_ACCESS_ENABLE) || \
  262. ((STATE) == MPU_INSTRUCTION_ACCESS_DISABLE))
  263. #define IS_MPU_ACCESS_SHAREABLE(STATE) (((STATE) == MPU_ACCESS_SHAREABLE) || \
  264. ((STATE) == MPU_ACCESS_NOT_SHAREABLE))
  265. #define IS_MPU_ACCESS_CACHEABLE(STATE) (((STATE) == MPU_ACCESS_CACHEABLE) || \
  266. ((STATE) == MPU_ACCESS_NOT_CACHEABLE))
  267. #define IS_MPU_ACCESS_BUFFERABLE(STATE) (((STATE) == MPU_ACCESS_BUFFERABLE) || \
  268. ((STATE) == MPU_ACCESS_NOT_BUFFERABLE))
  269. #define IS_MPU_TEX_LEVEL(TYPE) (((TYPE) == MPU_TEX_LEVEL0) || \
  270. ((TYPE) == MPU_TEX_LEVEL1) || \
  271. ((TYPE) == MPU_TEX_LEVEL2))
  272. #define IS_MPU_REGION_PERMISSION_ATTRIBUTE(TYPE) (((TYPE) == MPU_REGION_NO_ACCESS) || \
  273. ((TYPE) == MPU_REGION_PRIV_RW) || \
  274. ((TYPE) == MPU_REGION_PRIV_RW_URO) || \
  275. ((TYPE) == MPU_REGION_FULL_ACCESS) || \
  276. ((TYPE) == MPU_REGION_PRIV_RO) || \
  277. ((TYPE) == MPU_REGION_PRIV_RO_URO))
  278. #define IS_MPU_REGION_NUMBER(NUMBER) (((NUMBER) == MPU_REGION_NUMBER0) || \
  279. ((NUMBER) == MPU_REGION_NUMBER1) || \
  280. ((NUMBER) == MPU_REGION_NUMBER2) || \
  281. ((NUMBER) == MPU_REGION_NUMBER3) || \
  282. ((NUMBER) == MPU_REGION_NUMBER4) || \
  283. ((NUMBER) == MPU_REGION_NUMBER5) || \
  284. ((NUMBER) == MPU_REGION_NUMBER6) || \
  285. ((NUMBER) == MPU_REGION_NUMBER7))
  286. #define IS_MPU_REGION_SIZE(SIZE) (((SIZE) == MPU_REGION_SIZE_32B) || \
  287. ((SIZE) == MPU_REGION_SIZE_64B) || \
  288. ((SIZE) == MPU_REGION_SIZE_128B) || \
  289. ((SIZE) == MPU_REGION_SIZE_256B) || \
  290. ((SIZE) == MPU_REGION_SIZE_512B) || \
  291. ((SIZE) == MPU_REGION_SIZE_1KB) || \
  292. ((SIZE) == MPU_REGION_SIZE_2KB) || \
  293. ((SIZE) == MPU_REGION_SIZE_4KB) || \
  294. ((SIZE) == MPU_REGION_SIZE_8KB) || \
  295. ((SIZE) == MPU_REGION_SIZE_16KB) || \
  296. ((SIZE) == MPU_REGION_SIZE_32KB) || \
  297. ((SIZE) == MPU_REGION_SIZE_64KB) || \
  298. ((SIZE) == MPU_REGION_SIZE_128KB) || \
  299. ((SIZE) == MPU_REGION_SIZE_256KB) || \
  300. ((SIZE) == MPU_REGION_SIZE_512KB) || \
  301. ((SIZE) == MPU_REGION_SIZE_1MB) || \
  302. ((SIZE) == MPU_REGION_SIZE_2MB) || \
  303. ((SIZE) == MPU_REGION_SIZE_4MB) || \
  304. ((SIZE) == MPU_REGION_SIZE_8MB) || \
  305. ((SIZE) == MPU_REGION_SIZE_16MB) || \
  306. ((SIZE) == MPU_REGION_SIZE_32MB) || \
  307. ((SIZE) == MPU_REGION_SIZE_64MB) || \
  308. ((SIZE) == MPU_REGION_SIZE_128MB) || \
  309. ((SIZE) == MPU_REGION_SIZE_256MB) || \
  310. ((SIZE) == MPU_REGION_SIZE_512MB) || \
  311. ((SIZE) == MPU_REGION_SIZE_1GB) || \
  312. ((SIZE) == MPU_REGION_SIZE_2GB) || \
  313. ((SIZE) == MPU_REGION_SIZE_4GB))
  314. #define IS_MPU_SUB_REGION_DISABLE(SUBREGION) ((SUBREGION) < (uint16_t)0x00FF)
  315. #endif /* __MPU_PRESENT */
  316. /**
  317. * @}
  318. */
  319. /* Private functions ---------------------------------------------------------*/
  320. /** @defgroup CORTEX_Private_Functions CORTEX Private Functions
  321. * @brief CORTEX private functions
  322. * @{
  323. */
  324. /**
  325. * @}
  326. */
  327. /* Exported functions --------------------------------------------------------*/
  328. /** @addtogroup CORTEX_Exported_Functions
  329. * @{
  330. */
  331. /** @addtogroup CORTEX_Exported_Functions_Group1
  332. * @{
  333. */
  334. /* Initialization and de-initialization functions *****************************/
  335. void HAL_NVIC_SetPriorityGrouping(uint32_t PriorityGroup);
  336. void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority);
  337. void HAL_NVIC_EnableIRQ(IRQn_Type IRQn);
  338. void HAL_NVIC_DisableIRQ(IRQn_Type IRQn);
  339. void HAL_NVIC_SystemReset(void);
  340. uint32_t HAL_SYSTICK_Config(uint32_t TicksNumb);
  341. /**
  342. * @}
  343. */
  344. /** @addtogroup CORTEX_Exported_Functions_Group2
  345. * @{
  346. */
  347. /* Peripheral Control functions ***********************************************/
  348. #if (__MPU_PRESENT == 1)
  349. void HAL_MPU_Enable(uint32_t MPU_Control);
  350. void HAL_MPU_Disable(void);
  351. void HAL_MPU_ConfigRegion(MPU_Region_InitTypeDef *MPU_Init);
  352. #endif /* __MPU_PRESENT */
  353. uint32_t HAL_NVIC_GetPriorityGrouping(void);
  354. void HAL_NVIC_GetPriority(IRQn_Type IRQn, uint32_t PriorityGroup, uint32_t* pPreemptPriority, uint32_t* pSubPriority);
  355. uint32_t HAL_NVIC_GetPendingIRQ(IRQn_Type IRQn);
  356. void HAL_NVIC_SetPendingIRQ(IRQn_Type IRQn);
  357. void HAL_NVIC_ClearPendingIRQ(IRQn_Type IRQn);
  358. uint32_t HAL_NVIC_GetActive(IRQn_Type IRQn);
  359. void HAL_SYSTICK_CLKSourceConfig(uint32_t CLKSource);
  360. void HAL_SYSTICK_IRQHandler(void);
  361. void HAL_SYSTICK_Callback(void);
  362. /**
  363. * @}
  364. */
  365. /**
  366. * @}
  367. */
  368. /**
  369. * @}
  370. */
  371. /**
  372. * @}
  373. */
  374. #ifdef __cplusplus
  375. }
  376. #endif
  377. #endif /* __STM32L1xx_HAL_CORTEX_H */
  378. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/