stm32h7xx_hal_cortex.h 19 KB

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