stm32l4xx_ll_cortex.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_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 @ref LL_mDelay and @ref 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 STM32L4xx_LL_CORTEX_H
  34. #define STM32L4xx_LL_CORTEX_H
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38. /* Includes ------------------------------------------------------------------*/
  39. #include "stm32l4xx.h"
  40. /** @addtogroup STM32L4xx_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 0x00000000U /*!< 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 0x00000000U /*!< 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 0x00U /*!< REGION Number 0 */
  87. #define LL_MPU_REGION_NUMBER1 0x01U /*!< REGION Number 1 */
  88. #define LL_MPU_REGION_NUMBER2 0x02U /*!< REGION Number 2 */
  89. #define LL_MPU_REGION_NUMBER3 0x03U /*!< REGION Number 3 */
  90. #define LL_MPU_REGION_NUMBER4 0x04U /*!< REGION Number 4 */
  91. #define LL_MPU_REGION_NUMBER5 0x05U /*!< REGION Number 5 */
  92. #define LL_MPU_REGION_NUMBER6 0x06U /*!< REGION Number 6 */
  93. #define LL_MPU_REGION_NUMBER7 0x07U /*!< REGION Number 7 */
  94. /**
  95. * @}
  96. */
  97. /** @defgroup CORTEX_LL_EC_REGION_SIZE MPU Region Size
  98. * @{
  99. */
  100. #define LL_MPU_REGION_SIZE_32B (0x04U << MPU_RASR_SIZE_Pos) /*!< 32B Size of the MPU protection region */
  101. #define LL_MPU_REGION_SIZE_64B (0x05U << MPU_RASR_SIZE_Pos) /*!< 64B Size of the MPU protection region */
  102. #define LL_MPU_REGION_SIZE_128B (0x06U << MPU_RASR_SIZE_Pos) /*!< 128B Size of the MPU protection region */
  103. #define LL_MPU_REGION_SIZE_256B (0x07U << MPU_RASR_SIZE_Pos) /*!< 256B Size of the MPU protection region */
  104. #define LL_MPU_REGION_SIZE_512B (0x08U << MPU_RASR_SIZE_Pos) /*!< 512B Size of the MPU protection region */
  105. #define LL_MPU_REGION_SIZE_1KB (0x09U << MPU_RASR_SIZE_Pos) /*!< 1KB Size of the MPU protection region */
  106. #define LL_MPU_REGION_SIZE_2KB (0x0AU << MPU_RASR_SIZE_Pos) /*!< 2KB Size of the MPU protection region */
  107. #define LL_MPU_REGION_SIZE_4KB (0x0BU << MPU_RASR_SIZE_Pos) /*!< 4KB Size of the MPU protection region */
  108. #define LL_MPU_REGION_SIZE_8KB (0x0CU << MPU_RASR_SIZE_Pos) /*!< 8KB Size of the MPU protection region */
  109. #define LL_MPU_REGION_SIZE_16KB (0x0DU << MPU_RASR_SIZE_Pos) /*!< 16KB Size of the MPU protection region */
  110. #define LL_MPU_REGION_SIZE_32KB (0x0EU << MPU_RASR_SIZE_Pos) /*!< 32KB Size of the MPU protection region */
  111. #define LL_MPU_REGION_SIZE_64KB (0x0FU << MPU_RASR_SIZE_Pos) /*!< 64KB Size of the MPU protection region */
  112. #define LL_MPU_REGION_SIZE_128KB (0x10U << MPU_RASR_SIZE_Pos) /*!< 128KB Size of the MPU protection region */
  113. #define LL_MPU_REGION_SIZE_256KB (0x11U << MPU_RASR_SIZE_Pos) /*!< 256KB Size of the MPU protection region */
  114. #define LL_MPU_REGION_SIZE_512KB (0x12U << MPU_RASR_SIZE_Pos) /*!< 512KB Size of the MPU protection region */
  115. #define LL_MPU_REGION_SIZE_1MB (0x13U << MPU_RASR_SIZE_Pos) /*!< 1MB Size of the MPU protection region */
  116. #define LL_MPU_REGION_SIZE_2MB (0x14U << MPU_RASR_SIZE_Pos) /*!< 2MB Size of the MPU protection region */
  117. #define LL_MPU_REGION_SIZE_4MB (0x15U << MPU_RASR_SIZE_Pos) /*!< 4MB Size of the MPU protection region */
  118. #define LL_MPU_REGION_SIZE_8MB (0x16U << MPU_RASR_SIZE_Pos) /*!< 8MB Size of the MPU protection region */
  119. #define LL_MPU_REGION_SIZE_16MB (0x17U << MPU_RASR_SIZE_Pos) /*!< 16MB Size of the MPU protection region */
  120. #define LL_MPU_REGION_SIZE_32MB (0x18U << MPU_RASR_SIZE_Pos) /*!< 32MB Size of the MPU protection region */
  121. #define LL_MPU_REGION_SIZE_64MB (0x19U << MPU_RASR_SIZE_Pos) /*!< 64MB Size of the MPU protection region */
  122. #define LL_MPU_REGION_SIZE_128MB (0x1AU << MPU_RASR_SIZE_Pos) /*!< 128MB Size of the MPU protection region */
  123. #define LL_MPU_REGION_SIZE_256MB (0x1BU << MPU_RASR_SIZE_Pos) /*!< 256MB Size of the MPU protection region */
  124. #define LL_MPU_REGION_SIZE_512MB (0x1CU << MPU_RASR_SIZE_Pos) /*!< 512MB Size of the MPU protection region */
  125. #define LL_MPU_REGION_SIZE_1GB (0x1DU << MPU_RASR_SIZE_Pos) /*!< 1GB Size of the MPU protection region */
  126. #define LL_MPU_REGION_SIZE_2GB (0x1EU << MPU_RASR_SIZE_Pos) /*!< 2GB Size of the MPU protection region */
  127. #define LL_MPU_REGION_SIZE_4GB (0x1FU << MPU_RASR_SIZE_Pos) /*!< 4GB Size of the MPU protection region */
  128. /**
  129. * @}
  130. */
  131. /** @defgroup CORTEX_LL_EC_REGION_PRIVILEDGES MPU Region Privileges
  132. * @{
  133. */
  134. #define LL_MPU_REGION_NO_ACCESS (0x00U << MPU_RASR_AP_Pos) /*!< No access*/
  135. #define LL_MPU_REGION_PRIV_RW (0x01U << MPU_RASR_AP_Pos) /*!< RW privileged (privileged access only)*/
  136. #define LL_MPU_REGION_PRIV_RW_URO (0x02U << MPU_RASR_AP_Pos) /*!< RW privileged - RO user (Write in a user program generates a fault) */
  137. #define LL_MPU_REGION_FULL_ACCESS (0x03U << MPU_RASR_AP_Pos) /*!< RW privileged & user (Full access) */
  138. #define LL_MPU_REGION_PRIV_RO (0x05U << MPU_RASR_AP_Pos) /*!< RO privileged (privileged read only)*/
  139. #define LL_MPU_REGION_PRIV_RO_URO (0x06U << MPU_RASR_AP_Pos) /*!< RO privileged & user (read only) */
  140. /**
  141. * @}
  142. */
  143. /** @defgroup CORTEX_LL_EC_TEX MPU TEX Level
  144. * @{
  145. */
  146. #define LL_MPU_TEX_LEVEL0 (0x00U << MPU_RASR_TEX_Pos) /*!< b000 for TEX bits */
  147. #define LL_MPU_TEX_LEVEL1 (0x01U << MPU_RASR_TEX_Pos) /*!< b001 for TEX bits */
  148. #define LL_MPU_TEX_LEVEL2 (0x02U << MPU_RASR_TEX_Pos) /*!< b010 for TEX bits */
  149. #define LL_MPU_TEX_LEVEL4 (0x04U << MPU_RASR_TEX_Pos) /*!< b100 for TEX bits */
  150. /**
  151. * @}
  152. */
  153. /** @defgroup CORTEX_LL_EC_INSTRUCTION_ACCESS MPU Instruction Access
  154. * @{
  155. */
  156. #define LL_MPU_INSTRUCTION_ACCESS_ENABLE 0x00U /*!< Instruction fetches enabled */
  157. #define LL_MPU_INSTRUCTION_ACCESS_DISABLE MPU_RASR_XN_Msk /*!< Instruction fetches disabled*/
  158. /**
  159. * @}
  160. */
  161. /** @defgroup CORTEX_LL_EC_SHAREABLE_ACCESS MPU Shareable Access
  162. * @{
  163. */
  164. #define LL_MPU_ACCESS_SHAREABLE MPU_RASR_S_Msk /*!< Shareable memory attribute */
  165. #define LL_MPU_ACCESS_NOT_SHAREABLE 0x00U /*!< Not Shareable memory attribute */
  166. /**
  167. * @}
  168. */
  169. /** @defgroup CORTEX_LL_EC_CACHEABLE_ACCESS MPU Cacheable Access
  170. * @{
  171. */
  172. #define LL_MPU_ACCESS_CACHEABLE MPU_RASR_C_Msk /*!< Cacheable memory attribute */
  173. #define LL_MPU_ACCESS_NOT_CACHEABLE 0x00U /*!< Not Cacheable memory attribute */
  174. /**
  175. * @}
  176. */
  177. /** @defgroup CORTEX_LL_EC_BUFFERABLE_ACCESS MPU Bufferable Access
  178. * @{
  179. */
  180. #define LL_MPU_ACCESS_BUFFERABLE MPU_RASR_B_Msk /*!< Bufferable memory attribute */
  181. #define LL_MPU_ACCESS_NOT_BUFFERABLE 0x00U /*!< Not Bufferable memory attribute */
  182. /**
  183. * @}
  184. */
  185. #endif /* __MPU_PRESENT */
  186. /**
  187. * @}
  188. */
  189. /* Exported macro ------------------------------------------------------------*/
  190. /* Exported functions --------------------------------------------------------*/
  191. /** @defgroup CORTEX_LL_Exported_Functions CORTEX Exported Functions
  192. * @{
  193. */
  194. /** @defgroup CORTEX_LL_EF_SYSTICK SYSTICK
  195. * @{
  196. */
  197. /**
  198. * @brief This function checks if the Systick counter flag is active or not.
  199. * @note It can be used in timeout function on application side.
  200. * @rmtoll STK_CTRL COUNTFLAG LL_SYSTICK_IsActiveCounterFlag
  201. * @retval State of bit (1 or 0).
  202. */
  203. __STATIC_INLINE uint32_t LL_SYSTICK_IsActiveCounterFlag(void)
  204. {
  205. return ((SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk) == (SysTick_CTRL_COUNTFLAG_Msk));
  206. }
  207. /**
  208. * @brief Configures the SysTick clock source
  209. * @rmtoll STK_CTRL CLKSOURCE LL_SYSTICK_SetClkSource
  210. * @param Source This parameter can be one of the following values:
  211. * @arg @ref LL_SYSTICK_CLKSOURCE_HCLK_DIV8
  212. * @arg @ref LL_SYSTICK_CLKSOURCE_HCLK
  213. * @retval None
  214. */
  215. __STATIC_INLINE void LL_SYSTICK_SetClkSource(uint32_t Source)
  216. {
  217. if (Source == LL_SYSTICK_CLKSOURCE_HCLK)
  218. {
  219. SET_BIT(SysTick->CTRL, LL_SYSTICK_CLKSOURCE_HCLK);
  220. }
  221. else
  222. {
  223. CLEAR_BIT(SysTick->CTRL, LL_SYSTICK_CLKSOURCE_HCLK);
  224. }
  225. }
  226. /**
  227. * @brief Get the SysTick clock source
  228. * @rmtoll STK_CTRL CLKSOURCE LL_SYSTICK_GetClkSource
  229. * @retval Returned value can be one of the following values:
  230. * @arg @ref LL_SYSTICK_CLKSOURCE_HCLK_DIV8
  231. * @arg @ref LL_SYSTICK_CLKSOURCE_HCLK
  232. */
  233. __STATIC_INLINE uint32_t LL_SYSTICK_GetClkSource(void)
  234. {
  235. return READ_BIT(SysTick->CTRL, LL_SYSTICK_CLKSOURCE_HCLK);
  236. }
  237. /**
  238. * @brief Enable SysTick exception request
  239. * @rmtoll STK_CTRL TICKINT LL_SYSTICK_EnableIT
  240. * @retval None
  241. */
  242. __STATIC_INLINE void LL_SYSTICK_EnableIT(void)
  243. {
  244. SET_BIT(SysTick->CTRL, SysTick_CTRL_TICKINT_Msk);
  245. }
  246. /**
  247. * @brief Disable SysTick exception request
  248. * @rmtoll STK_CTRL TICKINT LL_SYSTICK_DisableIT
  249. * @retval None
  250. */
  251. __STATIC_INLINE void LL_SYSTICK_DisableIT(void)
  252. {
  253. CLEAR_BIT(SysTick->CTRL, SysTick_CTRL_TICKINT_Msk);
  254. }
  255. /**
  256. * @brief Checks if the SYSTICK interrupt is enabled or disabled.
  257. * @rmtoll STK_CTRL TICKINT LL_SYSTICK_IsEnabledIT
  258. * @retval State of bit (1 or 0).
  259. */
  260. __STATIC_INLINE uint32_t LL_SYSTICK_IsEnabledIT(void)
  261. {
  262. return (READ_BIT(SysTick->CTRL, SysTick_CTRL_TICKINT_Msk) == (SysTick_CTRL_TICKINT_Msk));
  263. }
  264. /**
  265. * @}
  266. */
  267. /** @defgroup CORTEX_LL_EF_LOW_POWER_MODE LOW POWER MODE
  268. * @{
  269. */
  270. /**
  271. * @brief Processor uses sleep as its low power mode
  272. * @rmtoll SCB_SCR SLEEPDEEP LL_LPM_EnableSleep
  273. * @retval None
  274. */
  275. __STATIC_INLINE void LL_LPM_EnableSleep(void)
  276. {
  277. /* Clear SLEEPDEEP bit of Cortex System Control Register */
  278. CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
  279. }
  280. /**
  281. * @brief Processor uses deep sleep as its low power mode
  282. * @rmtoll SCB_SCR SLEEPDEEP LL_LPM_EnableDeepSleep
  283. * @retval None
  284. */
  285. __STATIC_INLINE void LL_LPM_EnableDeepSleep(void)
  286. {
  287. /* Set SLEEPDEEP bit of Cortex System Control Register */
  288. SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
  289. }
  290. /**
  291. * @brief Configures sleep-on-exit when returning from Handler mode to Thread mode.
  292. * @note Setting this bit to 1 enables an interrupt-driven application to avoid returning to an
  293. * empty main application.
  294. * @rmtoll SCB_SCR SLEEPONEXIT LL_LPM_EnableSleepOnExit
  295. * @retval None
  296. */
  297. __STATIC_INLINE void LL_LPM_EnableSleepOnExit(void)
  298. {
  299. /* Set SLEEPONEXIT bit of Cortex System Control Register */
  300. SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPONEXIT_Msk));
  301. }
  302. /**
  303. * @brief Do not sleep when returning to Thread mode.
  304. * @rmtoll SCB_SCR SLEEPONEXIT LL_LPM_DisableSleepOnExit
  305. * @retval None
  306. */
  307. __STATIC_INLINE void LL_LPM_DisableSleepOnExit(void)
  308. {
  309. /* Clear SLEEPONEXIT bit of Cortex System Control Register */
  310. CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPONEXIT_Msk));
  311. }
  312. /**
  313. * @brief Enabled events and all interrupts, including disabled interrupts, can wakeup the
  314. * processor.
  315. * @rmtoll SCB_SCR SEVEONPEND LL_LPM_EnableEventOnPend
  316. * @retval None
  317. */
  318. __STATIC_INLINE void LL_LPM_EnableEventOnPend(void)
  319. {
  320. /* Set SEVEONPEND bit of Cortex System Control Register */
  321. SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SEVONPEND_Msk));
  322. }
  323. /**
  324. * @brief Only enabled interrupts or events can wakeup the processor, disabled interrupts are
  325. * excluded
  326. * @rmtoll SCB_SCR SEVEONPEND LL_LPM_DisableEventOnPend
  327. * @retval None
  328. */
  329. __STATIC_INLINE void LL_LPM_DisableEventOnPend(void)
  330. {
  331. /* Clear SEVEONPEND bit of Cortex System Control Register */
  332. CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SEVONPEND_Msk));
  333. }
  334. /**
  335. * @}
  336. */
  337. /** @defgroup CORTEX_LL_EF_HANDLER HANDLER
  338. * @{
  339. */
  340. /**
  341. * @brief Enable a fault in System handler control register (SHCSR)
  342. * @rmtoll SCB_SHCSR MEMFAULTENA LL_HANDLER_EnableFault
  343. * @param Fault This parameter can be a combination of the following values:
  344. * @arg @ref LL_HANDLER_FAULT_USG
  345. * @arg @ref LL_HANDLER_FAULT_BUS
  346. * @arg @ref LL_HANDLER_FAULT_MEM
  347. * @retval None
  348. */
  349. __STATIC_INLINE void LL_HANDLER_EnableFault(uint32_t Fault)
  350. {
  351. /* Enable the system handler fault */
  352. SET_BIT(SCB->SHCSR, Fault);
  353. }
  354. /**
  355. * @brief Disable a fault in System handler control register (SHCSR)
  356. * @rmtoll SCB_SHCSR MEMFAULTENA LL_HANDLER_DisableFault
  357. * @param Fault This parameter can be a combination of the following values:
  358. * @arg @ref LL_HANDLER_FAULT_USG
  359. * @arg @ref LL_HANDLER_FAULT_BUS
  360. * @arg @ref LL_HANDLER_FAULT_MEM
  361. * @retval None
  362. */
  363. __STATIC_INLINE void LL_HANDLER_DisableFault(uint32_t Fault)
  364. {
  365. /* Disable the system handler fault */
  366. CLEAR_BIT(SCB->SHCSR, Fault);
  367. }
  368. /**
  369. * @}
  370. */
  371. /** @defgroup CORTEX_LL_EF_MCU_INFO MCU INFO
  372. * @{
  373. */
  374. /**
  375. * @brief Get Implementer code
  376. * @rmtoll SCB_CPUID IMPLEMENTER LL_CPUID_GetImplementer
  377. * @retval Value should be equal to 0x41 for ARM
  378. */
  379. __STATIC_INLINE uint32_t LL_CPUID_GetImplementer(void)
  380. {
  381. return (uint32_t)(READ_BIT(SCB->CPUID, SCB_CPUID_IMPLEMENTER_Msk) >> SCB_CPUID_IMPLEMENTER_Pos);
  382. }
  383. /**
  384. * @brief Get Variant number (The r value in the rnpn product revision identifier)
  385. * @rmtoll SCB_CPUID VARIANT LL_CPUID_GetVariant
  386. * @retval Value between 0 and 255 (0x0: revision 0)
  387. */
  388. __STATIC_INLINE uint32_t LL_CPUID_GetVariant(void)
  389. {
  390. return (uint32_t)(READ_BIT(SCB->CPUID, SCB_CPUID_VARIANT_Msk) >> SCB_CPUID_VARIANT_Pos);
  391. }
  392. /**
  393. * @brief Get Constant number
  394. * @rmtoll SCB_CPUID ARCHITECTURE LL_CPUID_GetConstant
  395. * @retval Value should be equal to 0xF for Cortex-M4 devices
  396. */
  397. __STATIC_INLINE uint32_t LL_CPUID_GetConstant(void)
  398. {
  399. return (uint32_t)(READ_BIT(SCB->CPUID, SCB_CPUID_ARCHITECTURE_Msk) >> SCB_CPUID_ARCHITECTURE_Pos);
  400. }
  401. /**
  402. * @brief Get Part number
  403. * @rmtoll SCB_CPUID PARTNO LL_CPUID_GetParNo
  404. * @retval Value should be equal to 0xC24 for Cortex-M4
  405. */
  406. __STATIC_INLINE uint32_t LL_CPUID_GetParNo(void)
  407. {
  408. return (uint32_t)(READ_BIT(SCB->CPUID, SCB_CPUID_PARTNO_Msk) >> SCB_CPUID_PARTNO_Pos);
  409. }
  410. /**
  411. * @brief Get Revision number (The p value in the rnpn product revision identifier, indicates patch release)
  412. * @rmtoll SCB_CPUID REVISION LL_CPUID_GetRevision
  413. * @retval Value between 0 and 255 (0x1: patch 1)
  414. */
  415. __STATIC_INLINE uint32_t LL_CPUID_GetRevision(void)
  416. {
  417. return (uint32_t)(READ_BIT(SCB->CPUID, SCB_CPUID_REVISION_Msk) >> SCB_CPUID_REVISION_Pos);
  418. }
  419. /**
  420. * @}
  421. */
  422. #if __MPU_PRESENT
  423. /** @defgroup CORTEX_LL_EF_MPU MPU
  424. * @{
  425. */
  426. /**
  427. * @brief Enable MPU with input options
  428. * @rmtoll MPU_CTRL ENABLE LL_MPU_Enable
  429. * @param Options This parameter can be one of the following values:
  430. * @arg @ref LL_MPU_CTRL_HFNMI_PRIVDEF_NONE
  431. * @arg @ref LL_MPU_CTRL_HARDFAULT_NMI
  432. * @arg @ref LL_MPU_CTRL_PRIVILEGED_DEFAULT
  433. * @arg @ref LL_MPU_CTRL_HFNMI_PRIVDEF
  434. * @retval None
  435. */
  436. __STATIC_INLINE void LL_MPU_Enable(uint32_t Options)
  437. {
  438. /* Enable the MPU*/
  439. WRITE_REG(MPU->CTRL, (MPU_CTRL_ENABLE_Msk | Options));
  440. /* Ensure MPU settings take effects */
  441. __DSB();
  442. /* Sequence instruction fetches using update settings */
  443. __ISB();
  444. }
  445. /**
  446. * @brief Disable MPU
  447. * @rmtoll MPU_CTRL ENABLE LL_MPU_Disable
  448. * @retval None
  449. */
  450. __STATIC_INLINE void LL_MPU_Disable(void)
  451. {
  452. /* Make sure outstanding transfers are done */
  453. __DMB();
  454. /* Disable MPU*/
  455. WRITE_REG(MPU->CTRL, 0U);
  456. }
  457. /**
  458. * @brief Check if MPU is enabled or not
  459. * @rmtoll MPU_CTRL ENABLE LL_MPU_IsEnabled
  460. * @retval State of bit (1 or 0).
  461. */
  462. __STATIC_INLINE uint32_t LL_MPU_IsEnabled(void)
  463. {
  464. return (READ_BIT(MPU->CTRL, MPU_CTRL_ENABLE_Msk) == (MPU_CTRL_ENABLE_Msk));
  465. }
  466. /**
  467. * @brief Enable a MPU region
  468. * @rmtoll MPU_RASR ENABLE LL_MPU_EnableRegion
  469. * @param Region This parameter can be one of the following values:
  470. * @arg @ref LL_MPU_REGION_NUMBER0
  471. * @arg @ref LL_MPU_REGION_NUMBER1
  472. * @arg @ref LL_MPU_REGION_NUMBER2
  473. * @arg @ref LL_MPU_REGION_NUMBER3
  474. * @arg @ref LL_MPU_REGION_NUMBER4
  475. * @arg @ref LL_MPU_REGION_NUMBER5
  476. * @arg @ref LL_MPU_REGION_NUMBER6
  477. * @arg @ref LL_MPU_REGION_NUMBER7
  478. * @retval None
  479. */
  480. __STATIC_INLINE void LL_MPU_EnableRegion(uint32_t Region)
  481. {
  482. /* Set Region number */
  483. WRITE_REG(MPU->RNR, Region);
  484. /* Enable the MPU region */
  485. SET_BIT(MPU->RASR, MPU_RASR_ENABLE_Msk);
  486. }
  487. /**
  488. * @brief Configure and enable a region
  489. * @rmtoll MPU_RNR REGION LL_MPU_ConfigRegion\n
  490. * MPU_RBAR REGION LL_MPU_ConfigRegion\n
  491. * MPU_RBAR ADDR LL_MPU_ConfigRegion\n
  492. * MPU_RASR XN LL_MPU_ConfigRegion\n
  493. * MPU_RASR AP LL_MPU_ConfigRegion\n
  494. * MPU_RASR S LL_MPU_ConfigRegion\n
  495. * MPU_RASR C LL_MPU_ConfigRegion\n
  496. * MPU_RASR B LL_MPU_ConfigRegion\n
  497. * MPU_RASR SIZE LL_MPU_ConfigRegion
  498. * @param Region This parameter can be one of the following values:
  499. * @arg @ref LL_MPU_REGION_NUMBER0
  500. * @arg @ref LL_MPU_REGION_NUMBER1
  501. * @arg @ref LL_MPU_REGION_NUMBER2
  502. * @arg @ref LL_MPU_REGION_NUMBER3
  503. * @arg @ref LL_MPU_REGION_NUMBER4
  504. * @arg @ref LL_MPU_REGION_NUMBER5
  505. * @arg @ref LL_MPU_REGION_NUMBER6
  506. * @arg @ref LL_MPU_REGION_NUMBER7
  507. * @param Address Value of region base address
  508. * @param SubRegionDisable Sub-region disable value between Min_Data = 0x00 and Max_Data = 0xFF
  509. * @param Attributes This parameter can be a combination of the following values:
  510. * @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
  511. * 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
  512. * 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
  513. * 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
  514. * 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
  515. * or @ref LL_MPU_REGION_SIZE_1GB or @ref LL_MPU_REGION_SIZE_2GB or @ref LL_MPU_REGION_SIZE_4GB
  516. * @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
  517. * or @ref LL_MPU_REGION_PRIV_RO or @ref LL_MPU_REGION_PRIV_RO_URO
  518. * @arg @ref LL_MPU_TEX_LEVEL0 or @ref LL_MPU_TEX_LEVEL1 or @ref LL_MPU_TEX_LEVEL2 or @ref LL_MPU_TEX_LEVEL4
  519. * @arg @ref LL_MPU_INSTRUCTION_ACCESS_ENABLE or @ref LL_MPU_INSTRUCTION_ACCESS_DISABLE
  520. * @arg @ref LL_MPU_ACCESS_SHAREABLE or @ref LL_MPU_ACCESS_NOT_SHAREABLE
  521. * @arg @ref LL_MPU_ACCESS_CACHEABLE or @ref LL_MPU_ACCESS_NOT_CACHEABLE
  522. * @arg @ref LL_MPU_ACCESS_BUFFERABLE or @ref LL_MPU_ACCESS_NOT_BUFFERABLE
  523. * @retval None
  524. */
  525. __STATIC_INLINE void LL_MPU_ConfigRegion(uint32_t Region, uint32_t SubRegionDisable, uint32_t Address, uint32_t Attributes)
  526. {
  527. /* Set Region number */
  528. WRITE_REG(MPU->RNR, Region);
  529. /* Set base address */
  530. WRITE_REG(MPU->RBAR, (Address & 0xFFFFFFE0U));
  531. /* Configure MPU */
  532. WRITE_REG(MPU->RASR, (MPU_RASR_ENABLE_Msk | Attributes | SubRegionDisable << MPU_RASR_SRD_Pos));
  533. }
  534. /**
  535. * @brief Disable a region
  536. * @rmtoll MPU_RNR REGION LL_MPU_DisableRegion\n
  537. * MPU_RASR ENABLE LL_MPU_DisableRegion
  538. * @param Region This parameter can be one of the following values:
  539. * @arg @ref LL_MPU_REGION_NUMBER0
  540. * @arg @ref LL_MPU_REGION_NUMBER1
  541. * @arg @ref LL_MPU_REGION_NUMBER2
  542. * @arg @ref LL_MPU_REGION_NUMBER3
  543. * @arg @ref LL_MPU_REGION_NUMBER4
  544. * @arg @ref LL_MPU_REGION_NUMBER5
  545. * @arg @ref LL_MPU_REGION_NUMBER6
  546. * @arg @ref LL_MPU_REGION_NUMBER7
  547. * @retval None
  548. */
  549. __STATIC_INLINE void LL_MPU_DisableRegion(uint32_t Region)
  550. {
  551. /* Set Region number */
  552. WRITE_REG(MPU->RNR, Region);
  553. /* Disable the MPU region */
  554. CLEAR_BIT(MPU->RASR, MPU_RASR_ENABLE_Msk);
  555. }
  556. /**
  557. * @}
  558. */
  559. #endif /* __MPU_PRESENT */
  560. /**
  561. * @}
  562. */
  563. /**
  564. * @}
  565. */
  566. /**
  567. * @}
  568. */
  569. #ifdef __cplusplus
  570. }
  571. #endif
  572. #endif /* STM32L4xx_LL_CORTEX_H */