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 & NRF_ERROR_RESOURCES

Hey,

I´m working on a project based on nRF52840, SDK 15.0.0 Softdevice s140 v6.0.0 running FreeRTOS.

I´m reading data from an external Flash via SPI and transmitt the data using notifications to a Android Smartphone. However eventually at some point the device seems to get stuck and can´t send any data anymore.

I send data using "sd_ble_gatts_hvx" until I get a NRF_ERROR_RESOURCES event and then wait for BLE_GATTS_EVT_HVN_TX_COMPLETE until I queue more notifications. But for some reason at some point I just stop to receive BLE_GATTS_EVT_HVN_TX_COMPLETE event and no more data transmission is possible (I also have tried varios sizes for the HVN_QUEUE from 1-20 but the error still occurs occasionally, which makes it really hard to debug)

I also tried to just send data using a "do-while-loop" like in the nus example but at some point every call of sd_ble_gatts_hvx just returns NRF_ERROR_RESOURCES and the device keeps stuck in the do-while-loop forever.

Unfortunately this seems to happen very irregular. So I cannot reproduce the error every time. Sometimes I can transmitt up to 100MB before I reach this state where I can´t send any data any more, sometime it happens just after a few packages.

I also tried to monitor the packages which where queued to the notification buffer by incrementing a counter with every call of "sd_ble_gatts_hvx" and decrement this counter with every BLE_GATTS_EVT_HVN_TX_COMPLETE event by "p_ble_evt->evt.gatts_evt.params.hvn_tx_complete.count".

At the point where I cannot send any data anymore the size of my counter has the value of my before configured HVN_QUEUE size. So it makes sense that I always get the NRF_ERROR_RESOURCES error because the notification buffer is full. But why does the softdevice not send any notifications any more??

Is there something wrong with the Interrupts? In this question a similar behaviour was described: https://devzone.nordicsemi.com/f/nordic-q-a/39538/sd_ble_gatts_hvx-nrf_error_resources-in-do-while-loop

I build my application based on the ble_app_hrs_freertos example in the SDK 15.0.0

Thank you very much for any suggestions.