Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

NUS and dynamically allocated data

I'm trying to dynamically allocate some data, send it over NUS, and then free it, but I'm not sure when the SoftDevice is done with it and it's safe to free.  Would the following code work safely (assuming I get NRF_SUCCESS)?  Do I need to wait for some TX Complete event before it's safe to free it?

uint8_t length = 10;
void* some_data = malloc(length);
if (ble_nus_data_send(&m_nus, (uint8_t*)some_data, &length, m_conn_handle) == NRF_SUCCESS)
{
    free(some_data);
}

Thanks

Parents Reply Children
No Data
Related