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

Getting lots of NRF_ERROR_RESOURCES on notifications

We have an external interrupt every 4ms that collects one 24-bit sample from an analog front end via SPI. After Collecting 6 samples (18 bytes) we send a notification with the data which should then be every 4ms * 6 = 24ms. We're based on the ble_app_template example SDK v13 S132 (nRF52832) with default config settings and MIN_CONN_INTERVAL set to 7.5ms however, We're getting lots of NRF_ERROR_RESOURCES, what could be the problem?

Send function:

SEND_ERROR_CHECK(hrz_ecg_send_channel(&m_ecgs, m_ecgs.ecg_channel_1_handles, hrz_channel1, HRZ_ECGS_MAX_BUFFER_SIZE));

Error check:

#define SEND_ERROR_CHECK(ERR_CODE)                                  \
do                                                              \
{                                                               \
    const uint32_t LOCAL_ERR_CODE = (ERR_CODE);                 \
    if (LOCAL_ERR_CODE == NRF_ERROR_RESOURCES) {                \
      NRF_LOG_ERROR("Buffer full\r\n");                         \
    }                                                           \
    else if ((LOCAL_ERR_CODE != NRF_SUCCESS) &&                 \
          (LOCAL_ERR_CODE != NRF_ERROR_INVALID_STATE) &&        \
          (LOCAL_ERR_CODE != BLE_ERROR_GATTS_SYS_ATTR_MISSING)  \
        )                                                       \
      {                                                         \
          NRF_LOG_ERROR("Error code: %d\r\n", LOCAL_ERR_CODE);  \
          APP_ERROR_HANDLER(LOCAL_ERR_CODE);                    \
      }                                                         \
} while (0)

BLE_GATTS_EVT_HVN_TX_COMPLETE:

case BLE_GATTS_EVT_HVN_TX_COMPLETE:
         NRF_LOG_INFO("Buffer free ");
         NRF_LOG_INFO("Count: %d\r\n",p_ble_evt->evt.gatts_evt.params.hvn_tx_complete.count);
         break;

Maximum packets per connection event:

memset(&ble_cfg, 0, sizeof ble_cfg);
ble_cfg.conn_cfg.conn_cfg_tag                     = CONN_CFG_TAG;
ble_cfg.conn_cfg.params.gatts_conn_cfg.hvn_tx_queue_size = 20;
err_code = sd_ble_cfg_set(BLE_CONN_CFG_GATTS, &ble_cfg, ram_start);
APP_ERROR_CHECK(err_code);

Console output: image description

  • Hi,

    The NRF_ERROR_RESOURCES error means that all the BLE buffers in the SoftDevice are full, and that you can not upload any more notifications until the BLE_GATTS_EVT_HVN_TX_COMPLETE event occurs.

    The number of Handle Value Notifications that can be queued is configured by ble_gatts_conn_cfg_t::hvn_tx_queue_size. When the queue is full you will get the NRF_ERROR_RESOURCES error. I suggest that you try to increase the queue size.

    From S132 v.4.0.x migration document:

    /* set HVN queue size */
    
    memset(&cfg, 0, sizeof(ble_cfg_t));
    
    cfg.conn_cfg.conn_cfg_tag = high_bw_conn_cfg_tag;cfg.conn_cfg.params.gatts_conn_cfg.hvn_tx_queue_size = 7;
    
    /* application wants to queue 7 HVNs */
    
    sd_ble_cfg_set(BLE_CONN_CFG_GATTS, &cfg, ...);
    
  • Thanks for the recommendation. We made the modifications and added hvn_tx_queue_size = 20 but we are still getting NRF_ERROR_RESOURCES. By the way when inspecting the count on the BLE_GATTS_EVT_HVN_TX_COMPLETE we get 1.

  • Hi JD, Even if you set the hvn_tx_queue_size to 20 but if the speed when sending is slower than the speed when you queuing then you will have buffer full.

    Your observation of BLE_GATTS_EVT_HVN_TX_COMPLETE count= 1 implied that there was only one packet per connection event. This depends on the central device you connect to, some Android device only support 1 packet per connection event.

    If you match the number of packet you queue with the count number when you receive BLE_GATTS_EVT_HVN_TX_COMPLETE you should be fine. (In my implementation I simply queue continuously until I get NRF_ERROR_RESOURCES then I stop and wait for BLE_GATTS_EVT_HVN_TX_COMPLETE then queue again. )

  • Hi, you're right, the culprit in this case is most likely the central device, I've tested with different ones and some behave better with few or no errors at all, thanks.

  • Hello JD, Did you resolve issue with BLE_GATTS_EVT_HVN_TX_COMPLETE always equal to 1. I have the same problem, and I am not able to send more then three notification in one connection interval. Any help appreciate. BR, Bartek

Related