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

invaild parameter error about setting BLE4.2 ATT MTU and data length.

Hello all,

SDK:S332 V4.0.5(related to BLE V4.2).

Platform:NRF52832.

For improving BLE data throughout, i tried to set some configurations by other guidance.

Following:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//Macros
#define NRF_BLE_GATT_MAX_MTU_SIZE 158 //GATT_MTU_SIZE_DEFAULT -> 158
#define BLE_GATT_ATT_MTU_DEFAULT 23
static void gatt_mtu_set(uint16_t att_mtu) //set att_mtu 64
{
ret_code_t err_code;
err_code = nrf_ble_gatt_att_mtu_periph_set(&m_gatt, att_mtu);
APP_ERROR_CHECK(err_code);
}
static void conn_evt_len_ext_set(bool status) //status true
{
ret_code_t err_code;
ble_opt_t opt;
memset(&opt, 0x00, sizeof(opt));
opt.common_opt.conn_evt_ext.enable = status ? 1 : 0;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Unfortunately,when the device connceted to nRF Connect,always return "NRF_ERROR_INVALID_PARAM" printing by Logger.

When connected  was established,  void on_connected_evt(nrf_ble_gatt_t * p_gatt, ble_evt_t const * p_ble_evt) called, in this function,it will begin an ATT MTU exchange:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Begin an ATT MTU exchange if necessary.
if (p_link->att_mtu_desired > p_link->att_mtu_effective)
{
NRF_LOG_DEBUG("Requesting to update ATT MTU to %u bytes on connection 0x%x.\r\n",
p_link->att_mtu_desired, conn_handle);
err_code = sd_ble_gattc_exchange_mtu_request(conn_handle, p_link->att_mtu_desired);
if (err_code == NRF_SUCCESS)
{
p_link->att_mtu_exchange_requested = true;
}
else if (err_code == NRF_ERROR_BUSY)
{
p_link->att_mtu_exchange_pending = true;
NRF_LOG_DEBUG("sd_ble_gattc_exchange_mtu_request()"
" on connection 0x%x returned busy, will retry.\r\n", conn_handle);
}
else
{
NRF_LOG_ERROR("sd_ble_gattc_exchange_mtu_request()"
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

The logger shows:

nrf_ble_gatt:DEBUG:Requesting to update ATT MTU to 64 bytes on connection 0x0.
nrf_ble_gatt:ERROR:sd_ble_gattc_exchange_mtu_request() returned unexpected value 0x7.
nrf_ble_gatt:DEBUG:Requesting to update data length to 251 on connection 0x0.
nrf_ble_gatt:ERROR:sd_ble_gap_data_length_update() (request) on connection 0x0 returned unexpected value 0x13.
nrf_ble_gatt:INFO:nrf_ble_gatt_on_ble_evt
nrf_ble_gatt:DEBUG:Peer on connection 0x0 requested a data length of 27 bytes.
nrf_ble_gatt:DEBUG:Updating data length to 27 bytes on connection 0x0.
nrf_ble_gatt:INFO:nrf_ble_gatt_on_ble_evt
nrf_ble_gatt:DEBUG:Data length updated to 27 on connection 0x0.
nrf_ble_gatt:DEBUG:max_rx_octets: 27
nrf_ble_gatt:DEBUG:max_tx_octets: 27
nrf_ble_gatt:DEBUG:max_rx_time: 328
nrf_ble_gatt:DEBUG:max_tx_time: 328
:DEBUG:ATT MTU exchange completed. central 0xf7 peripheral 0x40

Is there any question?The setting parameters look correct,maybe other setting is must?

Thank you for you reply. 

Best regards