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

configUSE_TICKLESS_IDLE stopped working with SDK 17.0.2

We have a working app for SDK 16 and freeRTOS. We wanted to update to SDK 17.0.2 but after upgrading the app hangs up at the first vTaskDelay(). We use configUSE_TICKLESS_IDLE 1. With the help of debugger I found out that the app enters endless loop in vPortSuppressTicksAndSleep(). It looks like the problem is that nrf_rtc_counter_get() always returns 0 and thus the time does not go forward. So the vTaskDelay() timeout never expires. I checked the changes between SDK 17.0.2 and the previous version and I found this two addition in sdk/modules/nrfx/drivers/src/nrfx_clock.c:

@@ -245,6 +245,9 @@ void nrfx_clock_lfclk_start(void)
 void nrfx_clock_lfclk_stop(void)
 {
     NRFX_ASSERT(m_clock_cb.module_initialized);
+
+    nrf_clock_int_disable(NRF_CLOCK_INT_LF_STARTED_MASK);
+    nrf_clock_event_clear(NRF_CLOCK_EVENT_LFCLKSTARTED);
     nrf_clock_task_trigger(NRF_CLOCK_TASK_LFCLKSTOP);
     while (nrf_clock_lf_is_running())
     {}
@@ -261,6 +264,9 @@ void nrfx_clock_hfclk_start(void)
 void nrfx_clock_hfclk_stop(void)
 {
     NRFX_ASSERT(m_clock_cb.module_initialized);
+
+    nrf_clock_int_disable(NRF_CLOCK_INT_HF_STARTED_MASK);
+    nrf_clock_event_clear(NRF_CLOCK_EVENT_HFCLKSTARTED);
     nrf_clock_task_trigger(NRF_CLOCK_TASK_HFCLKSTOP);
     while (nrf_clock_hf_is_running(NRF_CLOCK_HFCLK_HIGH_ACCURACY))
     {}

Now if I remove those added lines disabling interrupt the app will work as normal. 

Below is a minimal code to reproduce the problem. The a_task will hang up at first call to vTaskDelay().

My question: do we need to add some special handling for RTC to make it work? It worked with the previous SDK and I don't see any info about changes related to clock in release notes.

static void a_task(void *arg)
{
  for (;;) {
    NRF_LOG_ERROR("a_task");
    vTaskDelay(1000);
  }
}

int main()
{
  NRF_LOG_INIT(xTaskGetTickCount);
  NRF_LOG_DEFAULT_BACKENDS_INIT();

  app_timer_init();

  nrf_drv_clock_init();

  xTaskCreate(a_task, "a_task", 2048, NULL, pdTASK_PRIORITY_MAIN, NULL);

  vTaskStartScheduler();
  APP_ERROR_CHECK_BOOL(false);
}
Parents Reply Children
No Data
Related