The S32 SDK provides a Peripheral Abstraction Layer for Memory Protection Unit (MPU) modules of S32 SDK devices.
The MPU PAL driver provides memory protection functionality via allocate regions and restrict access rights of all masters on the region. It was designed to be portable across all platforms and IPs which support Memory Protection Unit.
How to integrate MPU PAL in your application
Unlike the other drivers, MPU PAL modules need to include a configuration file named mpu_pal_cfg.h, which allows the user to specify which IPs are used and how many resources are allocated for each of them (state structures). The following code example shows how to configure one instance for each available MPU IPs.
#ifndef MPU_PAL_CFG_H
#define MPU_PAL_CFG_H
#define MPU_OVER_MPU
#define MPU_OVER_SMPU
#endif
The following tables contains IPs specification on platforms:
- Available
IP/MCU | S32K1xx | S32MTV | MPC574x |
MPU | x | x | |
SMPU | | | x |
- Number of supported instances
IP/MCU | S32K1xx | S32MTV | MPC574x |
MPU | 1 | 1 | – |
SMPU | – | – | 1(1) |
1: 2 instances with MPC5747C, MPC5748C, MPC5746G, MPC5747G and MPC5748G.
- Number of supported regions
IP/MCU | S32K1xx | S32MTV | MPC574x |
MPU | 8(1) | 8 | – |
SMPU | – | – | 16 |
1: 16 regions with S32K148.
Initialization & De-initialization
- In order to use the MPU PAL driver it must be first initialized, using MPU_Init() function to initialize or re-initialize module.
- Example:
- Definitions for MPU IP (MPU_OVER_MPU)
{
.instIdx = 0U
}
#define MPU_PAL_MASTER_COUNT (16U)
#define MPU_PAL_REGION_COUNT (1U)
- Region configuration
{
{
.accessRight = MPU_ACCESS_SUPERVISOR_RWX_USER_RWX
},
...
};
{
{
.endAddr = 0xFFFFFFFFU,
.masterAccRight = mpu_pal_masterAccRight,
.processIdEnable = 0x01U,
.processIdentifier = 0x00U,
.processIdMask = 0xFFU,
.extension = NULL
}
};
Or using MPU_GetDefaultConfig()
status = MPU_GetDefaultConfig(&mpu_pal_Instance, mpu_pal_masterAccRight, ®ionConfig0);
{
regionConfig0
};
- Initialization
status =
MPU_Init(&mpu_pal_Instance, MPU_PAL_REGION_COUNT, mpu_pal_regionConfigs);
- De-initialization
Updates region configuration
- The MPU PAL driver provides a function named MPU_UpdateRegion() to update a region configuration (address, access rights of all masters, process identifier,...).
- In order to remove unused region or add again, MPU_EnableRegion() can be used.
- Please note the region will be unlocked if the update succeed.
- Example:
- Modify (or add new) region after initialization
- Enables/Disables an exist region configuration
Detects access protection errors
- The MPU PAL driver provides a function named MPU_GetError() to detect an access protection error on error capture channel. The channel can be different among IPs.
- Example:
bool errStatus =
MPU_GetError(&mpu_pal_Instance, 0U, &mpu_pal_errVal)
Other IP specific details
- MPU (MPU_OVER_MPU)
- Support PID for specific masters corresponding with the processIdEnable bit index.
- Detects an access error on slave ports:
Source | Slave port | Destination | S32K11x | S32K14x | S32MTV |
Crossbar slave port 0 | 0 | Flash Controller | x | x | x |
Crossbar slave port 1 | 1 | SRAM backdoor | x(1) | x | x |
Code Bus | 2 | SRAM_L frontdoor | | x | x |
System Bus | 3 | SRAM_U frontdoor | | x | x |
Crossbar slave port 2 | 4 | QuadSPI | | x(2) | |
1: Destination: SRAM controller/MTB/DWT/MCM. 2: S32K148 only.
- SMPU (MPU_OVER_SMPU)
- Support PID for for all specific masters (processIdEnable same as bool)
- Detects an access error on bus masters.
- Supports lock and cache inhibit features in region extension.
- An address range specified in an MPU region descriptor for a cacheable space (that is, CI = 0) must be defined with a starting address aligned on a 0-modulo-32 byte address and with a multiple of the 32 byte cache line size factoring into the end address.
- MPU_UpdateRegionLock() can be used to update lock configuration on a region.
- MPU_GetRegionLockInfo() can be used to get lock status on a region.
- Example:
- Extension
mpu_over_smpu_extension mpu_pal_extension =
{
.specAccessEnable = false,
.specAccessSet = NULL,
.cacheInhibitEnable = true,
.lockConfig = MPU_UNLOCK
}
#define MPU_PAL_REGION_ACCESS_SET_COUNT 3U
mpu_specific_access_permission_t mpu_pal_SpecificAccessConfig[MPU_PAL_REGION_ACCESS_SET_COUNT] =
{
MPU_SUPERVISOR_RWX_USER_RWX
}
mpu_pal_extension.specAccessEnable = true;
mpu_pal_extension.specAccessSet = true;
{
.masterNum = FEATURE_SMPU_MASTER_CORE_Z4A,
.accessRight = MPU_RW_OR_SET_3
},
...
};
#define MPU_PAL_REGION_COUNT 1U
{
{
.endAddr = 0xFFFFFFFFU,
.masterAccRight = mpu_pal_masterAccRight,
.processIdEnable = true,
.processIdentifier = 0x00U,
.processIdMask = 0xFFU,
.extension = &mpu_pal_extension
}
}
...
- Update lock configuration and get lock status on region
status = MPU_UpdateRegionLock(&mpu_pal_Instance, 0U, MPU_ALL_LOCK);
mpu_region_lock_t lockStatus;
status = MPU_GetRegionLockInfo(&mpu_pal_Instance, 0U, &lockStatus);
|
| MPU PAL |
| Memory Protection Unit Peripheral Abstraction Layer.
|
|