You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

stm32l1xx_ll_cortex.h 24KB

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