Mistake on this page?
Report an issue in GitHub or email us


Implementing the MPU API enables Mbed OS to provide better security by preventing code execution and code modification where it shouldn't be allowed.


Defined behavior

  • The function mbed_mpu_init is safe to call repeatedly.
  • The function mbed_mpu_free disables MPU protection.
  • Execution from RAM results in a fault when execute never is enabled. This RAM includes heap, stack, data and zero init.
  • Writing to ROM results in a fault when write never is enabled.

Undefined behavior

  • Calling any function other than mbed_mpu_init before the initialization of the MPU.


Hardware MPU capabilities.

Implementing the MPU API

You can find the API and specification for the MPU API in the following header file:

To enable MPU support in Mbed OS, add the MPU label in the device_has option of the target's section in the targets.json file.

Targets with a standard ARMv7-M or ARMv8-M MPU, indicated by __MPU_PRESENT being defined to 1 in the target's CMSIS header, only need the MPU label in the device_has for MPU support. This pulls in a common Mbed OS MPU driver, so you don't need a target-specific driver.

Targets with a standard ARMv7-M or ARMv8-M MPU needing to override the common Mbed OS MPU driver can do so by defining MBED_MPU_CUSTOM. This removes the common Mbed OS MPU driver from builds, so you can use a target-specific one, instead.


The Mbed OS HAL provides a set of conformance tests for the MPU API. You can use these tests to validate the correctness of your implementation. To run the MPU HAL tests, use the following command:

mbed test -t <toolchain> -m <target> -n "tests-mbed_hal-mpu*"

You can read more about the test cases:

Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.