Skip to content

Commit 531c484

Browse files
erwangocarlescufi
authored andcommitted
tests/drivers/clock_control: stm32_common: Test HCLCK instead of SYSCLK
Rework test_*_freq to test HCLK freq instead of SYSCLK one, as it is not correct to compare CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC with SYSCLK. Additionally, add a test to verify use of AHB prescaler. Signed-off-by: Erwan Gouriou <[email protected]>
1 parent f6c665b commit 531c484

File tree

3 files changed

+48
-7
lines changed

3 files changed

+48
-7
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (c) 2022 STMicroelectronics
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/*
8+
* Warning: This overlay performs configuration from clean sheet.
9+
* It is assumed that it is applied after clear_clocks.overlay file.
10+
*/
11+
12+
&clk_hsi {
13+
status = "okay";
14+
};
15+
16+
&pll {
17+
div-m = <8>;
18+
mul-n = <200>;
19+
div-p = <4>;
20+
clocks = <&clk_hsi>;
21+
status = "okay";
22+
};
23+
24+
&rcc {
25+
clocks = <&pll>;
26+
ahb-prescaler = <2>;
27+
clock-frequency = <DT_FREQ_M(50)>; /* Pll Output (100) / AHB prescaler */
28+
apb1-prescaler = <2>;
29+
apb2-prescaler = <2>;
30+
};

tests/drivers/clock_control/stm32_clock_configuration/stm32_common/src/test_stm32_clock_configuration.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,27 @@
88
#include <soc.h>
99
#include <drivers/clock_control.h>
1010
#include <drivers/clock_control/stm32_clock_control.h>
11+
#include <stm32_ll_rcc.h>
1112
#include <logging/log.h>
1213
LOG_MODULE_REGISTER(test);
1314

15+
#if defined(CONFIG_SOC_SERIES_STM32WBX) || \
16+
defined(CONFIG_SOC_SERIES_STM32WLX)
17+
#define CALC_HCLK_FREQ __LL_RCC_CALC_HCLK1_FREQ
18+
#else
19+
#define CALC_HCLK_FREQ __LL_RCC_CALC_HCLK_FREQ
20+
#endif
1421

15-
static void test_sysclk_freq(void)
22+
static void test_hclk_freq(void)
1623
{
17-
uint32_t soc_sys_clk_freq;
24+
uint32_t soc_hclk_freq;
1825

19-
soc_sys_clk_freq = HAL_RCC_GetSysClockFreq();
26+
soc_hclk_freq = CALC_HCLK_FREQ(HAL_RCC_GetSysClockFreq(),
27+
LL_RCC_GetAHBPrescaler());
2028

21-
zassert_equal(CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC, soc_sys_clk_freq,
22-
"Expected sysclockfreq: %d. Actual sysclockfreq: %d",
23-
CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC, soc_sys_clk_freq);
29+
zassert_equal(CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC, soc_hclk_freq,
30+
"Expected hclck_freq: %d. Actual hclck_freq: %d",
31+
CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC, soc_hclk_freq);
2432
}
2533

2634
static void test_sysclk_src(void)
@@ -102,7 +110,7 @@ void test_main(void)
102110
{
103111
printk("testing clock config on %s\n", CONFIG_BOARD);
104112
ztest_test_suite(test_stm32_syclck_config,
105-
ztest_unit_test(test_sysclk_freq),
113+
ztest_unit_test(test_hclk_freq),
106114
ztest_unit_test(test_sysclk_src),
107115
ztest_unit_test(test_pll_src)
108116
);

tests/drivers/clock_control/stm32_clock_configuration/stm32_common/testcase.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,6 @@ tests:
115115
drivers.stm32_clock_configuration.common.f2_f4_f7.sysclksrc_pll_64_hse_8:
116116
extra_args: DTC_OVERLAY_FILE="boards/clear_f2_f4_f7_clocks.overlay;boards/f2_f4_f7_pll_64_hse_8.overlay"
117117
platform_allow: nucleo_f207zg nucleo_f429zi nucleo_f446re nucleo_f746zg
118+
drivers.stm32_clock_configuration.common.f2_f4_f7.sysclksrc_pll_100_hsi_16_ahb2:
119+
extra_args: DTC_OVERLAY_FILE="boards/clear_f2_f4_f7_clocks.overlay;boards/f2_f4_f7_pll_100_hsi_16_ahb_2.overlay"
120+
platform_allow: nucleo_f207zg nucleo_f429zi nucleo_f446re nucleo_f746zg

0 commit comments

Comments
 (0)