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

sd_ble_gatts_hvx error with serializer

Hi there!

I have been working with serializer and have the below issue: I am using sd_ble_gatts_hvx() to transfer 20 bytes in burst until I get an error (TX buffer full or other errors). However, I am getting an error code 9: INVALID length for sd_ble_gatts_hvx(). Debugging further I found that it is an error while decoding at the Nordic SDK. I guess decoding fails because of invalid length though the length was <= 20. But the problem here is in spite of getting an error response, the stack is transmitting this packet most of the times. So as a work around I stopped re-transmitting the packet if the error code is 9. This still doesn't solve my problem as sometimes the packet is not transmitted for this case. Can you help me out in fixing this issue? If there is an issue with the NRF stack/SDK, is there a workaround?

I am using nrf SDK 12.1 The APP is hosted on another controller and I am using the serializer code to interface with nrf52832, S132 through UART.

  • Can you track down which exact API threw the NRF_ERROR_INVALID_LENGTH ? It's very strange that after you get the error, the data still get through to the softdevice. It seems like a bug then.

    We need to find a way to reproduce the issue. How often do you receive error code 9 ? Do you have the same issue if you call other API, such as the sd_ble_gatts_value_set() ?

    If you don't do burst force, and simply call sd_ble_gatts_hvx() once after each TX_COMPLETE, do you see the issue ?

  • Hi! Thanks for your response!

    1. Out of 7000 packets, I get error code as 9 for 20 to 30 packets. By packet I mean 20 byte length BLE data. As far as sd_ble_gatts_value_set() is concerned (I have used itfor on connect), I don't see any error. But I have not used this API for repeated transmissions. Also I do not get BLE_EVT_TX_COMPLETE every time I get error code as 9. Out of 20 to 30 times I get 9, I receive BLE_EVT_TX_COMPLETE for 3 to 5 times.

    2. I see the problem even when I don't use burst mode. I call sd_ble_gatts_hvx() only after TX_COMPLETE.

    3. When I implemented point 2, I see another problem:

    I get buffer full error (12290). This should not be the case as I transmit my next 20 byte packet when I get the BLE_EVT_TX_COMPLETE callback. Can you also check if the buffer handling in stack is fine. And how much is the buffer size that is allocated in the nRF stack?

  • @Gauti: Have you tried to trace down in the serialization library on which function throw error code 9 ? Note that NRF_ERROR_INVALID_LENGTH is not in the list of return code of sd_ble_gatts_hvx().

    Error 12290 = 0x3002 means BLE_ERROR_INVALID_CONN_HANDLE not buffer full. Could you double check ? If you run out of buffer for notification, you should receive BLE_ERROR_NO_TX_PACKETS = 0x3004 instead.

  • @Hung Bui: I think it is caused by ble_gatts_hvx_params_t_dec() Sorry my bad I overlooked at the error code, 12290 = 0x3002 means BLE_ERROR_INVALID_CONN_HANDLE. As of now I do not see BLE_ERROR_NO_TX_PACKETS

  • @Gauti: I assume you have HWFC on the UART communication ? Could you reproduce the issue using nRF52 DK ? Can you provide some source code that we can try here and reproduce the issue here?

    BLE_ERROR_INVALID_CONN_HANDLE may come if the connection handle provided is incorrect or if the connection is already terminated.

Related