From 87375847892a84d39114b39ae848c79819780c67 Mon Sep 17 00:00:00 2001 From: Alex Lisitsyn Date: Mon, 19 Oct 2020 16:17:19 +0800 Subject: [PATCH] Bugfix/fix RS485 ut fail --- components/driver/test/test_rs485.c | 24 +++++++++++-------- .../protocols/modbus/serial/example_test.py | 2 +- tools/ci/config/target-test.yml | 2 +- tools/ci/setup_python.sh | 3 +-- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/components/driver/test/test_rs485.c b/components/driver/test/test_rs485.c index ba4feb064c..32bff7f8ac 100644 --- a/components/driver/test/test_rs485.c +++ b/components/driver/test/test_rs485.c @@ -160,18 +160,19 @@ static void rs485_init(void) .parity = UART_PARITY_DISABLE, .stop_bits = UART_STOP_BITS_1, .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, - .rx_flow_ctrl_thresh = 122, + .rx_flow_ctrl_thresh = 120, + .source_clk = UART_SCLK_APB, }; printf("RS485 port initialization...\r\n"); + TEST_ESP_OK(uart_wait_tx_idle_polling(UART_NUM1)); // Configure UART1 parameters - uart_param_config(UART_NUM1, &uart_config); - // Set UART1 pins(TX: IO4, RX: I05, RTS: IO18, CTS: IO19) - uart_set_pin(UART_NUM1, UART1_TX_PIN, UART1_RX_PIN, UART1_RTS_PIN, UART_PIN_NO_CHANGE); + TEST_ESP_OK(uart_param_config(UART_NUM1, &uart_config)); + // Set UART1 pins + TEST_ESP_OK(uart_set_pin(UART_NUM1, UART1_TX_PIN, UART1_RX_PIN, UART1_RTS_PIN, UART_PIN_NO_CHANGE)); // Install UART driver (we don't need an event queue here) - uart_driver_install(UART_NUM1, BUF_SIZE * 2, 0, 0, NULL, 0); + TEST_ESP_OK(uart_driver_install(UART_NUM1, BUF_SIZE * 2, 0, 0, NULL, 0)); // Setup rs485 half duplex mode - //uart_set_rs485_hd_mode(uart_num, true); - uart_set_mode(UART_NUM1, UART_MODE_RS485_HALF_DUPLEX); + TEST_ESP_OK(uart_set_mode(UART_NUM1, UART_MODE_RS485_HALF_DUPLEX)); } static esp_err_t print_packet_data(const char *str, uint8_t *buffer, uint16_t buffer_size) @@ -214,13 +215,14 @@ static void rs485_slave(void) // If received packet is correct then send it back if (status == ESP_OK) { uart_write_bytes(UART_NUM1, (char*)slave_data, len); + uart_wait_tx_idle_polling(UART_NUM1); good_count++; } else { printf("Incorrect packet received.\r\n"); err_count++; } } else { - printf("Incorrect data packet[%d] received.\r\n", pack_count); + printf("Incorrect data packet[%d], data length: %d, received.\r\n", pack_count, len); err_count++; } } @@ -252,6 +254,7 @@ static void rs485_master(void) esp_err_t status = print_packet_data("Send ", master_buffer, BUF_SIZE); TEST_ASSERT(status == ESP_OK); uart_write_bytes(UART_NUM1, (char*)master_buffer, BUF_SIZE); + uart_wait_tx_idle_polling(UART_NUM1); // Read translated packet from slave int len = uart_read_bytes(UART_NUM1, slave_buffer, BUF_SIZE, (PACKET_READ_TICS * 2)); // Check if the received packet is too short @@ -267,10 +270,11 @@ static void rs485_master(void) } } else { - printf("Incorrect answer from slave.\r\n"); + printf("Incorrect answer from slave, length = %d.\r\n", len); err_count++; } } + uart_wait_tx_done(UART_NUM1, PACKET_READ_TICS); // Free the buffer and delete driver at the end free(master_buffer); uart_driver_delete(UART_NUM1); @@ -287,4 +291,4 @@ TEST_CASE_MULTIPLE_DEVICES("RS485 half duplex uart multiple devices test.", "[dr #endif -#endif +#endif \ No newline at end of file diff --git a/examples/protocols/modbus/serial/example_test.py b/examples/protocols/modbus/serial/example_test.py index fb9ab2978b..bfc70f44bb 100644 --- a/examples/protocols/modbus/serial/example_test.py +++ b/examples/protocols/modbus/serial/example_test.py @@ -165,7 +165,7 @@ def test_check_mode(dut=None, mode_str=None, value=None): return False -@ttfw_idf.idf_example_test(env_tag='UT_T2_RS485') +@ttfw_idf.idf_example_test(env_tag='Example_T2_RS485') def test_modbus_communication(env, comm_mode): global logger diff --git a/tools/ci/config/target-test.yml b/tools/ci/config/target-test.yml index c344085dff..7c3183a9d0 100644 --- a/tools/ci/config/target-test.yml +++ b/tools/ci/config/target-test.yml @@ -336,7 +336,7 @@ example_test_011: extends: .example_debug_template tags: - ESP32 - - UT_T2_RS485 + - Example_T2_RS485 artifacts: when: always expire_in: 1 week diff --git a/tools/ci/setup_python.sh b/tools/ci/setup_python.sh index 6f0d8c9aa1..c23e58ce54 100644 --- a/tools/ci/setup_python.sh +++ b/tools/ci/setup_python.sh @@ -7,9 +7,8 @@ # Regexp for matching job names which are incompatible with Python 3 # - UT_009_ - multi-device tests are not compatible -# - UT_014_ - multi-device tests are not compatible # - UT_017_ - multi-device tests are not compatible -py3_incomp='UT_009_|UT_013_|UT_014_|UT_017_' +py3_incomp='UT_009_|UT_017_' if [ -z ${PYTHON_VER+x} ] || [[ $CI_JOB_NAME =~ $py3_incomp ]]; then # Use this version of the Python interpreter if it was not defined before or