Skip to content

Commit 31ea95f

Browse files
Raffael Rostagnokartben
authored andcommitted
tests: uart_basic_api: uart_elementary: Get baudrate from device tree
Add option (BAUDRATE_FROM_DTS) to get baudrate value from device tree, for devices which differ from standard (115200). Signed-off-by: Raffael Rostagno <[email protected]>
1 parent 4864289 commit 31ea95f

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

tests/drivers/uart/uart_basic_api/src/test_uart_config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
#include "test_uart.h"
2828
const struct uart_config uart_cfg = {
29-
.baudrate = 115200,
29+
.baudrate = DT_PROP_OR(DT_CHOSEN(zephyr_console), current_speed, 115200),
3030
.parity = UART_CFG_PARITY_NONE,
3131
.stop_bits = UART_CFG_STOP_BITS_1,
3232
.data_bits = UART_CFG_DATA_BITS_8,

tests/drivers/uart/uart_basic_api/src/test_uart_config_wide.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
#include "test_uart.h"
2828
const struct uart_config uart_cfg_wide = {
29-
.baudrate = 115200,
29+
.baudrate = DT_PROP_OR(DT_NODELABEL(dut), current_speed, 115200),
3030
.parity = UART_CFG_PARITY_NONE,
3131
.stop_bits = UART_CFG_STOP_BITS_1,
3232
.data_bits = UART_CFG_DATA_BITS_9,

tests/drivers/uart/uart_elementary/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,12 @@ config DUAL_UART_TEST
88
config SETUP_MISMATCH_TEST
99
bool "Enable mismatched configuration in dual UART test"
1010

11+
config UART_BAUDRATE_MISMATCH
12+
int "UART baudrate for DUT_AUX to test mismatch case"
13+
depends on SETUP_MISMATCH_TEST
14+
default 9600
15+
help
16+
UART baudrate for DUT_AUX that is intentionally different from DUT
17+
to test error detection.
18+
1119
source "Kconfig.zephyr"

tests/drivers/uart/uart_elementary/src/main.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#define SLEEP_TIME_US 1000
3131
#define TEST_BUFFER_LEN 10
3232

33+
#define UART_BAUDRATE DT_PROP_OR(UART_NODE, current_speed, 115200)
34+
3335
static const struct device *const uart_dev = DEVICE_DT_GET(UART_NODE);
3436

3537
const uint8_t test_pattern[TEST_BUFFER_LEN] = { 0x11, 0x12, 0x13, 0x14, 0x15,
@@ -135,7 +137,7 @@ ZTEST(uart_elementary, test_uart_proper_configuration)
135137

136138
int err;
137139
struct uart_config test_expected_uart_config;
138-
struct uart_config test_uart_config = { .baudrate = 115200,
140+
struct uart_config test_uart_config = { .baudrate = UART_BAUDRATE,
139141
.parity = UART_CFG_PARITY_NONE,
140142
.stop_bits = UART_CFG_STOP_BITS_1,
141143
.data_bits = UART_CFG_DATA_BITS_8,
@@ -176,7 +178,7 @@ ZTEST(uart_elementary, test_uart_improper_configuration)
176178
Z_TEST_SKIP_IFDEF(CONFIG_DUAL_UART_TEST);
177179

178180
int err;
179-
struct uart_config test_uart_config = { .baudrate = 115200,
181+
struct uart_config test_uart_config = { .baudrate = UART_BAUDRATE,
180182
.parity = 7,
181183
.stop_bits = UART_CFG_STOP_BITS_1,
182184
.data_bits = UART_CFG_DATA_BITS_8,
@@ -196,7 +198,7 @@ ZTEST(uart_elementary, test_uart_improper_configuration)
196198
ZTEST(uart_elementary, test_uart_basic_transmission)
197199
{
198200
int err;
199-
struct uart_config test_uart_config = { .baudrate = 115200,
201+
struct uart_config test_uart_config = { .baudrate = UART_BAUDRATE,
200202
.parity = UART_CFG_PARITY_ODD,
201203
.stop_bits = UART_CFG_STOP_BITS_1,
202204
.data_bits = UART_CFG_DATA_BITS_8,
@@ -233,14 +235,14 @@ ZTEST(uart_elementary, test_uart_basic_transmission)
233235
ZTEST(uart_elementary, test_uart_dual_port_transmission)
234236
{
235237
int err;
236-
struct uart_config test_uart_config = { .baudrate = 115200,
238+
struct uart_config test_uart_config = { .baudrate = UART_BAUDRATE,
237239
.parity = UART_CFG_PARITY_EVEN,
238240
.stop_bits = UART_CFG_STOP_BITS_2,
239241
.data_bits = UART_CFG_DATA_BITS_8,
240242
.flow_ctrl = UART_CFG_FLOW_CTRL_NONE };
241243

242244
#if defined(CONFIG_SETUP_MISMATCH_TEST)
243-
struct uart_config test_uart_config_aux = { .baudrate = 9600,
245+
struct uart_config test_uart_config_aux = { .baudrate = CONFIG_UART_BAUDRATE_MISMATCH,
244246
.parity = UART_CFG_PARITY_EVEN,
245247
.stop_bits = UART_CFG_STOP_BITS_2,
246248
.data_bits = UART_CFG_DATA_BITS_8,

0 commit comments

Comments
 (0)