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.

Parents
  • Hello,

    I see. Where do you have your do-while-loop? Are you calling sd_ble_gatts_hvx from the main application or from an interrupt? If in an interrupt, what interrupt are you sending from?

    The reason that I am asking is that I suspect that you are sending this from a softdevice interrupt, which you can do, but this will also block the TX_COMPLETE event, because you never leave the softdevice interrupt. A solution for this is to leave the softdevice interrupt, and e.g. set a flag that you can trigger the sending function (do-while-loop) from the main IRQ level.

    If this isn't the issue, have you tried to sniff the connection using e.g. the nRF Sniffer? Are the packets actually sent?

    Best regards,

    Edvin

  • Hi,Edvin

    i have the same problem with . I am calling sd_ble_gatts_hvx from an interrupt(bsp event handler:BSP_EVENT_KEY_3)."set a flag that you can trigger the sending function (do-while-loop) from the main IRQ level.",what the main IRQ level means? main application?besides where can i find the BSP_EVENT_KEY_3 IRQ level?

Reply Children
  • Hello,

    Please create a new thread. The BSP event IRQ is actually a mix of the GPIOTE_CONFIG_IRQ_PRIORITY and the APP_TIMER_CONFIG_IRQ_PRIORITY. The button push (gpiote-irq) starts a timer and the timeout from the app timer irq triggers the BSP events. 

    But this doesn't necessarily solve your issue? Is the issue related to IRQ or the return value from the hvx call? Please describe the issue in a new ticket.

    BR,

    Edvin

Related