stm32l4xx_ll_cortex.h 26 KB

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