]> granicus.if.org Git - esp-idf/commitdiff
Merge branch 'bugfix/uart_wait_idle' into 'master'
authorIvan Grokhotkov <ivan@espressif.com>
Thu, 18 Oct 2018 03:25:59 +0000 (11:25 +0800)
committerIvan Grokhotkov <ivan@espressif.com>
Thu, 18 Oct 2018 03:25:59 +0000 (11:25 +0800)
uart: fix uart_tx_wait_idle to wait for fifo empty

See merge request idf/esp-idf!3489

components/esp32/include/rom/uart.h
components/esp32/sleep_modes.c

index 0a3e1aeb644d4b3b80d60918463aece271a2cde0..872244573437312963249b86af717d6c4bb0ea51 100644 (file)
@@ -267,9 +267,11 @@ void uart_tx_flush(uint8_t uart_no);
   * here for compatibility.
   */
 static inline void IRAM_ATTR uart_tx_wait_idle(uint8_t uart_no) {
-    while(REG_GET_FIELD(UART_STATUS_REG(uart_no), UART_ST_UTX_OUT)) {
-        ;
-    }
+    uint32_t status;
+    do {
+        status = READ_PERI_REG(UART_STATUS_REG(uart_no));
+        /* either tx count or state is non-zero */
+    } while ((status & (UART_ST_UTX_OUT_M | UART_TXFIFO_CNT_M)) != 0);
 }
 
 /**
index da4a5f11a5a6de4888e267ab457f10f381119aef..f3bd071f3ff5e573b499a91c33e0e979b0c8dd28 100644 (file)
@@ -159,7 +159,9 @@ static void IRAM_ATTR suspend_uarts()
 {
     for (int i = 0; i < 3; ++i) {
         REG_SET_BIT(UART_FLOW_CONF_REG(i), UART_FORCE_XOFF);
-        uart_tx_wait_idle(i);
+        while (REG_GET_FIELD(UART_STATUS_REG(i), UART_ST_UTX_OUT) != 0) {
+            ;
+        }
     }
 }