Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Nordic UART Service (NUS) truncates received data due to wrong type (uint8_t instead of uint16_t) in ble_nus_c_evt_t

The problem applies to both, nRF5 SDK 15.2 as well as to the nRF5 SDK for Thread and Zigbee 2.0.0.

The Nordic UART Service Client (ble_nus_c.h) defines a struct that contains the NUS event data received from a peer.

In this struct, the data_len field is typed to an uint8_t (see ble_nus_c.h, line 142).

in all other parts of the software Bluetooth software stack invovled, as well as on the peer side (ble_nus.h), uint16_t is used as data length type.

The alleged truncation results in in wrong length information on the receiving end.

To reprodcue the issue, transfer more than 255 bytes via from the ble_app_uart example project to the the ble_app_uart_c example project, running both on an nRF528XX.

Fix:

Modify line 142 from

uint8_t              data_len;

to

uint16_t             data_len;

Related