cancel
Showing results for 
Search instead for 
Did you mean: 

bootloader + user mode -> problem

jkl
Associate II
Posted on February 14, 2008 at 07:13

bootloader + user mode -> problem

3 REPLIES 3
jkl
Associate II
Posted on May 17, 2011 at 09:47

Setup:

-Compiler = Keil

-Bootbank = bank1, main-code = bank0

-Using ST library and startup files (str91x.s)

Problem:

When jumping to main-code the processor is in user-mode, consequently the str91x.s startup code in main bank (bank0) is not allowed to change processor mode (only allowed with SWI). This means that the stack pointer is only updated for user-mode and the other modes (IRQ, SYS, etc.) are kept as in the bootloader code.

Thus when jumping to the interrupt handler the stack pointer is wrong and may overwrite some program variables or RAM code (and strange stuff happens).

My solution:

Remove the line in str91x.s of the bootbank where the user-mode is selected.

; Enter User Mode and set its Stack Pointer

 

; MSR CPSR_c, #Mode_USR

Has anyone else experienced this problem or is it just me doing something wrong??

Posted on May 17, 2011 at 09:47

In user mode is it not possible to modify some register, like the others stack pointers: if you try to access to a protected register like stacks

the processor cause an exception.

In any case pay attention to the following thing:

if you perform a manual reset or a watchdog reset, for a bug in the silicon

the ''not boot bank'' (in your case the bank0) is disabled and the program jump to a wrong location.

lodedeschepper
Associate II
Posted on May 17, 2011 at 09:47

hsa_jak,

Did you find a solution for this problem?

I'm using the same configuration but the startupcode from the bootloader (boot bank = bank1) AND from the main program (bank 0) doesn't update the other modes. Only USR mode is set up...

When my main program is running from bank 0 and bank 0 is the bootbank (The startupcode is not the same as starting after boot). Every mode is set up in the right way...

Is is possible that the cpsr register protected?

The code beneath is used in the startupcode in Bootloader and mainprogram:

// Setup Stack for each mode

LDR R0, =Stack_Top

// 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

MOV SP, R0

SUB SL, SP, USR_Stack_Size

Beste Regards,

LouisKatorz