diff --git a/tests/periph_uart_mode/Makefile b/tests/periph_uart_mode/Makefile index 04882515c0db..329a1ac63749 100644 --- a/tests/periph_uart_mode/Makefile +++ b/tests/periph_uart_mode/Makefile @@ -2,8 +2,7 @@ include ../Makefile.tests_common FEATURES_REQUIRED += periph_uart FEATURES_REQUIRED += periph_uart_modecfg - -USEMODULE += xtimer +FEATURES_OPTIONAL += periph_timer # Set this to prevent welcome message from printing and confusing output CFLAGS+=-DLOG_LEVEL=LOG_NONE diff --git a/tests/periph_uart_mode/Makefile.board.dep b/tests/periph_uart_mode/Makefile.board.dep new file mode 100644 index 000000000000..1da3893d4d81 --- /dev/null +++ b/tests/periph_uart_mode/Makefile.board.dep @@ -0,0 +1,3 @@ +ifneq (,$(filter periph_timer,$(FEATURES_USED))) + USEMODULE += xtimer +endif diff --git a/tests/periph_uart_mode/main.c b/tests/periph_uart_mode/main.c index d15df67ba039..b37d44796b54 100644 --- a/tests/periph_uart_mode/main.c +++ b/tests/periph_uart_mode/main.c @@ -22,7 +22,9 @@ #include #include +#include "board.h" #include "periph/uart.h" +#include "periph_conf.h" #include "stdio_uart.h" #include "xtimer.h" @@ -52,6 +54,25 @@ /* Stores each mode string for printing at the end of the test */ static char mode_strings[TOTAL_OPTIONS][MODE_STR_LEN]; +static void _delay(void) +{ + if (IS_USED(MODULE_XTIMER)) { + xtimer_usleep(DELAY_US); + } + else { + /* + * As fallback for freshly ported boards with no timer drivers written + * yet, we just use the CPU to delay execution and assume that roughly + * 20 CPU cycles are spend per loop iteration. + * + * Note that the volatile qualifier disables compiler optimizations for + * all accesses to the counter variable. Without volatile, modern + * compilers would detect that the loop is only wasting CPU cycles and + * optimize it out - but here the wasting of CPU cycles is desired. + */ + for (volatile uint32_t i = 0; i < CLOCK_CORECLOCK / 20; i++) { } + } +} static void _get_mode(const uart_data_bits_t data_bits, const uart_parity_t parity, const uart_stop_bits_t stop_bits, char* mode_str) { @@ -153,7 +174,7 @@ int main(void) if (status == UART_OK) { results[ridx] = true; printf("%s\n", mode_strings[ridx]); - xtimer_usleep(DELAY_US); + _delay(); } else { results[ridx] = false;