Search code examples
exceptioncortex-marm-mpu

How to generate memory management fault in cortex m3 based microcontroller


I'm an engineering student and currently studying cortex m3 processor and it's exception handling model. I have generated and tested usage fault, bus fault, hard fault with their corresponding fault handlers.

But I don't know how to generate memory management fault (without using a configured MPU)?

Is there any other way to generate memory management fault?


Solution

  • To quote the Architecture Reference Manual (emphasis mine):

    The MemManage fault handles memory protection faults that are determined by the Memory Protection Unit or by fixed memory protection constraints, for both instruction and data memory transactions.

    In other words, if you don't want to program the MPU, you're going to have to look for one of those fixed constraints, and the obvious place to start looking is the memory map. Execute Never sounds like a constraint to me, and sure enough, whilst the Cortex-M3 TRM is a bit vague ("a fault exception"), the architecture says:

    XN indicates an Execute Never region. Any attempt to execute code from an XN region faults, generating a MemManage exception.

    There we go. Looks like the easiest way is to simply branch into the System region (0xE0000000 - 0xFFFFFFFF) since that is always XN regardless of MPU configuration.