AnsweredAssumed Answered

LPC2368 Secondary Bootloader

Question asked by Giovanni Friolo on Feb 9, 2017
Latest reply on Feb 16, 2017 by Giovanni Friolo

Hi,

 

I'm developing a secondary bootloader on LPC2368.

The bootloader at startup initialize stack pointer:

 

....

   LDR     R0, =Top_Stack

 

#  Enter Undefined Instruction Mode and set its Stack Pointer        

 

   MSR   CPSR_c, #Mode_UND|I_Bit|F_Bit
   MOV   SP, R0
   SUB   R0, R0, #UND_Stack_Size

 

#  Enter Abort Mode and set its Stack Pointer

 

   MSR   CPSR_c, #Mode_ABT|I_Bit|F_Bit
   MOV   SP, R0
   SUB   R0, R0, #ABT_Stack_Size

 

#  Enter FIQ Mode and set its Stack Pointer

 

   MSR   CPSR_c, #Mode_FIQ|I_Bit|F_Bit
   MOV   SP, R0
   SUB   R0, R0, #FIQ_Stack_Size

 

#  Enter IRQ Mode and set its Stack Pointer

 

   MSR   CPSR_c, #Mode_IRQ|I_Bit|F_Bit
   MOV   SP, R0
   SUB   R0, R0, #IRQ_Stack_Size

 

#  Enter Supervisor Mode and set its Stack Pointer

 

   MSR   CPSR_c, #Mode_SVC|I_Bit|F_Bit
   MOV   SP, R0
   SUB   R0, R0, #SVC_Stack_Size

 

#  Enter User Mode and set its Stack Pointer

 

   MSR   CPSR_c, #Mode_USR/*|F_Bit                   /* |F_Bit         disabilito fiq */
   MOV   SP, R0

 

#  Setup a default Stack Limit (when compiled with "-mapcs-stack-check")

 

   SUB   SL, SP, #USR_Stack_Size

....

executes some code and then jump to the application code.

The application code also sets stack pointer accordings to its needs during initialization.

I noticed that the User Mode stack pointer is changed properly while the IRQ stack pointer is remained the one setted by the bootloader making the system crash.

The instructions used by the application are similar to the ones used by the bootloader, the only difference is that R0 holds different value.

There is the possibility of changing the IRQ stack pointer the second time?

 

Thank you

Outcomes