stm32h7xx_ll_cortex.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. /**
  2. ******************************************************************************
  3. * @file stm32h7xx_ll_cortex.h
  4. * @author MCD Application Team
  5. * @brief Header file of CORTEX LL module.
  6. @verbatim
  7. ==============================================================================
  8. ##### How to use this driver #####
  9. ==============================================================================
  10. [..]
  11. The LL CORTEX driver contains a set of generic APIs that can be
  12. used by user:
  13. (+) SYSTICK configuration used by LL_mDelay and LL_Init1msTick
  14. functions
  15. (+) Low power mode configuration (SCB register of Cortex-MCU)
  16. (+) MPU API to configure and enable regions
  17. (+) API to access to MCU info (CPUID register)
  18. (+) API to enable fault handler (SHCSR accesses)
  19. @endverbatim
  20. ******************************************************************************
  21. * @attention
  22. *
  23. * Copyright (c) 2017 STMicroelectronics.
  24. * All rights reserved.
  25. *
  26. * This software is licensed under terms that can be found in the LICENSE file in
  27. * the root directory of this software component.
  28. * If no LICENSE file comes with this software, it is provided AS-IS.
  29. *
  30. ******************************************************************************
  31. */
  32. /* Define to prevent recursive inclusion -------------------------------------*/
  33. #ifndef STM32H7xx_LL_CORTEX_H
  34. #define STM32H7xx_LL_CORTEX_H
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38. /* Includes ------------------------------------------------------------------*/
  39. #include "stm32h7xx.h"
  40. /** @addtogroup STM32H7xx_LL_Driver
  41. * @{
  42. */
  43. /** @defgroup CORTEX_LL CORTEX
  44. * @{
  45. */
  46. /* Private types -------------------------------------------------------------*/
  47. /* Private variables ---------------------------------------------------------*/
  48. /* Private constants ---------------------------------------------------------*/
  49. /* Private macros ------------------------------------------------------------*/
  50. /* Exported types ------------------------------------------------------------*/
  51. /* Exported constants --------------------------------------------------------*/
  52. /** @defgroup CORTEX_LL_Exported_Constants CORTEX Exported Constants
  53. * @{
  54. */
  55. /** @defgroup CORTEX_LL_EC_CLKSOURCE_HCLK SYSTICK Clock Source
  56. * @{
  57. */
  58. #define LL_SYSTICK_CLKSOURCE_HCLK_DIV8 0x00000000UL /*!< AHB clock divided by 8 selected as SysTick clock source.*/
  59. #define LL_SYSTICK_CLKSOURCE_HCLK SysTick_CTRL_CLKSOURCE_Msk /*!< AHB clock selected as SysTick clock source. */
  60. /**
  61. * @}
  62. */
  63. /** @defgroup CORTEX_LL_EC_FAULT Handler Fault type
  64. * @{
  65. */
  66. #define LL_HANDLER_FAULT_USG SCB_SHCSR_USGFAULTENA_Msk /*!< Usage fault */
  67. #define LL_HANDLER_FAULT_BUS SCB_SHCSR_BUSFAULTENA_Msk /*!< Bus fault */
  68. #define LL_HANDLER_FAULT_MEM SCB_SHCSR_MEMFAULTENA_Msk /*!< Memory management fault */
  69. /**
  70. * @}
  71. */
  72. #if __MPU_PRESENT
  73. /** @defgroup CORTEX_LL_EC_CTRL_HFNMI_PRIVDEF MPU Control
  74. * @{
  75. */
  76. #define LL_MPU_CTRL_HFNMI_PRIVDEF_NONE 0x00000000UL /*!< Disable NMI and privileged SW access */
  77. #define LL_MPU_CTRL_HARDFAULT_NMI MPU_CTRL_HFNMIENA_Msk /*!< Enables the operation of MPU during hard fault, NMI, and FAULTMASK handlers */
  78. #define LL_MPU_CTRL_PRIVILEGED_DEFAULT MPU_CTRL_PRIVDEFENA_Msk /*!< Enable privileged software access to default memory map */
  79. #define LL_MPU_CTRL_HFNMI_PRIVDEF (MPU_CTRL_HFNMIENA_Msk | MPU_CTRL_PRIVDEFENA_Msk) /*!< Enable NMI and privileged SW access */
  80. /**
  81. * @}
  82. */
  83. /** @defgroup CORTEX_LL_EC_REGION MPU Region Number
  84. * @{
  85. */
  86. #define LL_MPU_REGION_NUMBER0 0x00UL /*!< REGION Number 0 */
  87. #define LL_MPU_REGION_NUMBER1 0x01UL /*!< REGION Number 1 */
  88. #define LL_MPU_REGION_NUMBER2 0x02UL /*!< REGION Number 2 */
  89. #define LL_MPU_REGION_NUMBER3 0x03UL /*!< REGION Number 3 */
  90. #define LL_MPU_REGION_NUMBER4 0x04UL /*!< REGION Number 4 */
  91. #define LL_MPU_REGION_NUMBER5 0x05UL /*!< REGION Number 5 */
  92. #define LL_MPU_REGION_NUMBER6 0x06UL /*!< REGION Number 6 */
  93. #define LL_MPU_REGION_NUMBER7 0x07UL /*!< REGION Number 7 */
  94. #if !defined(CORE_CM4)
  95. #define LL_MPU_REGION_NUMBER8 0x08UL /*!< REGION Number 8 */
  96. #define LL_MPU_REGION_NUMBER9 0x09UL /*!< REGION Number 9 */
  97. #define LL_MPU_REGION_NUMBER10 0x0AUL /*!< REGION Number 10 */
  98. #define LL_MPU_REGION_NUMBER11 0x0BUL /*!< REGION Number 11 */
  99. #define LL_MPU_REGION_NUMBER12 0x0CUL /*!< REGION Number 12 */
  100. #define LL_MPU_REGION_NUMBER13 0x0DUL /*!< REGION Number 13 */
  101. #define LL_MPU_REGION_NUMBER14 0x0EUL /*!< REGION Number 14 */
  102. #define LL_MPU_REGION_NUMBER15 0x0FUL /*!< REGION Number 15 */
  103. #endif /* !defined(CORE_CM4) */
  104. /**
  105. * @}
  106. */
  107. /** @defgroup CORTEX_LL_EC_REGION_SIZE MPU Region Size
  108. * @{
  109. */
  110. #define LL_MPU_REGION_SIZE_32B (0x04UL << MPU_RASR_SIZE_Pos) /*!< 32B Size of the MPU protection region */
  111. #define LL_MPU_REGION_SIZE_64B (0x05UL << MPU_RASR_SIZE_Pos) /*!< 64B Size of the MPU protection region */
  112. #define LL_MPU_REGION_SIZE_128B (0x06UL << MPU_RASR_SIZE_Pos) /*!< 128B Size of the MPU protection region */
  113. #define LL_MPU_REGION_SIZE_256B (0x07UL << MPU_RASR_SIZE_Pos) /*!< 256B Size of the MPU protection region */
  114. #define LL_MPU_REGION_SIZE_512B (0x08UL << MPU_RASR_SIZE_Pos) /*!< 512B Size of the MPU protection region */
  115. #define LL_MPU_REGION_SIZE_1KB (0x09UL << MPU_RASR_SIZE_Pos) /*!< 1KB Size of the MPU protection region */
  116. #define LL_MPU_REGION_SIZE_2KB (0x0AUL << MPU_RASR_SIZE_Pos) /*!< 2KB Size of the MPU protection region */
  117. #define LL_MPU_REGION_SIZE_4KB (0x0BUL << MPU_RASR_SIZE_Pos) /*!< 4KB Size of the MPU protection region */
  118. #define LL_MPU_REGION_SIZE_8KB (0x0CUL << MPU_RASR_SIZE_Pos) /*!< 8KB Size of the MPU protection region */
  119. #define LL_MPU_REGION_SIZE_16KB (0x0DUL << MPU_RASR_SIZE_Pos) /*!< 16KB Size of the MPU protection region */
  120. #define LL_MPU_REGION_SIZE_32KB (0x0EUL << MPU_RASR_SIZE_Pos) /*!< 32KB Size of the MPU protection region */
  121. #define LL_MPU_REGION_SIZE_64KB (0x0FUL << MPU_RASR_SIZE_Pos) /*!< 64KB Size of the MPU protection region */
  122. #define LL_MPU_REGION_SIZE_128KB (0x10UL << MPU_RASR_SIZE_Pos) /*!< 128KB Size of the MPU protection region */
  123. #define LL_MPU_REGION_SIZE_256KB (0x11UL << MPU_RASR_SIZE_Pos) /*!< 256KB Size of the MPU protection region */
  124. #define LL_MPU_REGION_SIZE_512KB (0x12UL << MPU_RASR_SIZE_Pos) /*!< 512KB Size of the MPU protection region */
  125. #define LL_MPU_REGION_SIZE_1MB (0x13UL << MPU_RASR_SIZE_Pos) /*!< 1MB Size of the MPU protection region */
  126. #define LL_MPU_REGION_SIZE_2MB (0x14UL << MPU_RASR_SIZE_Pos) /*!< 2MB Size of the MPU protection region */
  127. #define LL_MPU_REGION_SIZE_4MB (0x15UL << MPU_RASR_SIZE_Pos) /*!< 4MB Size of the MPU protection region */
  128. #define LL_MPU_REGION_SIZE_8MB (0x16UL << MPU_RASR_SIZE_Pos) /*!< 8MB Size of the MPU protection region */
  129. #define LL_MPU_REGION_SIZE_16MB (0x17UL << MPU_RASR_SIZE_Pos) /*!< 16MB Size of the MPU protection region */
  130. #define LL_MPU_REGION_SIZE_32MB (0x18UL << MPU_RASR_SIZE_Pos) /*!< 32MB Size of the MPU protection region */
  131. #define LL_MPU_REGION_SIZE_64MB (0x19UL << MPU_RASR_SIZE_Pos) /*!< 64MB Size of the MPU protection region */
  132. #define LL_MPU_REGION_SIZE_128MB (0x1AUL << MPU_RASR_SIZE_Pos) /*!< 128MB Size of the MPU protection region */
  133. #define LL_MPU_REGION_SIZE_256MB (0x1BUL << MPU_RASR_SIZE_Pos) /*!< 256MB Size of the MPU protection region */
  134. #define LL_MPU_REGION_SIZE_512MB (0x1CUL << MPU_RASR_SIZE_Pos) /*!< 512MB Size of the MPU protection region */
  135. #define LL_MPU_REGION_SIZE_1GB (0x1DUL << MPU_RASR_SIZE_Pos) /*!< 1GB Size of the MPU protection region */
  136. #define LL_MPU_REGION_SIZE_2GB (0x1EUL << MPU_RASR_SIZE_Pos) /*!< 2GB Size of the MPU protection region */
  137. #define LL_MPU_REGION_SIZE_4GB (0x1FUL << MPU_RASR_SIZE_Pos) /*!< 4GB Size of the MPU protection region */
  138. /**
  139. * @}
  140. */
  141. /** @defgroup CORTEX_LL_EC_REGION_PRIVILEDGES MPU Region Privileges
  142. * @{
  143. */
  144. #define LL_MPU_REGION_NO_ACCESS (0x00UL << MPU_RASR_AP_Pos) /*!< No access*/
  145. #define LL_MPU_REGION_PRIV_RW (0x01UL << MPU_RASR_AP_Pos) /*!< RW privileged (privileged access only)*/
  146. #define LL_MPU_REGION_PRIV_RW_URO (0x02UL << MPU_RASR_AP_Pos) /*!< RW privileged - RO user (Write in a user program generates a fault) */
  147. #define LL_MPU_REGION_FULL_ACCESS (0x03UL << MPU_RASR_AP_Pos) /*!< RW privileged & user (Full access) */
  148. #define LL_MPU_REGION_PRIV_RO (0x05UL << MPU_RASR_AP_Pos) /*!< RO privileged (privileged read only)*/
  149. #define LL_MPU_REGION_PRIV_RO_URO (0x06UL << MPU_RASR_AP_Pos) /*!< RO privileged & user (read only) */
  150. /**
  151. * @}
  152. */
  153. /** @defgroup CORTEX_LL_EC_TEX MPU TEX Level
  154. * @{
  155. */
  156. #define LL_MPU_TEX_LEVEL0 (0x00UL << MPU_RASR_TEX_Pos) /*!< b000 for TEX bits */
  157. #define LL_MPU_TEX_LEVEL1 (0x01UL << MPU_RASR_TEX_Pos) /*!< b001 for TEX bits */
  158. #define LL_MPU_TEX_LEVEL2 (0x02UL << MPU_RASR_TEX_Pos) /*!< b010 for TEX bits */
  159. #define LL_MPU_TEX_LEVEL4 (0x04UL << MPU_RASR_TEX_Pos) /*!< b100 for TEX bits */
  160. /**
  161. * @}
  162. */
  163. /** @defgroup CORTEX_LL_EC_INSTRUCTION_ACCESS MPU Instruction Access
  164. * @{
  165. */
  166. #define LL_MPU_INSTRUCTION_ACCESS_ENABLE 0x00UL /*!< Instruction fetches enabled */
  167. #define LL_MPU_INSTRUCTION_ACCESS_DISABLE MPU_RASR_XN_Msk /*!< Instruction fetches disabled*/
  168. /**
  169. * @}
  170. */
  171. /** @defgroup CORTEX_LL_EC_SHAREABLE_ACCESS MPU Shareable Access
  172. * @{
  173. */
  174. #define LL_MPU_ACCESS_SHAREABLE MPU_RASR_S_Msk /*!< Shareable memory attribute */
  175. #define LL_MPU_ACCESS_NOT_SHAREABLE 0x00UL /*!< Not Shareable memory attribute */
  176. /**
  177. * @}
  178. */
  179. /** @defgroup CORTEX_LL_EC_CACHEABLE_ACCESS MPU Cacheable Access
  180. * @{
  181. */
  182. #define LL_MPU_ACCESS_CACHEABLE MPU_RASR_C_Msk /*!< Cacheable memory attribute */
  183. #define LL_MPU_ACCESS_NOT_CACHEABLE 0x00UL /*!< Not Cacheable memory attribute */
  184. /**
  185. * @}
  186. */
  187. /** @defgroup CORTEX_LL_EC_BUFFERABLE_ACCESS MPU Bufferable Access
  188. * @{
  189. */
  190. #define LL_MPU_ACCESS_BUFFERABLE MPU_RASR_B_Msk /*!< Bufferable memory attribute */
  191. #define LL_MPU_ACCESS_NOT_BUFFERABLE 0x00UL /*!< Not Bufferable memory attribute */
  192. /**
  193. * @}
  194. */
  195. #endif /* __MPU_PRESENT */
  196. /**
  197. * @}
  198. */
  199. /* Exported macro ------------------------------------------------------------*/
  200. /* Exported functions --------------------------------------------------------*/
  201. /** @defgroup CORTEX_LL_Exported_Functions CORTEX Exported Functions
  202. * @{
  203. */
  204. /** @defgroup CORTEX_LL_EF_SYSTICK SYSTICK
  205. * @{
  206. */
  207. /**
  208. * @brief This function checks if the Systick counter flag is active or not.
  209. * @note It can be used in timeout function on application side.
  210. * @rmtoll STK_CTRL COUNTFLAG LL_SYSTICK_IsActiveCounterFlag
  211. * @retval State of bit (1 or 0).
  212. */
  213. __STATIC_INLINE uint32_t LL_SYSTICK_IsActiveCounterFlag(void)
  214. {
  215. return (((SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk) == (SysTick_CTRL_COUNTFLAG_Msk)) ? 1UL : 0UL);
  216. }
  217. /**
  218. * @brief Configures the SysTick clock source
  219. * @rmtoll STK_CTRL CLKSOURCE LL_SYSTICK_SetClkSource
  220. * @param Source This parameter can be one of the following values:
  221. * @arg @ref LL_SYSTICK_CLKSOURCE_HCLK_DIV8
  222. * @arg @ref LL_SYSTICK_CLKSOURCE_HCLK
  223. * @retval None
  224. */
  225. __STATIC_INLINE void LL_SYSTICK_SetClkSource(uint32_t Source)
  226. {
  227. MODIFY_REG(SysTick->CTRL, LL_SYSTICK_CLKSOURCE_HCLK, Source);
  228. }
  229. /**
  230. * @brief Get the SysTick clock source
  231. * @rmtoll STK_CTRL CLKSOURCE LL_SYSTICK_GetClkSource
  232. * @retval Returned value can be one of the following values:
  233. * @arg @ref LL_SYSTICK_CLKSOURCE_HCLK_DIV8
  234. * @arg @ref LL_SYSTICK_CLKSOURCE_HCLK
  235. */
  236. __STATIC_INLINE uint32_t LL_SYSTICK_GetClkSource(void)
  237. {
  238. return (uint32_t)(READ_BIT(SysTick->CTRL, LL_SYSTICK_CLKSOURCE_HCLK));
  239. }
  240. /**
  241. * @brief Enable SysTick exception request
  242. * @rmtoll STK_CTRL TICKINT LL_SYSTICK_EnableIT
  243. * @retval None
  244. */
  245. __STATIC_INLINE void LL_SYSTICK_EnableIT(void)
  246. {
  247. SET_BIT(SysTick->CTRL, SysTick_CTRL_TICKINT_Msk);
  248. }
  249. /**
  250. * @brief Disable SysTick exception request
  251. * @rmtoll STK_CTRL TICKINT LL_SYSTICK_DisableIT
  252. * @retval None
  253. */
  254. __STATIC_INLINE void LL_SYSTICK_DisableIT(void)
  255. {
  256. CLEAR_BIT(SysTick->CTRL, SysTick_CTRL_TICKINT_Msk);
  257. }
  258. /**
  259. * @brief Checks if the SYSTICK interrupt is enabled or disabled.
  260. * @rmtoll STK_CTRL TICKINT LL_SYSTICK_IsEnabledIT
  261. * @retval State of bit (1 or 0).
  262. */
  263. __STATIC_INLINE uint32_t LL_SYSTICK_IsEnabledIT(void)
  264. {
  265. return ((READ_BIT(SysTick->CTRL, SysTick_CTRL_TICKINT_Msk) == (SysTick_CTRL_TICKINT_Msk)) ? 1UL : 0UL);
  266. }
  267. /**
  268. * @}
  269. */
  270. /** @defgroup CORTEX_LL_EF_LOW_POWER_MODE LOW POWER MODE
  271. * @{
  272. */
  273. /**
  274. * @brief Processor uses sleep as its low power mode
  275. * @rmtoll SCB_SCR SLEEPDEEP LL_LPM_EnableSleep
  276. * @retval None
  277. */
  278. __STATIC_INLINE void LL_LPM_EnableSleep(void)
  279. {
  280. /* Clear SLEEPDEEP bit of Cortex System Control Register */
  281. CLEAR_BIT(SCB->SCR, SCB_SCR_SLEEPDEEP_Msk);
  282. }
  283. /**
  284. * @brief Processor uses deep sleep as its low power mode
  285. * @rmtoll SCB_SCR SLEEPDEEP LL_LPM_EnableDeepSleep
  286. * @retval None
  287. */
  288. __STATIC_INLINE void LL_LPM_EnableDeepSleep(void)
  289. {
  290. /* Set SLEEPDEEP bit of Cortex System Control Register */
  291. SET_BIT(SCB->SCR, SCB_SCR_SLEEPDEEP_Msk);
  292. }
  293. /**
  294. * @brief Configures sleep-on-exit when returning from Handler mode to Thread mode.
  295. * @note Setting this bit to 1 enables an interrupt-driven application to avoid returning to an
  296. * empty main application.
  297. * @rmtoll SCB_SCR SLEEPONEXIT LL_LPM_EnableSleepOnExit
  298. * @retval None
  299. */
  300. __STATIC_INLINE void LL_LPM_EnableSleepOnExit(void)
  301. {
  302. /* Set SLEEPONEXIT bit of Cortex System Control Register */
  303. SET_BIT(SCB->SCR, SCB_SCR_SLEEPONEXIT_Msk);
  304. }
  305. /**
  306. * @brief Do not sleep when returning to Thread mode.
  307. * @rmtoll SCB_SCR SLEEPONEXIT LL_LPM_DisableSleepOnExit
  308. * @retval None
  309. */
  310. __STATIC_INLINE void LL_LPM_DisableSleepOnExit(void)
  311. {
  312. /* Clear SLEEPONEXIT bit of Cortex System Control Register */
  313. CLEAR_BIT(SCB->SCR, SCB_SCR_SLEEPONEXIT_Msk);
  314. }
  315. /**
  316. * @brief Enabled events and all interrupts, including disabled interrupts, can wakeup the
  317. * processor.
  318. * @rmtoll SCB_SCR SEVEONPEND LL_LPM_EnableEventOnPend
  319. * @retval None
  320. */
  321. __STATIC_INLINE void LL_LPM_EnableEventOnPend(void)
  322. {
  323. /* Set SEVEONPEND bit of Cortex System Control Register */
  324. SET_BIT(SCB->SCR, SCB_SCR_SEVONPEND_Msk);
  325. }
  326. /**
  327. * @brief Only enabled interrupts or events can wakeup the processor, disabled interrupts are
  328. * excluded
  329. * @rmtoll SCB_SCR SEVEONPEND LL_LPM_DisableEventOnPend
  330. * @retval None
  331. */
  332. __STATIC_INLINE void LL_LPM_DisableEventOnPend(void)
  333. {
  334. /* Clear SEVEONPEND bit of Cortex System Control Register */
  335. CLEAR_BIT(SCB->SCR, SCB_SCR_SEVONPEND_Msk);
  336. }
  337. /**
  338. * @}
  339. */
  340. /** @defgroup CORTEX_LL_EF_HANDLER HANDLER
  341. * @{
  342. */
  343. /**
  344. * @brief Enable a fault in System handler control register (SHCSR)
  345. * @rmtoll SCB_SHCSR MEMFAULTENA LL_HANDLER_EnableFault
  346. * @param Fault This parameter can be a combination of the following values:
  347. * @arg @ref LL_HANDLER_FAULT_USG
  348. * @arg @ref LL_HANDLER_FAULT_BUS
  349. * @arg @ref LL_HANDLER_FAULT_MEM
  350. * @retval None
  351. */
  352. __STATIC_INLINE void LL_HANDLER_EnableFault(uint32_t Fault)
  353. {
  354. /* Enable the system handler fault */
  355. SET_BIT(SCB->SHCSR, Fault);
  356. }
  357. /**
  358. * @brief Disable a fault in System handler control register (SHCSR)
  359. * @rmtoll SCB_SHCSR MEMFAULTENA LL_HANDLER_DisableFault
  360. * @param Fault This parameter can be a combination of the following values:
  361. * @arg @ref LL_HANDLER_FAULT_USG
  362. * @arg @ref LL_HANDLER_FAULT_BUS
  363. * @arg @ref LL_HANDLER_FAULT_MEM
  364. * @retval None
  365. */
  366. __STATIC_INLINE void LL_HANDLER_DisableFault(uint32_t Fault)
  367. {
  368. /* Disable the system handler fault */
  369. CLEAR_BIT(SCB->SHCSR, Fault);
  370. }
  371. /**
  372. * @}
  373. */
  374. /** @defgroup CORTEX_LL_EF_MCU_INFO MCU INFO
  375. * @{
  376. */
  377. /**
  378. * @brief Get Implementer code
  379. * @rmtoll SCB_CPUID IMPLEMENTER LL_CPUID_GetImplementer
  380. * @retval Value should be equal to 0x41 for ARM
  381. */
  382. __STATIC_INLINE uint32_t LL_CPUID_GetImplementer(void)
  383. {
  384. return (uint32_t)(READ_BIT(SCB->CPUID, SCB_CPUID_IMPLEMENTER_Msk) >> SCB_CPUID_IMPLEMENTER_Pos);
  385. }
  386. /**
  387. * @brief Get Variant number (The r value in the rnpn product revision identifier)
  388. * @rmtoll SCB_CPUID VARIANT LL_CPUID_GetVariant
  389. * @retval Value between 0 and 255 (0x0: revision 0)
  390. */
  391. __STATIC_INLINE uint32_t LL_CPUID_GetVariant(void)
  392. {
  393. return (uint32_t)(READ_BIT(SCB->CPUID, SCB_CPUID_VARIANT_Msk) >> SCB_CPUID_VARIANT_Pos);
  394. }
  395. /**
  396. * @brief Get Constant number
  397. * @rmtoll SCB_CPUID ARCHITECTURE LL_CPUID_GetConstant
  398. * @retval Value should be equal to 0xF for Cortex-M7 and Cortex-M4 devices
  399. */
  400. __STATIC_INLINE uint32_t LL_CPUID_GetConstant(void)
  401. {
  402. return (uint32_t)(READ_BIT(SCB->CPUID, SCB_CPUID_ARCHITECTURE_Msk) >> SCB_CPUID_ARCHITECTURE_Pos);
  403. }
  404. /**
  405. * @brief Get Part number
  406. * @rmtoll SCB_CPUID PARTNO LL_CPUID_GetParNo
  407. * @retval Value should be equal to 0xC27 for Cortex-M7 and equal to 0xC24 for Cortex-M4
  408. */
  409. __STATIC_INLINE uint32_t LL_CPUID_GetParNo(void)
  410. {
  411. return (uint32_t)(READ_BIT(SCB->CPUID, SCB_CPUID_PARTNO_Msk) >> SCB_CPUID_PARTNO_Pos);
  412. }
  413. /**
  414. * @brief Get Revision number (The p value in the rnpn product revision identifier, indicates patch release)
  415. * @rmtoll SCB_CPUID REVISION LL_CPUID_GetRevision
  416. * @retval Value between 0 and 255 (0x1: patch 1)
  417. */
  418. __STATIC_INLINE uint32_t LL_CPUID_GetRevision(void)
  419. {
  420. return (uint32_t)(READ_BIT(SCB->CPUID, SCB_CPUID_REVISION_Msk) >> SCB_CPUID_REVISION_Pos);
  421. }
  422. /**
  423. * @}
  424. */
  425. #if __MPU_PRESENT
  426. /** @defgroup CORTEX_LL_EF_MPU MPU
  427. * @{
  428. */
  429. /**
  430. * @brief Enable MPU with input options
  431. * @rmtoll MPU_CTRL ENABLE LL_MPU_Enable
  432. * @param Options This parameter can be one of the following values:
  433. * @arg @ref LL_MPU_CTRL_HFNMI_PRIVDEF_NONE
  434. * @arg @ref LL_MPU_CTRL_HARDFAULT_NMI
  435. * @arg @ref LL_MPU_CTRL_PRIVILEGED_DEFAULT
  436. * @arg @ref LL_MPU_CTRL_HFNMI_PRIVDEF
  437. * @retval None
  438. */
  439. __STATIC_INLINE void LL_MPU_Enable(uint32_t Options)
  440. {
  441. /* Enable the MPU*/
  442. WRITE_REG(MPU->CTRL, (MPU_CTRL_ENABLE_Msk | Options));
  443. /* Ensure MPU settings take effects */
  444. __DSB();
  445. /* Sequence instruction fetches using update settings */
  446. __ISB();
  447. }
  448. /**
  449. * @brief Disable MPU
  450. * @rmtoll MPU_CTRL ENABLE LL_MPU_Disable
  451. * @retval None
  452. */
  453. __STATIC_INLINE void LL_MPU_Disable(void)
  454. {
  455. /* Make sure outstanding transfers are done */
  456. __DMB();
  457. /* Disable MPU*/
  458. WRITE_REG(MPU->CTRL, 0U);
  459. }
  460. /**
  461. * @brief Check if MPU is enabled or not
  462. * @rmtoll MPU_CTRL ENABLE LL_MPU_IsEnabled
  463. * @retval State of bit (1 or 0).
  464. */
  465. __STATIC_INLINE uint32_t LL_MPU_IsEnabled(void)
  466. {
  467. return ((READ_BIT(MPU->CTRL, MPU_CTRL_ENABLE_Msk) == (MPU_CTRL_ENABLE_Msk)) ? 1UL : 0UL);
  468. }
  469. /**
  470. * @brief Enable a MPU region
  471. * @rmtoll MPU_RASR ENABLE LL_MPU_EnableRegion
  472. * @param Region This parameter can be one of the following values:
  473. * @arg @ref LL_MPU_REGION_NUMBER0
  474. * @arg @ref LL_MPU_REGION_NUMBER1
  475. * @arg @ref LL_MPU_REGION_NUMBER2
  476. * @arg @ref LL_MPU_REGION_NUMBER3
  477. * @arg @ref LL_MPU_REGION_NUMBER4
  478. * @arg @ref LL_MPU_REGION_NUMBER5
  479. * @arg @ref LL_MPU_REGION_NUMBER6
  480. * @arg @ref LL_MPU_REGION_NUMBER7
  481. * @arg @ref LL_MPU_REGION_NUMBER8
  482. * @arg @ref LL_MPU_REGION_NUMBER9
  483. * @arg @ref LL_MPU_REGION_NUMBER10
  484. * @arg @ref LL_MPU_REGION_NUMBER11
  485. * @arg @ref LL_MPU_REGION_NUMBER12
  486. * @arg @ref LL_MPU_REGION_NUMBER13
  487. * @arg @ref LL_MPU_REGION_NUMBER14
  488. * @arg @ref LL_MPU_REGION_NUMBER15
  489. * @note For cortex-M4 only 8 regions are available i.e only values from LL_MPU_REGION_NUMBER0 to LL_MPU_REGION_NUMBER7 are possible.
  490. * @retval None
  491. */
  492. __STATIC_INLINE void LL_MPU_EnableRegion(uint32_t Region)
  493. {
  494. /* Set Region number */
  495. WRITE_REG(MPU->RNR, Region);
  496. /* Enable the MPU region */
  497. SET_BIT(MPU->RASR, MPU_RASR_ENABLE_Msk);
  498. }
  499. /**
  500. * @brief Configure and enable a region
  501. * @rmtoll MPU_RNR REGION LL_MPU_ConfigRegion\n
  502. * MPU_RBAR REGION LL_MPU_ConfigRegion\n
  503. * MPU_RBAR ADDR LL_MPU_ConfigRegion\n
  504. * MPU_RASR XN LL_MPU_ConfigRegion\n
  505. * MPU_RASR AP LL_MPU_ConfigRegion\n
  506. * MPU_RASR S LL_MPU_ConfigRegion\n
  507. * MPU_RASR C LL_MPU_ConfigRegion\n
  508. * MPU_RASR B LL_MPU_ConfigRegion\n
  509. * MPU_RASR SIZE LL_MPU_ConfigRegion
  510. * @param Region This parameter can be one of the following values:
  511. * @arg @ref LL_MPU_REGION_NUMBER0
  512. * @arg @ref LL_MPU_REGION_NUMBER1
  513. * @arg @ref LL_MPU_REGION_NUMBER2
  514. * @arg @ref LL_MPU_REGION_NUMBER3
  515. * @arg @ref LL_MPU_REGION_NUMBER4
  516. * @arg @ref LL_MPU_REGION_NUMBER5
  517. * @arg @ref LL_MPU_REGION_NUMBER6
  518. * @arg @ref LL_MPU_REGION_NUMBER7
  519. * @arg @ref LL_MPU_REGION_NUMBER8
  520. * @arg @ref LL_MPU_REGION_NUMBER9
  521. * @arg @ref LL_MPU_REGION_NUMBER10
  522. * @arg @ref LL_MPU_REGION_NUMBER11
  523. * @arg @ref LL_MPU_REGION_NUMBER12
  524. * @arg @ref LL_MPU_REGION_NUMBER13
  525. * @arg @ref LL_MPU_REGION_NUMBER14
  526. * @arg @ref LL_MPU_REGION_NUMBER15
  527. * @param Address Value of region base address
  528. * @param SubRegionDisable Sub-region disable value between Min_Data = 0x00 and Max_Data = 0xFF
  529. * @param Attributes This parameter can be a combination of the following values:
  530. * @arg @ref LL_MPU_REGION_SIZE_32B or @ref LL_MPU_REGION_SIZE_64B or @ref LL_MPU_REGION_SIZE_128B or @ref LL_MPU_REGION_SIZE_256B or @ref LL_MPU_REGION_SIZE_512B
  531. * or @ref LL_MPU_REGION_SIZE_1KB or @ref LL_MPU_REGION_SIZE_2KB or @ref LL_MPU_REGION_SIZE_4KB or @ref LL_MPU_REGION_SIZE_8KB or @ref LL_MPU_REGION_SIZE_16KB
  532. * or @ref LL_MPU_REGION_SIZE_32KB or @ref LL_MPU_REGION_SIZE_64KB or @ref LL_MPU_REGION_SIZE_128KB or @ref LL_MPU_REGION_SIZE_256KB or @ref LL_MPU_REGION_SIZE_512KB
  533. * or @ref LL_MPU_REGION_SIZE_1MB or @ref LL_MPU_REGION_SIZE_2MB or @ref LL_MPU_REGION_SIZE_4MB or @ref LL_MPU_REGION_SIZE_8MB or @ref LL_MPU_REGION_SIZE_16MB
  534. * or @ref LL_MPU_REGION_SIZE_32MB or @ref LL_MPU_REGION_SIZE_64MB or @ref LL_MPU_REGION_SIZE_128MB or @ref LL_MPU_REGION_SIZE_256MB or @ref LL_MPU_REGION_SIZE_512MB
  535. * or @ref LL_MPU_REGION_SIZE_1GB or @ref LL_MPU_REGION_SIZE_2GB or @ref LL_MPU_REGION_SIZE_4GB
  536. * @arg @ref LL_MPU_REGION_NO_ACCESS or @ref LL_MPU_REGION_PRIV_RW or @ref LL_MPU_REGION_PRIV_RW_URO or @ref LL_MPU_REGION_FULL_ACCESS
  537. * or @ref LL_MPU_REGION_PRIV_RO or @ref LL_MPU_REGION_PRIV_RO_URO
  538. * @arg @ref LL_MPU_TEX_LEVEL0 or @ref LL_MPU_TEX_LEVEL1 or @ref LL_MPU_TEX_LEVEL2 or @ref LL_MPU_TEX_LEVEL4
  539. * @arg @ref LL_MPU_INSTRUCTION_ACCESS_ENABLE or @ref LL_MPU_INSTRUCTION_ACCESS_DISABLE
  540. * @arg @ref LL_MPU_ACCESS_SHAREABLE or @ref LL_MPU_ACCESS_NOT_SHAREABLE
  541. * @arg @ref LL_MPU_ACCESS_CACHEABLE or @ref LL_MPU_ACCESS_NOT_CACHEABLE
  542. * @arg @ref LL_MPU_ACCESS_BUFFERABLE or @ref LL_MPU_ACCESS_NOT_BUFFERABLE
  543. * @note For cortex-M4 only 8 regions are available i.e only values from LL_MPU_REGION_NUMBER0 to LL_MPU_REGION_NUMBER7 are possible.
  544. * @retval None
  545. */
  546. __STATIC_INLINE void LL_MPU_ConfigRegion(uint32_t Region, uint32_t SubRegionDisable, uint32_t Address, uint32_t Attributes)
  547. {
  548. /* Set Region number */
  549. WRITE_REG(MPU->RNR, Region);
  550. /* Set base address */
  551. WRITE_REG(MPU->RBAR, (Address & 0xFFFFFFE0U));
  552. /* Configure MPU */
  553. WRITE_REG(MPU->RASR, (MPU_RASR_ENABLE_Msk | Attributes | (SubRegionDisable << MPU_RASR_SRD_Pos)));
  554. }
  555. /**
  556. * @brief Disable a region
  557. * @rmtoll MPU_RNR REGION LL_MPU_DisableRegion\n
  558. * MPU_RASR ENABLE LL_MPU_DisableRegion
  559. * @param Region This parameter can be one of the following values:
  560. * @arg @ref LL_MPU_REGION_NUMBER0
  561. * @arg @ref LL_MPU_REGION_NUMBER1
  562. * @arg @ref LL_MPU_REGION_NUMBER2
  563. * @arg @ref LL_MPU_REGION_NUMBER3
  564. * @arg @ref LL_MPU_REGION_NUMBER4
  565. * @arg @ref LL_MPU_REGION_NUMBER5
  566. * @arg @ref LL_MPU_REGION_NUMBER6
  567. * @arg @ref LL_MPU_REGION_NUMBER7
  568. * @arg @ref LL_MPU_REGION_NUMBER8
  569. * @arg @ref LL_MPU_REGION_NUMBER9
  570. * @arg @ref LL_MPU_REGION_NUMBER10
  571. * @arg @ref LL_MPU_REGION_NUMBER11
  572. * @arg @ref LL_MPU_REGION_NUMBER12
  573. * @arg @ref LL_MPU_REGION_NUMBER13
  574. * @arg @ref LL_MPU_REGION_NUMBER14
  575. * @arg @ref LL_MPU_REGION_NUMBER15
  576. * @note For cortex-M4 only 8 regions are available i.e only values from LL_MPU_REGION_NUMBER0 to LL_MPU_REGION_NUMBER7 are possible.
  577. * @retval None
  578. */
  579. __STATIC_INLINE void LL_MPU_DisableRegion(uint32_t Region)
  580. {
  581. /* Set Region number */
  582. WRITE_REG(MPU->RNR, Region);
  583. /* Disable the MPU region */
  584. CLEAR_BIT(MPU->RASR, MPU_RASR_ENABLE_Msk);
  585. }
  586. /**
  587. * @}
  588. */
  589. #endif /* __MPU_PRESENT */
  590. /**
  591. * @}
  592. */
  593. /**
  594. * @}
  595. */
  596. /**
  597. * @}
  598. */
  599. #ifdef __cplusplus
  600. }
  601. #endif
  602. #endif /* STM32H7xx_LL_CORTEX_H */