This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
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

Help to understanding error Not able to allocate UART receive buffer

Hi everybody,

I am working in a project where there are one central_UART with multilink and diverse peripheral.

The devices are a custom board Fanstel BC840, nRF Connect 3.7.1 and SDK v1.6.1.

Everything works well.

The issue come when i try to send 20 bytes every 0.2 seconds, when i start to send data is okey but with the time Not able to allocate UART receive buffer is triggered, and with this every function relationed with UART is broken, triggering Not able to allocate UART receive buffer/Not able to allocate UART send data buffer.

I think is something about buffers space. If somebody could explain me how to solve i was gratefull,

Thank you,

regards.

  • Hi,

    it sounds like you may not be freeing your buffers properly. Could you doublecheck that?

    Is your code based on the sample at nrf/samples/bluetooth/central_uart? In that sample allocated 'buf's are passed to k_free() after they are used, to avoid memory leaks.

  • Hi,

    sorry for the delay, could you explain me  what is the properly way to do that??

    Yes, my code is based on nrf/samples/bluetooth/central_uart, where i don't modify UART structure of reception.

    There are many places along the code where a uart_data_t buffer is declared, later uses function k_malloc(buff), but there isn't a k_free later. For example here i got that error.

    On the another hand, there are some times that k_free is used and makes sense to me, like here:

    But all of this is the default example, and i can't understand how to implement these k_free.

    If I put at the end of the function on first image a k_free i got this error:


    ASSERTION FAIL [chunk_used(h, c)] @ WEST_TOPDIR/zephyr/lib/os/heap.c:154

    unexpected heap state (double-free?) for memory at 0x2000949c

    So please, i need a recomendation/guidance to how, where and when i need to clean that buffers.

    Thank u for the response,

    regards.

  • A buffer allocated for UART RX, like the one in uart_work_handler(), is freed after the data is sent over BLE.
    After the data is sent over BLE, the callback ble_data_sent() is called and this is where the buffer is passed to k_free().

    Have you made any changes to the application? Anything which allocates data or uses the FIFOs?

Related