Printf over UART at high rate

Hi Nordic, 

I am using the SDK 17, s140 and the nrf52840 , with a modified multilink NUS central example. The intention is to print over UART as fast as possible all data received from the BLE. But I get sometimes errors on the UART transmission -> while using cat in my terminal, there are several packages that are not transmitted complete.

I initialize the uart like this:

#define UART_TX_BUF_SIZE        16384 
#define UART_RX_BUF_SIZE       16384
static void uart_init(void)
{
    ret_code_t err_code;

    const app_uart_comm_params_t comm_params =
          {
              RX_PIN_NUMBER,
              TX_PIN_NUMBER,
              RTS_PIN_NUMBER,
              CTS_PIN_NUMBER,
			  APP_UART_FLOW_CONTROL_ENABLED, 
              false,
			  NRF_UART_BAUDRATE_1000000
          };

        APP_UART_FIFO_INIT(&comm_params,
                             UART_RX_BUF_SIZE,
                             UART_TX_BUF_SIZE,
                             uart_error_handle,
							 APP_IRQ_PRIORITY_HIGH, 
                             err_code);

        APP_ERROR_CHECK(err_code);
}

To print, i use printf() with the RETARGET_ENABLED enabled. 

Theoretically, dma should be enabled by #define UART0_CONFIG_USE_EASY_DMA 1

I'm only printing from one place of the application. Is there something else i could do to receive properly the packages? 

Maybe to use a better function than printf(). 

Any help is welcome. Thank you very much! 

Parents
  • Hi,

    app_uart (which is used by printf with RETARGET_ENABLED) is not the best library to use if you need high throughput. app_uart will only send/receive a single byte at a time, meaning the CPU will be very busy handling all the interrupts from the UART(E) peripheral when sending/receiving much data. The app_uart library was originally written for nRF51, which did not have support for EasyDMA, meaning there was always a need to update the data pointer for each byte being transmitted/received anyways. App_uart also does not implement any timeouts, meaning you would see delays in receiving data chunks if larger buffers are used.

    I would rather recommend you to switch to using the libUARTE library, which can handle larger buffers, automatic buffer swapping, and timeouts. I posted a modified version of ble_app_uart in this ticket, which replaces app_uart with libUARTE.

    Best regards,
    Jørgen

  • Hi Jorgen, thank you for your reply.

    I used the library but still don't get good uart transmissions.

    I changed the uart speed to 1Mbps and increased the timeout to 1ms to test if this could bring better results but no.
    I also constantly get the NRF_LIBUARTE_ASYNC_EVT_ERROR error.

    I'm using the nrf_libuarte_async_tx() fcn to transmit the messages.

    Is there something else that i need to change?  what's the maximum Throughput that we can obtain with that library?

    Thanks in advance!

Reply
  • Hi Jorgen, thank you for your reply.

    I used the library but still don't get good uart transmissions.

    I changed the uart speed to 1Mbps and increased the timeout to 1ms to test if this could bring better results but no.
    I also constantly get the NRF_LIBUARTE_ASYNC_EVT_ERROR error.

    I'm using the nrf_libuarte_async_tx() fcn to transmit the messages.

    Is there something else that i need to change?  what's the maximum Throughput that we can obtain with that library?

    Thanks in advance!

Children
No Data
Related