Skip to content

Commit 0148d5a

Browse files
committed
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 some STM32WB0 drivers due to the misunderstanding of its definition. Signed-off-by: Ali Hozhabri <[email protected]>
1 parent b3ccee4 commit 0148d5a

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

drivers/adc/adc_stm32wb0.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,10 @@ LOG_MODULE_REGISTER(adc_stm32wb0, CONFIG_ADC_LOG_LEVEL);
9797
#define ADC_CHANNEL_TYPE_DIFF (0x02U) /* Differential */
9898
#define ADC_CHANNEL_TYPE_INVALID (0xFFU) /* Invalid */
9999

100+
#define STM32_HCLK_FREQUENCY DT_PROP(DT_NODELABEL(rcc), clock_frequency)
101+
100102
/** See RM0505 §6.2.1 "System clock details" */
101-
BUILD_ASSERT(CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC >= (8 * 1000 * 1000),
103+
BUILD_ASSERT(STM32_HCLK_FREQUENCY >= (8 * 1000 * 1000),
102104
"STM32WB0: system clock frequency must be at least 8MHz to use ADC");
103105

104106
/**

drivers/clock_control/clock_stm32_ll_wb0.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#define CLOCK_FREQ_64MHZ (64000000U)
2929
#define CLOCK_FREQ_32MHZ (32000000U)
3030
#define CLOCK_FREQ_16MHZ (16000000U)
31+
#define STM32_HCLK_FREQUENCY DT_PROP(DT_NODELABEL(rcc), clock_frequency)
3132

3233
/* Device tree node definitions */
3334
#define DT_RCC_SLOWCLK_NODE DT_PHANDLE(STM32_CLOCK_CONTROL_NODE, slow_clock)
@@ -74,11 +75,11 @@ BUILD_ASSERT(!IS_ENABLED(STM32_SYSCLK_SRC_HSE) || STM32_WB0_CLKSYS_PRESCALER !=
7475
* the RC64M generator is imprecise. In this configuration, MR_BLE is broken.
7576
* The CPU and MR_BLE must be running at 32MHz for MR_BLE to work with HSI.
7677
*/
77-
BUILD_ASSERT(CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC >= CLOCK_FREQ_32MHZ,
78+
BUILD_ASSERT(STM32_HCLK_FREQUENCY >= CLOCK_FREQ_32MHZ,
7879
"System clock frequency must be at least 32MHz to use LSI");
7980
# else
8081
/* 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,
82+
BUILD_ASSERT(STM32_HCLK_FREQUENCY >= CLOCK_FREQ_16MHZ,
8283
"System clock frequency must be at least 16MHz to use LSI");
8384
# endif /* STM32_SYSCLK_SRC_HSI */
8485

@@ -711,7 +712,7 @@ int stm32_clock_control_init(const struct device *dev)
711712
* - 0 wait states otherwise (CLK_SYS <= 32MHz)
712713
*/
713714
LL_FLASH_SetLatency(
714-
(CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC >= CLOCK_FREQ_32MHZ)
715+
(STM32_HCLK_FREQUENCY >= CLOCK_FREQ_32MHZ)
715716
? LL_FLASH_LATENCY_1
716717
: LL_FLASH_LATENCY_0
717718
);
@@ -755,7 +756,7 @@ BUILD_ASSERT(IS_ENABLED(STM32_HSE_ENABLED),
755756
LL_RCC_SetRC64MPLLPrescaler(
756757
kconfig_to_ll_prescaler(STM32_WB0_CLKSYS_PRESCALER));
757758

758-
SystemCoreClock = CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC;
759+
SystemCoreClock = STM32_HCLK_FREQUENCY;
759760

760761
#if defined(STM32_LSI_ENABLED)
761762
/* Enable MR_BLE clock for LSI measurement.

drivers/entropy/entropy_stm32.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
#define STM32_CONDRST_SUPPORT
3737
#endif
3838

39+
#define STM32_HCLK_FREQUENCY DT_PROP(DT_NODELABEL(rcc), clock_frequency)
40+
3941
/*
4042
* This driver need to take into account all STM32 family:
4143
* - simple rng without hardware fifo and no DMA.
@@ -84,7 +86,7 @@ BUILD_ASSERT((CONFIG_ENTROPY_STM32_THR_POOL_SIZE &
8486
* at least 32 MHz. See also: §6.2.2 "Peripheral clock details".
8587
*/
8688
BUILD_ASSERT(!IS_ENABLED(CONFIG_SOC_STM32WB09XX) ||
87-
CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC >= (32 * 1000 * 1000),
89+
STM32_HCLK_FREQUENCY >= (32 * 1000 * 1000),
8890
"STM32WB09: TRNG requires system clock frequency >= 32MHz");
8991

9092
struct entropy_stm32_rng_dev_cfg {

drivers/rtc/rtc_ll_stm32.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242

4343
LOG_MODULE_REGISTER(rtc_stm32, CONFIG_RTC_LOG_LEVEL);
4444

45+
#define STM32_HCLK_FREQUENCY DT_PROP(DT_NODELABEL(rcc), clock_frequency)
46+
4547
#if (defined(CONFIG_SOC_SERIES_STM32L1X) && !defined(RTC_SUBSECOND_SUPPORT)) \
4648
|| defined(CONFIG_SOC_SERIES_STM32F2X)
4749
/* subsecond counting is not supported by some STM32L1x MCUs (Cat.1) & by STM32F2x SoC series */
@@ -358,7 +360,7 @@ static int rtc_stm32_init(const struct device *dev)
358360
* as time base, but SysTick is initialized after the RTC...
359361
*/
360362
const uint32_t cycles_to_waste =
361-
84 * (CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC / USEC_PER_SEC);
363+
84 * (STM32_HCLK_FREQUENCY / USEC_PER_SEC);
362364
volatile uint32_t i = cycles_to_waste;
363365

364366
while (--i > 0) {

0 commit comments

Comments
 (0)