Return from MemManageFault

Hi everyone, 

There was a post of this question here: Returning from MemFault - Architectures and Processors forum - Support forums - Arm Community
But I don't see any reply on this post and it has been locked

I cannot find any document or guideline about how to return from MemManageFault exception on Cortex-M4

I am using the stm32f4 (cortex m4), trying to set up a read-only region, enable MemManageFault and MPU, write to the read-only region

The MemManageFault is triggered:
    + MMFAR register update to the accessed address
    + CFSR.MemManage (MMFSR)  = 0x82

Everything is good but then I cannot return from the MemManageFault, the CPU constantly gets back to the write instruction which caused the error and the MemManageFault exception handler.

As the ARMv7-M Architecture RM states: write a one to a register bit to clear the corresponding fault.

I try to return from MemManageFault by clearing the error (write 0x84 to CFSR.MemManage (MMFSR) and clear the error address MMFAR. but it seems like the two registers are not cleared. then the exception re-trigger again and again.

In addition, I know we can back up the error information somewhere (for example non-volatile memory), then trigger a system reset. after system reset, the error is cleared.

My question is how to clear the MemManage error, and return from the exception to continue other instructions after the fault without reset the system.

I am really appreciate any reply. Thanks

Parents Reply Children
  • Hi  

    Thank you for your answer. Refer to the KBA, I understand how to handle the MemManageFault.

    I would like to summary the answer here for anyone who has the same question.

    -> ARMv7-M Architecture RM states: write a one to a register bit to clear the corresponding fault.

    This is correct, after clear the fault, the exception return to the instruction which caused the fault. this causes instruction to be fetched and executed again
    1. If the MemManageFault Handler resolved the fault, (the address able to access) then the execution flow normal
    2. If the MemManageFault Handler does nothing but only clear the error, the instruction causes the fault again, then the MemManageFault is triggered again and again

    The KBA guides how to skip the instruction which causes the fault, by determine stack pointer, get return address of the exception (the address of the instruction cause the fault) on the stack frame, then check if it was 16bit or 32bit instruction, skip the instruction by increase return address on the stack frame by 2 or 4 respectively. on Exception return, the CPU auto unstacking, return address (has been increased) will be placed in the PC and the fault instruction is skip