CMSIS-Core (Cortex-M): MPU Functions for Armv8-M

| CMSIS-Core (Cortex-M) Version 5.3.0 CMSIS-Core support for Cortex-M processor-based devices

- Main Page
- Usage and Description
- Reference

All Data Structures Files Functions Variables Enumerations Enumerator Groups Pages
Data Structures | Macros | Functions
MPU Functions for Armv8-M

Functions that relate to the Memory Protection Unit. More...

## Data Structures
struct | ARM_MPU_Region_t
| Setup information of a single MPU Region. More...

## Macros
#define | ARM_MPU_ATTR_DEVICE ( 0U )
| Attribute for device memory (outer only) More...
#define | ARM_MPU_ATTR_NON_CACHEABLE ( 4U )
| Attribute for non-cacheable, normal memory. More...
#define | ARM_MPU_ATTR_MEMORY_(NT, WB, RA, WA)
| Attribute for normal memory (outer and inner) More...
#define | ARM_MPU_ATTR_DEVICE_nGnRnE
| Device memory type non Gathering, non Re-ordering, non Early Write Acknowledgement. More...
#define | ARM_MPU_ATTR_DEVICE_nGnRE
| Device memory type non Gathering, non Re-ordering, Early Write Acknowledgement. More...
#define | ARM_MPU_ATTR_DEVICE_nGRE
| Device memory type non Gathering, Re-ordering, Early Write Acknowledgement. More...
#define | ARM_MPU_ATTR_DEVICE_GRE
| Device memory type Gathering, Re-ordering, Early Write Acknowledgement. More...
#define | ARM_MPU_ATTR(O, I)
| Memory Attribute. More...
#define | ARM_MPU_SH_NON
| Normal memory non-shareable. More...
#define | ARM_MPU_SH_OUTER
| Normal memory outer shareable. More...
#define | ARM_MPU_SH_INNER
| Normal memory inner shareable. More...
#define | ARM_MPU_AP_(RO, NP)
| Memory access permissions. More...
#define | ARM_MPU_RBAR(BASE, SH, RO, NP, XN)
| Region Base Address Register value. More...
#define | ARM_MPU_RLAR(LIMIT, IDX)
| Region Limit Address Register value. More...

## Functions
__STATIC_INLINE void | ARM_MPU_Enable (uint32_t MPU_Control)
__STATIC_INLINE void | ARM_MPU_Disable (void)
__STATIC_INLINE | ARM_MPU_Enable_NS (uint32_t MPU_Control)
__STATIC_INLINE void | ARM_MPU_Disable_NS (void)
__STATIC_INLINE void | ARM_MPU_SetMemAttrEx (MPU_Type *mpu, uint8_t idx, uint8_t attr)
__STATIC_INLINE void | ARM_MPU_SetMemAttr (uint8_t idx, uint8_t attr)
__STATIC_INLINE void | ARM_MPU_SetMemAttr_NS (uint8_t idx, uint8_t attr)
__STATIC_INLINE void | ARM_MPU_ClrRegionEx (MPU_Type *mpu, uint32_t rnr)
__STATIC_INLINE void | ARM_MPU_ClrRegion (uint32_t rnr)
__STATIC_INLINE void | ARM_MPU_ClrRegion_NS (uint32_t rnr)
__STATIC_INLINE void | ARM_MPU_SetRegionEx (MPU_Type *mpu, uint32_t rnr, uint32_t rbar, uint32_t rlar)
__STATIC_INLINE void | ARM_MPU_SetRegion (uint32_t rnr, uint32_t rbar, uint32_t rlar)
__STATIC_INLINE void | ARM_MPU_SetRegion_NS (uint32_t rnr, uint32_t rbar, uint32_t rlar)
__STATIC_INLINE void | ARM_MPU_OrderedMemcpy (volatile uint32_t *dst, const uint32_t *__RESTRICT src, uint32_t len)
__STATIC_INLINE void | ARM_MPU_LoadEx (MPU_Type *mpu, uint32_t rnr, ARM_MPU_Region_t const *table, uint32_t cnt)
__STATIC_INLINE void | ARM_MPU_Load (uint32_t rnr, ARM_MPU_Region_t const *table, uint32_t cnt)
__STATIC_INLINE void | ARM_MPU_Load_NS (uint32_t rnr, ARM_MPU_Region_t const *table, uint32_t cnt)

## Description

The following functions support the optional Memory Protection Unit (MPU) that is available on the Cortex-M23, M33, M35P processor.

The MPU is used to prevent from illegal memory accesses that are typically caused by errors in an application software.

Example:

