From 41e36a72f309fbfa5e2bdeebdca93661728bddb3 Mon Sep 17 00:00:00 2001 From: Pranav Cherukupalli Date: Fri, 4 Aug 2017 14:30:51 +0530 Subject: [PATCH] uartEnd: Unlock mutex before detaching rx and tx (#554) * uartEnd: Unlock mutex before detaching rx and tx This should solve the device freezing issue when Serial.end() is called * 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 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cores/esp32/esp32-hal-uart.c b/cores/esp32/esp32-hal-uart.c index 055e4fc6..02999993 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; @@ -228,11 +228,12 @@ void uartEnd(uart_t* uart) vQueueDelete(uart->queue); } + uart->dev->conf0.val = 0; + + UART_MUTEX_UNLOCK(); + uartDetachRx(uart); uartDetachTx(uart); - - uart->dev->conf0.val = 0; - UART_MUTEX_UNLOCK(); } uint32_t uartAvailable(uart_t* uart) @@ -419,4 +420,3 @@ int log_printf(const char *format, ...) } return len; } -