Unable to allocate TX context ENOBUFS

I am trying to call bt_gatt_notify_cb() from a for loop which occurs within a workqueue thread.

The work is submitted periodically through an interrupt call.

This works just fine while testing on the LightBlue app on an iOS device. However, when I test this on a Windows PC running the Python GATT client software Bleak, I get the error "Unable to allocate TX context" with error code -ENOBUFS after running the program for a few seconds.

I attempt to transmit 1952 bytes through this for loop every 488ms. The packet payload is 244 bytes. The number of tx buffers is 255.

I'd very much appreciate some help!

The connection parameters I'm using are:
interval: 30ms, latency: 3, timeout: 6s

I've increased the payload and TX buffer count in the prj.conf file:
CONFIG_BT_CONN_TX_MAX=255
CONFIG_BT_L2CAP_TX_BUF_COUNT=255
CONFIG_BT_L2CAP_TX_MTU=247
CONFIG_BT_BUF_ACL_TX_COUNT=255
CONFIG_BT_BUF_ACL_TX_SIZE=251
CONFIG_BT_BUF_ACL_RX_SIZE=251
CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS=y
CONFIG_BT_CTLR_DATA_LENGTH_MAX=251
CONFIG_BT_USER_PHY_UPDATE=y
CONFIG_BT_USER_DATA_LEN_UPDATE=y

  • Hi

    The only reason you should see these -ENOBUFS error messages should be because the devices transmit faster than the buffers are able to clear on either side. Seeing as you're not seeing this when using iOS devices (where MTU size is restricted to 184 IIRC) I think the throughput of 244 bytes fill up the buffers quicker than they are emptied. The best way to solve this would be to add a check that there are available buffers before sending the next packet(s). You can try tweaking the parameters as well to see if that helps at all, for example the event length  and latency numbers.

    I can also recommend checking out this throughput blog post over at Novel Bits where they do some testing finding the best throughput for a BLE application on nRF52840 devices: https://novelbits.io/bluetooth-5-speed-maximum-throughput/ 

    Best regards,

    Simon

Related