Skip to content

Commit 2ed292e

Browse files
FRASTMfabiobaltieri
authored andcommitted
drivers: stm32: do not enable the HSI48 locally
The HSI48 is enabled by clock control driver. It is no more done by each driver that requires this clock However when using rng or sdmmc or bluetooth/ipm or usb, the HSI48 clock must be present in the DTS. Add a warning for this particular check but keep the deprecated HSI48 clock enable : keeping for legacy but to remove later. Signed-off-by: Francois Ramu <[email protected]>
1 parent 8eb55b3 commit 2ed292e

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

drivers/bluetooth/hci/ipm_stm32wb.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -419,12 +419,16 @@ static void start_ble_rf(void)
419419
LL_RCC_SetRTCClockSource(LL_RCC_RTC_CLKSOURCE_LSI);
420420
#endif
421421

422-
/* Set RNG on HSI48 */
422+
/* HSI48 clock and CLK48 clock source are enabled using the device tree */
423+
#if !STM32_HSI48_ENABLED
424+
/* Deprecated: enable HSI48 using device tree */
425+
#warning Bluetooth IPM requires HSI48 clock to be enabled using device tree
426+
/* Keeping this sequence for legacy: */
423427
LL_RCC_HSI48_Enable();
424428
while (!LL_RCC_HSI48_IsReady()) {
425429
}
426430

427-
LL_RCC_SetCLK48ClockSource(LL_RCC_CLK48_CLKSOURCE_HSI48);
431+
#endif /* !STM32_HSI48_ENABLED */
428432
}
429433

430434
#ifdef CONFIG_BT_HCI_HOST

drivers/disk/sdmmc_stm32.c

+10-1
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,22 @@ static int stm32_sdmmc_clock_enable(struct stm32_sdmmc_priv *priv)
154154

155155
#if defined(CONFIG_SOC_SERIES_STM32L5X) || \
156156
defined(CONFIG_SOC_SERIES_STM32U5X)
157-
/* By default the SDMMC clock source is set to 0 --> 48MHz, must be enabled */
157+
#if !STM32_HSI48_ENABLED
158+
/* Deprecated: enable HSI48 using device tree */
159+
#warning USB device requires HSI48 clock to be enabled using device tree
160+
/*
161+
* Keeping this sequence for legacy :
162+
* By default the SDMMC clock source is set to 0 --> 48MHz, must be enabled
163+
*/
158164
LL_RCC_HSI48_Enable();
159165
while (!LL_RCC_HSI48_IsReady()) {
160166
}
167+
#endif /* !STM32_HSI48_ENABLED */
161168
#endif /* CONFIG_SOC_SERIES_STM32L5X ||
162169
* CONFIG_SOC_SERIES_STM32U5X
163170
*/
171+
172+
/* HSI48 Clock is enabled through using the device tree */
164173
clock = DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE);
165174

166175
/* Enable the APB clock for stm32_sdmmc */

drivers/entropy/entropy_stm32.c

+9
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,11 @@ static int entropy_stm32_rng_init(const struct device *dev)
603603
LL_RCC_SetRNGClockSource(LL_RCC_RNG_CLKSOURCE_PLL);
604604
#elif defined(RCC_CR2_HSI48ON) || defined(RCC_CR_HSI48ON) \
605605
|| defined(RCC_CRRCR_HSI48ON)
606+
#if !STM32_HSI48_ENABLED
607+
/* Deprecated: enable HSI48 using device tree */
608+
#warning RNG requires HSI48 clock to be enabled using device tree
606609

610+
/* Keeping this sequence for legacy: */
607611
#if CONFIG_SOC_SERIES_STM32L0X
608612
/* We need SYSCFG to control VREFINT, so make sure it is clocked */
609613
if (!LL_APB2_GRP1_IsEnabledClock(LL_APB2_GRP1_PERIPH_SYSCFG)) {
@@ -619,7 +623,12 @@ static int entropy_stm32_rng_init(const struct device *dev)
619623
while (!LL_RCC_HSI48_IsReady()) {
620624
/* Wait for HSI48 to become ready */
621625
}
626+
#else /* !STM32_HSI48_ENABLED */
627+
/* HSI48 is enabled by the DTS : lock the HSI48 clock for RNG use */
628+
z_stm32_hsem_lock(CFG_HW_CLK48_CONFIG_SEMID, HSEM_LOCK_DEFAULT_RETRY);
629+
#endif /* !STM32_HSI48_ENABLED */
622630

631+
/* HSI48 Clock is enabled through the DTS: set as RNG clock source */
623632
#if defined(CONFIG_SOC_SERIES_STM32WBX)
624633
LL_RCC_SetRNGClockSource(LL_RCC_RNG_CLKSOURCE_CLK48);
625634
LL_RCC_SetCLK48ClockSource(LL_RCC_CLK48_CLKSOURCE_HSI48);

drivers/usb/device/usb_dc_stm32.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,10 @@ static int usb_dc_stm32_clock_enable(void)
207207
defined(CONFIG_SOC_SERIES_STM32H7X) || \
208208
defined(CONFIG_SOC_SERIES_STM32L5X) || \
209209
defined(CONFIG_SOC_SERIES_STM32U5X)
210-
210+
#if !STM32_HSI48_ENABLED
211+
/* Deprecated: enable HSI48 using device tree */
212+
#warning USB device requires HSI48 clock to be enabled using device tree
213+
#endif /* ! STM32_HSI48_ENABLED*/
211214
/*
212215
* In STM32L0 series, HSI48 requires VREFINT and its buffer
213216
* with 48 MHz RC to be enabled.
@@ -226,6 +229,7 @@ static int usb_dc_stm32_clock_enable(void)
226229

227230
z_stm32_hsem_lock(CFG_HW_CLK48_CONFIG_SEMID, HSEM_LOCK_DEFAULT_RETRY);
228231

232+
/* Keeping this sequence for legacy: */
229233
LL_RCC_HSI48_Enable();
230234
while (!LL_RCC_HSI48_IsReady()) {
231235
/* Wait for HSI48 to become ready */

0 commit comments

Comments
 (0)