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

Soft device somtimes don't want to start advertising

I have an application based on ble_app_hrs_freertos from SDK14. Sometimes the application will not start advertising. When this happens, it does not help to power-cycle device. Sometimes it helps to reset the device with nRFgo Studio, simply to let it discover the device (Selecting "nRF5x Programming" in Device Manager). After this, the device sometimes suddenly start advertising.

Advertising is started (or is supposed to) right after init of BLE and creation of the softdevice_task (nrf_sdh_freertos_init())

I get no errors when initing BLE, and no error when start advertising (ble_advertising_start()). There are no asserts from softdevice. When advertising is erroneously not started, no advertising events are sent (the advertising event handler on_adv_evt() is never called).

Of course I can't see this behaviour when running the example applications, i.e. ble_app_hrs_freertos.

Do you have any suggestions what can cause this?

Regards, Jan

  • Sorry for the late reply. I somehow missed this thread.

    I think this is related to a bug we found recently in nrf_sdh_freertos.c. After flashing softdevice and initializing peer manager it tries to format internal flash memory to be ready for usage and emits NRF_EVT_FLASH_OPERATION_SUCCESS event which then fires SD_EVT_IRQHandler. Then using FreeRTOS, a notification is sent to softdevice_task task from SD_EVT_IRQHandler, but if a task is not yet created during that moment this notification gets lost. After softdevice_task task is created by calling nrf_sdh_freertos_init(), softdevice_task blocks on ulTaskNotifyTake() and waits for other BLE stack events before calling nrf_sdh_evts_poll(). So in the example, where the order of calls is first peer_manager_init() and then nrf_sdh_freertos_init(), then flash system is busy, NRF_EVT_FLASH_OPERATION_SUCCESS gets lost, and as a result, delayed advertising doesn't start.

    solution
    my suggestion is to switch the order of calls in softdevice_task() to firstly do a nrf_sdh_evts_poll() and only then block ulTaskNotifyTake(), so those first events in the queue could be properly read:

    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();   // <<--- now called before locking on the binary semaphore
    
            (void) ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
    
        }
    
    }
    
  • Thanks,

    I tried tihs now, and it seems to work fine.

    The problem occurred mostly after first-time flashing of the nRF52. Now, after the fix, It seems to start advertising immediately after application has started, as it should.

    Thanks for help, Jan

  • Has this been fixed in newer versions of the SDK?

  • Dear 

    I seem to suffer from the very same issue, I am using: S132 SoftDevice v2.0.0

    in my case also, after flashing the application will not start advertising (only after 2-4 reset cycles)

    I am not using: ble_app_hrs_freertos from SDK14 or other FreeRTOS

    I am only exposed to the nRF5_SDK_00.11.00

    I am looking for a solution that I can implement on my application and not on the Softdevice.

    What can be done on the application level?

    BR

    Erez

Related