Skip to content

Commit bd15bfa

Browse files
committed
tests: drivers: uart: uart_baudrate_test: skip for fast baudrates
Used gpio measurement method is not fast enought for faster baudrates. Signed-off-by: Piotr Kosycarz <[email protected]>
1 parent 7807cfa commit bd15bfa

File tree

1 file changed

+26
-20
lines changed
  • tests/drivers/uart/uart_baudrate_test/src

1 file changed

+26
-20
lines changed

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

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,30 @@ static void check_timing(const struct gpio_dt_spec *gpio_dt, uint32_t baudrate)
9292
gpio_read_time_us_mean /= (double)REPEAT_NUMBER;
9393
TC_PRINT("GPIO get takes: %.2f us\n", gpio_read_time_us_mean);
9494

95+
double expected_bit_period_us = 1e6 / (double)baudrate;
96+
double number_of_bits = 8;
97+
98+
number_of_bits += 1;
99+
if (test_uart_config.stop_bits == UART_CFG_STOP_BITS_1) {
100+
number_of_bits += 1;
101+
} else if (test_uart_config.stop_bits == UART_CFG_STOP_BITS_2) {
102+
number_of_bits += 2;
103+
} else {
104+
zassert_true(false, "Unsupported stop_bits: %d", test_uart_config.stop_bits);
105+
}
106+
if (test_uart_config.parity != UART_CFG_PARITY_NONE) {
107+
number_of_bits += 1;
108+
}
109+
double expected_symbol_period_us = number_of_bits * expected_bit_period_us;
110+
111+
TC_PRINT("[%d] Expected symbol time: %.2f us, expected bit time: %.2f us\n", baudrate,
112+
expected_symbol_period_us, expected_bit_period_us);
113+
114+
if (expected_bit_period_us < gpio_read_time_us_mean) {
115+
TC_PRINT("[%d] Not supported - gpio measurement is too slow.\n", baudrate);
116+
ztest_test_skip();
117+
}
118+
95119
start_index_count_zero = 0;
96120
bit_diviation_mean = 0;
97121
symbol_diviation_mean = 0;
@@ -139,29 +163,11 @@ static void check_timing(const struct gpio_dt_spec *gpio_dt, uint32_t baudrate)
139163
zassert_true(stop_index != -1, "Missing stop_index\n");
140164

141165
double measured_period_us = (stop_index - start_index) * gpio_read_time_us_mean;
142-
double expected_bit_period_us = 1e6 / (double)baudrate;
143-
double number_of_bits = 8;
144-
145-
number_of_bits += 1;
146-
if (test_uart_config.stop_bits == UART_CFG_STOP_BITS_1) {
147-
number_of_bits += 1;
148-
} else if (test_uart_config.stop_bits == UART_CFG_STOP_BITS_2) {
149-
number_of_bits += 2;
150-
} else {
151-
zassert_true(false, "Unsupported stop_bits: %d",
152-
test_uart_config.stop_bits);
153-
}
154-
if (test_uart_config.parity != UART_CFG_PARITY_NONE) {
155-
number_of_bits += 1;
156-
}
157166
double measured_bit_us = measured_period_us / (double)number_of_bits;
158-
double expected_symbol_period_us = number_of_bits * expected_bit_period_us;
159167

160168
TC_PRINT("[%d][%s][%d] Measured symbol period: %.2f us, measured bit time: %.2f "
161-
"us, expected "
162-
"symbol time: %.2f us, expected bit time: %.2f us\n",
163-
t, uart_dev->name, baudrate, measured_period_us, measured_bit_us,
164-
expected_symbol_period_us, expected_bit_period_us);
169+
"us\n",
170+
t, uart_dev->name, baudrate, measured_period_us, measured_bit_us);
165171

166172
double symbol_diviation = 100 *
167173
fabs(measured_period_us - expected_symbol_period_us) /

0 commit comments

Comments
 (0)