MPU Memory Protection

Example application that shows how to use the MPU module

Application description


The purpose of this demo application is to show you how to use the Memory Protection Unit of the S32K118 MCU with this SDK.

In this example, MPU regions are configured to have access rights as following:

Region Core Debugger DMA Address
1 rwx rwx rwx 0x00000000 - 0x0003FEFF

0 | 2 | -wx | rwx | rwx |0x0003FF00 - 0x0003FF1F | 3 | r– | rwx | rwx |0x0003FF00 - 0x0003FF1F | 4 | rwx | rwx | rwx |0x0003FF20 - 0xFFFFFFFF

Run the example

  1. After reset, MPU will be initialized according to configuration above.
  2. Read flash memory at address 0x0003FF04 is permitted.
  3. Press button (SW) on the board to ignore read permission by disabling region 3.
  4. Read flash memory at address 0x0003FF04 is violated.
  5. MPU report the detail of error access on slave port 0 (Crossbar slave port 0 -> Flash Controller).

Verification

  1. GREEN LED on indicate that MPU initialization successful.
  2. RED LED on (GREEN LED off) indicate that there is violated read access reported by MPU.

Prerequisites


The run the example you will need to have the following items:

  • 1 S32K118 board
  • 1 Power Adapter 12V (if the board cannot be powered from the USB port)
  • 1 Personal Computer
  • 1 Jlink Lite Debugger (optional, users can use Open SDA)

Boards supported


The following boards are supported by this application:

  • S32K118EVB-Q64
  • S32K118-MB

Hardware Wiring


The following connections must be done to for this example application to work:

PIN FUNCTION S32K118EVB-Q64 S32K118-MB
RED_LED (PTD16) RGB_RED - wired on the board LED1 - wired on the board
GREEN_LED (PTD15) RGB_GREEN - wired on the board LED2 - wired on the board
SW (PTD3) SW2_BTN0 - wired on the board BUTTON0 - wired on the board

How to run


1. Importing the project into the workspace

After opening S32 Design Studio, go to File -> New S32DS Project From... and select mpu_memory_protection_s32k118. Then click on Finish.
The project should now be copied into you current workspace.

2. Generating the Processor Expert configuration

First go to Project Explorer View in S32 DS and select the current project(mpu_memory_protection_s32k118). Then go to Project and click on Generate Processor Expert Code
Wait for the code generation to be completed before continuing to the next step.

3. Building the project

Select the configuration to be built FLASH (Debug_FLASH) or RAM (Debug_RAM) by left clicking on the downward arrow corresponding to the build button(. Wait for the build action to be completed before continuing to the next step.

4. Running the project

Go to Run and select Debug Configurations. There will be four debug configurations for this project:

Configuration Name Description
mpu_memory_protection_s32k118_debug_ram_jlink Debug the RAM configuration using Segger Jlink debuggers
mpu_memory_protection_s32k118_debug_flash_jlink Debug the FLASH configuration using Segger Jlink debuggers
mpu_memory_protection_s32k118_debug_ram_pemicro Debug the RAM configuration using PEMicro debuggers
mpu_memory_protection_s32k118_debug_flash_pemicro Debug the FLASH configuration using PEMicro debuggers


Select the desired debug configuration and click on Launch. Now the perspective will change to the Debug Perspective.
Use the controls to control the program flow.

Note
For more detailed information related to S32 Design Studio usage please consult the available documentation.