F1 and F3 HAL / LL libraries
[betaflight.git] / lib / main / STM32F3 / Drivers / STM32F3xx_HAL_Driver / Inc / stm32f3xx_ll_cortex.h
blob750930b90a753c4ff18066fdeddce9a2ee72b8a3
1 /**
2 ******************************************************************************
3 * @file stm32f3xx_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 (MPU services provided only on some devices)
18 (+) API to access to MCU info (CPUID register)
19 (+) API to enable fault handler (SHCSR accesses)
21 @endverbatim
22 ******************************************************************************
23 * @attention
25 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
27 * Redistribution and use in source and binary forms, with or without modification,
28 * are permitted provided that the following conditions are met:
29 * 1. Redistributions of source code must retain the above copyright notice,
30 * this list of conditions and the following disclaimer.
31 * 2. Redistributions in binary form must reproduce the above copyright notice,
32 * this list of conditions and the following disclaimer in the documentation
33 * and/or other materials provided with the distribution.
34 * 3. Neither the name of STMicroelectronics nor the names of its contributors
35 * may be used to endorse or promote products derived from this software
36 * without specific prior written permission.
38 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
39 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
41 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
42 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
43 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
44 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
45 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
46 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
47 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
49 ******************************************************************************
52 /* Define to prevent recursive inclusion -------------------------------------*/
53 #ifndef __STM32F3xx_LL_CORTEX_H
54 #define __STM32F3xx_LL_CORTEX_H
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
60 /* Includes ------------------------------------------------------------------*/
61 #include "stm32f3xx.h"
63 /** @addtogroup STM32F3xx_LL_Driver
64 * @{
67 /** @defgroup CORTEX_LL CORTEX
68 * @{
71 /* Private types -------------------------------------------------------------*/
72 /* Private variables ---------------------------------------------------------*/
74 /* Private constants ---------------------------------------------------------*/
76 /* Private macros ------------------------------------------------------------*/
78 /* Exported types ------------------------------------------------------------*/
79 /* Exported constants --------------------------------------------------------*/
80 /** @defgroup CORTEX_LL_Exported_Constants CORTEX Exported Constants
81 * @{
84 /** @defgroup CORTEX_LL_EC_CLKSOURCE_HCLK SYSTICK Clock Source
85 * @{
87 #define LL_SYSTICK_CLKSOURCE_HCLK_DIV8 0x00000000U /*!< AHB clock divided by 8 selected as SysTick clock source.*/
88 #define LL_SYSTICK_CLKSOURCE_HCLK SysTick_CTRL_CLKSOURCE_Msk /*!< AHB clock selected as SysTick clock source. */
89 /**
90 * @}
93 /** @defgroup CORTEX_LL_EC_FAULT Handler Fault type
94 * @{
96 #define LL_HANDLER_FAULT_USG SCB_SHCSR_USGFAULTENA_Msk /*!< Usage fault */
97 #define LL_HANDLER_FAULT_BUS SCB_SHCSR_BUSFAULTENA_Msk /*!< Bus fault */
98 #define LL_HANDLER_FAULT_MEM SCB_SHCSR_MEMFAULTENA_Msk /*!< Memory management fault */
99 /**
100 * @}
103 #if __MPU_PRESENT
105 /** @defgroup CORTEX_LL_EC_CTRL_HFNMI_PRIVDEF MPU Control
106 * @{
108 #define LL_MPU_CTRL_HFNMI_PRIVDEF_NONE 0x00000000U /*!< Disable NMI and privileged SW access */
109 #define LL_MPU_CTRL_HARDFAULT_NMI MPU_CTRL_HFNMIENA_Msk /*!< Enables the operation of MPU during hard fault, NMI, and FAULTMASK handlers */
110 #define LL_MPU_CTRL_PRIVILEGED_DEFAULT MPU_CTRL_PRIVDEFENA_Msk /*!< Enable privileged software access to default memory map */
111 #define LL_MPU_CTRL_HFNMI_PRIVDEF (MPU_CTRL_HFNMIENA_Msk | MPU_CTRL_PRIVDEFENA_Msk) /*!< Enable NMI and privileged SW access */
113 * @}
116 /** @defgroup CORTEX_LL_EC_REGION MPU Region Number
117 * @{
119 #define LL_MPU_REGION_NUMBER0 0x00U /*!< REGION Number 0 */
120 #define LL_MPU_REGION_NUMBER1 0x01U /*!< REGION Number 1 */
121 #define LL_MPU_REGION_NUMBER2 0x02U /*!< REGION Number 2 */
122 #define LL_MPU_REGION_NUMBER3 0x03U /*!< REGION Number 3 */
123 #define LL_MPU_REGION_NUMBER4 0x04U /*!< REGION Number 4 */
124 #define LL_MPU_REGION_NUMBER5 0x05U /*!< REGION Number 5 */
125 #define LL_MPU_REGION_NUMBER6 0x06U /*!< REGION Number 6 */
126 #define LL_MPU_REGION_NUMBER7 0x07U /*!< REGION Number 7 */
128 * @}
131 /** @defgroup CORTEX_LL_EC_REGION_SIZE MPU Region Size
132 * @{
134 #define LL_MPU_REGION_SIZE_32B (0x04U << MPU_RASR_SIZE_Pos) /*!< 32B Size of the MPU protection region */
135 #define LL_MPU_REGION_SIZE_64B (0x05U << MPU_RASR_SIZE_Pos) /*!< 64B Size of the MPU protection region */
136 #define LL_MPU_REGION_SIZE_128B (0x06U << MPU_RASR_SIZE_Pos) /*!< 128B Size of the MPU protection region */
137 #define LL_MPU_REGION_SIZE_256B (0x07U << MPU_RASR_SIZE_Pos) /*!< 256B Size of the MPU protection region */
138 #define LL_MPU_REGION_SIZE_512B (0x08U << MPU_RASR_SIZE_Pos) /*!< 512B Size of the MPU protection region */
139 #define LL_MPU_REGION_SIZE_1KB (0x09U << MPU_RASR_SIZE_Pos) /*!< 1KB Size of the MPU protection region */
140 #define LL_MPU_REGION_SIZE_2KB (0x0AU << MPU_RASR_SIZE_Pos) /*!< 2KB Size of the MPU protection region */
141 #define LL_MPU_REGION_SIZE_4KB (0x0BU << MPU_RASR_SIZE_Pos) /*!< 4KB Size of the MPU protection region */
142 #define LL_MPU_REGION_SIZE_8KB (0x0CU << MPU_RASR_SIZE_Pos) /*!< 8KB Size of the MPU protection region */
143 #define LL_MPU_REGION_SIZE_16KB (0x0DU << MPU_RASR_SIZE_Pos) /*!< 16KB Size of the MPU protection region */
144 #define LL_MPU_REGION_SIZE_32KB (0x0EU << MPU_RASR_SIZE_Pos) /*!< 32KB Size of the MPU protection region */
145 #define LL_MPU_REGION_SIZE_64KB (0x0FU << MPU_RASR_SIZE_Pos) /*!< 64KB Size of the MPU protection region */
146 #define LL_MPU_REGION_SIZE_128KB (0x10U << MPU_RASR_SIZE_Pos) /*!< 128KB Size of the MPU protection region */
147 #define LL_MPU_REGION_SIZE_256KB (0x11U << MPU_RASR_SIZE_Pos) /*!< 256KB Size of the MPU protection region */
148 #define LL_MPU_REGION_SIZE_512KB (0x12U << MPU_RASR_SIZE_Pos) /*!< 512KB Size of the MPU protection region */
149 #define LL_MPU_REGION_SIZE_1MB (0x13U << MPU_RASR_SIZE_Pos) /*!< 1MB Size of the MPU protection region */
150 #define LL_MPU_REGION_SIZE_2MB (0x14U << MPU_RASR_SIZE_Pos) /*!< 2MB Size of the MPU protection region */
151 #define LL_MPU_REGION_SIZE_4MB (0x15U << MPU_RASR_SIZE_Pos) /*!< 4MB Size of the MPU protection region */
152 #define LL_MPU_REGION_SIZE_8MB (0x16U << MPU_RASR_SIZE_Pos) /*!< 8MB Size of the MPU protection region */
153 #define LL_MPU_REGION_SIZE_16MB (0x17U << MPU_RASR_SIZE_Pos) /*!< 16MB Size of the MPU protection region */
154 #define LL_MPU_REGION_SIZE_32MB (0x18U << MPU_RASR_SIZE_Pos) /*!< 32MB Size of the MPU protection region */
155 #define LL_MPU_REGION_SIZE_64MB (0x19U << MPU_RASR_SIZE_Pos) /*!< 64MB Size of the MPU protection region */
156 #define LL_MPU_REGION_SIZE_128MB (0x1AU << MPU_RASR_SIZE_Pos) /*!< 128MB Size of the MPU protection region */
157 #define LL_MPU_REGION_SIZE_256MB (0x1BU << MPU_RASR_SIZE_Pos) /*!< 256MB Size of the MPU protection region */
158 #define LL_MPU_REGION_SIZE_512MB (0x1CU << MPU_RASR_SIZE_Pos) /*!< 512MB Size of the MPU protection region */
159 #define LL_MPU_REGION_SIZE_1GB (0x1DU << MPU_RASR_SIZE_Pos) /*!< 1GB Size of the MPU protection region */
160 #define LL_MPU_REGION_SIZE_2GB (0x1EU << MPU_RASR_SIZE_Pos) /*!< 2GB Size of the MPU protection region */
161 #define LL_MPU_REGION_SIZE_4GB (0x1FU << MPU_RASR_SIZE_Pos) /*!< 4GB Size of the MPU protection region */
163 * @}
166 /** @defgroup CORTEX_LL_EC_REGION_PRIVILEDGES MPU Region Privileges
167 * @{
169 #define LL_MPU_REGION_NO_ACCESS (0x00U << MPU_RASR_AP_Pos) /*!< No access*/
170 #define LL_MPU_REGION_PRIV_RW (0x01U << MPU_RASR_AP_Pos) /*!< RW privileged (privileged access only)*/
171 #define LL_MPU_REGION_PRIV_RW_URO (0x02U << MPU_RASR_AP_Pos) /*!< RW privileged - RO user (Write in a user program generates a fault) */
172 #define LL_MPU_REGION_FULL_ACCESS (0x03U << MPU_RASR_AP_Pos) /*!< RW privileged & user (Full access) */
173 #define LL_MPU_REGION_PRIV_RO (0x05U << MPU_RASR_AP_Pos) /*!< RO privileged (privileged read only)*/
174 #define LL_MPU_REGION_PRIV_RO_URO (0x06U << MPU_RASR_AP_Pos) /*!< RO privileged & user (read only) */
176 * @}
179 /** @defgroup CORTEX_LL_EC_TEX MPU TEX Level
180 * @{
182 #define LL_MPU_TEX_LEVEL0 (0x00U << MPU_RASR_TEX_Pos) /*!< b000 for TEX bits */
183 #define LL_MPU_TEX_LEVEL1 (0x01U << MPU_RASR_TEX_Pos) /*!< b001 for TEX bits */
184 #define LL_MPU_TEX_LEVEL2 (0x02U << MPU_RASR_TEX_Pos) /*!< b010 for TEX bits */
185 #define LL_MPU_TEX_LEVEL4 (0x04U << MPU_RASR_TEX_Pos) /*!< b100 for TEX bits */
187 * @}
190 /** @defgroup CORTEX_LL_EC_INSTRUCTION_ACCESS MPU Instruction Access
191 * @{
193 #define LL_MPU_INSTRUCTION_ACCESS_ENABLE 0x00U /*!< Instruction fetches enabled */
194 #define LL_MPU_INSTRUCTION_ACCESS_DISABLE MPU_RASR_XN_Msk /*!< Instruction fetches disabled*/
196 * @}
199 /** @defgroup CORTEX_LL_EC_SHAREABLE_ACCESS MPU Shareable Access
200 * @{
202 #define LL_MPU_ACCESS_SHAREABLE MPU_RASR_S_Msk /*!< Shareable memory attribute */
203 #define LL_MPU_ACCESS_NOT_SHAREABLE 0x00U /*!< Not Shareable memory attribute */
205 * @}
208 /** @defgroup CORTEX_LL_EC_CACHEABLE_ACCESS MPU Cacheable Access
209 * @{
211 #define LL_MPU_ACCESS_CACHEABLE MPU_RASR_C_Msk /*!< Cacheable memory attribute */
212 #define LL_MPU_ACCESS_NOT_CACHEABLE 0x00U /*!< Not Cacheable memory attribute */
214 * @}
217 /** @defgroup CORTEX_LL_EC_BUFFERABLE_ACCESS MPU Bufferable Access
218 * @{
220 #define LL_MPU_ACCESS_BUFFERABLE MPU_RASR_B_Msk /*!< Bufferable memory attribute */
221 #define LL_MPU_ACCESS_NOT_BUFFERABLE 0x00U /*!< Not Bufferable memory attribute */
223 * @}
225 #endif /* __MPU_PRESENT */
227 * @}
230 /* Exported macro ------------------------------------------------------------*/
232 /* Exported functions --------------------------------------------------------*/
233 /** @defgroup CORTEX_LL_Exported_Functions CORTEX Exported Functions
234 * @{
237 /** @defgroup CORTEX_LL_EF_SYSTICK SYSTICK
238 * @{
242 * @brief This function checks if the Systick counter flag is active or not.
243 * @note It can be used in timeout function on application side.
244 * @rmtoll STK_CTRL COUNTFLAG LL_SYSTICK_IsActiveCounterFlag
245 * @retval State of bit (1 or 0).
247 __STATIC_INLINE uint32_t LL_SYSTICK_IsActiveCounterFlag(void)
249 return ((SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk) == (SysTick_CTRL_COUNTFLAG_Msk));
253 * @brief Configures the SysTick clock source
254 * @rmtoll STK_CTRL CLKSOURCE LL_SYSTICK_SetClkSource
255 * @param Source This parameter can be one of the following values:
256 * @arg @ref LL_SYSTICK_CLKSOURCE_HCLK_DIV8
257 * @arg @ref LL_SYSTICK_CLKSOURCE_HCLK
258 * @retval None
260 __STATIC_INLINE void LL_SYSTICK_SetClkSource(uint32_t Source)
262 if (Source == LL_SYSTICK_CLKSOURCE_HCLK)
264 SET_BIT(SysTick->CTRL, LL_SYSTICK_CLKSOURCE_HCLK);
266 else
268 CLEAR_BIT(SysTick->CTRL, LL_SYSTICK_CLKSOURCE_HCLK);
273 * @brief Get the SysTick clock source
274 * @rmtoll STK_CTRL CLKSOURCE LL_SYSTICK_GetClkSource
275 * @retval Returned value can be one of the following values:
276 * @arg @ref LL_SYSTICK_CLKSOURCE_HCLK_DIV8
277 * @arg @ref LL_SYSTICK_CLKSOURCE_HCLK
279 __STATIC_INLINE uint32_t LL_SYSTICK_GetClkSource(void)
281 return READ_BIT(SysTick->CTRL, LL_SYSTICK_CLKSOURCE_HCLK);
285 * @brief Enable SysTick exception request
286 * @rmtoll STK_CTRL TICKINT LL_SYSTICK_EnableIT
287 * @retval None
289 __STATIC_INLINE void LL_SYSTICK_EnableIT(void)
291 SET_BIT(SysTick->CTRL, SysTick_CTRL_TICKINT_Msk);
295 * @brief Disable SysTick exception request
296 * @rmtoll STK_CTRL TICKINT LL_SYSTICK_DisableIT
297 * @retval None
299 __STATIC_INLINE void LL_SYSTICK_DisableIT(void)
301 CLEAR_BIT(SysTick->CTRL, SysTick_CTRL_TICKINT_Msk);
305 * @brief Checks if the SYSTICK interrupt is enabled or disabled.
306 * @rmtoll STK_CTRL TICKINT LL_SYSTICK_IsEnabledIT
307 * @retval State of bit (1 or 0).
309 __STATIC_INLINE uint32_t LL_SYSTICK_IsEnabledIT(void)
311 return (READ_BIT(SysTick->CTRL, SysTick_CTRL_TICKINT_Msk) == (SysTick_CTRL_TICKINT_Msk));
315 * @}
318 /** @defgroup CORTEX_LL_EF_LOW_POWER_MODE LOW POWER MODE
319 * @{
323 * @brief Processor uses sleep as its low power mode
324 * @rmtoll SCB_SCR SLEEPDEEP LL_LPM_EnableSleep
325 * @retval None
327 __STATIC_INLINE void LL_LPM_EnableSleep(void)
329 /* Clear SLEEPDEEP bit of Cortex System Control Register */
330 CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
334 * @brief Processor uses deep sleep as its low power mode
335 * @rmtoll SCB_SCR SLEEPDEEP LL_LPM_EnableDeepSleep
336 * @retval None
338 __STATIC_INLINE void LL_LPM_EnableDeepSleep(void)
340 /* Set SLEEPDEEP bit of Cortex System Control Register */
341 SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
345 * @brief Configures sleep-on-exit when returning from Handler mode to Thread mode.
346 * @note Setting this bit to 1 enables an interrupt-driven application to avoid returning to an
347 * empty main application.
348 * @rmtoll SCB_SCR SLEEPONEXIT LL_LPM_EnableSleepOnExit
349 * @retval None
351 __STATIC_INLINE void LL_LPM_EnableSleepOnExit(void)
353 /* Set SLEEPONEXIT bit of Cortex System Control Register */
354 SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPONEXIT_Msk));
358 * @brief Do not sleep when returning to Thread mode.
359 * @rmtoll SCB_SCR SLEEPONEXIT LL_LPM_DisableSleepOnExit
360 * @retval None
362 __STATIC_INLINE void LL_LPM_DisableSleepOnExit(void)
364 /* Clear SLEEPONEXIT bit of Cortex System Control Register */
365 CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPONEXIT_Msk));
369 * @brief Enabled events and all interrupts, including disabled interrupts, can wakeup the
370 * processor.
371 * @rmtoll SCB_SCR SEVEONPEND LL_LPM_EnableEventOnPend
372 * @retval None
374 __STATIC_INLINE void LL_LPM_EnableEventOnPend(void)
376 /* Set SEVEONPEND bit of Cortex System Control Register */
377 SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SEVONPEND_Msk));
381 * @brief Only enabled interrupts or events can wakeup the processor, disabled interrupts are
382 * excluded
383 * @rmtoll SCB_SCR SEVEONPEND LL_LPM_DisableEventOnPend
384 * @retval None
386 __STATIC_INLINE void LL_LPM_DisableEventOnPend(void)
388 /* Clear SEVEONPEND bit of Cortex System Control Register */
389 CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SEVONPEND_Msk));
393 * @}
396 /** @defgroup CORTEX_LL_EF_HANDLER HANDLER
397 * @{
401 * @brief Enable a fault in System handler control register (SHCSR)
402 * @rmtoll SCB_SHCSR MEMFAULTENA LL_HANDLER_EnableFault
403 * @param Fault This parameter can be a combination of the following values:
404 * @arg @ref LL_HANDLER_FAULT_USG
405 * @arg @ref LL_HANDLER_FAULT_BUS
406 * @arg @ref LL_HANDLER_FAULT_MEM
407 * @retval None
409 __STATIC_INLINE void LL_HANDLER_EnableFault(uint32_t Fault)
411 /* Enable the system handler fault */
412 SET_BIT(SCB->SHCSR, Fault);
416 * @brief Disable a fault in System handler control register (SHCSR)
417 * @rmtoll SCB_SHCSR MEMFAULTENA LL_HANDLER_DisableFault
418 * @param Fault This parameter can be a combination of the following values:
419 * @arg @ref LL_HANDLER_FAULT_USG
420 * @arg @ref LL_HANDLER_FAULT_BUS
421 * @arg @ref LL_HANDLER_FAULT_MEM
422 * @retval None
424 __STATIC_INLINE void LL_HANDLER_DisableFault(uint32_t Fault)
426 /* Disable the system handler fault */
427 CLEAR_BIT(SCB->SHCSR, Fault);
431 * @}
434 /** @defgroup CORTEX_LL_EF_MCU_INFO MCU INFO
435 * @{
439 * @brief Get Implementer code
440 * @rmtoll SCB_CPUID IMPLEMENTER LL_CPUID_GetImplementer
441 * @retval Value should be equal to 0x41 for ARM
443 __STATIC_INLINE uint32_t LL_CPUID_GetImplementer(void)
445 return (uint32_t)(READ_BIT(SCB->CPUID, SCB_CPUID_IMPLEMENTER_Msk) >> SCB_CPUID_IMPLEMENTER_Pos);
449 * @brief Get Variant number (The r value in the rnpn product revision identifier)
450 * @rmtoll SCB_CPUID VARIANT LL_CPUID_GetVariant
451 * @retval Value between 0 and 255 (0x0: revision 0)
453 __STATIC_INLINE uint32_t LL_CPUID_GetVariant(void)
455 return (uint32_t)(READ_BIT(SCB->CPUID, SCB_CPUID_VARIANT_Msk) >> SCB_CPUID_VARIANT_Pos);
459 * @brief Get Constant number
460 * @rmtoll SCB_CPUID ARCHITECTURE LL_CPUID_GetConstant
461 * @retval Value should be equal to 0xF for Cortex-M4 devices
463 __STATIC_INLINE uint32_t LL_CPUID_GetConstant(void)
465 return (uint32_t)(READ_BIT(SCB->CPUID, SCB_CPUID_ARCHITECTURE_Msk) >> SCB_CPUID_ARCHITECTURE_Pos);
469 * @brief Get Part number
470 * @rmtoll SCB_CPUID PARTNO LL_CPUID_GetParNo
471 * @retval Value should be equal to 0xC24 for Cortex-M4
473 __STATIC_INLINE uint32_t LL_CPUID_GetParNo(void)
475 return (uint32_t)(READ_BIT(SCB->CPUID, SCB_CPUID_PARTNO_Msk) >> SCB_CPUID_PARTNO_Pos);
479 * @brief Get Revision number (The p value in the rnpn product revision identifier, indicates patch release)
480 * @rmtoll SCB_CPUID REVISION LL_CPUID_GetRevision
481 * @retval Value between 0 and 255 (0x1: patch 1)
483 __STATIC_INLINE uint32_t LL_CPUID_GetRevision(void)
485 return (uint32_t)(READ_BIT(SCB->CPUID, SCB_CPUID_REVISION_Msk) >> SCB_CPUID_REVISION_Pos);
489 * @}
492 #if __MPU_PRESENT
493 /** @defgroup CORTEX_LL_EF_MPU MPU
494 * @{
498 * @brief Enable MPU with input options
499 * @rmtoll MPU_CTRL ENABLE LL_MPU_Enable
500 * @param Options This parameter can be one of the following values:
501 * @arg @ref LL_MPU_CTRL_HFNMI_PRIVDEF_NONE
502 * @arg @ref LL_MPU_CTRL_HARDFAULT_NMI
503 * @arg @ref LL_MPU_CTRL_PRIVILEGED_DEFAULT
504 * @arg @ref LL_MPU_CTRL_HFNMI_PRIVDEF
505 * @retval None
507 __STATIC_INLINE void LL_MPU_Enable(uint32_t Options)
509 /* Enable the MPU*/
510 WRITE_REG(MPU->CTRL, (MPU_CTRL_ENABLE_Msk | Options));
511 /* Ensure MPU settings take effects */
512 __DSB();
513 /* Sequence instruction fetches using update settings */
514 __ISB();
518 * @brief Disable MPU
519 * @rmtoll MPU_CTRL ENABLE LL_MPU_Disable
520 * @retval None
522 __STATIC_INLINE void LL_MPU_Disable(void)
524 /* Make sure outstanding transfers are done */
525 __DMB();
526 /* Disable MPU*/
527 WRITE_REG(MPU->CTRL, 0U);
531 * @brief Check if MPU is enabled or not
532 * @rmtoll MPU_CTRL ENABLE LL_MPU_IsEnabled
533 * @retval State of bit (1 or 0).
535 __STATIC_INLINE uint32_t LL_MPU_IsEnabled(void)
537 return (READ_BIT(MPU->CTRL, MPU_CTRL_ENABLE_Msk) == (MPU_CTRL_ENABLE_Msk));
541 * @brief Enable a MPU region
542 * @rmtoll MPU_RASR ENABLE LL_MPU_EnableRegion
543 * @param Region This parameter can be one of the following values:
544 * @arg @ref LL_MPU_REGION_NUMBER0
545 * @arg @ref LL_MPU_REGION_NUMBER1
546 * @arg @ref LL_MPU_REGION_NUMBER2
547 * @arg @ref LL_MPU_REGION_NUMBER3
548 * @arg @ref LL_MPU_REGION_NUMBER4
549 * @arg @ref LL_MPU_REGION_NUMBER5
550 * @arg @ref LL_MPU_REGION_NUMBER6
551 * @arg @ref LL_MPU_REGION_NUMBER7
552 * @retval None
554 __STATIC_INLINE void LL_MPU_EnableRegion(uint32_t Region)
556 /* Set Region number */
557 WRITE_REG(MPU->RNR, Region);
558 /* Enable the MPU region */
559 SET_BIT(MPU->RASR, MPU_RASR_ENABLE_Msk);
563 * @brief Configure and enable a region
564 * @rmtoll MPU_RNR REGION LL_MPU_ConfigRegion\n
565 * MPU_RBAR REGION LL_MPU_ConfigRegion\n
566 * MPU_RBAR ADDR LL_MPU_ConfigRegion\n
567 * MPU_RASR XN LL_MPU_ConfigRegion\n
568 * MPU_RASR AP LL_MPU_ConfigRegion\n
569 * MPU_RASR S LL_MPU_ConfigRegion\n
570 * MPU_RASR C LL_MPU_ConfigRegion\n
571 * MPU_RASR B LL_MPU_ConfigRegion\n
572 * MPU_RASR SIZE LL_MPU_ConfigRegion
573 * @param Region This parameter can be one of the following values:
574 * @arg @ref LL_MPU_REGION_NUMBER0
575 * @arg @ref LL_MPU_REGION_NUMBER1
576 * @arg @ref LL_MPU_REGION_NUMBER2
577 * @arg @ref LL_MPU_REGION_NUMBER3
578 * @arg @ref LL_MPU_REGION_NUMBER4
579 * @arg @ref LL_MPU_REGION_NUMBER5
580 * @arg @ref LL_MPU_REGION_NUMBER6
581 * @arg @ref LL_MPU_REGION_NUMBER7
582 * @param Address Value of region base address
583 * @param SubRegionDisable Sub-region disable value between Min_Data = 0x00 and Max_Data = 0xFF
584 * @param Attributes This parameter can be a combination of the following values:
585 * @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
586 * 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
587 * 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
588 * 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
589 * 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
590 * or @ref LL_MPU_REGION_SIZE_1GB or @ref LL_MPU_REGION_SIZE_2GB or @ref LL_MPU_REGION_SIZE_4GB
591 * @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
592 * or @ref LL_MPU_REGION_PRIV_RO or @ref LL_MPU_REGION_PRIV_RO_URO
593 * @arg @ref LL_MPU_TEX_LEVEL0 or @ref LL_MPU_TEX_LEVEL1 or @ref LL_MPU_TEX_LEVEL2 or @ref LL_MPU_TEX_LEVEL4
594 * @arg @ref LL_MPU_INSTRUCTION_ACCESS_ENABLE or @ref LL_MPU_INSTRUCTION_ACCESS_DISABLE
595 * @arg @ref LL_MPU_ACCESS_SHAREABLE or @ref LL_MPU_ACCESS_NOT_SHAREABLE
596 * @arg @ref LL_MPU_ACCESS_CACHEABLE or @ref LL_MPU_ACCESS_NOT_CACHEABLE
597 * @arg @ref LL_MPU_ACCESS_BUFFERABLE or @ref LL_MPU_ACCESS_NOT_BUFFERABLE
598 * @retval None
600 __STATIC_INLINE void LL_MPU_ConfigRegion(uint32_t Region, uint32_t SubRegionDisable, uint32_t Address, uint32_t Attributes)
602 /* Set Region number */
603 WRITE_REG(MPU->RNR, Region);
604 /* Set base address */
605 WRITE_REG(MPU->RBAR, (Address & 0xFFFFFFE0U));
606 /* Configure MPU */
607 WRITE_REG(MPU->RASR, (MPU_RASR_ENABLE_Msk | Attributes | SubRegionDisable << MPU_RASR_SRD_Pos));
611 * @brief Disable a region
612 * @rmtoll MPU_RNR REGION LL_MPU_DisableRegion\n
613 * MPU_RASR ENABLE LL_MPU_DisableRegion
614 * @param Region This parameter can be one of the following values:
615 * @arg @ref LL_MPU_REGION_NUMBER0
616 * @arg @ref LL_MPU_REGION_NUMBER1
617 * @arg @ref LL_MPU_REGION_NUMBER2
618 * @arg @ref LL_MPU_REGION_NUMBER3
619 * @arg @ref LL_MPU_REGION_NUMBER4
620 * @arg @ref LL_MPU_REGION_NUMBER5
621 * @arg @ref LL_MPU_REGION_NUMBER6
622 * @arg @ref LL_MPU_REGION_NUMBER7
623 * @retval None
625 __STATIC_INLINE void LL_MPU_DisableRegion(uint32_t Region)
627 /* Set Region number */
628 WRITE_REG(MPU->RNR, Region);
629 /* Disable the MPU region */
630 CLEAR_BIT(MPU->RASR, MPU_RASR_ENABLE_Msk);
634 * @}
637 #endif /* __MPU_PRESENT */
639 * @}
643 * @}
647 * @}
650 #ifdef __cplusplus
652 #endif
654 #endif /* __STM32F3xx_LL_CORTEX_H */
656 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/