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

BLE fragmentation issue

Hi 

I ran in some problems with my BLE fragmentation.
I want to send data (files) up to 6kBytes over BLE (Bluetooth 5 on nrf52840 to another nrf52840).
My project is based on the BLE APP UART EXAMPLE which I simply modified.

To send that amount of data, I wrote a BLE fragmentation function which sends out BLE fragments up to "BLE_NUS_MAX_DATA_LEN" (which are 244 Bytes).
Sending data up to roughly 960 Bytes works fine (4 BLE packets).
Exceeding the fourrh BLE packet, for example 990 Bytes (5 BLE packets) the program get stuck in something (like infinite loop) which I wasn't able to figure out yet. In debug mode after pausing the infinite loop, I end up in the "NRF_BREAKPOINT_COND", so restart is required. The Debug log just says: "Fatal error." (With Error-ID: 1)


I cannot figure out the reason why the programm stops working at that point.

I attached my fragmentation function below.

Thanks for your suggestions in advance.

  • Hi Alexander ,

    When do you call the ble_send_fragment_by_fragment() function ? 

    If you call the function from an interrupt handler it may not be the best idea. 

    Staying in the loop to try sending the data may block the softdevice handle to fetch the events. And it again resulted in that the softdevice can't send anything more. It can result in a deadlock. 

    Instead of staying in the loop trying to send data, you can instead wait for the BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE before you send more data. Try to call as much as possible of the write command inside that event, and stop and wait for next event if you hit buffer full. 

    I would suggest to have a look at ble_app_att_mtu_throughput example. 

  • Hi.

    Good thought.
    Actually, I am calling the function in the SPI handler, as I want to have a SPI-BLE interface. 

    I will try to rearange the program flow and put the ble_send_fragment_by_fragment in the main loop. 

    I will come back to you as soon as I got some new results.

    Thanks.

  • Looks like it works to far.

    Now I start the BLE data forwarding in the main as soon as the "spis_xfer_done" flag is set.
    And continue sending frames as soon as the "ble_evt_handler" will be called with the "BLE_GATTS_EVT_HVN_TX_COMPLETE" event ID.

    It looks like all packets will be send out now. 
    However the communication seem to be a little slow still (approx. 1,6 seconds for 6 kBytes), but that is what I will focus on now.
    So if you have hints on that in advance, I would appreciate that as well.

    Thanks!

  • I would suggest you to get a sniffer trace. So we can see what actually happens over the air. 

    Note that to be able to send longer packet over the air, you would need to have good NRF_SDH_BLE_GAP_DATA_LENGTH (251) and good NRF_SDH_BLE_GAP_EVENT_LENGTH so that it cover the whole connection interval . 

  • Hello, just saw your post. I understood the function but could someone explain to me how to implement this in my code? Where do I have to put this function in my main loop to have my packets in my app ? Thank you in advance 

Related