Question

I am trying to configure the MPU of lpc1788 to get the entire 4GB space as Executable Region. Following is the code that I have written so far and have managed to see the desired outcomes on keil uVision 4 debugger. I have no experience in assembly language programming of lpc1788. And, yet I have got the results. But What I dont know is whether it is normal that execution goes in hardFault Handler after the execution of the last instruction in the code below? Or I have made some mistake? Any suggestions would be of so much help.

#define MPU_CTRL  0xE000ED94    

__asm int mpu_init(void);  

int main()  
{  
    mpu_init();  
}  

_asm int mpu_init(void)  
{  
  LDR R0, =MPU_CTRL;  
  /* Disable MPU */  
  MOV R1, #0x4;  
  STR R1, [R0, #0x0];  
  MOV R2, #0x0;  
  STR R2, [R0, #0x4];   
  MOV R3, #0x030F;  
  LSL R6, R3, #16;  
  MOV R4, #0xFF3F;  
  STR R6, [R0, #0xC];  
  STRH R4, [R0, #0XC]  
  //MOV R5, #0x0;  
  //STR R5, [R0, #0x8];  
  /* Enable MPU */  
  MOV R1, #0x7;  
  STR R1, [R0, #0x0];    
}  
Was it helpful?

Solution

I think you forgot a return instruction (BX LR) so the execution continues into whatever data happens to be after the function.

I would actually recommend using C to initialize the MPU - less chance of making a mistake, and it's trivial to do using CMSIS headers.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top