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

sd_ble_gap_data_length_update gives NRF_ERROR_RESOURCES when setting max octets > 151 despite ATT_MTU set to 247 on initializing ble.

Hi, 

I'm using pc-ble-driver and a PCA10040 devkit. I'm having issues with using sd_ble_gap_data_length_update.


First, my configuration has ATT_MTU set to 247:

  memset(&ble_cfg, 0x00, sizeof(ble_cfg));
  ble_cfg.conn_cfg.conn_cfg_tag                 = conn_cfg_tag;
  ble_cfg.conn_cfg.params.gatt_conn_cfg.att_mtu = 247;

  error_code = sd_ble_cfg_set(m_adapter, BLE_CONN_CFG_GATT, &ble_cfg, ram_start)

Then some time later I run sd_ble_gap_data_length_update:

uint32_t SdSetMtu(unsigned int conn_handle, unsigned int data_len)
{
  ble_gap_data_length_params_t params;
  params.max_tx_octets = (uint16_t) data_len;
  params.max_rx_octets = (uint16_t) data_len;
  params.max_tx_time_us = BLE_GAP_DATA_LENGTH_AUTO;
  params.max_rx_time_us = BLE_GAP_DATA_LENGTH_AUTO;
  ble_gap_data_length_limitation_t p_dl_limitation;
  uint32_t err_code = sd_ble_gap_data_length_update(
    m_adapter,
    conn_handle,
    &params,
    &p_dl_limitation
  );
  return err_code;
}

I'm receiving an error_code NRF_ERROR_RESOURCES when data_len > 151 which is unexpected. When I set ATT_MTU to 50 in the config, I get the same error code for data_len > 54, which is expected.

It seems like somewhere either in possibly the connectivity firmware or elsewhere that the max MTU is capped at 147? But as I understand it, the maximum MTU for NRF52382 should be 247+4=251?

  • Ah, again I just found the answer immediately after posting. It seems that the event_length parameter in gap config needs to be >4 to allow for MTU sizes > 225. So what I've done is:

      memset(&ble_cfg, 0, sizeof(ble_cfg));
      ble_cfg.conn_cfg.conn_cfg_tag                     = conn_cfg_tag;
      ble_cfg.conn_cfg.params.gap_conn_cfg.conn_count   = MAX_PEER_COUNT;
      ble_cfg.conn_cfg.params.gap_conn_cfg.event_length = 5; // must be >4.

    According to the documentation, "The event length and the connection interval are the primary parameters for setting the throughput of a connection." A full explanation for why this is would be greatly appreciated.

  • Hi,

    Good to hear you found the solution. The explanation for this is that:

    1. The ATT_MTU size must be high enough so that the internal buffer is large enough.

    2. The configured event length must be long enough in time to actually fit the event. The longer the packet, the longer the event needs to be in order to have time to transmit the packet before the event ends.

Related