Merge branch 'bugfix/soft_uart_send_dummy_byte' into 'master'

fix(Peripheral Drivers/Dedicated GPIO): Remove dummy byte from the emulate_uart_send routine

See merge request espressif/esp-idf!28627
pull/13090/head
Omar Chebib 2024-01-24 10:38:12 +08:00
commit 0db3268713
3 zmienionych plików z 11 dodań i 7 usunięć

Wyświetl plik

@ -60,6 +60,10 @@ esp_err_t soft_uart_del(soft_uart_port_t port);
/**
* @brief Send the given bytes on the software UART port.
*
* @note Since toggling fast GPIOs for the first time may be slow (~1us), the first byte may be corrupted.
* If you are seeing this issue, prepend a dummy byte to the buffer to send when calling this
* function for the first time.
*
* @param port Software UART port to send data on.
* @param write_buffer Buffer containing the bytes to send on the buffer. Must not be NULL.
* @param write_size Size of the write buffer. Must not be 0.

Wyświetl plik

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2010-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: CC0-1.0
*/
@ -33,11 +33,6 @@ emulate_uart_send:
sll a2, t0, a2
/* Save return address in a4 */
mv a4, ra
/* As UART is very time sensitive, we want each bit sent to be very precise in terms of duration.
* The first toggle of the fast GPIO register may be slow, ~1us, so let's send a dummy byte here
* before the actual UART emulation start, else the first byte sent would be corrupted.*/
li t0, 0
call uart_send_byte
/* Reading the characters 4 by 4 would be much faster, but in our case, we don't need
* the process to be fast as the bottleneck is the UART speed */
uart_read_next:

Wyświetl plik

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2010-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: CC0-1.0
*/
@ -18,6 +18,7 @@ void app_main(void)
esp_err_t ret = ESP_OK;
uint8_t read_buffer[READ_COUNT] = { 0 };
const uint8_t write_buffer[] = "Hello, world! This is a message.\r\n";
uint8_t dummy = 0;
soft_uart_port_t port = NULL;
soft_uart_config_t config = {
.tx_pin = CONFIG_EMULATE_UART_GPIO_TX,
@ -29,6 +30,10 @@ void app_main(void)
ret = soft_uart_new(&config, &port);
ESP_GOTO_ON_ERROR(ret, error, EXAMPLE_TAG, "Error configuring software UART");
/* Send a dummy byte as the software UART driver may corrupt the first byte */
ret = soft_uart_send(port, &dummy, sizeof(uint8_t));
ESP_GOTO_ON_ERROR(ret, error, EXAMPLE_TAG, "Error writing a dummy byte");
/* Write few bytes to the UART */
ret = soft_uart_send(port, write_buffer, sizeof(write_buffer));
ESP_GOTO_ON_ERROR(ret, error, EXAMPLE_TAG, "Error writing to the software UART");