Context switching problem

jorick23 wrote on Tuesday, March 27, 2007:

I’m developing a test application under ARM9 (STR912F) with 2 tasks controlling the UART.  Initialization seems to run smoothly until the first task switch occurs.  In the portRESTORE_CONTEXT macro (in ISR_Support.h), the instruction “LDMFD    LR, {R0-R14}^” restores all registers for the task, including LR which now contains 0xAAAAAAAA (this value was set in the pxPortInitialiseStack function).  However, the next instruction is LDR LR, [LR, #+60] which reads the return address from 0xAAAAAAAA+60 which is a garbage address.  The value read is 0x00000000.  What am I missing here?

nobody wrote on Tuesday, March 27, 2007:

This is a bang on symptom of the processor not being in Supervisor mode when the context of the task is restored.

Are you starting in Supervisor mode?  Are interrupts occurring that use the UART prior to the scheduler being started?  Your answers should be "yes", "no", respectively.

Dave.

jorick23 wrote on Thursday, March 29, 2007:

The processor was starting in User mode.  I was using the wrong set of library files.  I downloaded the updated ones from ST and was using them instead of the ones from FreeRTOS.  I added the line to enter Supervisor mode and it works.  Thanks!