Skip to content

Commit f38a2e1

Browse files
committed
fix(uart): enlarged task stack size for uart_async_rxtxtasks example
Meanwhile, added CI pytest for some UART examples Closes #15363
1 parent 403cc24 commit f38a2e1

File tree

5 files changed

+76
-5
lines changed

5 files changed

+76
-5
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
menu "Example Configuration"
2+
3+
orsource "$IDF_PATH/examples/common_components/env_caps/$IDF_TARGET/Kconfig.env_caps"
4+
5+
config EXAMPLE_UART_BAUD_RATE
6+
int "UART communication speed"
7+
range 1200 115200
8+
default 115200
9+
help
10+
UART communication speed for the example.
11+
12+
config EXAMPLE_UART_RXD
13+
int "UART RXD pin number"
14+
range ENV_GPIO_RANGE_MIN ENV_GPIO_IN_RANGE_MAX
15+
default 5
16+
help
17+
GPIO number for UART RX pin. See UART documentation for more information
18+
about available pin numbers for UART.
19+
20+
config EXAMPLE_UART_TXD
21+
int "UART TXD pin number"
22+
range ENV_GPIO_RANGE_MIN ENV_GPIO_OUT_RANGE_MAX
23+
default 4
24+
help
25+
GPIO number for UART TX pin. See UART documentation for more information
26+
about available pin numbers for UART.
27+
28+
config EXAMPLE_TASK_STACK_SIZE
29+
int "Example task stack size"
30+
range 1024 16384
31+
default 3072
32+
help
33+
Defines stack size for UART TX and RX tasks. Insufficient stack size can cause crash.
34+
35+
endmenu

examples/peripherals/uart/uart_async_rxtxtasks/main/uart_async_rxtxtasks_main.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616

1717
static const int RX_BUF_SIZE = 1024;
1818

19-
#define TXD_PIN (GPIO_NUM_4)
20-
#define RXD_PIN (GPIO_NUM_5)
19+
#define TXD_PIN (CONFIG_EXAMPLE_UART_TXD)
20+
#define RXD_PIN (CONFIG_EXAMPLE_UART_RXD)
2121

2222
void init(void)
2323
{
2424
const uart_config_t uart_config = {
25-
.baud_rate = 115200,
25+
.baud_rate = CONFIG_EXAMPLE_UART_BAUD_RATE,
2626
.data_bits = UART_DATA_8_BITS,
2727
.parity = UART_PARITY_DISABLE,
2828
.stop_bits = UART_STOP_BITS_1,
@@ -72,6 +72,6 @@ static void rx_task(void *arg)
7272
void app_main(void)
7373
{
7474
init();
75-
xTaskCreate(rx_task, "uart_rx_task", 1024 * 2, NULL, configMAX_PRIORITIES - 1, NULL);
76-
xTaskCreate(tx_task, "uart_tx_task", 1024 * 2, NULL, configMAX_PRIORITIES - 2, NULL);
75+
xTaskCreate(rx_task, "uart_rx_task", CONFIG_EXAMPLE_TASK_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL);
76+
xTaskCreate(tx_task, "uart_tx_task", CONFIG_EXAMPLE_TASK_STACK_SIZE, NULL, configMAX_PRIORITIES - 2, NULL);
7777
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
2+
# SPDX-License-Identifier: CC0-1.0
3+
import pytest
4+
from pytest_embedded import Dut
5+
6+
7+
@pytest.mark.supported_targets
8+
@pytest.mark.generic
9+
def test_uart_async_rxtxtasks_example(dut: Dut) -> None:
10+
dut.expect_exact('TX_TASK: Wrote 11 bytes')
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
2+
# SPDX-License-Identifier: CC0-1.0
3+
import pytest
4+
from pytest_embedded import Dut
5+
6+
7+
@pytest.mark.supported_targets
8+
@pytest.mark.generic
9+
def test_uart_events_example(dut: Dut) -> None:
10+
dut.expect_exact('Returned from app_main()')
11+
dut.write('a')
12+
dut.expect_exact('uart_events: [UART DATA]: 2') # dut.write will add an extra '\n'
13+
dut.write('HA')
14+
dut.expect_exact('uart_events: [UART DATA]: 3') # dut.write will add an extra '\n'
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
2+
# SPDX-License-Identifier: CC0-1.0
3+
import pytest
4+
from pytest_embedded import Dut
5+
6+
7+
@pytest.mark.supported_targets
8+
@pytest.mark.generic
9+
def test_uart_select_example(dut: Dut) -> None:
10+
dut.expect_exact('uart_select_example: Timeout has been reached and nothing has been received')
11+
dut.write('a')
12+
dut.expect_exact('uart_select_example: Received: a')

0 commit comments

Comments
 (0)