Kinetis SDK v.1.3 API Reference Manual  Rev. 0
Freescale Semiconductor, Inc.
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
MPU Peripheral driver

Overview

This section describes the programming interface of the MPU Peripheral driver. The MPU driver configures MPU.

MPU Initialization

To initialize the MPU module, call the MPU_DRV_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:

// Define MPU memory access permission configuration structure . //
struct mpu_access_rights_t mpuAccessRights{
.m0UserMode = kMPUUserNoAccessRights;
.m0SupervisorMode = kMPUSupervisorReadWriteExecute;
.m0Process_identifier = kMPUIdentifierDisable;
.m1UserMode = kMPUUserNoAccessRights;
.m1SupervisorMode = kMPUSupervisorEqualToUsermode;
.m1Process_identifier = kMPUIdentifierDisable;
.m2UserMode = kMPUUserNoAccessRights;
.m2SupervisorMode = kMPUSupervisorEqualToUsermode;
.m2Process_identifier = kMPUIdentifierDisable;
.m3UserMode = kMPUUserNoAccessRights;
.m3SupervisorMode = kMPUSupervisorEqualToUsermode;
.m3Process_identifier = kMPUIdentifierDisable;
.m4WriteControl = kMPUAccessDisable;
.m4ReadControl = kMPUAccessDisable;
.m5WriteControl = kMPUAccessDisable;
.m5ReadControl = kMPUAccessDisable;
.m6WriteControl = kMPUAccessDisable;
.m6ReadControl = kMPUAccessDisable;
.m7WriteControl = kMPUAccessDisable;
.m7ReadControl = kMPUAccessDisable;
};
// Defines MPU region configuration structure . //
struct mpu_region_config_t mpuRegionConfig{
.regionNum = kMPURegionNum00;
.startAddr = 0x0;
.endAddr = 0xffffffff;
.accessRights = mpuAccessRights;
};
// Defines MPU user configuration structure . //
struct mpu_user_config_t mpuUserConfig{
.regionConfig = mpuRegionConfig;
.next = NULL;
// Initializes MPU region 0. //
MPU_DRV_Init(0, &mpuUserConfig);

MPU Interrupt

