Functions | |
void | MPUEnable (uint32_t ui32MPUConfig) |
void | MPUDisable (void) |
uint32_t | MPURegionCountGet (void) |
void | MPURegionEnable (uint32_t ui32Region) |
void | MPURegionDisable (uint32_t ui32Region) |
void | MPURegionSet (uint32_t ui32Region, uint32_t ui32Addr, uint32_t ui32Flags) |
void | MPURegionGet (uint32_t ui32Region, uint32_t *pui32Addr, uint32_t *pui32Flags) |
void | MPUIntRegister (void(*pfnHandler)(void)) |
void | MPUIntUnregister (void) |
void MPUEnable | ( | uint32_t | ui32MPUConfig | ) |
Enables and configures the MPU for use.
ui32MPUConfig | is the logical OR of the possible configurations. |
This function enables the Cortex-M memory protection unit. It also configures the default behavior when in privileged mode and while handling a hard fault or NMI. Prior to enabling the MPU, at least one region must be set by calling MPURegionSet() or else by enabling the default region for privileged mode by passing the MPU_CONFIG_PRIV_DEFAULT flag to MPUEnable(). Once the MPU is enabled, a memory management fault is generated for memory access violations.
The ui32MPUConfig parameter should be the logical OR of any of the following:
References ASSERT, HWREG, MPU_CONFIG_HARDFLT_NMI, MPU_CONFIG_PRIV_DEFAULT, NVIC_MPU_CTRL, and NVIC_MPU_CTRL_ENABLE.
void MPUDisable | ( | void | ) |
Disables the MPU for use.
This function disables the Cortex-M memory protection unit. When the MPU is disabled, the default memory map is used and memory management faults are not generated.
References HWREG, NVIC_MPU_CTRL, and NVIC_MPU_CTRL_ENABLE.
uint32_t MPURegionCountGet | ( | void | ) |
Gets the count of regions supported by the MPU.
This function is used to get the total number of regions that are supported by the MPU, including regions that are already programmed.
References HWREG, NVIC_MPU_TYPE, NVIC_MPU_TYPE_DREGION_M, and NVIC_MPU_TYPE_DREGION_S.
void MPURegionEnable | ( | uint32_t | ui32Region | ) |
Enables a specific region.
ui32Region | is the region number to enable. |
This function is used to enable a memory protection region. The region should already be configured with the MPURegionSet() function. Once enabled, the memory protection rules of the region are applied and access violations cause a memory management fault.
References ASSERT, HWREG, NVIC_MPU_ATTR, NVIC_MPU_ATTR_ENABLE, and NVIC_MPU_NUMBER.
void MPURegionDisable | ( | uint32_t | ui32Region | ) |
Disables a specific region.
ui32Region | is the region number to disable. |
This function is used to disable a previously enabled memory protection region. The region remains configured if it is not overwritten with another call to MPURegionSet(), and can be enabled again by calling MPURegionEnable().
References ASSERT, HWREG, NVIC_MPU_ATTR, NVIC_MPU_ATTR_ENABLE, and NVIC_MPU_NUMBER.
void MPURegionSet | ( | uint32_t | ui32Region, |
uint32_t | ui32Addr, | ||
uint32_t | ui32Flags | ||
) |
Sets up the access rules for a specific region.
ui32Region | is the region number to set up. |
ui32Addr | is the base address of the region. It must be aligned according to the size of the region specified in ui32Flags. |
ui32Flags | is a set of flags to define the attributes of the region. |
This function sets up the protection rules for a region. The region has a base address and a set of attributes including the size. The base address parameter, ui32Addr, must be aligned according to the size, and the size must be a power of 2.
The ui32Flags parameter is the logical OR of all of the attributes of the region. It is a combination of choices for region size, execute permission, read/write permissions, disabled sub-regions, and a flag to determine if the region is enabled.
The size flag determines the size of a region and must be one of the following:
The execute permission flag must be one of the following:
The read/write access permissions are applied separately for the privileged and user modes. The read/write access flags must be one of the following:
The region is automatically divided into 8 equally-sized sub-regions by the MPU. Sub-regions can only be used in regions of size 256 bytes or larger. Any of these 8 sub-regions can be disabled, allowing for creation of ``holes'' in a region which can be left open, or overlaid by another region with different attributes. Any of the 8 sub-regions can be disabled with a logical OR of any of the following flags:
Finally, the region can be initially enabled or disabled with one of the following flags:
As an example, to set a region with the following attributes: size of 32 KB, execution enabled, read-only for both privileged and user, one sub-region disabled, and initially enabled; the ui32Flags parameter would have the following value:
(MPU_RGN_SIZE_32K | MPU_RGN_PERM_EXEC | MPU_RGN_PERM_PRV_RO_USR_RO | MPU_SUB_RGN_DISABLE_2 | MPU_RGN_ENABLE)
References ASSERT, HWREG, NVIC_MPU_ATTR, NVIC_MPU_ATTR_BUFFRABLE, NVIC_MPU_ATTR_CACHEABLE, NVIC_MPU_ATTR_SHAREABLE, NVIC_MPU_ATTR_SIZE_M, NVIC_MPU_ATTR_TEX_M, NVIC_MPU_BASE, and NVIC_MPU_BASE_VALID.
void MPURegionGet | ( | uint32_t | ui32Region, |
uint32_t * | pui32Addr, | ||
uint32_t * | pui32Flags | ||
) |
Gets the current settings for a specific region.
ui32Region | is the region number to get. |
pui32Addr | points to storage for the base address of the region. |
pui32Flags | points to the attribute flags for the region. |
This function retrieves the configuration of a specific region. The meanings and format of the parameters is the same as that of the MPURegionSet() function.
This function can be used to save the configuration of a region for later use with the MPURegionSet() function. The region's enable state is preserved in the attributes that are saved.
References ASSERT, HWREG, NVIC_MPU_ATTR, NVIC_MPU_BASE, NVIC_MPU_BASE_ADDR_M, and NVIC_MPU_NUMBER.
void MPUIntRegister | ( | void(*)(void) | pfnHandler | ) |
Registers an interrupt handler for the memory management fault.
pfnHandler | is a pointer to the function to be called when the memory management fault occurs. |
This function sets and enables the handler to be called when the MPU generates a memory management fault due to a protection region access violation.
References ASSERT, FAULT_MPU, IntEnable(), and IntRegister().
void MPUIntUnregister | ( | void | ) |
Unregisters an interrupt handler for the memory management fault.
This function disables and clears the handler to be called when a memory management fault occurs.
References FAULT_MPU, IntDisable(), and IntUnregister().