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

Key sdk_config.h items for FreeRTOS RTC operation

I need FreeRTOS operation in my build. I've adopted the FreeRTOS.h file from the blinky_freertos example, unchanged aside from a larger heap size and setting INCLUDE_xSemaphoreGetMutexHolder to 1 'cos I need that.  I have verified that the example build works as intended on my NRF52840-DK board; FreeRTOS running with tickless idle from RTC, LEDs flashing as intended.

The problem I have is that my build hangs after a few hundred milliseconds. If I change FreeRTOS.h so that it uses SysTick instead of RTC then no such problem occurs.  Disabling configUSE_TICKLESS_IDLE doesn't make things better.  If I run under the debugger and pause it once things have hung it shows that the code has entered the idle task then, for some reason, the SPIM2_SPIS2_SPI2_IRQHandler(), which is not something I've enabled or am using so I guess is an artefact of the debugger, and then done nothing afterwards.

I call nrf_drv_clock_init() in main(), just as the blinky_freertos example does, so the likelihood is that a setting in my sdk_config.h file is somehow different-in-a-bad-way from that of the blinky_freertos example.  My sdk_config.h, originally derived from a different example, has 1155 #defines in it, in a different order to that of the blinky_freertos example, so it is quite difficult to find the needle in the haystack.

Hence my QUESTION is: what are the key things one needs to configure in sdk_config.h to achieve stable FreeRTOS operation with RTC as time base?

In case it's useful, find below a complete ZIP file containing a standalone build which reproduces my problem.

test.zip

Rob

Parents Reply Children
  • OK, I've tried again this morning and this time it ends up in TIMER1 IRQ instead of SPIM2 IRQ; the blinky FreeRTOS example doesn't have any sdk_config.h entries at all for any TIMERs and I only use TIMER0, not TIMER1.  Below is a screen capture of the NVIC register status when it is in this state and the entirety of my code involved in this:

      

    // The task within which testing runs.
    void testTask(void *pParam)
    {
        (void) pParam;
    
        NRF_LOG_RAW_INFO("\n\nCELLULAR_TEST: Test task started.\n");
    
        vTaskDelay(1000); // <- IT NEVER RETURNS FROM THIS CALL
    
        UNITY_BEGIN();
    
        NRF_LOG_RAW_INFO("CELLULAR_TEST: Tests available:\n\n");
        cellularPortUnityPrintAll("CELLULAR_TEST: ");
        NRF_LOG_RAW_INFO("CELLULAR_TEST: Running all tests.\n");
        cellularPortUnityRunAll("CELLULAR_TEST: ");
    
        UNITY_END();
    
        NRF_LOG_RAW_INFO("\n\nCELLULAR_TEST: Test task ended.\n");
        NRF_LOG_FLUSH();
    
        while(1){}
    }
    
    // Entry point
    int main(void)
    {
        TaskHandle_t taskHandle = NULL;
    
        NRF_LOG_INIT(NULL);
        NRF_LOG_DEFAULT_BACKENDS_INIT();
    
    #if configTICK_SOURCE == FREERTOS_USE_RTC
        // If the clock has not already been started, start it
        nrf_drv_clock_init();
    #endif
    
       // Create the test task and have it running
       // at a low priority
        assert(xTaskCreate(testTask, "TestTask",
                           CELLULAR_PORT_TEST_RUNNER_TASK_STACK_SIZE_BYTES / 4,
                           NULL, 14 /* Priority */,
                           &taskHandle) == pdPASS);
    
        // Activate deep sleep mode.
        SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
    
        // Start the scheduler.
        vTaskStartScheduler();
    
        // Should never get here
        assert(false);
    
        return 0;
    }

  • A bit more detail: the previous step in the call trace would suggest that we're just at the point that interrupts have been re-enabled by FreeRTOS:

  • OK, it does not look like you are using BLE, Is this correct? Is it possible that you attach your code here and I can try to replicate the issue? I can make this case private if you do not want to make your code publicly visible.

  • No problem, original text of this ticket edited to include a standalone .zip file containing a build which reproduces my problem.  And no, I'm not using BLE.

  • The problem was that you enabled POWER_ENABLED and disabled CLOCK_ENABLED. So it was not able to hook to the proper irq handler and hence ending up in the dummy power handler. Try this modified project where I fixed the sdk_config.h correctly

    test_susheel.zip

Related