  1. The interrupt corresponding to BUSFAULT causes an error by accessing the core.
  2. Definition for the MPU IRQ function.
    void MPU_DRV_IRQHandler(uint32_t instance)
    {
    assert(instance < HW_MPU_INSTANCE_COUNT);
    if (mpu_state_ptrs[instance])
    {
    if (mpu_state_ptrs[instance]->userCallbackFunc)
    {
    // Execute user-defined callback function. //
    (*(mpu_state_ptrs[instance]->userCallbackFunc))();
    }
    }
    }

Data Structures

struct  mpu_user_config_t
 Data The section describes the programming interface of the for MPU region initialization. More...
 

Variables

MPU_Type *const g_mpuBase []
 Table of base addresses for MPU instances. More...
 
const IRQn_Type g_mpuIrqId [MPU_INSTANCE_COUNT]
 Table to save MPU IRQ enumeration numbers defined in the CMSIS header file. More...
 

MPU Driver

MPU driver user callback function.

The contents of this structure provides a callback function.

mpu_status_t MPU_DRV_Init (uint32_t instance, const mpu_user_config_t *userConfigPtr)
 Initializes the MPU driver. More...
 
void MPU_DRV_Deinit (uint32_t instance)
 Deinitializes the MPU region. More...
 
mpu_status_t MPU_DRV_SetRegionConfig (uint32_t instance, const mpu_region_config_t *regionConfigPtr)
 Configures the MPU region. More...
 
void MPU_DRV_SetRegionAddr (uint32_t instance, mpu_region_num_t regionNum, uint32_t startAddr, uint32_t endAddr)
 Sets the region start address. More...
 
mpu_status_t MPU_DRV_SetLowMasterAccessRights (uint32_t instance, mpu_region_num_t regionNum, mpu_master_t masterNum, const mpu_low_masters_access_rights_t *accessRightsPtr)
 Configures the low master access permission. More...
 
mpu_status_t MPU_DRV_SetHighMasterAccessRights (uint32_t instance, mpu_region_num_t regionNum, mpu_master_t masterNum, const mpu_high_masters_access_rights_t *accessRightsPtr)
 Configures the high master access permission. More...
 
void MPU_DRV_SetRegionValidCmd (uint32_t instance, mpu_region_num_t regionNum, bool enable)
 Sets the MPU region valid. More...
 
mpu_status_t MPU_DRV_GetDetailErrorAccessInfo (uint32_t instance, mpu_access_err_info_t *errInfoArrayPtr)
 Gets the MPU access error detail information. More...
 

Data Structure Documentation

struct mpu_user_config_t

This structure is used when calling the MPU_DRV_Init function.

Data Fields

mpu_region_config_t regionConfig
 region access permission
 
struct MpuUserConfig * next
 pointer to the next structure
 

Function Documentation

mpu_status_t MPU_DRV_Init ( uint32_t  instance,
const mpu_user_config_t userConfigPtr 
)
Parameters
instanceThe MPU peripheral instance number.
userConfigPtrThe pointer to the MPU user configure structure, see mpu_user_config_t.
userStatePtrThe pointer of run time structure.
Returns
kStatus_MPU_Success means success. Otherwise, means failure.
void MPU_DRV_Deinit ( uint32_t  instance)
Parameters
instanceThe MPU peripheral instance number.
mpu_status_t MPU_DRV_SetRegionConfig ( uint32_t  instance,
const mpu_region_config_t regionConfigPtr 
)
Parameters
instanceThe MPU peripheral instance number.
regionConfigPtrThe pointer to the MPU user configure structure, see mpu_region_config_t.
Returns
kStatus_MPU_Success means success. Otherwise, means failure.
void MPU_DRV_SetRegionAddr ( uint32_t  instance,
mpu_region_num_t  regionNum,
uint32_t  startAddr,
uint32_t  endAddr 
)
Parameters
instanceThe MPU peripheral instance number.
regionNumThe region number.
startAddrRegion start address.
endAddrRegion end address.
mpu_status_t MPU_DRV_SetLowMasterAccessRights ( uint32_t  instance,
mpu_region_num_t  regionNum,
mpu_master_t  masterNum,
const mpu_low_masters_access_rights_t accessRightsPtr 
)
Parameters
instanceThe MPU peripheral instance number.
regionNumThe MPU region number.
masterNumThe MPU master number.
accessRightsPtrA pointer to access permission structure.
Returns
kStatus_MPU_Success means success. Otherwise, means failure.
mpu_status_t MPU_DRV_SetHighMasterAccessRights ( uint32_t  instance,
mpu_region_num_t  regionNum,
mpu_master_t  masterNum,
const mpu_high_masters_access_rights_t accessRightsPtr 
)
Parameters
instanceThe MPU peripheral instance number.
regionNumThe MPU region number.
masterNumThe MPU master number.
accessRightsPtrA pointer to access permission structure.
Returns
kStatus_MPU_Success means success. Otherwise, means failure.
void MPU_DRV_SetRegionValidCmd ( uint32_t  instance,
mpu_region_num_t  regionNum,
bool  enable 
)
Parameters
instanceThe MPU peripheral instance number.
regionNumMPU region number.
enableEnables or disables region.
mpu_status_t MPU_DRV_GetDetailErrorAccessInfo ( uint32_t  instance,
mpu_access_err_info_t errInfoArrayPtr 
)
Parameters
instanceThe MPU peripheral instance number.
errInfoArrayPtrA pointer to access error info structure.
Returns
kStatus_MPU_Success means success. Otherwise, means failure.

Variable Documentation

MPU_Type* const g_mpuBase[]
const IRQn_Type g_mpuIrqId[MPU_INSTANCE_COUNT]