CMSIS-Core (Cortex-M)
Version 5.1.1
CMSIS-Core support for Cortex-M processor-based devices
|
Functions that relate to the Memory Protection Unit. More...
Content | |
Define values | |
Define values for MPU region setup. | |
Data Structures | |
struct | MPU_Type |
Structure type to access the Memory Protection Unit (MPU). More... | |
struct | ARM_MPU_Region_t |
Setup information of a single MPU Region. More... | |
Macros | |
#define | ARM_MPU_RBAR(Region, BaseAddress) |
MPU Region Base Address Register Value. More... | |
#define | ARM_MPU_RASR(DisableExec, AccessPermission, TypeExtField, IsShareable, IsCacheable, IsBufferable, SubRegionDisable, Size) |
MPU Region Attribute and Size Register Value. More... | |
Functions | |
__STATIC_INLINE void | ARM_MPU_Enable (uint32_t MPU_CTRL) |
Enable the memory protection unit (MPU) and. More... | |
__STATIC_INLINE void | ARM_MPU_Disable () |
__STATIC_INLINE void | ARM_MPU_ClrRegion (uint32_t rnr) |
__STATIC_INLINE void | ARM_MPU_SetRegion (uint32_t rbar, uint32_t rasr) |
__STATIC_INLINE void | ARM_MPU_SetRegionEx (uint32_t rnr, uint32_t rbar, uint32_t rasr) |
__STATIC_INLINE void | ARM_MPU_Load (MPU_Region_t const *table, uint32_t cnt) |
The following functions support the optional Memory Protection Unit (MPU) that is available on the Cortex-M0+, M3, M4 and M7 processor.
The MPU is used to prevent from illegal memory accesses that are typically caused by errors in an application software.
Example:
#define ARM_MPU_RASR | ( | DisableExec, | |
AccessPermission, | |||
TypeExtField, | |||
IsShareable, | |||
IsCacheable, | |||
IsBufferable, | |||
SubRegionDisable, | |||
Size | |||
) |
This macro is used to construct a valid RASR value. The ENABLE bit of the RASR value is implicitly set to 1.
DisableExec | Instruction access disable bit. 1 = disable instruction fetches. |
AccessPermission | Data access permission configures read/write access for User and Privileged mode. Possible values see ARM_MPU_AP_xxx. |
TypeExtField | Type extension field, allows you to configure memory access type, for example strongly ordered, peripheral. |
IsShareable | 1 = region is shareable between multiple bus masters. |
IsCacheable | 1 = region is cacheable (values may be kept in cache). |
IsBufferable | 1 = region is bufferable (when using write-back caching). Cacheable but non-bufferable regions use write-through policy. |
SubRegionDisable | Sub-region disable field (8 bits). |
Size | Region size with values defined under ARM_MPU_REGION_SIZE_xxx. |
#define ARM_MPU_RBAR | ( | Region, | |
BaseAddress | |||
) |
This preprocessor function can be used to construct a valid RBAR value. The VALID bit is implicitly set to 1.
Region | The region to be configured, number 0 to 15. |
BaseAddress | The base address for the region. |
__STATIC_INLINE void ARM_MPU_ClrRegion | ( | uint32_t | rnr | ) |
Clear and disable the given MPU region.
rnr | Region number to be cleared. |
__STATIC_INLINE void ARM_MPU_Disable | ( | ) |
Disable the MPU.
__STATIC_INLINE void ARM_MPU_Enable | ( | uint32_t | MPU_CTRL | ) |
MPU_CTRL | Additional control settings that configure MPU behaviour |
The function ARM_MPU_Enable writes to the register MPU->CTRL and sets bit ENABLE. The parameter MPU_CTRL provides additional bit values (see table below) that configure the MPU behaviour. For processors that implement an MPU Fault Handler the MemoryManagement_IRQn exception is enabled by setting the bit MEMFAULTACT in register SBC->SHCSR.
The following table contains possible values for the parameter MPU_CTRL that set specific bits in register MPU->CTRL.
Bit | MPU_CTRL value | When applied | When not applied |
---|---|---|---|
1 | MPU_CTRL_HFNMIENA_Pos | Enable MPU during hard fault, NMI, and FAULTMASK handlers execution | Disable MPU during hard fault, NMI, and FAULTMASK handler execution |
2 | MPU_CTRL_PRIVDEFENA_Pos | Enable default memory map as a background region for privileged access | Use only MPU region settings |
Example:
__STATIC_INLINE void ARM_MPU_Load | ( | MPU_Region_t const * | table, |
uint32_t | cnt | ||
) |
Load the given number of MPU regions from a table.
table | Pointer to the MPU configuration table. |
cnt | Number of regions to be configured. |
Example:
__STATIC_INLINE void ARM_MPU_SetRegion | ( | uint32_t | rbar, |
uint32_t | rasr | ||
) |
__STATIC_INLINE void ARM_MPU_SetRegionEx | ( | uint32_t | rnr, |
uint32_t | rbar, | ||
uint32_t | rasr | ||
) |