This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

sd_ble_gattc_write and sd_ble_gatts_hvx who owns payload storage?

Hello, I have a question that I can't find an answer to in the documentation. The answer may be somewhere and I am just unable to find it.

My application utilizes sd_ble_gattc_write to send data to peripheral devices. This uses a (pointer to) a ble_gattc_write_params_t struct, which includes a pointer to the value data to be written. Does the internals of the softdevice copy the payload data from this pointer somewhere? Or is the data read from the pointer directly when the write actually occurs? I ask because I need to know if I am using malloc'ed storage, when I can free this pointer, or in the case where I use static allocation, when the contents can be updated with the next payload.  

Basically my question is does the call to sd_ble_gattc_write copy the data to the Softdevice memory and then send, or does it read from the application memory during send? I will be doing both writes with response and without response if that changes anything. 

I have the same question for sd_ble_gatts_hvx Will there be any problems if the pointer is freed or the data modified while writes are queued?

  • Hello,

    Does the internals of the softdevice copy the payload data from this pointer somewhere?

    Yes it does. Once sd_ble_gattc_write() (and sd_ble_gatts_hvx()) returns NRF_SUCCESS (==0), then the content of the buffer is copied into the softdevice, and you can safely modify the content of the input parameter (pointer).

    However, if sd_ble_gattc_write() returns NRF_ERROR_RESOURCES (==19), then the softdevice buffer is full, and you need to wait and try again. 

    Best regards,

    Edvin

Related