25 #if defined ( __ICCARM__ ) 26 #pragma system_include 27 #elif defined (__clang__) 28 #pragma clang system_header 31 #ifndef ARM_MPU_ARMV8_H 32 #define ARM_MPU_ARMV8_H 35 #define ARM_MPU_ATTR_DEVICE ( 0U ) 38 #define ARM_MPU_ATTR_NON_CACHEABLE ( 4U ) 46 #define ARM_MPU_ATTR_MEMORY_(NT, WB, RA, WA) \ 47 ((((NT) & 1U) << 3U) | (((WB) & 1U) << 2U) | (((RA) & 1U) << 1U) | ((WA) & 1U)) 50 #define ARM_MPU_ATTR_DEVICE_nGnRnE (0U) 53 #define ARM_MPU_ATTR_DEVICE_nGnRE (1U) 56 #define ARM_MPU_ATTR_DEVICE_nGRE (2U) 59 #define ARM_MPU_ATTR_DEVICE_GRE (3U) 64 #define MPU_ATTR_NORMAL_OUTER_NON_CACHEABLE (0b0100) 65 #define MPU_ATTR_NORMAL_OUTER_WT_TR_RA (0b0010) 66 #define MPU_ATTR_NORMAL_OUTER_WT_TR_WA (0b0001) 67 #define MPU_ATTR_NORMAL_OUTER_WT_TR_RA_WA (0b0011) 68 #define MPU_ATTR_NORMAL_OUTER_WT_RA (0b1010) 69 #define MPU_ATTR_NORMAL_OUTER_WT_WA (0b1001) 70 #define MPU_ATTR_NORMAL_OUTER_WT_RA_WA (0b1011) 71 #define MPU_ATTR_NORMAL_OUTER_WB_TR_RA (0b0101) 72 #define MPU_ATTR_NORMAL_OUTER_WB_TR_WA (0b0110) 73 #define MPU_ATTR_NORMAL_OUTER_WB_TR_RA_WA (0b0111) 74 #define MPU_ATTR_NORMAL_OUTER_WB_RA (0b1101) 75 #define MPU_ATTR_NORMAL_OUTER_WB_WA (0b1110) 76 #define MPU_ATTR_NORMAL_OUTER_WB_RA_WA (0b1111) 77 #define MPU_ATTR_NORMAL_INNER_NON_CACHEABLE (0b0100) 78 #define MPU_ATTR_NORMAL_INNER_WT_TR_RA (0b0010) 79 #define MPU_ATTR_NORMAL_INNER_WT_TR_WA (0b0001) 80 #define MPU_ATTR_NORMAL_INNER_WT_TR_RA_WA (0b0011) 81 #define MPU_ATTR_NORMAL_INNER_WT_RA (0b1010) 82 #define MPU_ATTR_NORMAL_INNER_WT_WA (0b1001) 83 #define MPU_ATTR_NORMAL_INNER_WT_RA_WA (0b1011) 84 #define MPU_ATTR_NORMAL_INNER_WB_TR_RA (0b0101) 85 #define MPU_ATTR_NORMAL_INNER_WB_TR_WA (0b0110) 86 #define MPU_ATTR_NORMAL_INNER_WB_TR_RA_WA (0b0111) 87 #define MPU_ATTR_NORMAL_INNER_WB_RA (0b1101) 88 #define MPU_ATTR_NORMAL_INNER_WB_WA (0b1110) 89 #define MPU_ATTR_NORMAL_INNER_WB_RA_WA (0b1111) 95 #define ARM_MPU_ATTR(O, I) ((((O) & 0xFU) << 4U) | ((((O) & 0xFU) != 0U) ? ((I) & 0xFU) : (((I) & 0x3U) << 2U))) 98 #define MAIR_ATTR(x) ((x > 7 || x < 0) ? 0 : x) 104 #define ARM_MPU_SH_NON (0U) 107 #define ARM_MPU_SH_OUTER (2U) 110 #define ARM_MPU_SH_INNER (3U) 117 #define ARM_MPU_AP_RW (0U) 120 #define ARM_MPU_AP_RO (1U) 123 #define ARM_MPU_AP_NP (1U) 126 #define ARM_MPU_AP_PO (0U) 133 #define ARM_MPU_XN (1U) 136 #define ARM_MPU_EX (0U) 142 #define ARM_MPU_AP_(RO, NP) ((((RO) & 1U) << 1U) | ((NP) & 1U)) 151 #define ARM_MPU_RBAR(BASE, SH, RO, NP, XN) \ 152 (((BASE) & MPU_RBAR_BASE_Msk) | \ 153 (((SH) << MPU_RBAR_SH_Pos) & MPU_RBAR_SH_Msk) | \ 154 ((ARM_MPU_AP_(RO, NP) << MPU_RBAR_AP_Pos) & MPU_RBAR_AP_Msk) | \ 155 (((XN) << MPU_RBAR_XN_Pos) & MPU_RBAR_XN_Msk)) 161 #define ARM_MPU_RLAR(LIMIT, IDX) \ 162 (((LIMIT) & MPU_RLAR_LIMIT_Msk) | \ 163 (((IDX) << MPU_RLAR_AttrIndx_Pos) & MPU_RLAR_AttrIndx_Msk) | \ 166 #if defined(MPU_RLAR_PXN_Pos) 173 #define ARM_MPU_RLAR_PXN(LIMIT, PXN, IDX) \ 174 (((LIMIT) & MPU_RLAR_LIMIT_Msk) | \ 175 (((PXN) << MPU_RLAR_PXN_Pos) & MPU_RLAR_PXN_Msk) | \ 176 (((IDX) << MPU_RLAR_AttrIndx_Pos) & MPU_RLAR_AttrIndx_Msk) | \ 195 return ((MPU->TYPE) >> 8);
204 MPU->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk;
205 #ifdef SCB_SHCSR_MEMFAULTENA_Msk 217 #ifdef SCB_SHCSR_MEMFAULTENA_Msk 220 MPU->CTRL &= ~MPU_CTRL_ENABLE_Msk;
232 MPU_NS->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk;
233 #ifdef SCB_SHCSR_MEMFAULTENA_Msk 245 #ifdef SCB_SHCSR_MEMFAULTENA_Msk 248 MPU_NS->CTRL &= ~MPU_CTRL_ENABLE_Msk;
261 const uint8_t reg = idx / 4U;
262 const uint32_t pos = ((idx % 4U) * 8U);
263 const uint32_t mask = 0xFFU << pos;
265 if (reg >= (
sizeof(mpu->MAIR) /
sizeof(mpu->MAIR[0]))) {
269 mpu->MAIR[reg] = ((mpu->MAIR[reg] & ~mask) | ((attr << pos) & mask));
349 __STATIC_INLINE void ARM_MPU_SetRegion_NS(uint32_t rnr, uint32_t rbar, uint32_t rlar)
363 for (i = 0U; i < len; ++i)
382 uint32_t rnrBase = rnr & ~(MPU_TYPE_RALIASES-1U);
383 uint32_t rnrOffset = rnr % MPU_TYPE_RALIASES;
386 while ((rnrOffset + cnt) > MPU_TYPE_RALIASES) {
387 uint32_t c = MPU_TYPE_RALIASES - rnrOffset;
392 rnrBase += MPU_TYPE_RALIASES;
__STATIC_INLINE void ARM_MPU_Load(uint32_t rnr, ARM_MPU_Region_t const *table, uint32_t cnt)
Definition: mpu_armv8.h:405
Definition: mpu_armv8.h:184
uint32_t RBAR
Definition: mpu_armv8.h:185
__STATIC_INLINE void ARM_MPU_ClrRegion(uint32_t rnr)
Definition: mpu_armv8.h:305
__STATIC_INLINE void ARM_MPU_SetMemAttrEx(MPU_Type *mpu, uint8_t idx, uint8_t attr)
Definition: mpu_armv8.h:259
__STATIC_FORCEINLINE void __DMB(void)
Data Memory Barrier.
Definition: cmsis_gcc.h:286
__STATIC_INLINE void ARM_MPU_SetMemAttr(uint8_t idx, uint8_t attr)
Definition: mpu_armv8.h:276
__STATIC_INLINE void ARM_MPU_SetRegionEx(MPU_Type *mpu, uint32_t rnr, uint32_t rbar, uint32_t rlar)
Definition: mpu_armv8.h:326
__STATIC_INLINE void ARM_MPU_LoadEx(MPU_Type *mpu, uint32_t rnr, ARM_MPU_Region_t const *table, uint32_t cnt)
Definition: mpu_armv8.h:375
#define SCB_SHCSR_MEMFAULTENA_Msk
Definition: core_armv81mml.h:740
__STATIC_FORCEINLINE void __DSB(void)
Data Synchronization Barrier.
Definition: cmsis_gcc.h:275
__STATIC_INLINE void ARM_MPU_Disable(void)
Definition: mpu_armv8.h:214
#define SCB
Definition: core_armv81mml.h:3129
#define __RESTRICT
Definition: cmsis_gcc.h:114
__STATIC_INLINE void ARM_MPU_OrderedMemcpy(volatile uint32_t *dst, const uint32_t *__RESTRICT src, uint32_t len)
Definition: mpu_armv8.h:360
uint32_t RLAR
Definition: mpu_armv8.h:186
__STATIC_INLINE uint32_t ARM_MPU_TYPE()
Read MPU Type Register.
Definition: mpu_armv8.h:193
__STATIC_INLINE void ARM_MPU_SetRegion(uint32_t rnr, uint32_t rbar, uint32_t rlar)
Definition: mpu_armv8.h:338
#define __STATIC_INLINE
Definition: cmsis_gcc.h:47
__STATIC_INLINE void ARM_MPU_Enable(uint32_t MPU_Control)
Definition: mpu_armv8.h:201
__STATIC_INLINE void ARM_MPU_ClrRegionEx(MPU_Type *mpu, uint32_t rnr)
Definition: mpu_armv8.h:296
__STATIC_FORCEINLINE void __ISB(void)
Instruction Synchronization Barrier.
Definition: cmsis_gcc.h:264