28#if defined ( __ICCARM__ )
29 #pragma system_include
30#elif defined (__clang__)
31 #pragma clang system_header
34#ifndef ARM_MPU_ARMV8_H
35#define ARM_MPU_ARMV8_H
38#define ARM_MPU_ATTR_DEVICE ( 0U )
41#define ARM_MPU_ATTR_NON_CACHEABLE ( 4U )
49#define ARM_MPU_ATTR_MEMORY_(NT, WB, RA, WA) \
50 ((((NT) & 1U) << 3U) | (((WB) & 1U) << 2U) | (((RA) & 1U) << 1U) | ((WA) & 1U))
53#define ARM_MPU_ATTR_DEVICE_nGnRnE (0U)
56#define ARM_MPU_ATTR_DEVICE_nGnRE (1U)
59#define ARM_MPU_ATTR_DEVICE_nGRE (2U)
62#define ARM_MPU_ATTR_DEVICE_GRE (3U)
67#define MPU_ATTR_NORMAL_OUTER_NON_CACHEABLE (0b0100)
68#define MPU_ATTR_NORMAL_OUTER_WT_TR_RA (0b0010)
69#define MPU_ATTR_NORMAL_OUTER_WT_TR_WA (0b0001)
70#define MPU_ATTR_NORMAL_OUTER_WT_TR_RA_WA (0b0011)
71#define MPU_ATTR_NORMAL_OUTER_WT_RA (0b1010)
72#define MPU_ATTR_NORMAL_OUTER_WT_WA (0b1001)
73#define MPU_ATTR_NORMAL_OUTER_WT_RA_WA (0b1011)
74#define MPU_ATTR_NORMAL_OUTER_WB_TR_RA (0b0101)
75#define MPU_ATTR_NORMAL_OUTER_WB_TR_WA (0b0110)
76#define MPU_ATTR_NORMAL_OUTER_WB_TR_RA_WA (0b0111)
77#define MPU_ATTR_NORMAL_OUTER_WB_RA (0b1101)
78#define MPU_ATTR_NORMAL_OUTER_WB_WA (0b1110)
79#define MPU_ATTR_NORMAL_OUTER_WB_RA_WA (0b1111)
80#define MPU_ATTR_NORMAL_INNER_NON_CACHEABLE (0b0100)
81#define MPU_ATTR_NORMAL_INNER_WT_TR_RA (0b0010)
82#define MPU_ATTR_NORMAL_INNER_WT_TR_WA (0b0001)
83#define MPU_ATTR_NORMAL_INNER_WT_TR_RA_WA (0b0011)
84#define MPU_ATTR_NORMAL_INNER_WT_RA (0b1010)
85#define MPU_ATTR_NORMAL_INNER_WT_WA (0b1001)
86#define MPU_ATTR_NORMAL_INNER_WT_RA_WA (0b1011)
87#define MPU_ATTR_NORMAL_INNER_WB_TR_RA (0b0101)
88#define MPU_ATTR_NORMAL_INNER_WB_TR_WA (0b0110)
89#define MPU_ATTR_NORMAL_INNER_WB_TR_RA_WA (0b0111)
90#define MPU_ATTR_NORMAL_INNER_WB_RA (0b1101)
91#define MPU_ATTR_NORMAL_INNER_WB_WA (0b1110)
92#define MPU_ATTR_NORMAL_INNER_WB_RA_WA (0b1111)
98#define ARM_MPU_ATTR(O, I) ((((O) & 0xFU) << 4U) | ((((O) & 0xFU) != 0U) ? ((I) & 0xFU) : (((I) & 0x3U) << 2U)))
101#define MAIR_ATTR(x) ((x > 7 || x < 0) ? 0 : x)
107#define ARM_MPU_SH_NON (0U)
110#define ARM_MPU_SH_OUTER (2U)
113#define ARM_MPU_SH_INNER (3U)
120#define ARM_MPU_AP_RW (0U)
123#define ARM_MPU_AP_RO (1U)
126#define ARM_MPU_AP_NP (1U)
129#define ARM_MPU_AP_PO (0U)
136#define ARM_MPU_XN (1U)
139#define ARM_MPU_EX (0U)
145#define ARM_MPU_AP_(RO, NP) ((((RO) & 1U) << 1U) | ((NP) & 1U))
154#define ARM_MPU_RBAR(BASE, SH, RO, NP, XN) \
155 (((BASE) & MPU_RBAR_BASE_Msk) | \
156 (((SH) << MPU_RBAR_SH_Pos) & MPU_RBAR_SH_Msk) | \
157 ((ARM_MPU_AP_(RO, NP) << MPU_RBAR_AP_Pos) & MPU_RBAR_AP_Msk) | \
158 (((XN) << MPU_RBAR_XN_Pos) & MPU_RBAR_XN_Msk))
164#define ARM_MPU_RLAR(LIMIT, IDX) \
165 (((LIMIT) & MPU_RLAR_LIMIT_Msk) | \
166 (((IDX) << MPU_RLAR_AttrIndx_Pos) & MPU_RLAR_AttrIndx_Msk) | \
169#if defined(MPU_RLAR_PXN_Pos)
176#define ARM_MPU_RLAR_PXN(LIMIT, PXN, IDX) \
177 (((LIMIT) & MPU_RLAR_LIMIT_Msk) | \
178 (((PXN) << MPU_RLAR_PXN_Pos) & MPU_RLAR_PXN_Msk) | \
179 (((IDX) << MPU_RLAR_AttrIndx_Pos) & MPU_RLAR_AttrIndx_Msk) | \
197__STATIC_INLINE uint32_t ARM_MPU_TYPE()
199__STATIC_INLINE uint32_t ARM_MPU_TYPE(
void)
202 return ((MPU->TYPE) >> 8);
211 MPU->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk;
212#ifdef SCB_SHCSR_MEMFAULTENA_Msk
224#ifdef SCB_SHCSR_MEMFAULTENA_Msk
225 SCB->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk;
227 MPU->CTRL &= ~MPU_CTRL_ENABLE_Msk;
236__STATIC_INLINE
void ARM_MPU_Enable_NS(uint32_t MPU_Control)
239 MPU_NS->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk;
240#ifdef SCB_SHCSR_MEMFAULTENA_Msk
249__STATIC_INLINE
void ARM_MPU_Disable_NS(
void)
252#ifdef SCB_SHCSR_MEMFAULTENA_Msk
253 SCB_NS->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk;
255 MPU_NS->CTRL &= ~MPU_CTRL_ENABLE_Msk;
266__STATIC_INLINE
void ARM_MPU_SetMemAttrEx(MPU_Type* mpu, uint8_t idx, uint8_t attr)
268 const uint8_t reg = idx / 4U;
269 const uint32_t pos = ((idx % 4U) * 8U);
270 const uint32_t mask = 0xFFU << pos;
271 const uint32_t val = (uint32_t)attr << pos;
273 if (reg >= (
sizeof(mpu->MAIR) /
sizeof(mpu->MAIR[0]))) {
277 mpu->MAIR[reg] = ((mpu->MAIR[reg] & ~mask) | (val & mask));
284__STATIC_INLINE
void ARM_MPU_SetMemAttr(uint8_t idx, uint8_t attr)
286 ARM_MPU_SetMemAttrEx(MPU, idx, attr);
294__STATIC_INLINE
void ARM_MPU_SetMemAttr_NS(uint8_t idx, uint8_t attr)
296 ARM_MPU_SetMemAttrEx(MPU_NS, idx, attr);
304__STATIC_INLINE
void ARM_MPU_ClrRegionEx(MPU_Type* mpu, uint32_t rnr)
315 ARM_MPU_ClrRegionEx(MPU, rnr);
322__STATIC_INLINE
void ARM_MPU_ClrRegion_NS(uint32_t rnr)
324 ARM_MPU_ClrRegionEx(MPU_NS, rnr);
334__STATIC_INLINE
void ARM_MPU_SetRegionEx(MPU_Type* mpu, uint32_t rnr, uint32_t rbar, uint32_t rlar)
346__STATIC_INLINE
void ARM_MPU_SetRegion(uint32_t rnr, uint32_t rbar, uint32_t rlar)
357__STATIC_INLINE
void ARM_MPU_SetRegion_NS(uint32_t rnr, uint32_t rbar, uint32_t rlar)
368__STATIC_INLINE
void ARM_MPU_OrderedMemcpy(
volatile uint32_t* dst,
const uint32_t* __RESTRICT src, uint32_t len)
371 for (i = 0U; i < len; ++i)
383__STATIC_INLINE
void ARM_MPU_LoadEx(MPU_Type* mpu, uint32_t rnr,
ARM_MPU_Region_t const* table, uint32_t cnt)
390 uint32_t rnrBase = rnr & ~(MPU_TYPE_RALIASES-1U);
391 uint32_t rnrOffset = rnr % MPU_TYPE_RALIASES;
394 while ((rnrOffset + cnt) > MPU_TYPE_RALIASES) {
395 uint32_t c = MPU_TYPE_RALIASES - rnrOffset;
400 rnrBase += MPU_TYPE_RALIASES;
415 ARM_MPU_LoadEx(MPU, rnr, table, cnt);
424__STATIC_INLINE
void ARM_MPU_Load_NS(uint32_t rnr,
ARM_MPU_Region_t const* table, uint32_t cnt)
426 ARM_MPU_LoadEx(MPU_NS, rnr, table, cnt);
__STATIC_FORCEINLINE void __DSB(void)
Data Synchronization Barrier.
Definition: cmsis_gcc.h:286
__STATIC_FORCEINLINE void __DMB(void)
Data Memory Barrier.
Definition: cmsis_gcc.h:297
__STATIC_FORCEINLINE void __ISB(void)
Instruction Synchronization Barrier.
Definition: cmsis_gcc.h:275
#define SCB_SHCSR_MEMFAULTENA_Msk
Definition: core_cm33.h:723
#define SCB
Definition: core_cm33.h:2237
__STATIC_INLINE void ARM_MPU_SetRegionEx(uint32_t rnr, uint32_t rbar, uint32_t rasr)
Definition: mpu_armv7.h:239
__STATIC_INLINE void ARM_MPU_SetRegion(uint32_t rbar, uint32_t rasr)
Definition: mpu_armv7.h:228
__STATIC_INLINE void ARM_MPU_Load(ARM_MPU_Region_t const *table, uint32_t cnt)
Definition: mpu_armv7.h:264
__STATIC_INLINE void ARM_MPU_Enable(uint32_t MPU_Control)
Definition: mpu_armv7.h:191
__STATIC_INLINE void ARM_MPU_Disable(void)
Definition: mpu_armv7.h:204
__STATIC_INLINE void ARM_MPU_ClrRegion(uint32_t rnr)
Definition: mpu_armv7.h:218
__STATIC_INLINE void ARM_MPU_OrderedMemcpy(volatile uint32_t *dst, const uint32_t *__RESTRICT src, uint32_t len)
Definition: mpu_armv7.h:251
Definition: mpu_armv7.h:183
uint32_t RLAR
Definition: mpu_armv8.h:189
uint32_t RBAR
The region base address register value (RBAR)
Definition: mpu_armv7.h:184