Getting started with FreeRTOS on nrf52

Hi, I'm trying to use FreeRTOS on a custom board featuring a nRF52832. I've started adapting the blinky_freertos example in the SDK 17.1.0 and replacing the code in led_toggle_task_function with the following snippet:

static int myVar;

static void led_toggle_task_function (void * pvParameter)
{
    UNUSED_PARAMETER(pvParameter);
    myVar = 0;
    while (true)
    {
        myVar++;
        vTaskDelay(100);
        myVar++;
    }
}

I'm using IAR (with low optimization) and a jlink and, apparently, the code never reaches the increment after the first vTaskDelay (i.e., myVar stays at 1). Or rather, sometimes it works as expected but it mostly doesn't.

Do you have any hint at what might be causing this? Is it the fact that I'm using a custom board (I doubt it, since there is no board specific initialization in the example, aside from the LEDs and the button), or is it maybe this bug still looming around?

I should probably mention that I already had a more serious try with the SDK 13.0.0, where I successfully started some tasks and communicated over SPI, but I noticed that some timers were not firing when they should have.

Thanks in advance for any feedback

Parents
  • The FreeRTOS example we have relies on the RTC to handle the kernel tick required for housekeeping of the kernel. IF the RTC is not ticking correctly then there are no interrupts generated. You can put a breakpoint in the nRF5_SDK_17.1.0_ddde560\external\freertos\portable\CMSIS\nrf52\port_cmsis_systick.c:: Line 117 and see if this interrupt is being triggered at all. My guess is that this interrupt might not be triggered at all (or enough) propbably due to issues in your external LFCLK needed by the RTC?

  • Hi Susheel, thanks for your answer. You were right, in fact I solved the issue adding before the task creation these lines, which I took from the radio transmitter example:

    NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
    NRF_CLOCK->TASKS_LFCLKSTART    = 1;
    while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0)
    {
        // Do nothing.
    }

    Now the theoretical question arises: how is it possible that the blinky example works on the nRF52 DK? I had look at the nrf_drv_clock source code in SDK 17.1 and it seems to me that the LFCLKSTART is not triggered, even though the data sheet states it is necessary to do that in order for the RTC to start.

  • The normal blinky example (not the freertos one) is not using LFCLK as it is not using any RTC timers. The blinky example uses busy wait which relies on CPU time and hence HFCLK.

    It is always good to start the lfclk in the main if you know that you are going to use some peripherals that need this clock.

  • I'm sorry, I was referring to the blinky freertos example, which does not start the lfclk in the main but apparently relies on that (at least on my board, but I guess also on the nRF52 DK)

Reply Children
Related