# FreeRTOS Scheduler doesn't resume/context switch tasks after the first tick interrupt

**URL:** <https://forums.freertos.org/t/freertos-scheduler-doesnt-resume-context-switch-tasks-after-the-first-tick-interrupt/6334>\
**Category:** Kernel\
**Created:** [December 16, 2016, 6:51am UTC](https://forums.freertos.org/t/freertos-scheduler-doesnt-resume-context-switch-tasks-after-the-first-tick-interrupt/6334 "2016-12-16T06:51:16Z")\
**Posts on this page:** 13\
**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:** [December 16, 2016, 6:51am UTC](https://forums.freertos.org/t/freertos-scheduler-doesnt-resume-context-switch-tasks-after-the-first-tick-interrupt/6334/1 "2016-12-16T06:51:16Z")

</div>

**[sunnshyamthella](https://sourceforge.net/u/sunnshyamthella/)** wrote on [Friday, December 16, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/22aeb5a4/#6ac4):

Hi All,

We have a Polaris FPGA board in which I am able to port FreeRTOS to some extent and able to see a task with high priority running. However this execution doesn’t last long as after the first tick interrupt is occured (&serviced) my high priority task should resume. This is not happening.

I have tried two tasks with same priority but still neither of the tasks were able to run after tick interrupt is handled.

Following are my two tasks built and run on CORTEX-M4F port in IAR workbench.

```
/* Create task to monitor processor activity */
if (xTaskCreate(prvSampleTask, "Sample", configMINIMAL_STACK_SIZE, NULL, 1, NULL) != pdPASS) {
      printf("Failed to create Sample task\r\n");
}

/* Create task to monitor processor activity */
if (xTaskCreate(prvSecond, "Secondtask", configMINIMAL_STACK_SIZE, NULL, 1, NULL) != pdPASS) {
      printf("Failed to create Second task\r\n");
}
vTaskStartScheduler();

```

static void prvSampleTask( void \*pvParameters )  
{  
int i=0;  
for( ; ; ) {  
printf(“In SampleTask… \n”);  
printf(“This task never ends… \n”);  
}  
}

static void prvSecond( void \*pvParameters )  
{  
for( ; ; ) {  
printf("\rTASK\n");  
vTaskDelay(100);  
}  
}

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [December 16, 2016, 6:13pm UTC](https://forums.freertos.org/t/freertos-scheduler-doesnt-resume-context-switch-tasks-after-the-first-tick-interrupt/6334/2 "2016-12-16T18:13:46Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Friday, December 16, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/22aeb5a4/#6ac4/81a1):

Have you installed the tick interrupt handler? Search for the text  
“Special note to ARM Cortex-M users” on this page  
[http://www.freertos.org/FAQHelp.html](http://www.freertos.org/FAQHelp.html)

Also, have you tried without the calls to printf()? I’m not sure how  
your printf() works but (as noted in the book) often non-thread safe or  
extremely stack hungry implementations of printf are actually the root  
cause of issues, which users then try and debug by adding even more  
calls to printf().

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [December 19, 2016, 3:07am UTC](https://forums.freertos.org/t/freertos-scheduler-doesnt-resume-context-switch-tasks-after-the-first-tick-interrupt/6334/3 "2016-12-19T03:07:07Z")

</div>

**[sunnshyamthella](https://sourceforge.net/u/sunnshyamthella/)** wrote on [Monday, December 19, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/22aeb5a4/#ec84):

Hi,

Attached file which contains vector table for CORTEX\_M4F

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [December 19, 2016, 3:10am UTC](https://forums.freertos.org/t/freertos-scheduler-doesnt-resume-context-switch-tasks-after-the-first-tick-interrupt/6334/4 "2016-12-19T03:10:38Z")

</div>

**[sunnshyamthella](https://sourceforge.net/u/sunnshyamthella/)** wrote on [Monday, December 19, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/22aeb5a4/#48d9):

On printf, I just implemented function putchar() as shown in attached file.  
I don’t think this has something to do with the task resuming after a tick interrupt. Am I right?

My problem here is suppose if I have only one high priority task, the scheduler should resume same task after tick interrupt is seved(no preemption of task is required).

When I debug line by line, controller reached end of tick handler (SysTick\_Handler()) and doesn’t start/resume high priority task. Instead it executes instructions that follows tick handler.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [December 19, 2016, 3:16am UTC](https://forums.freertos.org/t/freertos-scheduler-doesnt-resume-context-switch-tasks-after-the-first-tick-interrupt/6334/5 "2016-12-19T03:16:53Z")

</div>

**[sunnshyamthella](https://sourceforge.net/u/sunnshyamthella/)** wrote on [Monday, December 19, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/22aeb5a4/#9a56):

As fas as I understand in FreeRTOS xTaskIncrementTick() has some logic which decides whether the current running task should be preempted or not.

Two possible values returned by this function are:

1. False (means no pre emption is required), now who will bring the same task to running state? which is paused by tick handler.

2. True, preemption is happened with setting PENDSV bit, even this is also not helping for me. Setting PENDSV bit doesn’t trigger pendsv interrupt for my CORTEX\_M4F

Regards  
Shyam

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [December 19, 2016, 3:31am UTC](https://forums.freertos.org/t/freertos-scheduler-doesnt-resume-context-switch-tasks-after-the-first-tick-interrupt/6334/6 "2016-12-19T03:31:47Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Monday, December 19, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/22aeb5a4/#ec84/07a1):

This start up file is importing the FreeRTOS interrupt handlers:

```
     EXTERN vPortSVCHandler
     EXTERN xPortPendSVHandler
     EXTERN xPortSysTickHandler

```

but not installing them, as the relevant snippet of the vector table shows:

```
     DCD SVC_Handler ; SVCall Handler
     DCD DebugMon_Handler ; Debug Monitor Handler
     DCD 0 ; Reserved
     DCD PendSV_Handler ; PendSV Handler
     DCD SysTick_Handler ; SysTick Handler

```

With this setting you would need to call the FreeRTOS handlers the same  
names as the handlers you have actually installed (each of which ends  
with “\_Handler” in the code snippet above). Have you done that? The  
code needing to be added to FreeRTOSConfig.h to map the FreeRTOS names  
to the names you have actually installed is provided on the link from  
the first reply above in this thread.

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [December 19, 2016, 3:33am UTC](https://forums.freertos.org/t/freertos-scheduler-doesnt-resume-context-switch-tasks-after-the-first-tick-interrupt/6334/7 "2016-12-19T03:33:07Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Monday, December 19, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/22aeb5a4/#48d9/fddd):

I don’t think that printf() would cause the issue, but it is not thread  
safe. Did you actually try without the printf()?

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [December 19, 2016, 4:04am UTC](https://forums.freertos.org/t/freertos-scheduler-doesnt-resume-context-switch-tasks-after-the-first-tick-interrupt/6334/8 "2016-12-19T04:04:54Z")

</div>

**[sunnshyamthella](https://sourceforge.net/u/sunnshyamthella/)** wrote on [Monday, December 19, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/22aeb5a4/#48d9/fddd/a66a):

Yeah I have tried without printf()

The result is same

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [December 19, 2016, 4:07am UTC](https://forums.freertos.org/t/freertos-scheduler-doesnt-resume-context-switch-tasks-after-the-first-tick-interrupt/6334/9 "2016-12-19T04:07:10Z")

</div>

**[sunnshyamthella](https://sourceforge.net/u/sunnshyamthella/)** wrote on [Monday, December 19, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/22aeb5a4/#ec84/07a1/e2a7):

They are being called from same file here

PUBWEAK SysTick\_Handler  
SECTION .text:CODE:REORDER(1)  
SysTick\_Handler  
LDR R0, =xPortSysTickHandler  
BLX R0

```
           PUBWEAK SVC_Handler
    SECTION .text:CODE:REORDER(1)

```

SVC\_Handler  
LDR R0, =vPortSVCHandler  
BLX R0

```
    PUBWEAK PendSV_Handler
    SECTION .text:CODE:REORDER(1)

```

PendSV\_Handler  
LDR R0, =xPortPendSVHandler  
BLX R0

```
    And I am able to go vPortSVCHandler, xPortPendSVHandler when appropriate interrutps are triggered. Validated this with debugger
```

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [December 19, 2016, 5:17am UTC](https://forums.freertos.org/t/freertos-scheduler-doesnt-resume-context-switch-tasks-after-the-first-tick-interrupt/6334/10 "2016-12-19T05:17:52Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Monday, December 19, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/22aeb5a4/#ec84/07a1/e2a7/e5eb):

Please try installing the handlers using the #defines as per the link in  
the original reply.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [December 19, 2016, 6:10am UTC](https://forums.freertos.org/t/freertos-scheduler-doesnt-resume-context-switch-tasks-after-the-first-tick-interrupt/6334/11 "2016-12-19T06:10:37Z")

</div>

**[sunnshyamthella](https://sourceforge.net/u/sunnshyamthella/)** wrote on [Monday, December 19, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/22aeb5a4/#ec84/07a1/e2a7/e5eb/58dd):

Your soulution worked for me. But couldn’t conclude how…

I was just calling the same handlers from the pubweak functions. Why is that the scheduler not able to resume in the previous setup?

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [December 19, 2016, 7:34pm UTC](https://forums.freertos.org/t/freertos-scheduler-doesnt-resume-context-switch-tasks-after-the-first-tick-interrupt/6334/12 "2016-12-19T19:34:57Z")

</div>

**[edwards3](https://sourceforge.net/u/edwards3/)** wrote on [Monday, December 19, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/22aeb5a4/#24d3):

Your code was changing the stack before calling the FreeRTOS handler.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [December 20, 2016, 3:17am UTC](https://forums.freertos.org/t/freertos-scheduler-doesnt-resume-context-switch-tasks-after-the-first-tick-interrupt/6334/13 "2016-12-20T03:17:54Z")

</div>

**[sunnshyamthella](https://sourceforge.net/u/sunnshyamthella/)** wrote on [Tuesday, December 20, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/22aeb5a4/#24d3/8677):

Thanks for your support
