stm32f7xx_hal_cortex.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. /**
  2. ******************************************************************************
  3. * @file stm32f7xx_hal_cortex.h
  4. * @author MCD Application Team
  5. * @version V1.2.0
  6. * @date 30-December-2016
  7. * @brief Header file of CORTEX HAL module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
  12. *
  13. * Redistribution and use in source and binary forms, with or without modification,
  14. * are permitted provided that the following conditions are met:
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  21. * may be used to endorse or promote products derived from this software
  22. * without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  28. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  31. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  32. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. ******************************************************************************
  36. */
  37. /* Define to prevent recursive inclusion -------------------------------------*/
  38. #ifndef __STM32F7xx_HAL_CORTEX_H
  39. #define __STM32F7xx_HAL_CORTEX_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32f7xx_hal_def.h"
  45. /** @addtogroup STM32F7xx_HAL_Driver
  46. * @{
  47. */
  48. /** @addtogroup CORTEX
  49. * @{
  50. */
  51. /* Exported types ------------------------------------------------------------*/
  52. /** @defgroup CORTEX_Exported_Types Cortex Exported Types
  53. * @{
  54. */
  55. #if (__MPU_PRESENT == 1)
  56. /** @defgroup CORTEX_MPU_Region_Initialization_Structure_definition MPU Region Initialization Structure Definition
  57. * @brief MPU Region initialization structure
  58. * @{
  59. */
  60. typedef struct
  61. {
  62. uint8_t Enable; /*!< Specifies the status of the region.
  63. This parameter can be a value of @ref CORTEX_MPU_Region_Enable */
  64. uint8_t Number; /*!< Specifies the number of the region to protect.
  65. This parameter can be a value of @ref CORTEX_MPU_Region_Number */
  66. uint32_t BaseAddress; /*!< Specifies the base address of the region to protect. */
  67. uint8_t Size; /*!< Specifies the size of the region to protect.
  68. This parameter can be a value of @ref CORTEX_MPU_Region_Size */
  69. uint8_t SubRegionDisable; /*!< Specifies the number of the subregion protection to disable.
  70. This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFF */
  71. uint8_t TypeExtField; /*!< Specifies the TEX field level.
  72. This parameter can be a value of @ref CORTEX_MPU_TEX_Levels */
  73. uint8_t AccessPermission; /*!< Specifies the region access permission type.
  74. This parameter can be a value of @ref CORTEX_MPU_Region_Permission_Attributes */
  75. uint8_t DisableExec; /*!< Specifies the instruction access status.
  76. This parameter can be a value of @ref CORTEX_MPU_Instruction_Access */
  77. uint8_t IsShareable; /*!< Specifies the shareability status of the protected region.
  78. This parameter can be a value of @ref CORTEX_MPU_Access_Shareable */
  79. uint8_t IsCacheable; /*!< Specifies the cacheable status of the region protected.
  80. This parameter can be a value of @ref CORTEX_MPU_Access_Cacheable */
  81. uint8_t IsBufferable; /*!< Specifies the bufferable status of the protected region.
  82. This parameter can be a value of @ref CORTEX_MPU_Access_Bufferable */
  83. }MPU_Region_InitTypeDef;
  84. /**
  85. * @}
  86. */
  87. #endif /* __MPU_PRESENT */
  88. /**
  89. * @}
  90. */
  91. /* Exported constants --------------------------------------------------------*/
  92. /** @defgroup CORTEX_Exported_Constants CORTEX Exported Constants
  93. * @{
  94. */
  95. /** @defgroup CORTEX_Preemption_Priority_Group CORTEX Preemption Priority Group
  96. * @{
  97. */
  98. #define NVIC_PRIORITYGROUP_0 ((uint32_t)0x00000007U) /*!< 0 bits for pre-emption priority
  99. 4 bits for subpriority */
  100. #define NVIC_PRIORITYGROUP_1 ((uint32_t)0x00000006U) /*!< 1 bits for pre-emption priority
  101. 3 bits for subpriority */
  102. #define NVIC_PRIORITYGROUP_2 ((uint32_t)0x00000005U) /*!< 2 bits for pre-emption priority
  103. 2 bits for subpriority */
  104. #define NVIC_PRIORITYGROUP_3 ((uint32_t)0x00000004U) /*!< 3 bits for pre-emption priority
  105. 1 bits for subpriority */
  106. #define NVIC_PRIORITYGROUP_4 ((uint32_t)0x00000003U) /*!< 4 bits for pre-emption priority
  107. 0 bits for subpriority */
  108. /**
  109. * @}
  110. */
  111. /** @defgroup CORTEX_SysTick_clock_source CORTEX _SysTick clock source
  112. * @{
  113. */
  114. #define SYSTICK_CLKSOURCE_HCLK_DIV8 ((uint32_t)0x00000000U)
  115. #define SYSTICK_CLKSOURCE_HCLK ((uint32_t)0x00000004U)
  116. /**
  117. * @}
  118. */
  119. #if (__MPU_PRESENT == 1)
  120. /** @defgroup CORTEX_MPU_HFNMI_PRIVDEF_Control MPU HFNMI and PRIVILEGED Access control
  121. * @{
  122. */
  123. #define MPU_HFNMI_PRIVDEF_NONE ((uint32_t)0x00000000U)
  124. #define MPU_HARDFAULT_NMI ((uint32_t)0x00000002U)
  125. #define MPU_PRIVILEGED_DEFAULT ((uint32_t)0x00000004U)
  126. #define MPU_HFNMI_PRIVDEF ((uint32_t)0x00000006U)
  127. /**
  128. * @}
  129. */
  130. /** @defgroup CORTEX_MPU_Region_Enable CORTEX MPU Region Enable
  131. * @{
  132. */
  133. #define MPU_REGION_ENABLE ((uint8_t)0x01U)
  134. #define MPU_REGION_DISABLE ((uint8_t)0x00U)
  135. /**
  136. * @}
  137. */
  138. /** @defgroup CORTEX_MPU_Instruction_Access CORTEX MPU Instruction Access
  139. * @{
  140. */
  141. #define MPU_INSTRUCTION_ACCESS_ENABLE ((uint8_t)0x00U)
  142. #define MPU_INSTRUCTION_ACCESS_DISABLE ((uint8_t)0x01U)
  143. /**
  144. * @}
  145. */
  146. /** @defgroup CORTEX_MPU_Access_Shareable CORTEX MPU Instruction Access Shareable
  147. * @{
  148. */
  149. #define MPU_ACCESS_SHAREABLE ((uint8_t)0x01U)
  150. #define MPU_ACCESS_NOT_SHAREABLE ((uint8_t)0x00U)
  151. /**
  152. * @}
  153. */
  154. /** @defgroup CORTEX_MPU_Access_Cacheable CORTEX MPU Instruction Access Cacheable
  155. * @{
  156. */
  157. #define MPU_ACCESS_CACHEABLE ((uint8_t)0x01U)
  158. #define MPU_ACCESS_NOT_CACHEABLE ((uint8_t)0x00U)
  159. /**
  160. * @}
  161. */
  162. /** @defgroup CORTEX_MPU_Access_Bufferable CORTEX MPU Instruction Access Bufferable
  163. * @{
  164. */
  165. #define MPU_ACCESS_BUFFERABLE ((uint8_t)0x01U)
  166. #define MPU_ACCESS_NOT_BUFFERABLE ((uint8_t)0x00U)
  167. /**
  168. * @}
  169. */
  170. /** @defgroup CORTEX_MPU_TEX_Levels MPU TEX Levels
  171. * @{
  172. */
  173. #define MPU_TEX_LEVEL0 ((uint8_t)0x00U)
  174. #define MPU_TEX_LEVEL1 ((uint8_t)0x01U)
  175. #define MPU_TEX_LEVEL2 ((uint8_t)0x02U)
  176. /**
  177. * @}
  178. */
  179. /** @defgroup CORTEX_MPU_Region_Size CORTEX MPU Region Size
  180. * @{
  181. */
  182. #define MPU_REGION_SIZE_32B ((uint8_t)0x04U)
  183. #define MPU_REGION_SIZE_64B ((uint8_t)0x05U)
  184. #define MPU_REGION_SIZE_128B ((uint8_t)0x06U)
  185. #define MPU_REGION_SIZE_256B ((uint8_t)0x07U)
  186. #define MPU_REGION_SIZE_512B ((uint8_t)0x08U)
  187. #define MPU_REGION_SIZE_1KB ((uint8_t)0x09U)
  188. #define MPU_REGION_SIZE_2KB ((uint8_t)0x0AU)
  189. #define MPU_REGION_SIZE_4KB ((uint8_t)0x0BU)
  190. #define MPU_REGION_SIZE_8KB ((uint8_t)0x0CU)
  191. #define MPU_REGION_SIZE_16KB ((uint8_t)0x0DU)
  192. #define MPU_REGION_SIZE_32KB ((uint8_t)0x0EU)
  193. #define MPU_REGION_SIZE_64KB ((uint8_t)0x0FU)
  194. #define MPU_REGION_SIZE_128KB ((uint8_t)0x10U)
  195. #define MPU_REGION_SIZE_256KB ((uint8_t)0x11U)
  196. #define MPU_REGION_SIZE_512KB ((uint8_t)0x12U)
  197. #define MPU_REGION_SIZE_1MB ((uint8_t)0x13U)
  198. #define MPU_REGION_SIZE_2MB ((uint8_t)0x14U)
  199. #define MPU_REGION_SIZE_4MB ((uint8_t)0x15U)
  200. #define MPU_REGION_SIZE_8MB ((uint8_t)0x16U)
  201. #define MPU_REGION_SIZE_16MB ((uint8_t)0x17U)
  202. #define MPU_REGION_SIZE_32MB ((uint8_t)0x18U)
  203. #define MPU_REGION_SIZE_64MB ((uint8_t)0x19U)
  204. #define MPU_REGION_SIZE_128MB ((uint8_t)0x1AU)
  205. #define MPU_REGION_SIZE_256MB ((uint8_t)0x1BU)
  206. #define MPU_REGION_SIZE_512MB ((uint8_t)0x1CU)
  207. #define MPU_REGION_SIZE_1GB ((uint8_t)0x1DU)
  208. #define MPU_REGION_SIZE_2GB ((uint8_t)0x1EU)
  209. #define MPU_REGION_SIZE_4GB ((uint8_t)0x1FU)
  210. /**
  211. * @}
  212. */
  213. /** @defgroup CORTEX_MPU_Region_Permission_Attributes CORTEX MPU Region Permission Attributes
  214. * @{
  215. */
  216. #define MPU_REGION_NO_ACCESS ((uint8_t)0x00U)
  217. #define MPU_REGION_PRIV_RW ((uint8_t)0x01U)
  218. #define MPU_REGION_PRIV_RW_URO ((uint8_t)0x02U)
  219. #define MPU_REGION_FULL_ACCESS ((uint8_t)0x03U)
  220. #define MPU_REGION_PRIV_RO ((uint8_t)0x05U)
  221. #define MPU_REGION_PRIV_RO_URO ((uint8_t)0x06U)
  222. /**
  223. * @}
  224. */
  225. /** @defgroup CORTEX_MPU_Region_Number CORTEX MPU Region Number
  226. * @{
  227. */
  228. #define MPU_REGION_NUMBER0 ((uint8_t)0x00U)
  229. #define MPU_REGION_NUMBER1 ((uint8_t)0x01U)
  230. #define MPU_REGION_NUMBER2 ((uint8_t)0x02U)
  231. #define MPU_REGION_NUMBER3 ((uint8_t)0x03U)
  232. #define MPU_REGION_NUMBER4 ((uint8_t)0x04U)
  233. #define MPU_REGION_NUMBER5 ((uint8_t)0x05U)
  234. #define MPU_REGION_NUMBER6 ((uint8_t)0x06U)
  235. #define MPU_REGION_NUMBER7 ((uint8_t)0x07U)
  236. /**
  237. * @}
  238. */
  239. #endif /* __MPU_PRESENT */
  240. /**
  241. * @}
  242. */
  243. /* Exported Macros -----------------------------------------------------------*/
  244. /* Exported functions --------------------------------------------------------*/
  245. /** @addtogroup CORTEX_Exported_Functions
  246. * @{
  247. */
  248. /** @addtogroup CORTEX_Exported_Functions_Group1
  249. * @{
  250. */
  251. /* Initialization and de-initialization functions *****************************/
  252. void HAL_NVIC_SetPriorityGrouping(uint32_t PriorityGroup);
  253. void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority);
  254. void HAL_NVIC_EnableIRQ(IRQn_Type IRQn);
  255. void HAL_NVIC_DisableIRQ(IRQn_Type IRQn);
  256. void HAL_NVIC_SystemReset(void);
  257. uint32_t HAL_SYSTICK_Config(uint32_t TicksNumb);
  258. /**
  259. * @}
  260. */
  261. /** @addtogroup CORTEX_Exported_Functions_Group2
  262. * @{
  263. */
  264. /* Peripheral Control functions ***********************************************/
  265. #if (__MPU_PRESENT == 1)
  266. void HAL_MPU_Enable(uint32_t MPU_Control);
  267. void HAL_MPU_Disable(void);
  268. void HAL_MPU_ConfigRegion(MPU_Region_InitTypeDef *MPU_Init);
  269. #endif /* __MPU_PRESENT */
  270. uint32_t HAL_NVIC_GetPriorityGrouping(void);
  271. void HAL_NVIC_GetPriority(IRQn_Type IRQn, uint32_t PriorityGroup, uint32_t* pPreemptPriority, uint32_t* pSubPriority);
  272. uint32_t HAL_NVIC_GetPendingIRQ(IRQn_Type IRQn);
  273. void HAL_NVIC_SetPendingIRQ(IRQn_Type IRQn);
  274. void HAL_NVIC_ClearPendingIRQ(IRQn_Type IRQn);
  275. uint32_t HAL_NVIC_GetActive(IRQn_Type IRQn);
  276. void HAL_SYSTICK_CLKSourceConfig(uint32_t CLKSource);
  277. void HAL_SYSTICK_IRQHandler(void);
  278. void HAL_SYSTICK_Callback(void);
  279. /**
  280. * @}
  281. */
  282. /**
  283. * @}
  284. */
  285. /* Private types -------------------------------------------------------------*/
  286. /* Private variables ---------------------------------------------------------*/
  287. /* Private constants ---------------------------------------------------------*/
  288. /* Private macros ------------------------------------------------------------*/
  289. /** @defgroup CORTEX_Private_Macros CORTEX Private Macros
  290. * @{
  291. */
  292. #define IS_NVIC_PRIORITY_GROUP(GROUP) (((GROUP) == NVIC_PRIORITYGROUP_0) || \
  293. ((GROUP) == NVIC_PRIORITYGROUP_1) || \
  294. ((GROUP) == NVIC_PRIORITYGROUP_2) || \
  295. ((GROUP) == NVIC_PRIORITYGROUP_3) || \
  296. ((GROUP) == NVIC_PRIORITYGROUP_4))
  297. #define IS_NVIC_PREEMPTION_PRIORITY(PRIORITY) ((PRIORITY) < 0x10U)
  298. #define IS_NVIC_SUB_PRIORITY(PRIORITY) ((PRIORITY) < 0x10U)
  299. #define IS_NVIC_DEVICE_IRQ(IRQ) ((IRQ) >= 0x00)
  300. #define IS_SYSTICK_CLK_SOURCE(SOURCE) (((SOURCE) == SYSTICK_CLKSOURCE_HCLK) || \
  301. ((SOURCE) == SYSTICK_CLKSOURCE_HCLK_DIV8))
  302. #if (__MPU_PRESENT == 1)
  303. #define IS_MPU_REGION_ENABLE(STATE) (((STATE) == MPU_REGION_ENABLE) || \
  304. ((STATE) == MPU_REGION_DISABLE))
  305. #define IS_MPU_INSTRUCTION_ACCESS(STATE) (((STATE) == MPU_INSTRUCTION_ACCESS_ENABLE) || \
  306. ((STATE) == MPU_INSTRUCTION_ACCESS_DISABLE))
  307. #define IS_MPU_ACCESS_SHAREABLE(STATE) (((STATE) == MPU_ACCESS_SHAREABLE) || \
  308. ((STATE) == MPU_ACCESS_NOT_SHAREABLE))
  309. #define IS_MPU_ACCESS_CACHEABLE(STATE) (((STATE) == MPU_ACCESS_CACHEABLE) || \
  310. ((STATE) == MPU_ACCESS_NOT_CACHEABLE))
  311. #define IS_MPU_ACCESS_BUFFERABLE(STATE) (((STATE) == MPU_ACCESS_BUFFERABLE) || \
  312. ((STATE) == MPU_ACCESS_NOT_BUFFERABLE))
  313. #define IS_MPU_TEX_LEVEL(TYPE) (((TYPE) == MPU_TEX_LEVEL0) || \
  314. ((TYPE) == MPU_TEX_LEVEL1) || \
  315. ((TYPE) == MPU_TEX_LEVEL2))
  316. #define IS_MPU_REGION_PERMISSION_ATTRIBUTE(TYPE) (((TYPE) == MPU_REGION_NO_ACCESS) || \
  317. ((TYPE) == MPU_REGION_PRIV_RW) || \
  318. ((TYPE) == MPU_REGION_PRIV_RW_URO) || \
  319. ((TYPE) == MPU_REGION_FULL_ACCESS) || \
  320. ((TYPE) == MPU_REGION_PRIV_RO) || \
  321. ((TYPE) == MPU_REGION_PRIV_RO_URO))
  322. #define IS_MPU_REGION_NUMBER(NUMBER) (((NUMBER) == MPU_REGION_NUMBER0) || \
  323. ((NUMBER) == MPU_REGION_NUMBER1) || \
  324. ((NUMBER) == MPU_REGION_NUMBER2) || \
  325. ((NUMBER) == MPU_REGION_NUMBER3) || \
  326. ((NUMBER) == MPU_REGION_NUMBER4) || \
  327. ((NUMBER) == MPU_REGION_NUMBER5) || \
  328. ((NUMBER) == MPU_REGION_NUMBER6) || \
  329. ((NUMBER) == MPU_REGION_NUMBER7))
  330. #define IS_MPU_REGION_SIZE(SIZE) (((SIZE) == MPU_REGION_SIZE_32B) || \
  331. ((SIZE) == MPU_REGION_SIZE_64B) || \
  332. ((SIZE) == MPU_REGION_SIZE_128B) || \
  333. ((SIZE) == MPU_REGION_SIZE_256B) || \
  334. ((SIZE) == MPU_REGION_SIZE_512B) || \
  335. ((SIZE) == MPU_REGION_SIZE_1KB) || \
  336. ((SIZE) == MPU_REGION_SIZE_2KB) || \
  337. ((SIZE) == MPU_REGION_SIZE_4KB) || \
  338. ((SIZE) == MPU_REGION_SIZE_8KB) || \
  339. ((SIZE) == MPU_REGION_SIZE_16KB) || \
  340. ((SIZE) == MPU_REGION_SIZE_32KB) || \
  341. ((SIZE) == MPU_REGION_SIZE_64KB) || \
  342. ((SIZE) == MPU_REGION_SIZE_128KB) || \
  343. ((SIZE) == MPU_REGION_SIZE_256KB) || \
  344. ((SIZE) == MPU_REGION_SIZE_512KB) || \
  345. ((SIZE) == MPU_REGION_SIZE_1MB) || \
  346. ((SIZE) == MPU_REGION_SIZE_2MB) || \
  347. ((SIZE) == MPU_REGION_SIZE_4MB) || \
  348. ((SIZE) == MPU_REGION_SIZE_8MB) || \
  349. ((SIZE) == MPU_REGION_SIZE_16MB) || \
  350. ((SIZE) == MPU_REGION_SIZE_32MB) || \
  351. ((SIZE) == MPU_REGION_SIZE_64MB) || \
  352. ((SIZE) == MPU_REGION_SIZE_128MB) || \
  353. ((SIZE) == MPU_REGION_SIZE_256MB) || \
  354. ((SIZE) == MPU_REGION_SIZE_512MB) || \
  355. ((SIZE) == MPU_REGION_SIZE_1GB) || \
  356. ((SIZE) == MPU_REGION_SIZE_2GB) || \
  357. ((SIZE) == MPU_REGION_SIZE_4GB))
  358. #define IS_MPU_SUB_REGION_DISABLE(SUBREGION) ((SUBREGION) < (uint16_t)0x00FFU)
  359. #endif /* __MPU_PRESENT */
  360. /**
  361. * @}
  362. */
  363. /**
  364. * @}
  365. */
  366. /**
  367. * @}
  368. */
  369. #ifdef __cplusplus
  370. }
  371. #endif
  372. #endif /* __STM32F7xx_HAL_CORTEX_H */
  373. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/