nRF5 SDK is not maintained anymore
More Info: Consider nRF Connect SDK for new designs
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

nrf logging api

hi, 

sdk 17.1.0

Can I call "NRF_LOG_INFO" API back to back ? Does it copy the contents of the buffer (var) to an internal buffer ?

For example, in the below code, does the second call "NRF_LOG_INFO" corrupt the buffer 'var' ?

uint8_t var[31];

//fill var[]

NRF_LOG_INFO("%s", var);

//changing var[] array

NRF_LOG_INFO("%s", var);

Parents
  • Hi,

    If you do not use deferred logging, then this would be OK as logging happens immediately. With deferred logging this will not be OK though, as data is not copied to a dedicated buffer by default. So for volatile data like stack variables or variables that are overwritten (both is the case here), no should explicitly use NRF_LOG_PUSH to copy the string to an internal logger buffer. For instance like this:

    NRF_LOG_INFO("Message: \"%s\"", NRF_LOG_PUSH(my_volatile_string));

Reply
  • Hi,

    If you do not use deferred logging, then this would be OK as logging happens immediately. With deferred logging this will not be OK though, as data is not copied to a dedicated buffer by default. So for volatile data like stack variables or variables that are overwritten (both is the case here), no should explicitly use NRF_LOG_PUSH to copy the string to an internal logger buffer. For instance like this:

    NRF_LOG_INFO("Message: \"%s\"", NRF_LOG_PUSH(my_volatile_string));

Children
Related