# Context switching problem

**URL:** <https://forums.freertos.org/t/context-switching-problem/2790>\
**Category:** Kernel\
**Created:** [March 27, 2007, 8:29pm UTC](https://forums.freertos.org/t/context-switching-problem/2790 "2007-03-27T20:29:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [March 27, 2007, 8:29pm UTC](https://forums.freertos.org/t/context-switching-problem/2790/1 "2007-03-27T20:29:38Z")

</div>

**[jorick23](https://sourceforge.net/u/jorick23/)** wrote on [Tuesday, March 27, 2007](https://sourceforge.net/p/freertos/discussion/382005/thread/7c3ce10c/#7963):

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

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [March 27, 2007, 8:35pm UTC](https://forums.freertos.org/t/context-switching-problem/2790/2 "2007-03-27T20:35:27Z")

</div>

**nobody** wrote on [Tuesday, March 27, 2007](https://sourceforge.net/p/freertos/discussion/382005/thread/7c3ce10c/#7963/2ad5):

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?&nbsp; Are interrupts occurring that use the UART prior to the scheduler being started?&nbsp; Your answers should be "yes", "no", respectively.

Dave.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [March 29, 2007, 8:25pm UTC](https://forums.freertos.org/t/context-switching-problem/2790/3 "2007-03-29T20:25:57Z")

</div>

**[jorick23](https://sourceforge.net/u/jorick23/)** wrote on [Thursday, March 29, 2007](https://sourceforge.net/p/freertos/discussion/382005/thread/7c3ce10c/#7963/2ad5/52f8):

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