Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: uart: esp32: Test configuration #81159

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion drivers/serial/uart_esp32.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,29 @@ static int uart_esp32_err_check(const struct device *dev)
}

#ifdef CONFIG_UART_USE_RUNTIME_CONFIGURE

static uint32_t uart_esp32_get_standard_baud(uint32_t calc_baud)
{
const uint32_t standard_bauds[] = {9600, 14400, 19200, 38400, 57600,
74880, 115200, 230400, 460800, 921600};
int num_bauds = ARRAY_SIZE(standard_bauds);
uint32_t baud = calc_baud;

/* Find the standard baudrate within 0.1% range. If no close
* value is found, input is returned.
*/
for (int i = 0; i < num_bauds; i++) {
float range = (float)abs(calc_baud - standard_bauds[i]) / standard_bauds[i];

if (range < 0.001f) {
baud = standard_bauds[i];
break;
}
}

return baud;
}

static int uart_esp32_config_get(const struct device *dev, struct uart_config *cfg)
{
struct uart_esp32_data *data = dev->data;
Expand All @@ -179,11 +202,14 @@ static int uart_esp32_config_get(const struct device *dev, struct uart_config *c
uart_hw_flowcontrol_t hw_flow;
uart_sclk_t src_clk;
uint32_t sclk_freq;
uint32_t calc_baud;

uart_hal_get_sclk(&data->hal, &src_clk);
esp_clk_tree_src_get_freq_hz((soc_module_clk_t)src_clk,
ESP_CLK_TREE_SRC_FREQ_PRECISION_CACHED, &sclk_freq);
uart_hal_get_baudrate(&data->hal, &cfg->baudrate, sclk_freq);

uart_hal_get_baudrate(&data->hal, &calc_baud, sclk_freq);
cfg->baudrate = uart_esp32_get_standard_baud(calc_baud);

uart_hal_get_parity(&data->hal, &parity);
switch (parity) {
Expand Down
2 changes: 1 addition & 1 deletion tests/drivers/uart/uart_basic_api/src/test_uart_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#include "test_uart.h"
const struct uart_config uart_cfg = {
.baudrate = 115200,
.baudrate = DT_PROP_OR(DT_CHOSEN(zephyr_console), current_speed, 115200),
.parity = UART_CFG_PARITY_NONE,
.stop_bits = UART_CFG_STOP_BITS_1,
.data_bits = UART_CFG_DATA_BITS_8,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#include "test_uart.h"
const struct uart_config uart_cfg_wide = {
.baudrate = 115200,
.baudrate = DT_PROP_OR(DT_NODELABEL(dut), current_speed, 115200),
.parity = UART_CFG_PARITY_NONE,
.stop_bits = UART_CFG_STOP_BITS_1,
.data_bits = UART_CFG_DATA_BITS_9,
Expand Down
8 changes: 8 additions & 0 deletions tests/drivers/uart/uart_elementary/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@ config DUAL_UART_TEST
config SETUP_MISMATCH_TEST
bool "Enable mismatched configuration in dual UART test"

config UART_BAUDRATE_MISMATCH
int "UART baudrate for DUT_AUX to test mismatch case"
depends on SETUP_MISMATCH_TEST
default 9600
help
UART baudrate for DUT_AUX that is intentionally different from DUT
to test error detection.

source "Kconfig.zephyr"
1 change: 1 addition & 0 deletions tests/drivers/uart/uart_elementary/socs/esp32_procpu.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONFIG_DUAL_UART_TEST=y
50 changes: 50 additions & 0 deletions tests/drivers/uart/uart_elementary/socs/esp32_procpu.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
*/

&pinctrl {
uart1_test: uart1_test {
group1 {
pinmux = <UART1_TX_GPIO2>,
<UART1_RTS_GPIO4>;
input-enable;
output-high;
};
group2 {
pinmux = <UART1_RX_GPIO3>,
<UART1_CTS_GPIO5>;
output-enable;
bias-pull-up;
};
};

uart2_test: uart2_test {
group1 {
pinmux = <UART2_TX_GPIO3>,
<UART1_RTS_GPIO5>;
input-enable;
output-high;
};
group2 {
pinmux = <UART2_RX_GPIO2>,
<UART1_CTS_GPIO4>;
output-enable;
bias-pull-up;
};
};
};

dut: &uart1 {
status = "okay";
pinctrl-0 = <&uart1_test>;
pinctrl-names = "default";
current-speed = <115200>;
};

dut_aux: &uart2 {
status = "okay";
pinctrl-0 = <&uart2_test>;
pinctrl-names = "default";
current-speed = <115200>;
};
28 changes: 28 additions & 0 deletions tests/drivers/uart/uart_elementary/socs/esp32c2.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
*/

&pinctrl {
uart1_test: uart1_test {
group1 {
pinmux = <UART1_TX_GPIO2>,
<UART1_RTS_GPIO3>;
input-enable;
output-high;
};
group2 {
pinmux = <UART1_RX_GPIO2>,
<UART1_CTS_GPIO3>;
output-enable;
bias-pull-up;
};
};
};

dut: &uart1 {
status = "okay";
pinctrl-0 = <&uart1_test>;
pinctrl-names = "default";
current-speed = <74880>;
};
28 changes: 28 additions & 0 deletions tests/drivers/uart/uart_elementary/socs/esp32c3.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
*/

&pinctrl {
uart1_test: uart1_test {
group1 {
pinmux = <UART1_TX_GPIO2>,
<UART1_RTS_GPIO3>;
input-enable;
output-high;
};
group2 {
pinmux = <UART1_RX_GPIO2>,
<UART1_CTS_GPIO3>;
output-enable;
bias-pull-up;
};
};
};

dut: &uart1 {
status = "okay";
pinctrl-0 = <&uart1_test>;
pinctrl-names = "default";
current-speed = <115200>;
};
28 changes: 28 additions & 0 deletions tests/drivers/uart/uart_elementary/socs/esp32c6.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
*/

&pinctrl {
uart1_test: uart1_test {
group1 {
pinmux = <UART1_TX_GPIO2>,
<UART1_RTS_GPIO3>;
input-enable;
output-high;
};
group2 {
pinmux = <UART1_RX_GPIO2>,
<UART1_CTS_GPIO3>;
output-enable;
bias-pull-up;
};
};
};

dut: &uart1 {
status = "okay";
pinctrl-0 = <&uart1_test>;
pinctrl-names = "default";
current-speed = <115200>;
};
28 changes: 28 additions & 0 deletions tests/drivers/uart/uart_elementary/socs/esp32s2.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
*/

&pinctrl {
uart1_test: uart1_test {
group1 {
pinmux = <UART1_TX_GPIO2>,
<UART1_RTS_GPIO3>;
input-enable;
output-high;
};
group2 {
pinmux = <UART1_RX_GPIO2>,
<UART1_CTS_GPIO3>;
output-enable;
bias-pull-up;
};
};
};

dut: &uart1 {
status = "okay";
pinctrl-0 = <&uart1_test>;
pinctrl-names = "default";
current-speed = <115200>;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONFIG_DUAL_UART_TEST=y
sylvioalves marked this conversation as resolved.
Show resolved Hide resolved
50 changes: 50 additions & 0 deletions tests/drivers/uart/uart_elementary/socs/esp32s3_procpu.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
*/

&pinctrl {
uart1_test: uart1_test {
group1 {
pinmux = <UART1_TX_GPIO2>,
<UART1_RTS_GPIO4>;
input-enable;
output-high;
};
group2 {
pinmux = <UART1_RX_GPIO3>,
<UART1_CTS_GPIO5>;
output-enable;
bias-pull-up;
};
};

uart2_test: uart2_test {
group1 {
pinmux = <UART2_TX_GPIO3>,
<UART1_RTS_GPIO5>;
input-enable;
output-high;
};
group2 {
pinmux = <UART2_RX_GPIO2>,
<UART1_CTS_GPIO4>;
output-enable;
bias-pull-up;
};
};
};

dut: &uart1 {
status = "okay";
pinctrl-0 = <&uart1_test>;
pinctrl-names = "default";
current-speed = <115200>;
};

dut_aux: &uart2 {
status = "okay";
pinctrl-0 = <&uart2_test>;
pinctrl-names = "default";
current-speed = <115200>;
};
12 changes: 7 additions & 5 deletions tests/drivers/uart/uart_elementary/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#define SLEEP_TIME_US 1000
#define TEST_BUFFER_LEN 10

#define UART_BAUDRATE DT_PROP_OR(UART_NODE, current_speed, 115200)

static const struct device *const uart_dev = DEVICE_DT_GET(UART_NODE);

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

int err;
struct uart_config test_expected_uart_config;
struct uart_config test_uart_config = { .baudrate = 115200,
struct uart_config test_uart_config = { .baudrate = UART_BAUDRATE,
.parity = UART_CFG_PARITY_NONE,
.stop_bits = UART_CFG_STOP_BITS_1,
.data_bits = UART_CFG_DATA_BITS_8,
Expand Down Expand Up @@ -176,7 +178,7 @@ ZTEST(uart_elementary, test_uart_improper_configuration)
Z_TEST_SKIP_IFDEF(CONFIG_DUAL_UART_TEST);

int err;
struct uart_config test_uart_config = { .baudrate = 115200,
struct uart_config test_uart_config = { .baudrate = UART_BAUDRATE,
.parity = 7,
.stop_bits = UART_CFG_STOP_BITS_1,
.data_bits = UART_CFG_DATA_BITS_8,
Expand All @@ -196,7 +198,7 @@ ZTEST(uart_elementary, test_uart_improper_configuration)
ZTEST(uart_elementary, test_uart_basic_transmission)
{
int err;
struct uart_config test_uart_config = { .baudrate = 115200,
struct uart_config test_uart_config = { .baudrate = UART_BAUDRATE,
.parity = UART_CFG_PARITY_ODD,
.stop_bits = UART_CFG_STOP_BITS_1,
.data_bits = UART_CFG_DATA_BITS_8,
Expand Down Expand Up @@ -233,14 +235,14 @@ ZTEST(uart_elementary, test_uart_basic_transmission)
ZTEST(uart_elementary, test_uart_dual_port_transmission)
{
int err;
struct uart_config test_uart_config = { .baudrate = 115200,
struct uart_config test_uart_config = { .baudrate = UART_BAUDRATE,
.parity = UART_CFG_PARITY_EVEN,
.stop_bits = UART_CFG_STOP_BITS_2,
.data_bits = UART_CFG_DATA_BITS_8,
.flow_ctrl = UART_CFG_FLOW_CTRL_NONE };

#if defined(CONFIG_SETUP_MISMATCH_TEST)
struct uart_config test_uart_config_aux = { .baudrate = 9600,
struct uart_config test_uart_config_aux = { .baudrate = CONFIG_UART_BAUDRATE_MISMATCH,
.parity = UART_CFG_PARITY_EVEN,
.stop_bits = UART_CFG_STOP_BITS_2,
.data_bits = UART_CFG_DATA_BITS_8,
Expand Down
6 changes: 6 additions & 0 deletions tests/drivers/uart/uart_elementary/testcase.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ tests:
- nrf54l15dk/nrf54l15/cpuapp
- nrf54l15dk/nrf54l15/cpuflpr
- nrf5340dk/nrf5340/cpuapp
- esp32_devkitc_wrover/esp32/procpu
- esp8684_devkitm
- esp32c3_devkitm
- esp32c6_devkitc
- esp32s2_saola
- esp32s3_devkitm/esp32s3/procpu
integration_platforms:
- nrf54h20dk/nrf54h20/cpuapp
drivers.uart.uart_elementary_dual_nrf54h:
Expand Down
Loading