This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Task Not Switching in FreeRTOS example in Nordic SDK

Hi All,

Am using NRF52, SDK 11.0.0.2 alpha , I am using HRS free RTOS example. In that I just created two tasks of equal priority. As per Free RTOS two task must switch without giving any task delay. But In my case Task is not switching .

Task Creation:

// Start execution.
    if(pdPASS != xTaskCreate(ble_stack_thread, "BLE", 128, NULL, 2, &m_ble_stack_thread))
    {
        APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
    }
    if(pdPASS != xTaskCreate(user_thread, "USER", 128, NULL, 2, &m_user_thread))
    {
        APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
    }
    /* Activate deep sleep mode */
    SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;

    // Start FreeRTOS scheduler.
    vTaskStartScheduler();

Tasks:-

static void user_thread(void *arg)
{
	while(1){
		printf("test\r\n");
		
	}
}

static void ble_stack_thread(void * arg)
{
	while(1){
		printf("BLE\r\n");
	}
}

I also changed the config

#define configUSE_TIME_SLICING                                                    1
#define configUSE_PREEMPTION                                                      1
Parents
  • printf() can cause issues, depending on how it is implemented. What happens if you take the printf() statements out, and just increment a counter instead? If you use a different counter in each task - do both counters increment?

    volatile uint32_t user_thread_counter = 0, ble_stack_counter = 0;
    static void user_thread(void *arg)
    {
        while(1){
            user_thread_counter++;
    
        }
    }
    
    static void ble_stack_thread(void * arg)
    {
        while(1){
            ble_stack_counter++;
        }
    }
    

    As neither task is blocking then a context switch should occur on each tick interrupt. If a context switch is not occurring then only one task will execute. Have you installed the systick handler (the tick interrupt comes from the systick by default, so assumes you are using the default port). See item 1 on this FAQ item for information on installing the handler.

Reply
  • printf() can cause issues, depending on how it is implemented. What happens if you take the printf() statements out, and just increment a counter instead? If you use a different counter in each task - do both counters increment?

    volatile uint32_t user_thread_counter = 0, ble_stack_counter = 0;
    static void user_thread(void *arg)
    {
        while(1){
            user_thread_counter++;
    
        }
    }
    
    static void ble_stack_thread(void * arg)
    {
        while(1){
            ble_stack_counter++;
        }
    }
    

    As neither task is blocking then a context switch should occur on each tick interrupt. If a context switch is not occurring then only one task will execute. Have you installed the systick handler (the tick interrupt comes from the systick by default, so assumes you are using the default port). See item 1 on this FAQ item for information on installing the handler.

Children
Related