void main()
{
// Set Region 0 using Attr 0
ARM_MPU_SetMemAttr(0UL, ARM_MPU_ATTR( /* Normal memory */
ARM_MPU_ATTR_MEMORY_(0UL, 1UL, 1UL, 1UL), /* Outer Write-Back transient with read and write allocate */
ARM_MPU_ATTR_MEMORY_(0UL, 0UL, 1UL, 1UL) /* Inner Write-Through transient with read and write allocate */
));
ARM_MPU_SetRegion(0UL,
ARM_MPU_RBAR(0x08000000UL, ARM_MPU_SH_NON, 0UL, 1UL, 1UL), /* Non-shareable, read/write, non-privileged, execute-never */
ARM_MPU_RLAR(0x080FFFFFUL, 0UL) /* 1MB memory block using Attr 0 */
);
ARM_MPU_Enable(0);
// Execute application code that is access protected by the MPU
ARM_MPU_Disable();
}

## Macro Definition Documentation

#define ARM_MPU_AP_ | ( |  | RO,
|  |  | NP
| ) |  |

Parameters

  RO | Read-Only: Set to 1 for read-only memory.
  NP | Non-Privileged: Set to 1 for non-privileged memory.

#define ARM_MPU_ATTR | ( |  | O,
|  |  | I
| ) |  |

Parameters

  O | Outer memory attributes
  I | O == ARM_MPU_ATTR_DEVICE: Device memory attributes, else: Inner memory attributes

#define ARM_MPU_ATTR_DEVICE ( 0U )

#define ARM_MPU_ATTR_DEVICE_GRE

#define ARM_MPU_ATTR_DEVICE_nGnRE

#define ARM_MPU_ATTR_DEVICE_nGnRnE

#define ARM_MPU_ATTR_DEVICE_nGRE

#define ARM_MPU_ATTR_MEMORY_ | ( |  | NT,
|  |  | WB,
|  |  | RA,
|  |  | WA
| ) |  |

Parameters

  NT | Non-Transient: Set to 1 for non-transient data.
  WB | Write-Back: Set to 1 to use write-back update policy.
  RA | Read Allocation: Set to 1 to use cache allocation on read miss.
  WA | Write Allocation: Set to 1 to use cache allocation on write miss.

#define ARM_MPU_ATTR_NON_CACHEABLE ( 4U )

#define ARM_MPU_RBAR | ( |  | BASE,
|  |  | SH,
|  |  | RO,
|  |  | NP,
|  |  | XN
| ) |  |

Parameters

  BASE | The base address bits [31:5] of a memory region. The value is zero extended. Effective address gets 32 byte aligned.
  SH | Defines the Shareability domain for this memory region.
  RO | Read-Only: Set to 1 for a read-only memory region.
  NP | Non-Privileged: Set to 1 for a non-privileged memory region.
  XN | eXecute Never: Set to 1 for a non-executable memory region.

#define ARM_MPU_RLAR | ( |  | LIMIT,
|  |  | IDX
| ) |  |

Parameters

  LIMIT | The limit address bits [31:5] for this memory region. The value is one extended.
  IDX | The attribute index to be associated with this memory region.

#define ARM_MPU_SH_INNER

#define ARM_MPU_SH_NON

#define ARM_MPU_SH_OUTER

## Function Documentation

__STATIC_INLINE void ARM_MPU_ClrRegion | ( | uint32_t | rnr | ) |

Clear and disable the given MPU region.

Parameters

  rnr | Region number to be cleared.

__STATIC_INLINE void ARM_MPU_ClrRegion_NS | ( | uint32_t | rnr | ) |

Clear and disable the given Non-secure MPU region.

Parameters

  rnr | Region number to be cleared.

__STATIC_INLINE void ARM_MPU_ClrRegionEx | ( | MPU_Type * | mpu,
|  | uint32_t | rnr
| ) |  |

Clear and disable the given MPU region of the given MPU.

Parameters

  mpu | Pointer to MPU to be used.
  rnr | Region number to be cleared.

__STATIC_INLINE void ARM_MPU_Disable | ( | void |  | ) |

Disable the MPU.

__STATIC_INLINE void ARM_MPU_Disable_NS | ( | void |  | ) |

Disable the Non-secure MPU.

__STATIC_INLINE void ARM_MPU_Enable | ( | uint32_t | MPU_Control | ) |

Enable the MPU.

Parameters

  MPU_Control | Default access permissions for unconfigured regions.

__STATIC_INLINE ARM_MPU_Enable_NS | ( | uint32_t | MPU_Control | ) |

Enable the Non-secure MPU.

Parameters

  MPU_Control | Default access permissions for unconfigured regions.

__STATIC_INLINE void ARM_MPU_Load | ( | uint32_t | rnr,
|  | ARM_MPU_Region_t const * | table,
|  | uint32_t | cnt
| ) |  |

Load the given number of MPU regions from a table.

