nrf_ringbuf has a bug which happens when mixing nrf_ringbuf_cpy_put() with nrf_ringbuf_alloc() and nrf_ringbuf_put(). After copying data with nrf_ringbuf_cpy_put() a later alloc will overwrite the same buffer. See the following example code:
I would expect the output to be:
got 15: a1 a2 a3 a4 a5 a6 a7 a8 a9 aa b1 b2 b3 b4 b5
But instead it overwrites the first bytes:
got 15: b1 b2 b3 b4 b5 a6 a7 a8 a9 aa 0 0 0 0 0
Adding the following to nrf_ringbuf.c line 138 in nrf_ringbuf_cpy_put() fixes it:
p_ringbuf->p_cb->tmp_wr_idx = p_ringbuf->p_cb->wr_idx;
Also I suspect there may be a similar bug when getting with nrf_ringbuf_cpy_get() vs nrf_ringbuf_get() and nrf_ringbuf_free() but i have not verified or used it.
The bug is present in SDK 16 and 17.
Please fix, I find it very disturbing that I can't trust even such a simple library function within the official SDK!