This article explains what the Memory Mapping Tool (MMT) is and how to use it through examples.
1. What is MMT ?
MMT stands for Memory Management Tool. This STM32CubeMX feature handle the memory mapping in a more visual way. The tool goal is to make easy the creation, the partition and the deletion of memory blocks in RAM, FLASH or external memory (thanks to connectivity IP : OctoSPI & FMC). In fact, the MMT abstracts the difficulty from the linker file by providing a simple use.
2. Visual presentation
The MMT is under Tools > Memory Management.
2.1. Secure application
Let's introduce the Memory Management Tool with the picture below.
The MMT pannel is split in 6 parts:
1. The main pannel is a memory view by the CPU and the application with addresses on the left.
2. The second point is the legend indicating the corresponding color from memory.
3. The third block is composed of two toggle buttons which indicates the Code Generation Configuration :
- if the application regions settings are applied to peripherals
- if the application regions settings will be applied into linker files during code generation.
4. This Search bar allows to easily find an application region
5. This fifth section shows the selected Application Region in the main pannel. It lists many useful information. (Code Name, Start address, Size, Security, Access Permission, Code execution, Shareability and Cacheability)
6. The Display Settings and Reset View handle the memory view and allow to hide Security or Reseved regions
2.2. Non Secure application
The Non Secure (NS) application have exactly the same interface except there aren't Secure (S) and Non Secure Callable (NSC) region. However, the principle remains strictly the same.
3. Configure MMT to handle memory
3.1. Objectives
- Create a simple project with a Secure (S) and a Non-Secure (NS) application.
- Learn how to configure the memory through the tool.
- Verify the correct functionality by checking the linker file.
3.2. Create the project in STM32CubeMX
- File > New Project > Board Selector in the main panel or click on the shortcut Access to Board Selector.
The example uses the NUCLEO-U575ZI-Q board.
- Enter NUCLEO-U575ZI-Q in the Commercial Part Number as shown in the figure below.
- Select the NUCLEO-U575ZI-Q in the Board List
- And then click on Start Project.
- Select Yes in the pop-up window to initialize all peripherals with their default mode.
- Answer with TrustZone activated to the question "Do you want to create a new project ?" and OK
3.3. Memory zone definition
Go to the Memory Management Tool located under Tools > Memory Management.
The memory is in the default case, we create two Application Regions :
1 : A Secure Application Region :
- Select the RAM (S) region at the address 0x30000000.
- Change the size to 192kB.
- A new Application Region appears in white, when you mouse over it, a green cross appears.
- Click on this green cross section and the popup below pops up.
- In the name field, enter App_Secure.
- The Address is the base address from the selected memory block.
- You can keep the default size.
- Click on Add
2 : A Non Secure Application Region :
- Select the RAM (NS) region at the address 0x20040000.
- Change the size to 256 kB.
- A new Application Region appears in white, when you mouse over it, a green cross appears.
- Click on this green cross section and the popup below pops up.
- In the Name field, enter App_NonSecure.
- The Address is the base address from the selected memory block, you can keep it by default.
- Change the Size to 128 kB.
- Click on Add
Go to code generation configuration as below:
- Click on the first toggle button to apply Application Regions to Peripherals :
- And Click on the second button to apply Application Regions into linker files during the code generation :
3.4. Configuration
- Now, Pinout & Configuration > System Core > SAU, the SAU is under MMT control and is Read Only.
3.5. Generate project and edit linker file
The easiest way to generate the code is to :
- Click on Project Manager > Project > Project Settings
- Enter a Project Name and select STM32CubeIDE in the ToolChain / IDE
- Then select the Code Generator menu
- Check the box to Generate peripheral initialization as a pair of '.c/.h' files per peripheral
- Click on Generate Code
- Click on Open Project
The code is generated so you can see it in the left side of the screen in the project explorer.
Now, open the linker files (.ld) which are the mapping source file for Secure and Non-Secure application.
Look at the memory definition :
- Check that "App_Secure" has been declared in the Secure world and the "App_NonSecure" in the Non Secure world.