On Thu, 23 May 2024 at 20:44, Inès Varhol <ines.var...@telecom-paris.fr> wrote:
>
> For USART, GPIO and SYSCFG devices, check that clock frequency before
> and after enabling the peripheral clock in RCC is correct.
>
> Signed-off-by: Inès Varhol <ines.var...@telecom-paris.fr>
> ---
>  tests/qtest/stm32l4x5.h             | 43 +++++++++++++++++++++++++++++
>  tests/qtest/stm32l4x5_gpio-test.c   | 23 +++++++++++++++
>  tests/qtest/stm32l4x5_syscfg-test.c | 20 ++++++++++++--
>  tests/qtest/stm32l4x5_usart-test.c  | 26 +++++++++++++++++
>  4 files changed, 110 insertions(+), 2 deletions(-)
>  create mode 100644 tests/qtest/stm32l4x5.h
>
> diff --git a/tests/qtest/stm32l4x5.h b/tests/qtest/stm32l4x5.h
> new file mode 100644
> index 0000000000..cf59aeb019
> --- /dev/null
> +++ b/tests/qtest/stm32l4x5.h
> @@ -0,0 +1,43 @@
> +/*
> + * QTest testcase header for STM32L4X5 :
> + * used for consolidating common objects in stm32l4x5_*-test.c
> + *
> + * Copyright (c) 2024 Arnaud Minier <arnaud.min...@telecom-paris.fr>
> + * Copyright (c) 2024 Inès Varhol <ines.var...@telecom-paris.fr>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or later.
> + * See the COPYING file in the top-level directory.
> + */
> +
> +#include "qemu/osdep.h"

Header files must never include osdep.h. The rules for
osdep.h are:
 * never included in a .h file
 * always included as the first include in every .c file

> +#include "libqtest.h"
> +
> +/*
> + * MSI (4 MHz) is used as system clock source after startup
> + * from Reset.
> + * AHB, APB1 and APB2 prescalers are set to 1 at reset.
> + *
> + * A clock period is stored in units of 2^-32 ns :
> + * 10^9 * 2^32 / 4000000 = 1073741824000
> + */
> +#define SYSCLK_PERIOD 1073741824000UL

Rather than doing the calculation by hand, it would be
clearer to use the CLOCK_PERIOD_FROM_HZ() macro from hw/clock.h.
(If #including clock.h from the test C file doesn't work for
some reason, you can copy the macro definition; it's a one-liner).

#define SYSCLK_PERIOD CLOCK_PERIOD_FROM_HZ(4000000)

Otherwise
Reviewed-by: Peter Maydell <peter.mayd...@linaro.org>

thanks
-- PMM

Reply via email to