This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Get the available space of the UART tx buffer

Hello,

I have a application on a nRF52840DK as central. The code is based on the ble_app_uart_c example. 

I need to send a lot of data through UART into the serial port of my pc (~120 kBit/s). I want to make sure that the tx buffer of the UART does not overflow. 

So here is my question:

Is there a way to read out the available space of the UART tx buffer in the ble_app_uart_c example? 

Thank you very much in advance.

Kind regards,

Maria

Parents
  • Hi,

    If you are using the unmodified ble_app_uart_c example with app_uart_fifo for sending data over UART, you should get a NRF_ERROR_NO_MEM return code from app_uart_put when the FIFO TX buffer configured for app_uart is full. The FIFO is not available outside of the library, but you can create a function to return the available size like this:

    uint32_t app_uart_get_tx_fifo_size(void)
    {
        return (m_tx_fifo.buf_size_mask + 1) - FIFO_LENGTH(m_tx_fifo);
    }

    Note that app_uart transmits a single byte over UART at a time. If you need to transfer large amounts of data over UART quickly, you may be better off with using the UARTE driver with EasyDMA support, or the new libUARTE library. These allows you to send larger chunks of data over UARTE (up to 65535 bytes for nRF52840) directly from RAM, without any CPU intervention.

    Best regards,
    Jørgen

Reply
  • Hi,

    If you are using the unmodified ble_app_uart_c example with app_uart_fifo for sending data over UART, you should get a NRF_ERROR_NO_MEM return code from app_uart_put when the FIFO TX buffer configured for app_uart is full. The FIFO is not available outside of the library, but you can create a function to return the available size like this:

    uint32_t app_uart_get_tx_fifo_size(void)
    {
        return (m_tx_fifo.buf_size_mask + 1) - FIFO_LENGTH(m_tx_fifo);
    }

    Note that app_uart transmits a single byte over UART at a time. If you need to transfer large amounts of data over UART quickly, you may be better off with using the UARTE driver with EasyDMA support, or the new libUARTE library. These allows you to send larger chunks of data over UARTE (up to 65535 bytes for nRF52840) directly from RAM, without any CPU intervention.

    Best regards,
    Jørgen

Children
No Data
Related