Merge branch 'fix/lp_uart_garbled_print' into 'master'

fix(lp_uart): Added lp_uart_tx_flush API

Closes IDFGH-13650

See merge request espressif/esp-idf!33487
This commit is contained in:
Sudeep Mohanty 2024-09-19 19:54:36 +08:00
commit 13d4235d73
3 changed files with 32 additions and 2 deletions

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -59,6 +59,16 @@ esp_err_t lp_core_uart_write_bytes(uart_port_t lp_uart_num, const void *src, siz
*/
int lp_core_uart_read_bytes(uart_port_t lp_uart_num, void *buf, size_t size, int32_t timeout);
/**
* @brief Flush LP UART Tx FIFO
*
* This function is automatically called before the LP core powers down once the main() function returns.
* It can also be called manually in the application to flush the Tx FIFO.
*
* @param lp_uart_num LP UART port number
*/
void lp_core_uart_tx_flush(uart_port_t lp_uart_num);
#ifdef __cplusplus
}
#endif

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -63,6 +63,24 @@ int lp_core_uart_tx_chars(uart_port_t lp_uart_num, const void *src, size_t size)
return tx_len;
}
void lp_core_uart_tx_flush(uart_port_t lp_uart_num)
{
(void)lp_uart_num;
int loop_cnt = 0;
if (uart_ll_is_enabled(LP_UART_NUM_0) && !uart_hal_is_tx_idle(&hal)) {
/* Wait for the Tx FIFO to be empty */
while (!(uart_hal_get_intraw_mask(&hal) & (LP_UART_TX_INT_FLAG | LP_UART_ERR_INT_FLAG))) {
loop_cnt++;
if (loop_cnt > 10000) {
/* Bail out */
break;
}
}
uart_hal_clr_intsts_mask(&hal, LP_UART_TX_INT_FLAG | LP_UART_ERR_INT_FLAG);
}
}
esp_err_t lp_core_uart_write_bytes(uart_port_t lp_uart_num, const void *src, size_t size, int32_t timeout)
{
(void)lp_uart_num;

View File

@ -7,6 +7,7 @@
#include <stdint.h>
#include "ulp_lp_core_print.h"
#include "ulp_lp_core_utils.h"
#include "ulp_lp_core_uart.h"
int main (void)
{
@ -17,6 +18,7 @@ int main (void)
lp_core_printf("This program has run %d times\r\n", ++iteration);
lp_core_printf("%s", separator);
lp_core_printf("\n");
lp_core_uart_tx_flush(LP_UART_NUM_0);
return 0;
}