mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
fix(lp_uart): Added lp_uart flush feature
This commit adds the lp_core_uart_flush() API to flush the LP UART Tx FIFO. This API is automatically called once the program returns from the main function(). Closes https://github.com/espressif/esp-idf/issues/14530
This commit is contained in:
parent
115dec68ae
commit
3c65f1b654
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user