MPU Functions

group group_prot_functions_mpu

Functions

cy_en_prot_status_t Cy_Prot_ConfigMpuStruct(PROT_MPU_MPU_STRUCT_Type *base, const cy_stc_mpu_cfg_t *config)

This function configures a memory protection unit (MPU) struct with its protection attributes.

The protection structs act like the gatekeepers for a master’s accesses to memory, allowing only the permitted transactions to go through.

note

This function is applicable for both CPUSS ver_1 and ver_2.

Status

Description

CY_PROT_SUCCESS

The MPU struct was configured.

CY_PROT_FAILURE

Configuration failed due to a protection violation.

Return

Status of the function call.

Function Usage

    {
        /* Scenario: Crypto bus master must not be able access the memory region 
                     0x08000020 ~ 0x080000FF unless it is operating in privileged
                     and secure mode */
        
        cy_stc_mpu_cfg_t mpuCfg = {
            /*.address =*/ (uint32_t *)0x08000000UL,    /* Starting address at start of SRAM */
            /*.regionSize =*/ CY_PROT_SIZE_256B,        /* Protect block of 256 Bytes */
            /*.subregions =*/ CY_PROT_SUBREGION_DIS0,   /* Disable protection for first 32 (256/8) Bytes */
            /*.userPermission =*/ CY_PROT_PERM_DISABLED,/* Disallow all user mode accesses */
            /*.privPermission =*/ CY_PROT_PERM_RWX,     /* Allow all privileged mode accesses */
            /*.secure =*/ true                          /* Require the bus master to have "secure" attribute */
        };
        
        /* Configure the Crypto (CPUSS_MS_ID_CRYPTO = 1) MPU struct #0 */
        if(CY_PROT_SUCCESS != Cy_Prot_ConfigMpuStruct(PROT_MPU1_MPU_STRUCT0, &mpuCfg))
        {
            /* Insert error handling */
        }
        else
        {
            /* Enable the Crypto MPU struct #0 */
            if(CY_PROT_SUCCESS != Cy_Prot_EnableMpuStruct(PROT_MPU1_MPU_STRUCT0))
            {
                /* Insert error handling */
            }
        }
    }

Parameters
  • base: The base address for the MPU struct being configured.

  • config: Initialization structure containing all the protection attributes.

cy_en_prot_status_t Cy_Prot_EnableMpuStruct(PROT_MPU_MPU_STRUCT_Type *base)

Enables the MPU struct, which allows the MPU protection attributes to take effect.

note

This function is applicable for both CPUSS ver_1 and ver_2.

Status

Description

CY_PROT_SUCCESS

The MPU struct was enabled.

CY_PROT_FAILURE

The MPU struct is disabled and possibly locked.

Return

Status of the function call.

Function Usage


    /* Scenario: PROT_MPU1_MPU_STRUCT0 is configured to protect a resource and
                 needs to be enabled. */

    if(CY_PROT_SUCCESS != Cy_Prot_EnableMpuStruct(PROT_MPU1_MPU_STRUCT0))
    {
        /* Insert error handling */
    }

Parameters
  • base: The base address of the MPU struct being configured.

cy_en_prot_status_t Cy_Prot_DisableMpuStruct(PROT_MPU_MPU_STRUCT_Type *base)

Disables the MPU struct, which prevents the MPU protection attributes from taking effect.

note

This function is applicable for both CPUSS ver_1 and ver_2.

Status

Description

CY_PROT_SUCCESS

The MPU struct was disabled.

CY_PROT_FAILURE

The MPU struct is enabled and possibly locked.

Return

Status of the function call.

Function Usage

    
    /* Scenario: PROT_MPU1_MPU_STRUCT0 needs to be disabled. Or it needs to be
                 reconfigured and hence must first be disabled. */
    
    if(CY_PROT_SUCCESS != Cy_Prot_DisableMpuStruct(PROT_MPU1_MPU_STRUCT0))
    {
        /* Insert error handling */
    }

Parameters
  • base: The base address of the MPU struct being configured.