Skip to content

Commit 416bae1

Browse files
nordic-krchnordic-piks
authored andcommitted
tests: drivers: uart: uart_baudrate_test: Handle low baudrates
Fast UARTE instances cannot generate precisely low baudrates as BAUDRATE register which holds the divider has only top 16 bits implemented so if peripheral clock frequency is high and baudrate is low then those missing bits results in deviation of the baudrate. Mainly visible on 4800 baudrate with UARTE clocked by 320 MHz clock. Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
1 parent 62760f4 commit 416bae1

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

  • tests/drivers/uart/uart_baudrate_test/src

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ static void check_timing(uint32_t baudrate)
6464
double symbol_diviation_mean;
6565
bool once = true;
6666
int key;
67+
uint32_t uart_freq = NRF_PERIPH_GET_FREQUENCY(DT_NODELABEL(dut));
68+
uint32_t accepted_deviation = CONFIG_TEST_ALLOWED_DEVIATION;
69+
70+
/* Baudrate register has only top 16 bits implemented so if baudrate is
71+
* significantly lower than the peripheral frequency, accuracy of the baudrate
72+
* decreases.
73+
*/
74+
if (uart_freq / 10000) {
75+
accepted_deviation += 5;
76+
}
6777

6878
ret = uart_config_get(uart_dev, &test_uart_config);
6979
zassert_equal(ret, 0, "uart_config_get: %d\n", ret);
@@ -195,12 +205,12 @@ static void check_timing(uint32_t baudrate)
195205
uart_dev->name, baudrate, symbol_diviation_mean, bit_diviation_mean);
196206

197207
if (start_index_count_zero == 0) {
198-
zassert_true(symbol_diviation_mean <= (double)CONFIG_TEST_ALLOWED_DEVIATION,
199-
"Symbol diviation %0.f%% higher than %d%%\n", symbol_diviation_mean,
200-
CONFIG_TEST_ALLOWED_DEVIATION);
201-
zassert_true(bit_diviation_mean <= (double)CONFIG_TEST_ALLOWED_DEVIATION,
202-
"Bit diviation %0.f%% higher than %d%%\n", bit_diviation_mean,
203-
CONFIG_TEST_ALLOWED_DEVIATION);
208+
zassert_true(symbol_diviation_mean <= (double)accepted_deviation,
209+
"Symbol diviation %0.f%% higher than %d%%\n",
210+
symbol_diviation_mean, accepted_deviation);
211+
zassert_true(bit_diviation_mean <= (double)accepted_deviation,
212+
"Bit diviation %0.f%% higher than %d%%\n",
213+
bit_diviation_mean, accepted_deviation);
204214
} else {
205215
TC_PRINT("Not checking diviation due to lost start of start bit\n");
206216
}

0 commit comments

Comments
 (0)