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

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 taskrn");
}

/* Create task to monitor processor activity */
if (xTaskCreate(prvSecond, "Secondtask", configMINIMAL_STACK_SIZE, NULL, 1, NULL) != pdPASS) {
      printf("Failed to create Second taskrn");
}
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(“rTASKn”); vTaskDelay(100); } }

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

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 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().

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

Hi, Attached file which contains vector table for CORTEX_M4F

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

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.

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

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.
  1. 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

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

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.

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

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

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

Yeah I have tried without printf() The result is same

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

They are being called from same file here PUBWEAK SysTickHandler SECTION .text:CODE:REORDER(1) SysTickHandler 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

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

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

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

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?

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

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

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

Thanks for your support