MPU on nRF52832

Hi,

We are developing on a nRF52832 MCU and we tried to enable MPU on the whole RAM region (addr: 0x20000000, size : 0x10000)
But when we create a new MPU region around the RAM with the function nrf_mpu_lib_region_create(), it triggers an Hard Fault error
in the CRITICAL_REGION_EXIT(), inside the nrf_mpu_lib_region_create() function.

Is it possible to activate MPU on whole RAM ? Can you help me to enable the MPU step by step on the whole RAM using nrf_mpu_lib_region_create?

Best regards,

Parents
  • Hi Thomas,

    I am not sure which SDK version you are using and which tools you use to build your project.

    I am giving you a generic reply and few steps how to do this., it is possible to activate the Memory Protection Unit (MPU) on the whole RAM. Here are the steps to do it using the `nrf_mpu_lib_region_create()` function:

    1. First, you need to initialize the MPU and its driver using the `nrf_mpu_lib_init()` function. This function returns `NRF_SUCCESS` on success, otherwise, it returns an error code.

    ret_code_t status = nrf_mpu_lib_init();

    ```

    2. After initializing the MPU, you can create a new MPU region using the `nrf_mpu_lib_region_create()` function. This function takes four parameters: a pointer to an `nrf_mpu_lib_region_t` variable, a pointer to the base address of the region, the size of the region, and the attributes of the region.

    nrf_mpu_lib_region_t region;
    uint32_t attributes = (0x05 << MPU_RASR_TEX_Pos) | (1 << MPU_RASR_B_Pos) | (0x07 << MPU_RASR_AP_Pos) | (1 << MPU_RASR_XN_Pos);
    ret_code_t status = nrf_mpu_lib_region_create(&region, (void *)0x20000000, 0x10000, attributes);

    3. If you want to remove the protection and release the region, you can destroy the MPU region using the `nrf_mpu_lib_region_destroy()` function.

    ret_code_t status = nrf_mpu_lib_region_destroy(region);

    Please note that the `nrf_mpu_lib_region_create()` function returns `NRF_SUCCESS` on success, otherwise, it returns an error code. If you are getting a Hard Fault error, it might be due to incorrect parameters or conflicts with other parts of your code.

  • Hi Susheel,

    Thanks for you reply,

    The problem came from the attributes we put on the creation of the region : we only put (1 << MPU_RASR_XN_Pos) as attribute, and it misses the others attributes to work as it should be.

    We succeeded to protect the whole RAM by creating 2 different regions (RAM can be accessed by 2 different ranges of addresses : 0x2000 0000 and 0x0080 0000).

    Thanks

    I close this ticket (resolved)

  • Thomas, Thanks for letting us know the reason for this behavior. Very helpful :)

Reply Children
No Data
Related