CM-MPU Module¶
This device has dedicated MPU for each bus-master for access protection. The Cortex-M4 comes with in-built MPU and has a separate driver. The CMMPU has been added for other AHB bus masters such as uDMA(DMPU) & Ethernet(EMPU). Access permission for each region is programmable. CM-MPU supports following protections: Read only; Full access where both Read and Write access is allowed; and No access where Read and Write access is not allowed.
CM-MPU supports 8 regions with programmable start address & size. Start address of a region must be aligned to its size. Min size of the region is limited to 1KB to optimize address decode logic, 1KB granularity should suffice requirements on uDMA and EtherNET DMA.
Regions can overlap, when regions are overlapped, a fixed priority scheme is used to resolve the access protections. Region-7 is highest priority and region-0 is lowest priority. This feature is useful to define different set of access permissions for a part of already defined bigger region. This feature can be used to work around any limitations with any aligned start address to its size.
There are 8 sub-regions for every region. Sub-regions are useful to protect memory regions smaller than 2^N KB size with fewer numbers of regions. E.g., defining protection for 6K region can be achieved with single region otherwise 3 regions would be needed.
-
group
cmmpu_api Defines
-
CMMPU_ACC_VIO_KEY0xA5A50000U¶ Key for ACC VIO Registers.
-
CMMPU_ACC_VIO_FLAGS_READCMMPU_ACC_VIO_FLAGS_RD¶ Read Violation.
-
CMMPU_ACC_VIO_FLAGS_WRITECMMPU_ACC_VIO_FLAGS_WR¶ Write Violation.
-
CMMPU_RGN_00x0U¶ Select uDMA/EMAC MPU Region 0.
-
CMMPU_RGN_10x1U¶ Select uDMA/EMAC MPU Region 1.
-
CMMPU_RGN_20x2U¶ Select uDMA/EMAC MPU Region 2.
-
CMMPU_RGN_30x3U¶ Select uDMA/EMAC MPU Region 3.
-
CMMPU_RGN_40x4U¶ Select uDMA/EMAC MPU Region 4.
-
CMMPU_RGN_50x5U¶ Select uDMA/EMAC MPU Region 5.
-
CMMPU_RGN_60x6U¶ Select uDMA/EMAC MPU Region 6.
-
CMMPU_RGN_70x7U¶ Select uDMA/EMAC MPU Region 7.
-
CMMPU_RGN_ENABLE0x1U¶ Enable MPU Region.
-
CMMPU_RGN_DISABLE0x0U¶ Disable MPU Region.
-
CMMPU_RGN_PERM_READ_ONLY0x00U¶ Read Only Access.
-
CMMPU_RGN_PERM_NO_ACCESS0x20U¶ No Access(R/W)
-
CMMPU_RGN_PERM_FULL_ACCESS0x10U¶ Full Access(R/W)
-
CMMPU_RGN_SIZE_1K(0x0U << 8U)¶ Region Size is 1K-bytes.
-
CMMPU_RGN_SIZE_2K(0x1U << 8U)¶ Region Size is 2K-bytes.
-
CMMPU_RGN_SIZE_4K(0x2U << 8U)¶ Region Size is 4K-bytes.
-
CMMPU_RGN_SIZE_8K(0x3U << 8U)¶ Region Size is 8K-bytes.
-
CMMPU_RGN_SIZE_16K(0x4U << 8U)¶ Region Size is 16K-bytes.
-
CMMPU_RGN_SIZE_32K(0x5U << 8U)¶ Region Size is 32K-bytes.
-
CMMPU_RGN_SIZE_64K(0x6U << 8U)¶ Region Size is 64K-bytes.
-
CMMPU_RGN_SIZE_128K(0x7U << 8U)¶ Region Size is 128K-bytes.
-
CMMPU_RGN_SIZE_256K(0x8U << 8U)¶ Region Size is 256K-bytes.
-
CMMPU_RGN_SIZE_512K(0x9U << 8U)¶ Region Size is 512K-bytes.
-
CMMPU_RGN_SIZE_1M(0xAU << 8U)¶ Region Size is 1M-bytes.
-
CMMPU_RGN_SIZE_2M(0xBU << 8U)¶ Region Size is 2M-bytes.
-
CMMPU_RGN_SIZE_4M(0xCU << 8U)¶ Region Size is 4M-bytes.
-
CMMPU_RGN_SIZE_8M(0xDU << 8U)¶ Region Size is 8M-bytes.
-
CMMPU_RGN_SIZE_16M(0xEU << 8U)¶ Region Size is 16M-bytes.
-
CMMPU_RGN_SIZE_32M(0xFU << 8U)¶ Region Size is 32M-bytes.
-
CMMPU_RGN_SIZE_64M(0x10U << 8U)¶ Region Size is 64M-bytes.
-
CMMPU_RGN_SIZE_128M(0x11U << 8U)¶ Region Size is 128M-bytes.
-
CMMPU_RGN_SIZE_256M(0x12U << 8U)¶ Region Size is 256M-bytes.
-
CMMPU_RGN_SIZE_512M(0x13U << 8U)¶ Region Size is 512M-bytes.
-
CMMPU_RGN_SIZE_1G(0x14U << 8U)¶ Region Size is 1G-bytes.
-
CMMPU_RGN_SIZE_2G(0x15U << 8U)¶ Region Size is 2G-bytes.
-
CMMPU_RGN_SIZE_4G(0x16U << 8U)¶ Region Size is 4G-bytes.
-
CMMPU_SUB_RGN_DISABLE_00x00010000U¶ Disable sub-region 0.
-
CMMPU_SUB_RGN_DISABLE_10x00020000U¶ Disable sub-region 1.
-
CMMPU_SUB_RGN_DISABLE_20x00040000U¶ Disable sub-region 2.
-
CMMPU_SUB_RGN_DISABLE_30x00080000U¶ Disable sub-region 3.
-
CMMPU_SUB_RGN_DISABLE_40x00100000U¶ Disable sub-region 4.
-
CMMPU_SUB_RGN_DISABLE_50x00200000U¶ Disable sub-region 5.
-
CMMPU_SUB_RGN_DISABLE_60x00400000U¶ Disable sub-region 6.
-
CMMPU_SUB_RGN_DISABLE_70x00800000U¶ Disable sub-region 7.
-
CMMPU_RGN_CONFIG_M((uint32_t)CMMPU_REGION0_CONFIG_ENABLE| \
(uint32_t)
CMMPU_REGION0_CONFIG_PROT_TYPE_M| \
(uint32_t)
CMMPU_REGION0_CONFIG_SIZE_M| \
(uint32_t)0xFF0000U)
¶
Functions
-
void
CMMPU_enable(uint32_t base)¶ Enables and configures the MPU for use.
This function enables either the DMA or EMAC memory protection unit. Prior to enabling the MPU, at least one region must be set by calling
CMMPU_setRegionAttributes(). Once the MPU is enabled, access violation interrupts are generated if enabled.- Parameters
base: is the base address of the MPU instance used.
- Return
None.
-
void
CMMPU_disable(uint32_t base)¶ Disables the MPU for use.
This function disables either the DMA or EMAC memory protection unit. When the MPU is disabled, the default memory map is used and access violation interrupts are not generated.
- Parameters
base: is the base address of the MPU instance used.
- Return
None.
-
void
CMMPU_enableAccessViolationInterrupt(uint32_t base)¶ Enables the MPU RD/WR Access Violation Interrupts.
This function enables either the DMA or EMAC MPU read/write access violation interrupts.
- Parameters
base: is the base address of the MPU instance used.
- Return
None.
-
void
CMMPU_disableAccessViolationInterrupt(uint32_t base)¶ Disables the MPU RD/WR Access Violation Interrupts.
This function enables either the DMA or EMAC MPU read/write access violation interrupts.
- Parameters
base: is the base address of the MPU instance used.
- Return
None.
-
uint32_t
CMMPU_getAccessViolationFlags(uint32_t base)¶ Gets the status of MPU RD/WR Access Violation Interrupts.
This function return the status of either the DMA or EMAC MPU read/write access violation interrupts.
- Parameters
base: is the base address of the MPU instance used.
- Return
Returns the access violation interrupt status. It can return following values: CMMPU_ACC_VIO_FLAGS_READ, CMMPU_ACC_VIO_FLAGS_WRITE
-
void
CMMPU_setAccessViolationFlags(uint32_t base, uint32_t flags)¶ Sets the MPU RD/WR Access Violation Interrupts.
This function sets either the DMA or EMAC MPU read/write access violation interrupts. The parameter
flags can take following values: CMMPU_ACC_VIO_FLAGS_READ, or CMMPU_ACC_VIO_FLAGS_WRITE.- Parameters
base: is the base address of the MPU instance used.flags: is the flag for rd/wr violation.
- Return
None.
-
void
CMMPU_clearAccessViolationFlags(uint32_t base, uint32_t flags)¶ Clears the MPU RD/WR Access Violation Interrupt Status.
This function clears either the DMA or EMAC MPU read/write access violation interrupt status.The parameter
flags can take following values: CMMPU_ACC_VIO_FLAGS_READ, or CMMPU_ACC_VIO_FLAGS_WRITE.- Parameters
base: is the base address of the MPU instance used.flags: is the flag for rd/wr violation.
- Return
None.
-
uint32_t
CMMPU_getAccessViolationAddr(uint32_t base)¶ Gets the MPU RD/WR Access Violation Address.
This function enables either the DMA or EMAC MPU read/write access violation interrupts.
- Parameters
base: is the base address of the MPU instance used.
- Return
Returns the MPU RD/WR access violation address.
-
void
CMMPU_setRegionAttributes(uint32_t base, uint32_t regionNum, uint32_t baseAddr, uint32_t attrFlags)¶ Sets up the access rules for a specific 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.
- Parameters
base: is the base address of the MPU instance used.regionNum: is the region number to set up.baseAddr: is the base address of the region. It must be aligned according to the size of the region specified in attrFlags.attrFlags: is a set of flags to define the attributes of the region.
The region number parameter, regionNum specifies region number to setup. Valid values for regionNum paramter are:
CMMPU_RGN_0
CMMPU_RGN_1
CMMPU_RGN_2
CMMPU_RGN_3
CMMPU_RGN_4
CMMPU_RGN_5
CMMPU_RGN_6
CMMPU_RGN_7
The base address parameter, baseAddr, must be aligned according to the size, and the size must be a power of 2.
The attrFlags parameter is the logical OR of all of the attributes of the region. It is a combination of choices for region size, 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:
CMMPU_RGN_SIZE_1K
CMMPU_RGN_SIZE_2K
CMMPU_RGN_SIZE_4K
CMMPU_RGN_SIZE_8K
CMMPU_RGN_SIZE_16K
CMMPU_RGN_SIZE_32K
CMMPU_RGN_SIZE_64K
CMMPU_RGN_SIZE_128K
CMMPU_RGN_SIZE_256K
CMMPU_RGN_SIZE_512K
CMMPU_RGN_SIZE_1M
CMMPU_RGN_SIZE_2M
CMMPU_RGN_SIZE_4M
CMMPU_RGN_SIZE_8M
CMMPU_RGN_SIZE_16M
CMMPU_RGN_SIZE_32M
CMMPU_RGN_SIZE_64M
CMMPU_RGN_SIZE_128M
CMMPU_RGN_SIZE_256M
CMMPU_RGN_SIZE_512M
CMMPU_RGN_SIZE_1G
CMMPU_RGN_SIZE_2G
CMMPU_RGN_SIZE_4G
The read/write access permission flag must be one of the following:
CMMPU_RGN_PERM_READ_ONLY- read only permission to MPU region
CMMPU_RGN_PERM_NO_ACCESS- disables read/write permission to MPU region
CMMPU_RGN_PERM_FULL_ACCESS- read/write permission to MPU region
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:
CMMPU_SUB_RGN_DISABLE_0
CMMPU_SUB_RGN_DISABLE_1
CMMPU_SUB_RGN_DISABLE_2
CMMPU_SUB_RGN_DISABLE_3
CMMPU_SUB_RGN_DISABLE_4
CMMPU_SUB_RGN_DISABLE_5
CMMPU_SUB_RGN_DISABLE_6
CMMPU_SUB_RGN_DISABLE_7
Finally, the region can be initially enabled or disabled with one of the following flags:
CMMPU_RGN_ENABLE
CMMPU_RGN_DISABLE
As an example, to set a region with the following attributes: size of 32 KB, read-only access, one sub-region disabled, and initially enabled, the attrFlags parameter would have the following value:
(CMMPU_RGN_SIZE_32K | CMMPU_RGN_PERM_READ_ONLY | CMMPU_SUB_RGN_DISABLE_2 | CMMPU_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.
- Return
None.
-
void
CMMPU_getRegionAttributes(uint32_t base, uint32_t regionNum, uint32_t *baseAddr, uint32_t *attrFlags)¶ Gets the current settings for a specific region.
This function retrieves the configuration of a specific region. The meanings and format of the parameters is the same as that of the
CMMPU_setRegionAttributes() function.- Parameters
base: is the base address of the MPU instance used.regionNum: is the region number to get.baseAddr: points to storage for the base address of the region.attrFlags: points to the attribute flags for the region.
This function can be used to save the configuration of a region for later use with the CMMPU_setRegionAttributes() function. The region’s enable state is preserved in the attributes that are saved.
- Return
None.
-
void
CMMPU_enableRegion(uint32_t base, uint32_t regionNum)¶ Enables a specific region.
This function is used to enable a memory protection region. The region should already be configured with the
CMMPU_setRegionAttributes() function. Once enabled, the memory protection rules of the region are applied and access violations cause a bus fault.- Parameters
base: is the base address of the MPU instance used.regionNum: is the region number to enable.
- Return
None.
-
void
CMMPU_disableRegion(uint32_t base, uint32_t regionNum)¶ Disables a specific region.
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
CMMPU_setRegionAttributes(), and can be enabled again by calling CMMPU_enableRegion().- Parameters
base: is the base address of the MPU instance used.regionNum: is the region number to disable.
- Return
None.
-
void
CMMPU_registerHandler(uint32_t intNum, void (*fnHandler)(void))¶ Registers an interrupt handler for the memory management fault.
This function sets and enables the handler to be called when the MPU generates a bus fault due to a protection region access violation.
- Parameters
intNum: is the interrupt number to be registered.fnHandler: is a pointer to the function to be called when the memory management fault occurs.
- See
Interrupt_registerHandler() for important information about registering interrupt handlers.
- Return
None.
-
void
CMMPU_unregisterHandler(uint32_t intNum)¶ 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.
- Parameters
intNum: is the interrupt number to be unregistered.
- See
Interrupt_registerHandler() for important information about registering interrupt handlers.
- Return
None.
-
APIs are available to set/get CM-MPU region attributes, enable/disable CM-MPU regions, enable/disable CM-MPU and register/unregister interrupt handler for CM-MPU access violation faults.
The code for this module is contained in driverlib_cm/cmmpu.c and driverlib_cm/cmmpu.h.