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

BLE_GATTS_EVT_HVN_TX_COMPLETE not called after NRF_ERROR_RESOURCES

Hi everyone,

I work on an custom board with the nrf52840, the SDK 15.2.0, the SoftDevice 140 6.1.0 and FreeRTOS.

My problem is that during a BLE transfert of a lot of small packets (16 Bytes) I go stuck in the do while loop with sd_ble_gatts_hvx().

The context is that we ask on mobile phone side the donwload of the data. On each BLE_GATTS_EVT_HVN_TX_COMPLETE event we send a new packet on a queue.

We run a task which dequeue all notification to send them over the sd_ble_gatts_hvx() function.

During the process of sending we use a do-while loop as suggested in few other topics.

But the problem is that there is a moment the notification are not send any more. We have an NRF_ERROR_RESOURCES and we don't receive any BLE_GATTS_EVT_HVN_TX_COMPLETE event after this error occured so even if we wait for BLE_GATTS_EVT_HVN_TX_COMPLETE we are not able to continue any ble transfert.

Is anyone have a idea why ?

The softdevice task run with a priority of 3 (in FreeRTOS) and other task run with a priority of 2.

Thanks in advance for any response.

Etienne D

Parents
  • Hi Etienne

    What is the conditions for exiting the loop where you are sending notifications?

    The recommended way to maximize throughput is to upload notifications continuously until the NRF_ERROR_RESOURCES error occurs. Then you should stop calling the sd_ble_gatts_hvx() function until the BLE_GATTS_EVT_HVN_TX_COMPLETE event occurs, at which point the stack will be ready to accept more packets. 

    Best regards
    Torbjørn

  • Hi Trobjorn, 

    Thank you for your response. 

    The loop look like the loop below.

        do{
            err_code = sd_ble_gatts_hvx(conn_handle, &hvx_params);
        }while(err_code == NRF_ERROR_RESOURCES);

    I try to push all notification into my queue and then treat them with the other task. But at some point an error NRF_ERROR_RESOURCES comes and we don not receive any TX_COMPLETE to continue the transfert.

    To do the waiting stage for the TX_COMPLETE we use a xEventGroupWaitBits in our notification function. And we use xEventGroupSetBits in the nrf_sdh_ble_evts_poll function inside the nrf_sdh_ble.c file. 

    Best regards

    Etienne D

  • Hi Etienne

    I would not recommend doing the loop in this way. 

    You can keep calling sd_ble_gatts_hvx as long as it returns NRF_SUCCESS, but once you get an error code in return you should hold off and wait for the BLE_GATTS_EVT_HVN_TX_COMPLETE event to occur:

    do{
        err_code = sd_ble_gatts_hvx(conn_handle, &hvx_params);
    }while(err_code == NRF_SUCCESS);
    
    // Set some flag to indicate that you are waiting for the BLE_GATTS_EVT_HVN_TX_COMPLETE event

    Otherwise you are wasting a lot of CPU cycles continuously trying to upload data to the stack, and you risk blocking SoftDevice events being handled. 

    Best regards
    Torbjørn

Reply
  • Hi Etienne

    I would not recommend doing the loop in this way. 

    You can keep calling sd_ble_gatts_hvx as long as it returns NRF_SUCCESS, but once you get an error code in return you should hold off and wait for the BLE_GATTS_EVT_HVN_TX_COMPLETE event to occur:

    do{
        err_code = sd_ble_gatts_hvx(conn_handle, &hvx_params);
    }while(err_code == NRF_SUCCESS);
    
    // Set some flag to indicate that you are waiting for the BLE_GATTS_EVT_HVN_TX_COMPLETE event

    Otherwise you are wasting a lot of CPU cycles continuously trying to upload data to the stack, and you risk blocking SoftDevice events being handled. 

    Best regards
    Torbjørn

Children
Related