paul20 wrote on Monday, January 14, 2008:
Hello,
I’ve been working with FreeRTOS in ARM mode successfully for a while
but Thumb mode always crahes when portRESTORE_CONTEXT() is called
in vPortISRStartFirstTask() to start the scheduler:
Disassembly (portISR.c compiled in ARM mode)
portRESTORE_CONTEXT()
…
ldr r0, [pc, #684] ; 0x780
ldr r0, [r0]
ldr lr, [r0]
ldr r0, [pc, #676] ; 0x784
ldm lr!, {r1}
str r1, [r0]
ldm lr!, {r0}
msr SPSR_fc, r0
// it crashed on the next line with "data abort exception"
ldm lr, {r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, sp, lr}^
nop (mov r0,r0)
ldr lr, [lr, #60]
subs pc, lr, #4 ; 0x4
…
At the point of the crash:
lr=0x40000a20
pxCurrentTCB->pxTopOfStack = 0x40000a18
pxCurrentTCB->pxStack = 0x400003a0
#define portRESTORE_CONTEXT()
…
/* Set the LR to the task stack. */
LDR R0, =pxCurrentTCB
LDR R0, [R0]
LDR LR, [R0]
/* The critical nesting depth is the first item on the stack. */
/* Load it into the ulCriticalNesting variable. */
LDR R0, =ulCriticalNesting
LDMFD LR!, {R1}
STR R1, [R0]
/* Get the SPSR from the stack. */
LDMFD LR!, {R0}
MSR SPSR, R0
/* Restore all system mode registers for the task. */
LDMFD LR, {R0-R14}^
NOP
/* Restore the return address. */
LDR LR, [LR, #+60]
/* And return - correcting the offset in the LR to obtain the */
/* correct address. */
SUBS PC, LR, #4
…
MCU: LPC2148
FreeRTOS: 4.7.0
GCC: 4.2.2
Source/portable/GCC/ARM7_LPC2000/portISR.c
arm-elf-gcc -c -mtune=arm7tdmi-s -mthumb-interwork -I. -gstabs -DRUN_FROM_ROM -DGCC_ARM7
-DYES -D__WinARM__ -DTHUMB_INTERWORK -O0 -Wall -Wextra -Wimplicit -Wpointer-arith -Wswitch
-Wredundant-decls -Wreturn-type -Wshadow -Wunused -Wbad-function-cast -Wsign-compare
-Waggregate-return -fno-strict-aliasing -Wa,-adhlns=Source/portable/GCC/ARM7_LPC2000/portISR.lst
-ISource/include -ISource/portable/GCC/ARM7_LPC2000 -MD -MP -MF .dep/portISR.o.d -std=gnu99
Any ideas?