The MPU driver provides hardware access control for all memory references generated in the device. Use the MPU driver to program the region descriptors that define memory spaces and their access rights. After initialization, the MPU concurrently monitors the system bus transactions and evaluates the appropriateness.
Initialization and Deinitialize
To initialize the MPU module, call the MPU_Init() function and provide the user configuration data structure. This function sets the configuration of the MPU module automatically and enables the MPU module.
Note that the configuration start address, end address, the region valid value, and the debugger's access permission for the MPU region 0 cannot be changed.
This is example code to configure the MPU driver:
{
kMPU_IdentifierDisable,
kMPU_IdentifierDisable,
kMPU_IdentifierDisable,
kMPU_IdentifierDisable
}
{
false,
false,
false,
false,
false,
false,
false,
false
};
{
kMPU_RegionNum00,
0x0,
0xffffffff,
mpuLowAccessRights,
mpuHighAccessRights,
0,
0
};
{
mpuRegionConfig,
NULL
};
Basic Control Operations
MPU can be enabled/disabled for the entire memory protection region by calling the MPU_Enable(). To save the power for any unused special regions when the entire memory protection region is disabled, call the MPU_RegionEnable().
After MPU initialization, the MPU_SetRegionLowMasterAccessRights() and MPU_SetRegionHighMasterAccessRights() can be used to change the access rights for special master ports and for special region numbers. The MPU_SetRegionConfig can be used to set the whole region with the start/end address with access rights.
The MPU_GetHardwareInfo() API is provided to get the hardware information for the device. The MPU_GetSlavePortErrorStatus() API is provided to get the error status of a special slave port. When an error happens in this port, the MPU_GetDetailErrorAccessInfo() API is provided to get the detailed error information.
|
enum | mpu_region_num_t |
| MPU region number. More...
|
|
enum | mpu_master_t |
| MPU master number. More...
|
|
enum | mpu_region_total_num_t {
kMPU_8Regions = 0x0U,
kMPU_12Regions = 0x1U,
kMPU_16Regions = 0x2U
} |
| Describes the number of MPU regions. More...
|
|
enum | mpu_slave_t {
kMPU_Slave0 = 4U,
kMPU_Slave1 = 3U,
kMPU_Slave2 = 2U,
kMPU_Slave3 = 1U,
kMPU_Slave4 = 0U
} |
| MPU slave port number. More...
|
|
enum | mpu_err_access_control_t {
kMPU_NoRegionHit = 0U,
kMPU_NoneOverlappRegion = 1U,
kMPU_OverlappRegion = 2U
} |
| MPU error access control detail. More...
|
|
enum | mpu_err_access_type_t {
kMPU_ErrTypeRead = 0U,
kMPU_ErrTypeWrite = 1U
} |
| MPU error access type. More...
|
|
enum | mpu_err_attributes_t {
kMPU_InstructionAccessInUserMode = 0U,
kMPU_DataAccessInUserMode = 1U,
kMPU_InstructionAccessInSupervisorMode = 2U,
kMPU_DataAccessInSupervisorMode = 3U
} |
| MPU access error attributes. More...
|
|
enum | mpu_supervisor_access_rights_t {
kMPU_SupervisorReadWriteExecute = 0U,
kMPU_SupervisorReadExecute = 1U,
kMPU_SupervisorReadWrite = 2U,
kMPU_SupervisorEqualToUsermode = 3U
} |
| MPU access rights in supervisor mode for master port 0 ~ port 3. More...
|
|
enum | mpu_user_access_rights_t {
kMPU_UserNoAccessRights = 0U,
kMPU_UserExecute = 1U,
kMPU_UserWrite = 2U,
kMPU_UserWriteExecute = 3U,
kMPU_UserRead = 4U,
kMPU_UserReadExecute = 5U,
kMPU_UserReadWrite = 6U,
kMPU_UserReadWriteExecute = 7U
} |
| MPU access rights in user mode for master port 0 ~ port 3. More...
|
|
|
static void | MPU_Enable (MPU_Type *base, bool enable) |
| Enables/disables the MPU globally. More...
|
|
static void | MPU_RegionEnable (MPU_Type *base, mpu_region_num_t number, bool enable) |
| Enables/disables the MPU for a special region. More...
|
|
void | MPU_GetHardwareInfo (MPU_Type *base, mpu_hardware_info_t *hardwareInform) |
| Gets the MPU basic hardware information. More...
|
|
void | MPU_SetRegionConfig (MPU_Type *base, const mpu_region_config_t *regionConfig) |
| Sets the MPU region. More...
|
|
void | MPU_SetRegionAddr (MPU_Type *base, mpu_region_num_t regionNum, uint32_t startAddr, uint32_t endAddr) |
| Sets the region start and end address. More...
|
|
void | MPU_SetRegionLowMasterAccessRights (MPU_Type *base, mpu_region_num_t regionNum, mpu_master_t masterNum, const mpu_low_masters_access_rights_t *accessRights) |
| Sets the MPU region access rights for low master port 0 ~ port 3. More...
|
|
void | MPU_SetRegionHighMasterAccessRights (MPU_Type *base, mpu_region_num_t regionNum, mpu_master_t masterNum, const mpu_high_masters_access_rights_t *accessRights) |
| Sets the MPU region access rights for high master port 4 ~ port 7. More...
|
|
bool | MPU_GetSlavePortErrorStatus (MPU_Type *base, mpu_slave_t slaveNum) |
| Gets the numbers of slave ports where errors occur. More...
|
|
void | MPU_GetDetailErrorAccessInfo (MPU_Type *base, mpu_slave_t slaveNum, mpu_access_err_info_t *errInform) |
| Gets the MPU detailed error access information. More...
|
|
struct mpu_hardware_info_t |
uint8_t mpu_hardware_info_t::hardwareRevisionLevel |
uint8_t mpu_hardware_info_t::slavePortsNumbers |
struct mpu_access_err_info_t |
uint32_t mpu_access_err_info_t::address |
struct mpu_low_masters_access_rights_t |
struct mpu_high_masters_access_rights_t |
bool mpu_high_masters_access_rights_t::writeEnable |
bool mpu_high_masters_access_rights_t::readEnable |
struct mpu_region_config_t |
This structure is used to configure the regionNum region. The accessRights1[0] ~ accessRights1[3] are used to configure the four low master numbers: master 0 ~ master 3. The accessRights2[0] ~ accessRights2[3] are used to configure the four high master numbers: master 4 ~ master 7. The master port assignment is the chip configuration. Normally, the core is the master 0, debugger is the master 1. Note: MPU assigns a priority scheme where the debugger is treated as the highest priority master followed by the core and then all the remaining masters. MPU protection does not allow writes from the core to affect the "regionNum 0" start and end address nor the permissions associated with the debugger. It can only write the permission fields associated with the other masters. This protection guarantee the debugger always has access to the entire address space and those rights can't be changed by the core or any other bus master. Prepare the region configuration when regionNum is kMPU_RegionNum00.
uint32_t mpu_region_config_t::startAddress |
Note: bit0 ~ bit4 always be marked as 0 by MPU. The actual start address is 0-modulo-32 byte address.
uint32_t mpu_region_config_t::endAddress |
Note: bit0 ~ bit4 always be marked as 1 by MPU. The actual end address is 31-modulo-32 byte address.
This structure is used when calling the MPU_Init function.
struct _mpu_config* mpu_config_t::next |
#define MPU_WORD_LOW_MASTER_SHIFT |
( |
|
n | ) |
(n * 6) |
#define MPU_WORD_LOW_MASTER_MASK |
( |
|
n | ) |
(0x1Fu << MPU_WORD_LOW_MASTER_SHIFT(n)) |
#define MPU_WORD_LOW_MASTER_WIDTH 5 |
#define MPU_LOW_MASTER_PE_SHIFT |
( |
|
n | ) |
(n * 6 + 5) |
#define MPU_LOW_MASTER_PE_MASK |
( |
|
n | ) |
(0x1u << MPU_LOW_MASTER_PE_SHIFT(n)) |
#define MPU_WORD_MASTER_PE_WIDTH 1 |
#define MPU_WORD_HIGH_MASTER_SHIFT |
( |
|
n | ) |
(n * 2 + 24) |
#define MPU_WORD_HIGH_MASTER_MASK |
( |
|
n | ) |
(0x03u << MPU_WORD_HIGH_MASTER_SHIFT(n)) |
#define MPU_WORD_HIGH_MASTER_WIDTH 2 |
Enumerator |
---|
kMPU_8Regions |
MPU supports 8 regions.
|
kMPU_12Regions |
MPU supports 12 regions.
|
kMPU_16Regions |
MPU supports 16 regions.
|
Enumerator |
---|
kMPU_Slave0 |
MPU slave port 0.
|
kMPU_Slave1 |
MPU slave port 1.
|
kMPU_Slave2 |
MPU slave port 2.
|
kMPU_Slave3 |
MPU slave port 3.
|
kMPU_Slave4 |
MPU slave port 4.
|
Enumerator |
---|
kMPU_NoRegionHit |
No region hit error.
|
kMPU_NoneOverlappRegion |
Access single region error.
|
kMPU_OverlappRegion |
Access overlapping region error.
|
Enumerator |
---|
kMPU_ErrTypeRead |
MPU error access type — read.
|
kMPU_ErrTypeWrite |
MPU error access type — write.
|
Enumerator |
---|
kMPU_InstructionAccessInUserMode |
Access instruction error in user mode.
|
kMPU_DataAccessInUserMode |
Access data error in user mode.
|
kMPU_InstructionAccessInSupervisorMode |
Access instruction error in supervisor mode.
|
kMPU_DataAccessInSupervisorMode |
Access data error in supervisor mode.
|
Enumerator |
---|
kMPU_SupervisorReadWriteExecute |
Read write and execute operations are allowed in supervisor mode.
|
kMPU_SupervisorReadExecute |
Read and execute operations are allowed in supervisor mode.
|
kMPU_SupervisorReadWrite |
Read write operations are allowed in supervisor mode.
|
kMPU_SupervisorEqualToUsermode |
Access permission equal to user mode.
|
Enumerator |
---|
kMPU_UserNoAccessRights |
No access allowed in user mode.
|
kMPU_UserExecute |
Execute operation is allowed in user mode.
|
kMPU_UserWrite |
Write operation is allowed in user mode.
|
kMPU_UserWriteExecute |
Write and execute operations are allowed in user mode.
|
kMPU_UserRead |
Read is allowed in user mode.
|
kMPU_UserReadExecute |
Read and execute operations are allowed in user mode.
|
kMPU_UserReadWrite |
Read and write operations are allowed in user mode.
|
kMPU_UserReadWriteExecute |
Read write and execute operations are allowed in user mode.
|
void MPU_Init |
( |
MPU_Type * |
base, |
|
|
const mpu_config_t * |
config |
|
) |
| |
This function configures the MPU module with the user-defined configuration.
- Parameters
-
base | MPU peripheral base address. |
config | The pointer to the configuration structure. |
void MPU_Deinit |
( |
MPU_Type * |
base | ) |
|
- Parameters
-
base | MPU peripheral base address. |
static void MPU_Enable |
( |
MPU_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
Call this API to enable or disable the MPU module.
- Parameters
-
base | MPU peripheral base address. |
enable | True enable MPU, false disable MPU. |
static void MPU_RegionEnable |
( |
MPU_Type * |
base, |
|
|
mpu_region_num_t |
number, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
When MPU is enabled, call this API to disable an unused region of an enabled MPU. Call this API to minimize the power dissipation.
- Parameters
-
base | MPU peripheral base address. |
number | MPU region number. |
enable | True enable the special region MPU, false disable the special region MPU. |
- Parameters
-
base | MPU peripheral base address. |
hardwareInform | The pointer to the MPU hardware information structure. See "mpu_hardware_info_t". |
Note: Due to the MPU protection, the kMPU_RegionNum00 does not allow writes from the core to affect the start and end address nor the permissions associated with the debugger. It can only write the permission fields associated with the other masters.
- Parameters
-
base | MPU peripheral base address. |
regionConfig | The pointer to the MPU user configuration structure. See "mpu_region_config_t". |
void MPU_SetRegionAddr |
( |
MPU_Type * |
base, |
|
|
mpu_region_num_t |
regionNum, |
|
|
uint32_t |
startAddr, |
|
|
uint32_t |
endAddr |
|
) |
| |
Memory region start address. Note: bit0 ~ bit4 is always marked as 0 by MPU. The actual start address by MPU is 0-modulo-32 byte address. Memory region end address. Note: bit0 ~ bit4 always be marked as 1 by MPU. The actual end address used by MPU is 31-modulo-32 byte address. Note: Due to the MPU protection, the startAddr and endAddr can't be changed by the core when regionNum is "kMPU_RegionNum00".
- Parameters
-
base | MPU peripheral base address. |
regionNum | MPU region number. |
startAddr | Region start address. |
endAddr | Region end address. |
This can be used to change the region access rights for any master port for any region.
- Parameters
-
base | MPU peripheral base address. |
regionNum | MPU region number. |
masterNum | MPU master number. Should range from kMPU_Master0 ~ kMPU_Master3. |
accessRights | The pointer to the MPU access rights configuration. See "mpu_low_masters_access_rights_t". |
This can be used to change the region access rights for any master port for any region.
- Parameters
-
base | MPU peripheral base address. |
regionNum | MPU region number. |
masterNum | MPU master number. Should range from kMPU_Master4 ~ kMPU_Master7. |
accessRights | The pointer to the MPU access rights configuration. See "mpu_high_masters_access_rights_t". |
bool MPU_GetSlavePortErrorStatus |
( |
MPU_Type * |
base, |
|
|
mpu_slave_t |
slaveNum |
|
) |
| |
- Parameters
-
base | MPU peripheral base address. |
slaveNum | MPU slave port number. |
- Returns
- The slave ports error status. true - error happens in this slave port. false - error didn't happen in this slave port.
- Parameters
-
base | MPU peripheral base address. |
slaveNum | MPU slave port number. |
errInform | The pointer to the MPU access error information. See "mpu_access_err_info_t". |