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

printf with UART - blocking way?

Hello,

I used the uart example to print text over serial communication from the SDK v11.

The problem is when I write lot of text consecutively, I don't receive all data on the terminal. (It clearly appears when I change the UART_TX_BUF_SIZE to a small value) I found that the file \sdk\components\libraries\uart\retarget.c implements the IO primitives. In the function _write, it appears that the FIFO memory is quiclky full.

int _write(int file, const char * p_char, int len) {
    int i;
    UNUSED_PARAMETER(file);

    for (i = 0; i < len; i++)
    {
        if (app_uart_put(*p_char++) == NRF_ERROR_NO_MEM)
		blinkErr(); // or return i; to allow printf to report error to application code
    }
    return len;
}

And it blinks. I also found that app_uart_put is a non-blocking call. It explains that I can fill the FIFO before it is empty.

According to this question, there was a bug (devzone.nordicsemi.com/.../) but it should be fixed in the SDK v11.

In any case, I am looking for a way to send data over UART synchronously (yes, 'A' is for asynchronous...) Do you have any ideas ? Make a loop, uart option ?

Thank you in advance !

Parents
  • The app_uart library returns an event when the TX buffer is empty, and you can wait for this event to make the library appear blocking:

    Pseudo code:

    // Declare variable
    static volatile bool uart_tx_in_progress = false;

    // Write to the uart
    uart_tx_in_progress = true;
    app_uart_put(...);
    while(uart_tx_in_progress);

    // Excerpt from UART event handler
    if(p_event->evt_type == APP_UART_TX_EMPTY)
    {
    uart_tx_in_progress = false;
    }

    Regards Torbjørn

  • nRF51, SDK11. UART fifo init. I resolved this problem with estimated delay (vs. message size&baudrate) and larger FIFO size (515 bytes). Unfortunately I have already removed this control sequence. Obviously no event has fired when FIFO was empty. The event handler was well initiated in uart_init function. I will reestablish sequences & zip the project soon...

Reply Children
No Data
Related