From 4c5099d1942b254f8daab4235c04dd20131b3f43 Mon Sep 17 00:00:00 2001 From: aleks Date: Thu, 10 Dec 2020 17:30:08 +0100 Subject: [PATCH 1/3] freemodbus: fix modbus rs485 rts enable fail v42 --- components/freemodbus/port/portserial.c | 2 +- components/freemodbus/port/portserial_m.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/components/freemodbus/port/portserial.c b/components/freemodbus/port/portserial.c index 9218ccb382..ed77fe2d1a 100644 --- a/components/freemodbus/port/portserial.c +++ b/components/freemodbus/port/portserial.c @@ -119,7 +119,7 @@ BOOL xMBPortSerialTxPoll(void) } ESP_LOGD(TAG, "MB_TX_buffer send: (%d) bytes\n", (uint16_t)usCount); // Waits while UART sending the packet - esp_err_t xTxStatus = uart_wait_tx_done(ucUartNumber, MB_SERIAL_TX_TOUT_TICKS); + esp_err_t xTxStatus = uart_wait_tx_idle_polling(ucUartNumber); vMBPortSerialEnable(TRUE, FALSE); MB_PORT_CHECK((xTxStatus == ESP_OK), FALSE, "mb serial sent buffer failure."); return TRUE; diff --git a/components/freemodbus/port/portserial_m.c b/components/freemodbus/port/portserial_m.c index feddbf75af..7ae8bfc9c9 100644 --- a/components/freemodbus/port/portserial_m.c +++ b/components/freemodbus/port/portserial_m.c @@ -113,8 +113,8 @@ BOOL xMBMasterPortSerialTxPoll(void) } ESP_LOGD(TAG, "MB_TX_buffer sent: (%d) bytes.", (uint16_t)(usCount - 1)); // Waits while UART sending the packet - esp_err_t xTxStatus = uart_wait_tx_done(ucUartNumber, MB_SERIAL_TX_TOUT_TICKS); - vMBMasterPortSerialEnable( TRUE, FALSE ); + esp_err_t xTxStatus = uart_wait_tx_idle_polling(ucUartNumber); + vMBMasterPortSerialEnable(TRUE, FALSE); MB_PORT_CHECK((xTxStatus == ESP_OK), FALSE, "mb serial sent buffer failure."); return TRUE; } From 9ac82052082b52da57796b1165e71dee6895396c Mon Sep 17 00:00:00 2001 From: aleks Date: Mon, 26 Jul 2021 07:40:10 +0200 Subject: [PATCH 2/3] freemodbus: fix rts enable fail when transmit frame --- components/freemodbus/port/port.h | 2 +- components/freemodbus/port/portserial.c | 2 +- components/freemodbus/port/portserial_m.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/components/freemodbus/port/port.h b/components/freemodbus/port/port.h index 06d7a28c79..5307f371fc 100644 --- a/components/freemodbus/port/port.h +++ b/components/freemodbus/port/port.h @@ -37,7 +37,7 @@ #define MB_SERIAL_BUF_SIZE (CONFIG_FMB_SERIAL_BUF_SIZE) // common definitions for serial port implementations -#define MB_SERIAL_TX_TOUT_MS (100) +#define MB_SERIAL_TX_TOUT_MS (2200) // maximum time for transmission of longest allowed frame buffer #define MB_SERIAL_TX_TOUT_TICKS pdMS_TO_TICKS(MB_SERIAL_TX_TOUT_MS) // timeout for transmission #define MB_SERIAL_RX_TOUT_MS (1) #define MB_SERIAL_RX_TOUT_TICKS pdMS_TO_TICKS(MB_SERIAL_RX_TOUT_MS) // timeout for receive diff --git a/components/freemodbus/port/portserial.c b/components/freemodbus/port/portserial.c index ed77fe2d1a..9218ccb382 100644 --- a/components/freemodbus/port/portserial.c +++ b/components/freemodbus/port/portserial.c @@ -119,7 +119,7 @@ BOOL xMBPortSerialTxPoll(void) } ESP_LOGD(TAG, "MB_TX_buffer send: (%d) bytes\n", (uint16_t)usCount); // Waits while UART sending the packet - esp_err_t xTxStatus = uart_wait_tx_idle_polling(ucUartNumber); + esp_err_t xTxStatus = uart_wait_tx_done(ucUartNumber, MB_SERIAL_TX_TOUT_TICKS); vMBPortSerialEnable(TRUE, FALSE); MB_PORT_CHECK((xTxStatus == ESP_OK), FALSE, "mb serial sent buffer failure."); return TRUE; diff --git a/components/freemodbus/port/portserial_m.c b/components/freemodbus/port/portserial_m.c index 7ae8bfc9c9..1ab6ae7f3c 100644 --- a/components/freemodbus/port/portserial_m.c +++ b/components/freemodbus/port/portserial_m.c @@ -113,7 +113,7 @@ BOOL xMBMasterPortSerialTxPoll(void) } ESP_LOGD(TAG, "MB_TX_buffer sent: (%d) bytes.", (uint16_t)(usCount - 1)); // Waits while UART sending the packet - esp_err_t xTxStatus = uart_wait_tx_idle_polling(ucUartNumber); + esp_err_t xTxStatus = uart_wait_tx_done(ucUartNumber, MB_SERIAL_TX_TOUT_TICKS); vMBMasterPortSerialEnable(TRUE, FALSE); MB_PORT_CHECK((xTxStatus == ESP_OK), FALSE, "mb serial sent buffer failure."); return TRUE; From 239e56541c0e7aa4bc735b0c6c1cc17df643369c Mon Sep 17 00:00:00 2001 From: aleks Date: Mon, 26 Jul 2021 07:50:53 +0200 Subject: [PATCH 3/3] freemodbus: fix uart_wait_tx_done() reenable tx_done interrupt --- components/driver/uart.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/components/driver/uart.c b/components/driver/uart.c index 35cce7b349..6b4c72f06a 100644 --- a/components/driver/uart.c +++ b/components/driver/uart.c @@ -1025,7 +1025,6 @@ esp_err_t uart_wait_tx_done(uart_port_t uart_num, TickType_t ticks_to_wait) xSemaphoreGive(p_uart_obj[uart_num]->tx_mux); return ESP_OK; } - uart_hal_clr_intsts_mask(&(uart_context[uart_num].hal), UART_INTR_TX_DONE); UART_ENTER_CRITICAL(&(uart_context[uart_num].spinlock)); uart_hal_ena_intr_mask(&(uart_context[uart_num].hal), UART_INTR_TX_DONE); UART_EXIT_CRITICAL(&(uart_context[uart_num].spinlock)); @@ -1039,9 +1038,7 @@ esp_err_t uart_wait_tx_done(uart_port_t uart_num, TickType_t ticks_to_wait) //take 2nd tx_done_sem, wait given from ISR res = xSemaphoreTake(p_uart_obj[uart_num]->tx_done_sem, (portTickType)ticks_to_wait); if (res == pdFALSE) { - UART_ENTER_CRITICAL(&(uart_context[uart_num].spinlock)); - uart_hal_disable_intr_mask(&(uart_context[uart_num].hal), UART_INTR_TX_DONE); - UART_EXIT_CRITICAL(&(uart_context[uart_num].spinlock)); + // The TX_DONE interrupt will be disabled in ISR xSemaphoreGive(p_uart_obj[uart_num]->tx_mux); return ESP_ERR_TIMEOUT; }