This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

MPU is not triggering MemFault or HardFault

MPU is not triggering MemManage fault. I want to protect a memory region of 64 bytes starting from 0x20000000. I've configured the MPU registers accordingly, but when I write in a protected memory location, MPU does not trigger fault.

Here's a code that demonstrate the problem,

#define MPU_CTRL  (*((volatile unsigned long*) 0xE000ED94))
#define MPU_RNR   (*((volatile unsigned long*) 0xE000ED98))
#define MPU_RBAR (*((volatile unsigned long*) 0xE000ED9C))
#define MPU_RASR (*((volatile unsigned long*) 0xE000EDA0))

#define SCB_SHCSR (*((volatile unsigned long*) 0xE000ED24))        //System handler control and state register


void Registers_Init(void)
{
    //MPU Configuring    

    MPU_RNR = 0x00000000;                // region in 0.
    MPU_RBAR = 0x20000000;              // base address is 0x20000000.
    MPU_RASR = 0x1608FF0B;             // 64 bytes, ro/ro, b=s=c=0 
    SCB_SHCSR |= 0x00010000;           // enable MemManage Fault
   

    MPU_CTRL = 0x00000005;              // enable memory protection unit,guaranteeing default priviliged access
}

void MemManage_Handler(void) 
{

    __asm(
        "MOV R4, 0x77777777\n\t"
        "MOV R5, 0x77777777\n\t"
    );
}

void HardFault_Handler(void)
{
    __asm(
        "MOV R6, 0x77777777\n\t"
        "MOV R7, 0x77777777\n\t"
    );
}


int main(void)
{
    Registers_Init();

    while(1)
    {
        __asm(
            "LDR R0, =0x20000000\n\t"
            "MOV R1, 0x77777777\n\t"
            "STR R1, [R5,#0]"
        );
    }
    return (1);
}

void SystemInit(void)
{
}

So, in main function I am writing in a memory location protected by mpu. But instead of generating MemManage fault or even HardFault, it writes successfully.

Why is that?

Parents Reply Children
No data