diff --git a/examples/peripherals/uart/uart_async_rxtxtasks/main/Kconfig.projbuild b/examples/peripherals/uart/uart_async_rxtxtasks/main/Kconfig.projbuild new file mode 100644 index 0000000000..3068b7abea --- /dev/null +++ b/examples/peripherals/uart/uart_async_rxtxtasks/main/Kconfig.projbuild @@ -0,0 +1,35 @@ +menu "Example Configuration" + + orsource "$IDF_PATH/examples/common_components/env_caps/$IDF_TARGET/Kconfig.env_caps" + + config EXAMPLE_UART_BAUD_RATE + int "UART communication speed" + range 1200 115200 + default 115200 + help + UART communication speed for the example. + + config EXAMPLE_UART_RXD + int "UART RXD pin number" + range ENV_GPIO_RANGE_MIN ENV_GPIO_IN_RANGE_MAX + default 5 + help + GPIO number for UART RX pin. See UART documentation for more information + about available pin numbers for UART. + + config EXAMPLE_UART_TXD + int "UART TXD pin number" + range ENV_GPIO_RANGE_MIN ENV_GPIO_OUT_RANGE_MAX + default 4 + help + GPIO number for UART TX pin. See UART documentation for more information + about available pin numbers for UART. + + config EXAMPLE_TASK_STACK_SIZE + int "Example task stack size" + range 1024 16384 + default 3072 + help + Defines stack size for UART TX and RX tasks. Insufficient stack size can cause crash. + +endmenu diff --git a/examples/peripherals/uart/uart_async_rxtxtasks/main/uart_async_rxtxtasks_main.c b/examples/peripherals/uart/uart_async_rxtxtasks/main/uart_async_rxtxtasks_main.c index cf67cc86f3..d6d48f7ee2 100644 --- a/examples/peripherals/uart/uart_async_rxtxtasks/main/uart_async_rxtxtasks_main.c +++ b/examples/peripherals/uart/uart_async_rxtxtasks/main/uart_async_rxtxtasks_main.c @@ -16,13 +16,13 @@ static const int RX_BUF_SIZE = 1024; -#define TXD_PIN (GPIO_NUM_4) -#define RXD_PIN (GPIO_NUM_5) +#define TXD_PIN (CONFIG_EXAMPLE_UART_TXD) +#define RXD_PIN (CONFIG_EXAMPLE_UART_RXD) void init(void) { const uart_config_t uart_config = { - .baud_rate = 115200, + .baud_rate = CONFIG_EXAMPLE_UART_BAUD_RATE, .data_bits = UART_DATA_8_BITS, .parity = UART_PARITY_DISABLE, .stop_bits = UART_STOP_BITS_1, @@ -72,6 +72,6 @@ static void rx_task(void *arg) void app_main(void) { init(); - xTaskCreate(rx_task, "uart_rx_task", 1024 * 2, NULL, configMAX_PRIORITIES - 1, NULL); - xTaskCreate(tx_task, "uart_tx_task", 1024 * 2, NULL, configMAX_PRIORITIES - 2, NULL); + xTaskCreate(rx_task, "uart_rx_task", CONFIG_EXAMPLE_TASK_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL); + xTaskCreate(tx_task, "uart_tx_task", CONFIG_EXAMPLE_TASK_STACK_SIZE, NULL, configMAX_PRIORITIES - 2, NULL); } diff --git a/examples/peripherals/uart/uart_async_rxtxtasks/pytest_async_rxtxtasks.py b/examples/peripherals/uart/uart_async_rxtxtasks/pytest_async_rxtxtasks.py new file mode 100644 index 0000000000..b039660e56 --- /dev/null +++ b/examples/peripherals/uart/uart_async_rxtxtasks/pytest_async_rxtxtasks.py @@ -0,0 +1,10 @@ +# SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: CC0-1.0 +import pytest +from pytest_embedded import Dut + + +@pytest.mark.supported_targets +@pytest.mark.generic +def test_uart_async_rxtxtasks_example(dut: Dut) -> None: + dut.expect_exact('TX_TASK: Wrote 11 bytes') diff --git a/examples/peripherals/uart/uart_events/pytest_events.py b/examples/peripherals/uart/uart_events/pytest_events.py new file mode 100644 index 0000000000..fb4a8a4611 --- /dev/null +++ b/examples/peripherals/uart/uart_events/pytest_events.py @@ -0,0 +1,14 @@ +# SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: CC0-1.0 +import pytest +from pytest_embedded import Dut + + +@pytest.mark.supported_targets +@pytest.mark.generic +def test_uart_events_example(dut: Dut) -> None: + dut.expect_exact('Returned from app_main()') + dut.write('a') + dut.expect_exact('uart_events: [UART DATA]: 2') # dut.write will add an extra '\n' + dut.write('HA') + dut.expect_exact('uart_events: [UART DATA]: 3') # dut.write will add an extra '\n' diff --git a/examples/peripherals/uart/uart_select/pytest_uart_select.py b/examples/peripherals/uart/uart_select/pytest_uart_select.py new file mode 100644 index 0000000000..eb37f26cee --- /dev/null +++ b/examples/peripherals/uart/uart_select/pytest_uart_select.py @@ -0,0 +1,12 @@ +# SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: CC0-1.0 +import pytest +from pytest_embedded import Dut + + +@pytest.mark.supported_targets +@pytest.mark.generic +def test_uart_select_example(dut: Dut) -> None: + dut.expect_exact('uart_select_example: Timeout has been reached and nothing has been received') + dut.write('a') + dut.expect_exact('uart_select_example: Received: a')