diff --git a/components/hal/esp32c2/include/hal/uart_ll.h b/components/hal/esp32c2/include/hal/uart_ll.h index 2c84599ea6..ed1d1973e5 100644 --- a/components/hal/esp32c2/include/hal/uart_ll.h +++ b/components/hal/esp32c2/include/hal/uart_ll.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -345,8 +345,11 @@ FORCE_INLINE_ATTR void uart_ll_read_rxfifo(uart_dev_t *hw, uint8_t *buf, uint32_ */ FORCE_INLINE_ATTR void uart_ll_write_txfifo(uart_dev_t *hw, const uint8_t *buf, uint32_t wr_len) { + // Write to the FIFO should make sure only involve write operation, any read operation would cause data lost. + // Non-32-bit access would lead to a read-modify-write operation to the register, which is undesired. + // Therefore, use 32-bit access to avoid any potential problem. for (int i = 0; i < (int)wr_len; i++) { - hw->ahb_fifo.rw_byte = buf[i]; + hw->ahb_fifo.val = (int)buf[i]; } } diff --git a/components/hal/esp32c3/include/hal/uart_ll.h b/components/hal/esp32c3/include/hal/uart_ll.h index f73bf79f38..221bee0f0c 100644 --- a/components/hal/esp32c3/include/hal/uart_ll.h +++ b/components/hal/esp32c3/include/hal/uart_ll.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -348,8 +348,11 @@ FORCE_INLINE_ATTR void uart_ll_read_rxfifo(uart_dev_t *hw, uint8_t *buf, uint32_ */ FORCE_INLINE_ATTR void uart_ll_write_txfifo(uart_dev_t *hw, const uint8_t *buf, uint32_t wr_len) { + // Write to the FIFO should make sure only involve write operation, any read operation would cause data lost. + // Non-32-bit access would lead to a read-modify-write operation to the register, which is undesired. + // Therefore, use 32-bit access to avoid any potential problem. for (int i = 0; i < (int)wr_len; i++) { - hw->ahb_fifo.rw_byte = buf[i]; + hw->ahb_fifo.val = (int)buf[i]; } } diff --git a/components/hal/esp32c5/include/hal/uart_ll.h b/components/hal/esp32c5/include/hal/uart_ll.h index 52e3d1cd11..511e0606e7 100644 --- a/components/hal/esp32c5/include/hal/uart_ll.h +++ b/components/hal/esp32c5/include/hal/uart_ll.h @@ -540,8 +540,11 @@ FORCE_INLINE_ATTR void uart_ll_read_rxfifo(uart_dev_t *hw, uint8_t *buf, uint32_ */ FORCE_INLINE_ATTR void uart_ll_write_txfifo(uart_dev_t *hw, const uint8_t *buf, uint32_t wr_len) { + // Write to the FIFO should make sure only involve write operation, any read operation would cause data lost. + // Non-32-bit access would lead to a read-modify-write operation to the register, which is undesired. + // Therefore, use 32-bit access to avoid any potential problem. for (int i = 0; i < (int)wr_len; i++) { - hw->fifo.rxfifo_rd_byte = buf[i]; + hw->fifo.val = (int)buf[i]; } } diff --git a/components/hal/esp32c6/include/hal/uart_ll.h b/components/hal/esp32c6/include/hal/uart_ll.h index db306abf9c..950b1215f7 100644 --- a/components/hal/esp32c6/include/hal/uart_ll.h +++ b/components/hal/esp32c6/include/hal/uart_ll.h @@ -521,8 +521,11 @@ FORCE_INLINE_ATTR void uart_ll_read_rxfifo(uart_dev_t *hw, uint8_t *buf, uint32_ */ FORCE_INLINE_ATTR void uart_ll_write_txfifo(uart_dev_t *hw, const uint8_t *buf, uint32_t wr_len) { + // Write to the FIFO should make sure only involve write operation, any read operation would cause data lost. + // Non-32-bit access would lead to a read-modify-write operation to the register, which is undesired. + // Therefore, use 32-bit access to avoid any potential problem. for (int i = 0; i < (int)wr_len; i++) { - hw->fifo.rxfifo_rd_byte = buf[i]; + hw->fifo.val = (int)buf[i]; } } diff --git a/components/hal/esp32h2/include/hal/uart_ll.h b/components/hal/esp32h2/include/hal/uart_ll.h index 64b678e31b..f3f63de978 100644 --- a/components/hal/esp32h2/include/hal/uart_ll.h +++ b/components/hal/esp32h2/include/hal/uart_ll.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -373,8 +373,11 @@ FORCE_INLINE_ATTR void uart_ll_read_rxfifo(uart_dev_t *hw, uint8_t *buf, uint32_ */ FORCE_INLINE_ATTR void uart_ll_write_txfifo(uart_dev_t *hw, const uint8_t *buf, uint32_t wr_len) { + // Write to the FIFO should make sure only involve write operation, any read operation would cause data lost. + // Non-32-bit access would lead to a read-modify-write operation to the register, which is undesired. + // Therefore, use 32-bit access to avoid any potential problem. for (int i = 0; i < (int)wr_len; i++) { - hw->fifo.rxfifo_rd_byte = buf[i]; + hw->fifo.val = (int)buf[i]; } } diff --git a/components/hal/esp32p4/include/hal/uart_ll.h b/components/hal/esp32p4/include/hal/uart_ll.h index 3f0a08da91..49c5e5da98 100644 --- a/components/hal/esp32p4/include/hal/uart_ll.h +++ b/components/hal/esp32p4/include/hal/uart_ll.h @@ -634,8 +634,11 @@ FORCE_INLINE_ATTR void uart_ll_read_rxfifo(uart_dev_t *hw, uint8_t *buf, uint32_ */ FORCE_INLINE_ATTR void uart_ll_write_txfifo(uart_dev_t *hw, const uint8_t *buf, uint32_t wr_len) { + // Write to the FIFO should make sure only involve write operation, any read operation would cause data lost. + // Non-32-bit access would lead to a read-modify-write operation to the register, which is undesired. + // Therefore, use 32-bit access to avoid any potential problem. for (int i = 0; i < (int)wr_len; i++) { - hw->fifo.rxfifo_rd_byte = buf[i]; + hw->fifo.val = (int)buf[i]; } } diff --git a/components/hal/esp32s3/include/hal/uart_ll.h b/components/hal/esp32s3/include/hal/uart_ll.h index 0d5911e5a8..082cf369e5 100644 --- a/components/hal/esp32s3/include/hal/uart_ll.h +++ b/components/hal/esp32s3/include/hal/uart_ll.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -332,8 +332,11 @@ FORCE_INLINE_ATTR void uart_ll_read_rxfifo(uart_dev_t *hw, uint8_t *buf, uint32_ */ FORCE_INLINE_ATTR void uart_ll_write_txfifo(uart_dev_t *hw, const uint8_t *buf, uint32_t wr_len) { + // Write to the FIFO should make sure only involve write operation, any read operation would cause data lost. + // Non-32-bit access would lead to a read-modify-write operation to the register, which is undesired. + // Therefore, use 32-bit access to avoid any potential problem. for (int i = 0; i < (int)wr_len; i++) { - hw->fifo.rxfifo_rd_byte = buf[i]; + hw->fifo.val = (int)buf[i]; } }