Possible to check UART0 Tx buffer empty before light sleep?

dalbert
Posts: 7
Joined: Wed Nov 16, 2016 3:45 am

Possible to check UART0 Tx buffer empty before light sleep?

Postby dalbert » Tue Oct 31, 2023 12:39 am

A call to esp_light_sleep_start(), immediately stops UART0 output, this can have a number of undesirable consequences. Is there any way to check whether the Tx buffer empty status so you can delay sleep entry until UART output is finished? I didn't see anything in the HardwareSerial class. If not, is there a recommended workaround? Thanks!

lbernstone
Posts: 792
Joined: Mon Jul 22, 2019 3:20 pm

Re: Possible to check UART0 Tx buffer empty before light sleep?

Postby lbernstone » Tue Oct 31, 2023 12:48 am

HardwareSerial::flush() will block until the uart queue is cleared.

dalbert
Posts: 7
Joined: Wed Nov 16, 2016 3:45 am

Re: Possible to check UART0 Tx buffer empty before light sleep?

Postby dalbert » Sat Nov 04, 2023 11:20 pm

Thanks @lbernstone, that is indeed a good workaround in many cases. I was (and still am) hoping to find a non-blocking solution; the flush code eventually gets to this:

Code: Select all

    UART_MUTEX_LOCK();
    while(!uart_ll_is_tx_idle(UART_LL_GET_HW(uart->num)));

    if ( !txOnly ) {
        ESP_ERROR_CHECK(uart_flush_input(uart->num));
    }
    UART_MUTEX_UNLOCK();
I'll check to see if it's feasible to grab the mutex lock and call uart_ll_is_tx_idle() externally.

Who is online

Users browsing this forum: Google [Bot] and 119 guests