driver: add rs485 half duplex interface support to uart driver (update after review)

An existing UART driver does not support RS485 half duplex mode.
This task adds this functionality to ESP_IDF UART driver.
driver/uart.c/h: updated to add support of RS485 half duplex mode
examples/peripherals/uart_echo_rs485/main/rs485_example.c: added test example
components/driver/test/test_uart.c: added test of RS485 half duplex mode
docs/en/api-reference/peripherals/uart.rst: updated documentation
test_uart.c: suppress GCC warnings about discarded const qualifiers
uart.rst: remove sphinx warning - "Duplicate explicit target name"
simple change in uart.h file
update (test_uart.c) after rebase from master
update uart.rst, uart.c, rs485_example.c
Update example description in file Readme.md
update uart.c/h, uart.rst, test_uart.c according to review results
update uart.h (uart_set_rx_timeout() description
test_uart.c remove ignore tag
uart.c/h: fix param errors
test_uart.c: Remove GCC warning supress
uart.rst: fix the notes
rs485_example.c: fix output

The tests are completed using RS485 adapters hardware connected to two ESP32 WROVER KITs.

TW#13812
Closes https://github.com/espressif/esp-idf/pull/667
Closes https://github.com/espressif/esp-idf/pull/1006
This commit is contained in:
Alex Lisitsyn
2018-06-27 16:48:14 +02:00
parent 0ec81181b4
commit ef5dc73f6f
5 changed files with 45 additions and 43 deletions
@@ -30,10 +30,10 @@
*
*/
// Note io16 , io17 does not work on wrover module
// Note: UART2 default pins IO16, IO17 do not work on ESP32-WROVER module
// because these pins connected to PSRAM
#define ECHO_TEST_TXD (23) //(17)
#define ECHO_TEST_RXD (22) //(16)
#define ECHO_TEST_TXD (23)
#define ECHO_TEST_RXD (22)
// RTS for RS485 Half-Duplex Mode manages DE/~RE
#define ECHO_TEST_RTS (18)
@@ -50,6 +50,8 @@
#define ECHO_TASK_PRIO (10)
#define ECHO_UART_PORT (UART_NUM_2)
static const char *TAG = "RS485_ECHO_APP";
// An example of echo test with hardware flow control on UART
static void echo_task()
{
@@ -63,13 +65,15 @@ static void echo_task()
.rx_flow_ctrl_thresh = 122,
};
printf("Start RS485 application test.\r\n");
printf("Configure UART.\r\n");
// Set UART log level
esp_log_level_set(TAG, ESP_LOG_INFO);
ESP_LOGI(TAG, "Start RS485 application test and configure UART.");
// Configure UART parameters
uart_param_config(uart_num, &uart_config);
printf("UART set pins.\r\n");
ESP_LOGI(TAG, "UART set pins, mode and install driver.");
// Set UART1 pins(TX: IO23, RX: I022, RTS: IO18, CTS: IO19)
uart_set_pin(uart_num, ECHO_TEST_TXD, ECHO_TEST_RXD, ECHO_TEST_RTS, ECHO_TEST_CTS);
@@ -83,7 +87,7 @@ static void echo_task()
// Allocate buffers for UART
uint8_t* data = (uint8_t*) malloc(BUF_SIZE);
printf("Start recieve loop.\r\n");
ESP_LOGI(TAG, "UART start recieve loop.\r\n");
uart_write_bytes(uart_num, "Start RS485 UART test.\r\n", 24);
while(1) {
@@ -96,7 +100,8 @@ static void echo_task()
char prefix[] = "RS485 Received: [";
uart_write_bytes(uart_num, prefix, (sizeof(prefix) - 1));
printf("Received [ ");
ESP_LOGI(TAG, "Received %u bytes:", len);
printf("[ ");
for (int i = 0; i < len; i++) {
printf("0x%.2X ", (uint8_t)data[i]);
uart_write_bytes(uart_num, (const char*)&data[i], 1);