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

BLE won't work with FreeRTOS if call nrf_pwr_mgmt_run()

Hi Guys!

Could you help me with one issue. 

I am trying to run my own project that I build according to the example "ble_app_hrs_freertos". If I am calling "nrf_pwr_mgmt_run()" in "vApplicationIdleHook":

void vApplicationIdleHook( void )
{
#if NRF_LOG_ENABLED
     vTaskResume(m_logger_thread);
#endif
    nrf_pwr_mgmt_run();
}

my BLE does not want to work. The NRF Connect application sees the device, but can not connect to it. From the log I see next:

V	22:57:56.889	Connecting to E2:ED:AD:A0:FE:F8...
D	22:57:56.889	gatt = device.connectGatt(autoConnect = false, TRANSPORT_LE, preferred PHY = LE 1M)
D	22:57:57.540	[Broadcast] Action received: android.bluetooth.device.action.ACL_CONNECTED
D	22:57:57.586	[Callback] Connection state changed with status: 0 and new state: CONNECTED (2)
I	22:57:57.586	Connected to E2:ED:AD:A0:FE:F8
V	22:57:57.627	Discovering services...
D	22:57:57.627	gatt.discoverServices()
I	22:57:57.840	Connection parameters updated (interval: 7.5ms, latency: 0, timeout: 5000ms)
D	22:58:27.658	[Callback] Connection state changed with status: 22 and new state: DISCONNECTED (0)
E	22:58:27.658	Error 22 (0x16): GATT CONN TERMINATE LOCAL HOST
I	22:58:27.658	Disconnected
D	22:58:27.730	[Broadcast] Action received: android.bluetooth.device.action.ACL_DISCONNECTED

If I remove "nrf_pwr_mgmt_run()" from "vApplicationIdleHook", the BLE starts working properly.

Thanks!

  • Hi.

    Looks like something in your app is getting blocked.

    Could you try to debug your application and see where the block is happening?

    Hard to say what is happening without knowing what you have implemented and at what priority.

    Br,
    Joakim

  • Hi Joakim,

    I debug my application and it seems like the NRF does not want even wake up.

     

    static void softdevice_task(void * pvParameter)
    {
        NRF_LOG_DEBUG("Enter softdevice_task.");
    
        if (m_task_hook != NULL)
        {
            m_task_hook(pvParameter);
        }
    
        while (true)
        {
            nrf_sdh_evts_poll();                    /* let the handlers run first, incase the EVENT occured before creating this task */
    
            (void) ulTaskNotifyTake(pdTRUE,         /* Clear the notification value before exiting (equivalent to the binary semaphore). */
                                    portMAX_DELAY); /* Block indefinitely (INCLUDE_vTaskSuspend has to be enabled).*/
        }
    }

    At the power up, the process enters in ulTaskNotifyTake() in function softdevice_task() and after that never exit. As soon as I remove nrf_pwr_mgmt_run(); from idle task the NRF starts wake up.

    I have only 2 active task: advertasing and logs.

    I assume that I miss some define in sdk_config.h file. Here is my FreeRTOSConfig.h and sdk_config.h files. 5618.FreeRTOSConfig.h6278.sdk_config.h 

    Could you check configs? Maybe I miss some important config.

    softdevice_task priority is 3.

    logger_thread priorityis is 1.

    One more thing: If I add the 3rd thread with priority 2, which makes some routine every 30 seconds. The 3rd thread works well. But softdevice_task thread still does not want work.

    So I think, that function nrf_pwr_mgmt_run() disables BLE events/intterupts.

  • Hi Mark,

    You have enabled tickless idle sleep in your freertos config file.

    Enabling tickless idle is telling the RTOS to take control of the sleep in the idle state and also disable rtc ticks until next scheduled wake up.

    If you want explicit control on when your chip should sleep, then you should disable tickless idle. If your application works well by letting the rtos decide to make the chip go to sleep in idle then leave the tickless enabled but do not call any other chip level sleep functions in the app. I think you should just remove nrf_pwr module from your application and enable the tickless idle. You can still see that the chip will maintain its low level sleep states

  • Hi Susheel,

    I debugged a little bit and found out that the device does not want wake up if the NRF_PWR_MGMT_CONFIG_FPU_SUPPORT_ENABLED is enable.

    So, my test was next:

    1. Application has only 1 task - advertising and Idle task.

    2. I am still calling the nrf_pwr_mgmt_run() in Idle task.

    3. If NRF_PWR_MGMT_CONFIG_FPU_SUPPORT_ENABLED is disable all works fine.

    4. If the  NRF_PWR_MGMT_CONFIG_FPU_SUPPORT_ENABLED is enabled the device behaves as I described earlier and does not want to connect tot the phone etc.

    Could you explane why using of NRF_PWR_MGMT_CONFIG_FPU_SUPPORT_ENABLED leads to such behavior? How to resolve this issue?

    Notes, I can not disable NRF_PWR_MGMT_CONFIG_FPU_SUPPORT_ENABLED, because my application makes some float calculation. In this case if I disable  NRF_PWR_MGMT_CONFIG_FPU_SUPPORT_ENABLED, the device will never go to sleep, because the FPU interrupts flags are not cleared.

    Thanks!

  • Hi.

    Sorry about the long delay in response here.

    Have you made any progress on this issue, or do you still need assistance?

    Br,
    JOakim

Related