From bdf89b4e06ef1f3e8ef12f61ae9b83add305f66f Mon Sep 17 00:00:00 2001 From: Raienryu97 Date: Wed, 2 Aug 2017 15:56:59 +0530 Subject: [PATCH 1/2] uartEnd: Unlock mutex before detaching rx and tx This should solve the device freezing issue when Serial.end() is called --- cores/esp32/esp32-hal-uart.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cores/esp32/esp32-hal-uart.c b/cores/esp32/esp32-hal-uart.c index 055e4fc6833..7ee145c597e 100644 --- a/cores/esp32/esp32-hal-uart.c +++ b/cores/esp32/esp32-hal-uart.c @@ -197,7 +197,7 @@ uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rx uart->dev->conf0.val = config; #define TWO_STOP_BITS_CONF 0x3 #define ONE_STOP_BITS_CONF 0x1 - + if ( uart->dev->conf0.stop_bit_num == TWO_STOP_BITS_CONF) { uart->dev->conf0.stop_bit_num = ONE_STOP_BITS_CONF; uart->dev->rs485_conf.dl1_en = 1; @@ -227,12 +227,12 @@ void uartEnd(uart_t* uart) while(xQueueReceive(uart->queue, &c, 0)); vQueueDelete(uart->queue); } + UART_MUTEX_UNLOCK(); uartDetachRx(uart); uartDetachTx(uart); uart->dev->conf0.val = 0; - UART_MUTEX_UNLOCK(); } uint32_t uartAvailable(uart_t* uart) @@ -419,4 +419,3 @@ int log_printf(const char *format, ...) } return len; } - From 7556063b4c6b075d3e2abd7feeaa11769f43c23d Mon Sep 17 00:00:00 2001 From: Raienryu97 Date: Thu, 3 Aug 2017 19:22:36 +0530 Subject: [PATCH 2/2] Unlock UART MUTEX only for detaching Rx and Tx * Thanks to @me-no-dev for pointing it out that uart->dev->conf0.val can be inside mutex lock --- cores/esp32/esp32-hal-uart.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cores/esp32/esp32-hal-uart.c b/cores/esp32/esp32-hal-uart.c index 7ee145c597e..02999993dec 100644 --- a/cores/esp32/esp32-hal-uart.c +++ b/cores/esp32/esp32-hal-uart.c @@ -227,12 +227,13 @@ void uartEnd(uart_t* uart) while(xQueueReceive(uart->queue, &c, 0)); vQueueDelete(uart->queue); } + + uart->dev->conf0.val = 0; + UART_MUTEX_UNLOCK(); uartDetachRx(uart); uartDetachTx(uart); - - uart->dev->conf0.val = 0; } uint32_t uartAvailable(uart_t* uart)