Skip to content

Commit f7f67de

Browse files
erwangocfriedt
authored andcommitted
tests/drivers/clock_control: stm32u5: Add tests on clock configs
Add a test suite to check various clocks configurations. Test is based on HAL functions that read clock configuration from registers. One test is build only, as there is no available hw to test it today. Others can be tested on target. More configurations and test points could be added in future. Signed-off-by: Erwan Gouriou <[email protected]>
1 parent a26ee7c commit f7f67de

File tree

10 files changed

+380
-0
lines changed

10 files changed

+380
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
5+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6+
project(stm32_clock_configuration)
7+
8+
FILE(GLOB app_sources src/*.c)
9+
target_sources(app PRIVATE ${app_sources})
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2021 Linaro Limited
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/*
8+
* Warning: This overlay relies on initial board configuration.
9+
* For clarity, nodes are over written instead of deleted.
10+
* Any change to board configuration has impact on this file.
11+
*/
12+
13+
&clk_lse {
14+
status = "okay";
15+
};
16+
17+
&clk_msis {
18+
status = "okay";
19+
msi-range = <1>; /* Range 1: 24MHz */
20+
msi-pll-mode;
21+
};
22+
23+
&pll1 { /* PLL disabled */
24+
/delete-property/ div-m;
25+
/delete-property/ mul-n;
26+
/delete-property/ div-q;
27+
/delete-property/ div-r;
28+
/delete-property/ clocks;
29+
status = "disabled";
30+
};
31+
32+
&rcc {
33+
clocks = <&clk_msis>; /* clck src MSIS */
34+
clock-frequency = <DT_FREQ_M(24)>; /* clck freq 24MHz */
35+
ahb-prescaler = <1>;
36+
apb1-prescaler = <1>;
37+
apb2-prescaler = <1>;
38+
apb3-prescaler = <1>;
39+
};
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2021 Linaro Limited
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/*
8+
* Warning: This overlay relies on initial board configuration.
9+
* For clarity, nodes are over written instead of deleted.
10+
* Any change to board configuration has impact on this file.
11+
*/
12+
13+
&clk_lse {
14+
status = "okay";
15+
};
16+
17+
&clk_msis {
18+
status = "okay";
19+
msi-range = <0>; /* Range 0: 48MHz */
20+
msi-pll-mode;
21+
};
22+
23+
&pll1 { /* PLL disabled */
24+
/delete-property/ div-m;
25+
/delete-property/ mul-n;
26+
/delete-property/ div-q;
27+
/delete-property/ div-r;
28+
/delete-property/ clocks;
29+
status = "disabled";
30+
};
31+
32+
&rcc {
33+
clocks = <&clk_msis>; /* clck src MSIS */
34+
clock-frequency = <DT_FREQ_M(48)>; /* clck freq 48MHz */
35+
ahb-prescaler = <1>;
36+
apb1-prescaler = <1>;
37+
apb2-prescaler = <1>;
38+
apb3-prescaler = <1>;
39+
};
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2021 Linaro Limited
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/*
8+
* Warning: This overlay relies on initial board configuration.
9+
* For clarity, nodes are over written instead of deleted.
10+
* Any change to board configuration has impact on this file.
11+
*/
12+
13+
&clk_lse {
14+
status = "disabled"; /* LSE disabled */
15+
};
16+
17+
&clk_msis { /* MSI disabled */
18+
status = "disabled";
19+
/delete-property/ msi-range;
20+
/delete-property/ msi-pll-mode;
21+
};
22+
23+
&clk_hsi { /* HSI enabled */
24+
status = "okay";
25+
};
26+
27+
&pll1 {
28+
div-m = <4>; /* Update PLL config */
29+
mul-n = <40>;
30+
div-q = <2>;
31+
div-r = <1>;
32+
clocks = <&clk_hsi>; /* PLL src HSI */
33+
status = "okay";
34+
};
35+
36+
&rcc {
37+
clocks = <&pll1>;
38+
clock-frequency = <DT_FREQ_M(160)>; /* clck freq 40MHz */
39+
ahb-prescaler = <1>;
40+
apb1-prescaler = <1>;
41+
apb2-prescaler = <1>;
42+
apb3-prescaler = <1>;
43+
};
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2021 Linaro Limited
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/*
8+
* Warning: This overlay relies on initial board configuration.
9+
* For clarity, nodes are over written instead of deleted.
10+
* Any change to board configuration has impact on this file.
11+
*/
12+
13+
&clk_lse {
14+
status = "disabled"; /* LSE disabled */
15+
};
16+
17+
&clk_msis { /* MSI disabled */
18+
status = "disabled";
19+
/delete-property/ msi-range;
20+
/delete-property/ msi-pll-mode;
21+
};
22+
23+
&clk_hsi { /* HSI enabled */
24+
status = "okay";
25+
};
26+
27+
&pll1 {
28+
div-m = <4>; /* Update PLL config */
29+
mul-n = <10>;
30+
div-q = <2>;
31+
div-r = <1>;
32+
clocks = <&clk_hsi>; /* PLL src HSI */
33+
status = "okay";
34+
};
35+
36+
&rcc {
37+
clocks = <&pll1>;
38+
clock-frequency = <DT_FREQ_M(40)>; /* clck freq 40MHz */
39+
ahb-prescaler = <1>;
40+
apb1-prescaler = <1>;
41+
apb2-prescaler = <1>;
42+
apb3-prescaler = <1>;
43+
};
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2021 Linaro Limited
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/*
8+
* Warning: This overlay relies on initial board configuration.
9+
* For clarity, nodes are over written instead of deleted.
10+
* Any change to board configuration has impact on this file.
11+
*/
12+
13+
&clk_lse {
14+
status = "okay";
15+
};
16+
17+
&clk_msis {
18+
status = "okay";
19+
msi-range = <4>;
20+
msi-pll-mode;
21+
};
22+
23+
&pll1 {
24+
div-m = <2>; /* Update PLL config */
25+
mul-n = <40>;
26+
div-q = <2>;
27+
div-r = <1>;
28+
clocks = <&clk_msis>;
29+
status = "okay";
30+
};
31+
32+
&rcc {
33+
clocks = <&pll1>;
34+
clock-frequency = <DT_FREQ_M(80)>; /* clck freq 80MHz */
35+
ahb-prescaler = <1>;
36+
apb1-prescaler = <1>;
37+
apb2-prescaler = <1>;
38+
apb3-prescaler = <1>;
39+
};
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 2021 Linaro Limited
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/*
8+
* Warning: This overlay relies on initial board configuration.
9+
* For clarity, nodes are over written instead of deleted.
10+
* Any change to board configuration has impact on this file.
11+
*/
12+
13+
/*
14+
* Warning: HSE is not implmeneed on the board, hence:
15+
* This configuration is only available for build
16+
*/
17+
18+
&clk_lse {
19+
status = "disabled"; /* LSE disabled */
20+
};
21+
22+
&clk_msis { /* MSI disabled */
23+
status = "disabled";
24+
/delete-property/ msi-range;
25+
/delete-property/ msi-pll-mode;
26+
};
27+
28+
&clk_hse { /* HSE enabled */
29+
status = "okay";
30+
clock-frequency = <DT_FREQ_M(16)>; /* HSE clk freq 16MHz */
31+
hse-bypass;
32+
};
33+
34+
&pll1 {
35+
div-m = <4>; /* Update PLL config */
36+
mul-n = <40>;
37+
div-q = <2>;
38+
div-r = <1>;
39+
clocks = <&clk_hse>; /* PLL src HSE */
40+
status = "okay";
41+
};
42+
43+
&rcc {
44+
clocks = <&pll>;
45+
clock-frequency = <DT_FREQ_M(160)>;
46+
ahb-prescaler = <1>;
47+
apb1-prescaler = <1>;
48+
apb2-prescaler = <1>;
49+
apb3-prescaler = <1>;
50+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_ZTEST=y
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Copyright (c) 2021 Linaro Limited
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <ztest.h>
8+
#include <soc.h>
9+
#include <drivers/clock_control.h>
10+
#include <drivers/clock_control/stm32_clock_control.h>
11+
#include <logging/log.h>
12+
LOG_MODULE_REGISTER(test);
13+
14+
static void test_sysclk_freq(void)
15+
{
16+
uint32_t soc_sys_clk_freq;
17+
18+
soc_sys_clk_freq = HAL_RCC_GetSysClockFreq();
19+
20+
zassert_equal(CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC, soc_sys_clk_freq,
21+
"Expected sysclockfreq: %d. Actual sysclockfreq: %d",
22+
CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC, soc_sys_clk_freq);
23+
}
24+
25+
static void test_sysclk_src(void)
26+
{
27+
int sys_clk_src = __HAL_RCC_GET_SYSCLK_SOURCE();
28+
29+
#if STM32_SYSCLK_SRC_PLL
30+
zassert_equal(RCC_SYSCLKSOURCE_STATUS_PLLCLK, sys_clk_src,
31+
"Expected sysclk src: PLL1. Actual sysclk src: %d",
32+
sys_clk_src);
33+
#elif STM32_SYSCLK_SRC_HSE
34+
zassert_equal(RCC_SYSCLKSOURCE_STATUS_HSE, sys_clk_src,
35+
"Expected sysclk src: HSE. Actual sysclk src: %d",
36+
sys_clk_src);
37+
#elif STM32_SYSCLK_SRC_HSI
38+
zassert_equal(RCC_SYSCLKSOURCE_STATUS_HSI, sys_clk_src,
39+
"Expected sysclk src: HSI. Actual sysclk src: %d",
40+
sys_clk_src);
41+
#elif STM32_SYSCLK_SRC_MSIS
42+
zassert_equal(RCC_SYSCLKSOURCE_STATUS_MSI, sys_clk_src,
43+
"Expected sysclk src: MSI. Actual sysclk src: %d",
44+
sys_clk_src);
45+
#else
46+
/* Case not expected */
47+
zassert_true((STM32_SYSCLK_SRC_PLL ||
48+
STM32_SYSCLK_SRC_HSE ||
49+
STM32_SYSCLK_SRC_HSI ||
50+
STM32_SYSCLK_SRC_MSIS),
51+
"Not expected. sys_clk_src: %d\n", sys_clk_src);
52+
#endif
53+
54+
}
55+
56+
static void test_pll_src(void)
57+
{
58+
uint32_t pll_src = __HAL_RCC_GET_PLL_OSCSOURCE();
59+
60+
#if STM32_PLL_SRC_HSE
61+
zassert_equal(RCC_PLLSOURCE_HSE, pll_src,
62+
"Expected PLL src: HSE. Actual PLL src: %d",
63+
pll_src);
64+
#elif STM32_PLL_SRC_HSI
65+
zassert_equal(RCC_PLLSOURCE_HSI, pll_src,
66+
"Expected PLL src: HSI. Actual PLL src: %d",
67+
pll_src);
68+
#elif STM32_PLL_SRC_MSIS
69+
zassert_equal(RCC_PLLSOURCE_MSI, pll_src,
70+
"Expected PLL src: MSI. Actual PLL src: %d",
71+
pll_src);
72+
#else
73+
zassert_equal(RCC_PLLSOURCE_NONE, pll_src,
74+
"Expected PLL src: None. Actual PLL src: %d",
75+
pll_src);
76+
#endif
77+
78+
}
79+
80+
void test_main(void)
81+
{
82+
ztest_test_suite(test_stm32_syclck_config,
83+
ztest_unit_test(test_sysclk_freq),
84+
ztest_unit_test(test_sysclk_src),
85+
ztest_unit_test(test_pll_src)
86+
);
87+
ztest_run_test_suite(test_stm32_syclck_config);
88+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
tests:
2+
drivers.stm32_clock_configuration.u5.sysclksrc_pll_msis_160:
3+
timeout: 5
4+
platform_allow: b_u585i_iot02a
5+
drivers.stm32_clock_configuration.u5.sysclksrc_pll_msis_80:
6+
extra_args: DTC_OVERLAY_FILE=boards/b_u585i_iot02a_pll_msi_80.overlay
7+
timeout: 5
8+
platform_allow: b_u585i_iot02a
9+
drivers.stm32_clock_configuration.u5.sysclksrc_pll_hsi_160:
10+
extra_args: DTC_OVERLAY_FILE=boards/b_u585i_iot02a_pll_hsi_160.overlay
11+
platform_allow: b_u585i_iot02a
12+
timeout: 5
13+
drivers.stm32_clock_configuration.u5.sysclksrc_pll_hsi_40:
14+
extra_args: DTC_OVERLAY_FILE=boards/b_u585i_iot02a_pll_hsi_40.overlay
15+
platform_allow: b_u585i_iot02a
16+
timeout: 5
17+
drivers.stm32_clock_configuration.u5.sysclksrc_msis_48:
18+
extra_args: DTC_OVERLAY_FILE=boards/b_u585i_iot02a_msis_48.overlay
19+
platform_allow: b_u585i_iot02a
20+
timeout: 5
21+
drivers.stm32_clock_configuration.u5.sysclksrc_msis_24:
22+
extra_args: DTC_OVERLAY_FILE=boards/b_u585i_iot02a_msis_24.overlay
23+
platform_allow: b_u585i_iot02a
24+
timeout: 5
25+
drivers.stm32_clock_configuration.u5.sysclksrc_pll_hse_160:
26+
extra_args: DTC_OVERLAY_FILE=boards/nucleo_u575zi_q_pll_hse_160.overlay
27+
timeout: 5
28+
platform_allow: nucleo_u575zi_q
29+
build_only: true # Build only as HSE not implemened on the board

0 commit comments

Comments
 (0)