Parameters

  rnr | First region number to be configured.
  table | Pointer to the MPU configuration table.
  cnt | Amount of regions to be configured.

Example:

const ARM_MPU_Region_t mpuTable[1][4] = {
{
// BASE SH RO NP XN LIMIT ATTR
{ .RBAR = ARM_MPU_RBAR(0x08000000UL, ARM_MPU_SH_NON, 0UL, 1UL, 0UL), .RLAR = ARM_MPU_RLAR(0x080FFFFFUL, 0UL) },
{ .RBAR = ARM_MPU_RBAR(0x20000000UL, ARM_MPU_SH_NON, 0UL, 1UL, 1UL), .RLAR = ARM_MPU_RLAR(0x20007FFFUL, 0UL) },
{ .RBAR = ARM_MPU_RBAR(0x40020000UL, ARM_MPU_SH_NON, 0UL, 1UL, 1UL), .RLAR = ARM_MPU_RLAR(0x40021FFFUL, 1UL) },
{ .RBAR = ARM_MPU_RBAR(0x40022000UL, ARM_MPU_SH_NON, 0UL, 1UL, 1UL), .RLAR = ARM_MPU_RLAR(0x40022FFFUL, 1UL) }
}
};
void UpdateMpu(uint32_t idx)
{
ARM_MPU_Load(0, mpuTable[idx], 4);
}

__STATIC_INLINE void ARM_MPU_Load_NS | ( | uint32_t | rnr,
|  | ARM_MPU_Region_t const * | table,
|  | uint32_t | cnt
| ) |  |

Load the given number of MPU regions from a table to the Non-secure MPU.

Parameters

  rnr | First region number to be configured.
  table | Pointer to the MPU configuration table.
  cnt | Amount of regions to be configured.

__STATIC_INLINE void ARM_MPU_LoadEx | ( | MPU_Type * | mpu,
|  | uint32_t | rnr,
|  | ARM_MPU_Region_t const * | table,
|  | uint32_t | cnt
| ) |  |

Load the given number of MPU regions from a table to the given MPU.

Parameters

  mpu | Pointer to the MPU registers to be used.
  rnr | First region number to be configured.
  table | Pointer to the MPU configuration table.
  cnt | Amount of regions to be configured.

__STATIC_INLINE void ARM_MPU_OrderedMemcpy | ( | volatile uint32_t * | dst,
|  | const uint32_t *__RESTRICT | src,
|  | uint32_t | len
| ) |  |

Memcopy with strictly ordered memory access, e.g. for register targets.

Parameters

  dst | Destination data is copied to.
  src | Source data is copied from.
  len | Amount of data words to be copied.

__STATIC_INLINE void ARM_MPU_SetMemAttr | ( | uint8_t | idx,
|  | uint8_t | attr
| ) |  |

Set the memory attribute encoding.

Parameters

  idx | The attribute index to be set [0-7]
  attr | The attribute value to be set.

__STATIC_INLINE void ARM_MPU_SetMemAttr_NS | ( | uint8_t | idx,
|  | uint8_t | attr
| ) |  |

Set the memory attribute encoding to the Non-secure MPU.

Parameters

  idx | The attribute index to be set [0-7]
  attr | The attribute value to be set.

__STATIC_INLINE void ARM_MPU_SetMemAttrEx | ( | MPU_Type * | mpu,
|  | uint8_t | idx,
|  | uint8_t | attr
| ) |  |

Set the memory attribute encoding to the given MPU.

Parameters

  mpu | Pointer to the MPU to be configured.
  idx | The attribute index to be set [0-7]
  attr | The attribute value to be set.

__STATIC_INLINE void ARM_MPU_SetRegion | ( | uint32_t | rnr,
|  | uint32_t | rbar,
|  | uint32_t | rlar
| ) |  |

Configure the given MPU region.

Parameters

  rnr | Region number to be configured.
  rbar | Value for RBAR register.
  rlar | Value for RLAR register.

__STATIC_INLINE void ARM_MPU_SetRegion_NS | ( | uint32_t | rnr,
|  | uint32_t | rbar,
|  | uint32_t | rlar
| ) |  |

Configure the given Non-secure MPU region.

Parameters

  rnr | Region number to be configured.
  rbar | Value for RBAR register.
  rlar | Value for RLAR register.

__STATIC_INLINE void ARM_MPU_SetRegionEx | ( | MPU_Type * | mpu,
|  | uint32_t | rnr,
|  | uint32_t | rbar,
|  | uint32_t | rlar
| ) |  |

Configure the given MPU region of the given MPU.

Parameters

  mpu | Pointer to MPU to be used.
  rnr | Region number to be configured.
  rbar | Value for RBAR register.
  rlar | Value for RLAR register.