freeRTOS hangs on bx r14 only during debug mode

mamarina wrote on Tuesday, October 27, 2015:

freertos hangs during execution of prvPortStartFirstTask. Specifically, it hangs during the svc handler, when it tries to jump to r14 (via bx r14). r14 before the jump contains 0xFFFF FFFD. I am using lpc1768, with gcc on eclipse.
This only happens on debug, and runs fine otherwise (i have 2 tasks running). i am suspecting it has something to do with my debug configurations (ie startup commands), but I have no idea how to fix it. any pointer is appreciated.

rtel wrote on Tuesday, October 27, 2015:

It is most likely something to do with the interrupt vector table. See the red text in FAQ 1 on this page:

Is it possible that the debugger is running a scrip that changes the vector table base address, but when you run without the debugger the change doesn’t happen?

mamarina wrote on Wednesday, October 28, 2015:

hi. thanks for the pointers. but still cant get it to work.
i have the 3 interrupt vectors mentioned on the faq. They’re defined in the freertosconfig.h

I am running from flash, so I didnt relocate the vector table to somewhere else.
i have these lines in my startup:

monitor writeu32 0xE000ED08 = 0x00000000
monitor reg r13 = (0x00000000)
monitor reg pc = (0x00000004)

any more idea?


davedoors wrote on Wednesday, October 28, 2015:

0xFFFF FFFD is the return code, not the address it is returning too, and looks right. The address it returns to comes off the stack. The return code just tells the LPC the state being returned too.

mamarina wrote on Thursday, October 29, 2015:

Hi Dave, thanks for replying…
But I thought that bx r14 would cause the processor to jump to the address in r14, which in this case is 0xFFFF …
The arm website says so…
Or did i misunderstood something?

Anyway, here is the full function:

	__asm volatile (
					"	ldr	r3, pxCurrentTCBConst2		\n" /* Restore the context. */
					"	ldr r1, [r3]					\n" /* Use pxCurrentTCBConst to get the pxCurrentTCB address. */
					"	ldr r0, [r1]					\n" /* The first item in pxCurrentTCB is the task top of stack. */
					"	ldmia r0!, {r4-r11}				\n" /* Pop the registers that are not automatically saved on exception entry and the critical nesting count. */
					"	msr psp, r0						\n" /* Restore the task stack pointer. */
					"	isb								\n"
					"	mov r0, #0 						\n"
					"	msr	basepri, r0					\n"
					"	orr r14, #0xd					\n"
					"	bx r14							\n"
					"									\n"
					"	.align 2						\n"
					"pxCurrentTCBConst2: .word pxCurrentTCB				\n"

I checked that the r3 (at the beginning of the function) points to 1000 xxxx, so that looks correct since thats where my stack is. Any other pointers how I can debug this?

rtel wrote on Thursday, October 29, 2015:

See the bottom of the following page: