Showing results for 
Search instead for 
Did you mean: 

How to configure the MPU of an STM32 using STM32CubeMX

ST AME Support NF
ST Employee

How to configure the MPU of an STM32 using STM32CubeMX

1. Introduction

The MPU (Memory Protection Unit) is included in the Cortex-M4 and M7 based STM32 Microcontrollers (refer to specific product datasheets to confirm availability). The MPU can be used to make an embedded system more robust and more secure by:
  • prohibiting the user applications from corrupting data used by critical tasks (such as the operating system kernel)
  • defining the SRAM memory region as non-executable (execute never XN) to prevent code injection attacks
  • changing the memory access attributes
 This article shows how to enable and configure the MPU using the STM32CubeMX software.

2. Pre-requisite

  • Software
    • STM32CubeMX

3. Theory

The purpose of this article is to explain how to use STM32CubeMX to configure the MPU. For details about the MPU please refer to the Application Note (AN), Managing memory protection unit in STM32 MCUs - Application note
As an example configuration, we will define three MPU regions following the example provided in the application note as shown below:
Note: All the terms in this table are explained in the application note as well as all the definitions and explanations.

The STM32H743AI microcontroller will be used as the target device. It uses an Arm Cortex-M7 core that embeds the MPU.

4.  Steps

  1. Open STM32CubeMX  
  2. Create a new project and select the STM32H743AI for this example

  1. MPU settings
  • To gain access to the MPU settings, go to the Pinout & Configuration Tab and then click on Cortex-M7 as shown below:
  1. Enable the MPU by selecting one of the four possible modes
  1. Enable and configure the different MPU regions as show below:
  1. Configure the three regions as defined in the table from the application note:
  1. Region 0 settings:

  • In STM32CubeMX, make the following selections:

  1. Region 1 settings:
  • In STM32CubeMX, the configuration for this region should be set to:
  1. Region 2 settings:
  • In STM32CubeMX, the configuration for this region should be set to:
The MPU configuration is now complete. While this article shows how to configure the MPU for the STM32H743AI following the example table in the application note, the MPU is highly configurable and can be tailored to variety of application needs.

5. Links

STM32H753xI - Datasheet
STM32H742, STM32H743/753 and STM32H750 Value line advanced Arm®-based 32-bit MCUs - Reference manual
STM32F7 Series and STM32H7 Series Cortex®-M7 processor programming manual

Managing memory protection unit in STM32 MCUs - Application note
STM32CubeMX - STM32Cube initialization code generator - STMicroelectronics
Associate II

Hi community. I am new using ST MCUs and I have to say that I am very pleased.

I am planning to use memory protection unit (MPU) in my project. My MCU is STM32G031K8 but I cannot find how to activate this function with CubeMX. I would want to do the same as the example above:

In addition in the reference manual there is no much information about this function or the registers involved:

or in the datasheet

An I wrong? or maybe this function is not available for this MCU. According to this is link I can use this function but I am not sure.

Thanks for your help!

ST Employee

Hello @OAgui.1​ ,

@ST AME Support NF​ should be able to help you.

Thank you,


ST AME Support NF
ST Employee


You are correct.

For STM32G0 you cannot configure the MPU from CubeMX, you can configure the MPU by code and here is an example from the STM32CubeG0.




Associate II

Thank you so much for your explanation.

Associate III

Hello, how to config Static Ram, Flash Memory and LCD ? I'm trying config, but displaying message conflict NE2 and NE3....

Version history
Last update:
‎2021-11-16 02:19 AM
Updated by: