nRF5 SDK v17.1.0
MPU driver

The MPU (Memory Protection Unit) driver module is a driver for ARM Cortex-M Memory Protection Unit (MPU).

MPU has multiple regions which can be used to detect access to a block of RAM memory (for example, to detect stack violation). The module manages access to regions and validates input parameters. Command Line Interface commands can be used to get the current state of MPU regions.

Usage

In order to protect a block of memory, an MPU region must be created. Destroying the region removes protection and releases the region.

uint32_t attributes = (0x05 << MPU_RASR_TEX_Pos) | (1 << MPU_RASR_B_Pos)
(0x07 << MPU_RASR_AP_Pos) | (1 << MPU_RASR_XN_Pos);
(void *)block_addr,
block_size,
attributes);
//Block of memory is protected.
//Block of memory is no longer protected. The MPU region is available.

CLI commands

The macro NRF_MPU_LIB_CLI_CMDS is used to enable commands. To view the available commands, run mpu –help.


Documentation feedback | Developer Zone | Subscribe | Updated