Skip to content

Commit

Permalink
Merge branch 'fix/lp_uart_garbled_print' into 'master'
Browse files Browse the repository at this point in the history
fix(lp_uart): Added lp_uart_tx_flush API

Closes IDFGH-13650

See merge request espressif/esp-idf!33487
  • Loading branch information
sudeep-mohanty committed Sep 19, 2024
2 parents ca331a2 + 3c65f1b commit 13d4235
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
12 changes: 11 additions & 1 deletion components/ulp/lp_core/lp_core/include/ulp_lp_core_uart.h
Original file line number Diff line number Diff line change
@@ -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
*/
Expand Down Expand Up @@ -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
20 changes: 19 additions & 1 deletion components/ulp/lp_core/lp_core/lp_core_uart.c
Original file line number Diff line number Diff line change
@@ -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
*/
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;
}

0 comments on commit 13d4235

Please sign in to comment.