Skip to content

Commit f965565

Browse files
HoZHelcfriedt
authored andcommitted
drivers: Fix the improper use of CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC
Fix the improper use of CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC for STM32WB0 drivers due to the misunderstanding of its definition. Signed-off-by: Ali Hozhabri <[email protected]>
1 parent 8f34d0f commit f965565

File tree

5 files changed

+10
-7
lines changed

5 files changed

+10
-7
lines changed

drivers/adc/adc_stm32wb0.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ LOG_MODULE_REGISTER(adc_stm32wb0, CONFIG_ADC_LOG_LEVEL);
9898
#define ADC_CHANNEL_TYPE_INVALID (0xFFU) /* Invalid */
9999

100100
/** See RM0505 §6.2.1 "System clock details" */
101-
BUILD_ASSERT(CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC >= (8 * 1000 * 1000),
101+
BUILD_ASSERT(STM32_HCLK_FREQUENCY >= (8 * 1000 * 1000),
102102
"STM32WB0: system clock frequency must be at least 8MHz to use ADC");
103103

104104
/**

drivers/clock_control/clock_stm32_ll_wb0.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ BUILD_ASSERT(!IS_ENABLED(STM32_SYSCLK_SRC_HSE) || STM32_WB0_CLKSYS_PRESCALER !=
7474
* the RC64M generator is imprecise. In this configuration, MR_BLE is broken.
7575
* The CPU and MR_BLE must be running at 32MHz for MR_BLE to work with HSI.
7676
*/
77-
BUILD_ASSERT(CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC >= CLOCK_FREQ_32MHZ,
77+
BUILD_ASSERT(STM32_HCLK_FREQUENCY >= CLOCK_FREQ_32MHZ,
7878
"System clock frequency must be at least 32MHz to use LSI");
7979
# else
8080
/* In PLL or Direct HSE mode, the clock is stable, so 16MHz can be used. */
81-
BUILD_ASSERT(CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC >= CLOCK_FREQ_16MHZ,
81+
BUILD_ASSERT(STM32_HCLK_FREQUENCY >= CLOCK_FREQ_16MHZ,
8282
"System clock frequency must be at least 16MHz to use LSI");
8383
# endif /* STM32_SYSCLK_SRC_HSI */
8484

@@ -711,7 +711,7 @@ int stm32_clock_control_init(const struct device *dev)
711711
* - 0 wait states otherwise (CLK_SYS <= 32MHz)
712712
*/
713713
LL_FLASH_SetLatency(
714-
(CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC >= CLOCK_FREQ_32MHZ)
714+
(STM32_HCLK_FREQUENCY >= CLOCK_FREQ_32MHZ)
715715
? LL_FLASH_LATENCY_1
716716
: LL_FLASH_LATENCY_0
717717
);
@@ -755,7 +755,7 @@ BUILD_ASSERT(IS_ENABLED(STM32_HSE_ENABLED),
755755
LL_RCC_SetRC64MPLLPrescaler(
756756
kconfig_to_ll_prescaler(STM32_WB0_CLKSYS_PRESCALER));
757757

758-
SystemCoreClock = CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC;
758+
SystemCoreClock = STM32_HCLK_FREQUENCY;
759759

760760
#if defined(STM32_LSI_ENABLED)
761761
/* Enable MR_BLE clock for LSI measurement.

drivers/entropy/entropy_stm32.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ BUILD_ASSERT((CONFIG_ENTROPY_STM32_THR_POOL_SIZE &
8484
* at least 32 MHz. See also: §6.2.2 "Peripheral clock details".
8585
*/
8686
BUILD_ASSERT(!IS_ENABLED(CONFIG_SOC_STM32WB09XX) ||
87-
CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC >= (32 * 1000 * 1000),
87+
STM32_HCLK_FREQUENCY >= (32 * 1000 * 1000),
8888
"STM32WB09: TRNG requires system clock frequency >= 32MHz");
8989

9090
struct entropy_stm32_rng_dev_cfg {

drivers/rtc/rtc_ll_stm32.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ static int rtc_stm32_init(const struct device *dev)
475475
* as time base, but SysTick is initialized after the RTC...
476476
*/
477477
const uint32_t cycles_to_waste =
478-
84 * (CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC / USEC_PER_SEC);
478+
84 * (STM32_HCLK_FREQUENCY / USEC_PER_SEC);
479479
volatile uint32_t i = cycles_to_waste;
480480

481481
while (--i > 0) {

include/zephyr/drivers/clock_control/stm32_clock_control.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
#include <zephyr/drivers/clock_control.h>
1414

15+
/* Retrieve the main system clock from DTS. */
16+
#define STM32_HCLK_FREQUENCY DT_PROP(DT_NODELABEL(rcc), clock_frequency)
17+
1518
#if defined(CONFIG_SOC_SERIES_STM32C0X)
1619
#include <zephyr/dt-bindings/clock/stm32c0_clock.h>
1720
#elif defined(CONFIG_SOC_SERIES_STM32F0X)

0 commit comments

Comments
 (0)