This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

FreeRTOS thread runs only 12 times and twice when debugging

Hi,

I'm using nrf52 dev board on sdk version 14.0 with GCC compiler. I modified the hrs freertos example to add a simple thread with same priority as of logger thread. The new thread will just print a line and then suspend itself. The idle thread will then wake it up - just like logger thread.

As per my understanding, the new thread should keep on executing. But I see the print statements only 12 times. But when I debugging with gdb, the new thread is only executed twice. Afterwards, the debugger never hits the breakpoint set for the thread. When I force stopped the execution, the system is apparently executing a busy wait hoping for some interrupts } while (0 == (NVIC->ISPR[0] | NVIC->ISPR[1])); at external/freertos/portable/CMSIS/nrf52/port_cmsis_systick.c:294

Here is the code:

static void a_thread(void * arg)
{
    UNUSED_PARAMETER(arg);

    while (1)
    {
        NRF_LOG_DEBUG("Printing from the thread");
        NRF_LOG_FLUSH();

        vTaskSuspend(NULL); // Suspend myself
    }
}

void vApplicationIdleHook( void )
{
     vTaskResume(m_logger_thread);
     vTaskResume(m_a_thread);
}

int main(void)
{
    bool erase_bonds;

    clock_init();

    // Do not start any interrupt that uses system functions before system initialisation.
    // The best solution is to start the OS before any other initalisation.

    log_init();

#if NRF_LOG_ENABLED
    // Start execution.
    if (pdPASS != xTaskCreate(logger_thread, "LOGGER", 256, NULL, 1, &m_logger_thread))
    {
        APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
    }
#endif

    // Activate deep sleep mode.
    SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
 
    if (pdPASS != xTaskCreate(a_thread, "THREAD", 128, NULL, 1, &m_a_thread))
    {
        APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
    }


    // Start FreeRTOS scheduler.
    NRF_LOG_DEBUG("Starting FreeRTOS scheduler");
    NRF_LOG_FLUSH();
    vTaskStartScheduler();


    while (true)
    {
        APP_ERROR_HANDLER(NRF_ERROR_FORBIDDEN);
    }
}

What could be happening? Is something wrong with freertos configuration or is it my understanding ?

Related