Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

How can I check printf's buffer?

Hi

Using nRF52DK + SDK17.1 + S112

I have retarget enabled & using printf to output over UART (no DMA)

What's the best way to check if printf is busy outputting data? I want to disable the UART after a print to save power but need to wait until all characters have been transmitted and the UART is empty.

Nick

Parents
  • Hi Nick,

    The app uart libary used by retarget.c does not expose an API to check if there are pending TX transfers. So, the simplest solution is probably to add a small busy-wait (nrf_delay_ms(), etc) before you disable the peripheral. Otherwise, you would have to modify app_uart_fifo.c to include a function to check if there are bytes left in the TX fifo.

    Possibly something like this:

    bool app_uart_tx_in_progress(void)
    {
        bool fifo_empty = false;
        uint32_t size;
    
        if (FIFO_LENGTH(m_tx_fifo) == 0)
        {
            fifo_empty = true;
        }
        
        return (fifo_empty == false);
    }

    Best regards,

    Vidar

Reply
  • Hi Nick,

    The app uart libary used by retarget.c does not expose an API to check if there are pending TX transfers. So, the simplest solution is probably to add a small busy-wait (nrf_delay_ms(), etc) before you disable the peripheral. Otherwise, you would have to modify app_uart_fifo.c to include a function to check if there are bytes left in the TX fifo.

    Possibly something like this:

    bool app_uart_tx_in_progress(void)
    {
        bool fifo_empty = false;
        uint32_t size;
    
        if (FIFO_LENGTH(m_tx_fifo) == 0)
        {
            fifo_empty = true;
        }
        
        return (fifo_empty == false);
    }

    Best regards,

    Vidar

Children
Related