From c4173b298d5ed2241d96ae55e2eac63505bbff37 Mon Sep 17 00:00:00 2001 From: morris Date: Mon, 14 Oct 2024 18:26:06 +0800 Subject: [PATCH] test(rmt): the way to keep io level after channel delete Closes https://github.com/espressif/esp-idf/issues/15049 --- .../test_apps/rmt/main/test_rmt_common.c | 2 +- .../test_apps/rmt/main/test_rmt_tx.c | 42 ++++++++++++++++--- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/components/esp_driver_rmt/test_apps/rmt/main/test_rmt_common.c b/components/esp_driver_rmt/test_apps/rmt/main/test_rmt_common.c index deaf99fa33..fa00514215 100644 --- a/components/esp_driver_rmt/test_apps/rmt/main/test_rmt_common.c +++ b/components/esp_driver_rmt/test_apps/rmt/main/test_rmt_common.c @@ -100,7 +100,7 @@ TEST_CASE("rmt channel install & uninstall", "[rmt]") #endif // SOC_RMT_SUPPORT_DMA } -TEST_CASE("RMT interrupt priority", "[rmt]") +TEST_CASE("rmt interrupt priority", "[rmt]") { rmt_tx_channel_config_t tx_channel_cfg = { .mem_block_symbols = SOC_RMT_MEM_WORDS_PER_CHANNEL, diff --git a/components/esp_driver_rmt/test_apps/rmt/main/test_rmt_tx.c b/components/esp_driver_rmt/test_apps/rmt/main/test_rmt_tx.c index 15cf1a5512..ad38fefabb 100644 --- a/components/esp_driver_rmt/test_apps/rmt/main/test_rmt_tx.c +++ b/components/esp_driver_rmt/test_apps/rmt/main/test_rmt_tx.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -10,6 +10,7 @@ #include "freertos/task.h" #include "unity.h" #include "driver/rmt_tx.h" +#include "driver/gpio.h" #include "esp_timer.h" #include "soc/soc_caps.h" #include "test_util_rmt_encoders.h" @@ -23,12 +24,24 @@ TEST_CASE("rmt bytes encoder", "[rmt]") { + // If you want to keep the IO level after unintall the RMT channel, a workaround is to set the pull up/down register here + // because when we uninstall the RMT channel, we will also disable the GPIO output + gpio_config_t io_conf = { + .pin_bit_mask = (1ULL << TEST_RMT_GPIO_NUM_B), + .mode = GPIO_MODE_INPUT, + .pull_up_en = GPIO_PULLUP_DISABLE, + // Note: make sure the test board doesn't have a pull-up resistor attached to the GPIO, otherwise this test case will fail in the check + .pull_down_en = GPIO_PULLDOWN_ENABLE, + .intr_type = GPIO_INTR_DISABLE, + }; + TEST_ESP_OK(gpio_config(&io_conf)); + rmt_tx_channel_config_t tx_channel_cfg = { .mem_block_symbols = SOC_RMT_MEM_WORDS_PER_CHANNEL, .clk_src = RMT_CLK_SRC_DEFAULT, .resolution_hz = 1000000, // 1MHz, 1 tick = 1us .trans_queue_depth = 4, - .gpio_num = TEST_RMT_GPIO_NUM_A, + .gpio_num = TEST_RMT_GPIO_NUM_B, .intr_priority = 3 }; printf("install tx channel\r\n"); @@ -73,14 +86,31 @@ TEST_CASE("rmt bytes encoder", "[rmt]") vTaskDelay(pdMS_TO_TICKS(500)); printf("disable tx channel\r\n"); + TEST_ESP_OK(rmt_disable(tx_channel)); + + printf("remove tx channel\r\n"); + TEST_ESP_OK(rmt_del_channel(tx_channel)); + vTaskDelay(pdMS_TO_TICKS(500)); + + // check the IO level after uninstall the RMT channel + TEST_ASSERT_EQUAL(0, gpio_get_level(TEST_RMT_GPIO_NUM_B)); + + printf("install tx channel again\r\n"); + TEST_ESP_OK(rmt_new_tx_channel(&tx_channel_cfg, &tx_channel)); + printf("enable tx channel\r\n"); + TEST_ESP_OK(rmt_enable(tx_channel)); + + printf("start transaction\r\n"); + TEST_ESP_OK(rmt_transmit(tx_channel, bytes_encoder, (uint8_t[]) { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 + }, 6, &transmit_config)); + // adding extra delay here for visualizing + vTaskDelay(pdMS_TO_TICKS(500)); + TEST_ESP_OK(rmt_disable(tx_channel)); printf("remove tx channel and encoder\r\n"); TEST_ESP_OK(rmt_del_channel(tx_channel)); TEST_ESP_OK(rmt_del_encoder(bytes_encoder)); - - // Test if intr_priority check works - tx_channel_cfg.intr_priority = 4; // 4 is an invalid interrupt priority - TEST_ESP_ERR(rmt_new_tx_channel(&tx_channel_cfg, &tx_channel), ESP_ERR_INVALID_ARG); } static void test_rmt_channel_single_trans(size_t mem_block_symbols, bool with_dma)