Tiva Driver Lib
Functions
Mpu_api

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)
 

Detailed Description

Function Documentation

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.

Returns
None.
void MPUEnable ( uint32_t  ui32MPUConfig)

Enables and configures the MPU for use.

Parameters
ui32MPUConfigis 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:

  • MPU_CONFIG_PRIV_DEFAULT enables the default memory map when in privileged mode and when no other regions are defined. If this option is not enabled, then there must be at least one valid region already defined when the MPU is enabled.
  • MPU_CONFIG_HARDFLT_NMI enables the MPU while in a hard fault or NMI exception handler. If this option is not enabled, then the MPU is disabled while in one of these exception handlers and the default memory map is applied.
  • MPU_CONFIG_NONE chooses none of the above options. In this case, no default memory map is provided in privileged mode, and the MPU is not enabled in the fault handlers.
Returns
None.
void MPUIntRegister ( void(*)(void)  pfnHandler)

Registers an interrupt handler for the memory management fault.

Parameters
pfnHandleris 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.

See also
IntRegister() for important information about registering interrupt handlers.
Returns
None.
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.

See also
IntRegister() for important information about registering interrupt handlers.
Returns
None.
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.

Returns
The number of memory protection regions that are available for programming using MPURegionSet().
void MPURegionDisable ( uint32_t  ui32Region)

Disables a specific region.

Parameters
ui32Regionis 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().

Returns
None.
void MPURegionEnable ( uint32_t  ui32Region)

Enables a specific region.

Parameters
ui32Regionis 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.

Returns
None.
void MPURegionGet ( uint32_t  ui32Region,
uint32_t *  pui32Addr,
uint32_t *  pui32Flags 
)

Gets the current settings for a specific region.

Parameters
ui32Regionis the region number to get.
pui32Addrpoints to storage for the base address of the region.
pui32Flagspoints 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.

Returns
None.
void MPURegionSet ( uint32_t  ui32Region,
uint32_t  ui32Addr,
uint32_t  ui32Flags 
)

Sets up the access rules for a specific region.

Parameters
ui32Regionis the region number to set up.
ui32Addris the base address of the region. It must be aligned according to the size of the region specified in ui32Flags.
ui32Flagsis 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:

  • MPU_RGN_SIZE_32B
  • MPU_RGN_SIZE_64B
  • MPU_RGN_SIZE_128B
  • MPU_RGN_SIZE_256B
  • MPU_RGN_SIZE_512B
  • MPU_RGN_SIZE_1K
  • MPU_RGN_SIZE_2K
  • MPU_RGN_SIZE_4K
  • MPU_RGN_SIZE_8K
  • MPU_RGN_SIZE_16K
  • MPU_RGN_SIZE_32K
  • MPU_RGN_SIZE_64K
  • MPU_RGN_SIZE_128K
  • MPU_RGN_SIZE_256K
  • MPU_RGN_SIZE_512K
  • MPU_RGN_SIZE_1M
  • MPU_RGN_SIZE_2M
  • MPU_RGN_SIZE_4M
  • MPU_RGN_SIZE_8M
  • MPU_RGN_SIZE_16M
  • MPU_RGN_SIZE_32M
  • MPU_RGN_SIZE_64M
  • MPU_RGN_SIZE_128M
  • MPU_RGN_SIZE_256M
  • MPU_RGN_SIZE_512M
  • MPU_RGN_SIZE_1G
  • MPU_RGN_SIZE_2G
  • MPU_RGN_SIZE_4G

The execute permission flag must be one of the following:

  • MPU_RGN_PERM_EXEC enables the region for execution of code
  • MPU_RGN_PERM_NOEXEC disables the region for execution of code

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:

  • MPU_RGN_PERM_PRV_NO_USR_NO - no access in privileged or user mode
  • MPU_RGN_PERM_PRV_RW_USR_NO - privileged read/write, user no access
  • MPU_RGN_PERM_PRV_RW_USR_RO - privileged read/write, user read-only
  • MPU_RGN_PERM_PRV_RW_USR_RW - privileged read/write, user read/write
  • MPU_RGN_PERM_PRV_RO_USR_NO - privileged read-only, user no access
  • MPU_RGN_PERM_PRV_RO_USR_RO - privileged read-only, user read-only

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:

  • MPU_SUB_RGN_DISABLE_0
  • MPU_SUB_RGN_DISABLE_1
  • MPU_SUB_RGN_DISABLE_2
  • MPU_SUB_RGN_DISABLE_3
  • MPU_SUB_RGN_DISABLE_4
  • MPU_SUB_RGN_DISABLE_5
  • MPU_SUB_RGN_DISABLE_6
  • MPU_SUB_RGN_DISABLE_7

Finally, the region can be initially enabled or disabled with one of the following flags:

  • MPU_RGN_ENABLE
  • MPU_RGN_DISABLE

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)

Note
This function writes to multiple registers and is not protected from interrupts. It is possible that an interrupt which accesses a region may occur while that region is in the process of being changed. The safest way to handle this is to disable a region before changing it. Refer to the discussion of this in the API Detailed Description section.
Returns
None.