@@ -578,73 +578,26 @@ static int entropy_stm32_rng_init(const struct device *dev)
578
578
__ASSERT_NO_MSG (dev_data != NULL );
579
579
__ASSERT_NO_MSG (dev_cfg != NULL );
580
580
581
- #if CONFIG_SOC_SERIES_STM32L4X
582
- /* Configure PLLSA11 to enable 48M domain */
583
- LL_RCC_PLLSAI1_ConfigDomain_48M (LL_RCC_PLLSOURCE_MSI ,
584
- LL_RCC_PLLM_DIV_1 ,
585
- 24 , LL_RCC_PLLSAI1Q_DIV_2 );
586
-
587
- /* Enable PLLSA1 */
588
- LL_RCC_PLLSAI1_Enable ();
589
-
590
- /* Enable PLLSAI1 output mapped on 48MHz domain clock */
591
- LL_RCC_PLLSAI1_EnableDomain_48M ();
592
-
593
- /* Wait for PLLSA1 ready flag */
594
- while (LL_RCC_PLLSAI1_IsReady () != 1 ) {
595
- }
596
-
597
- /* Write the peripherals independent clock configuration register :
598
- * choose PLLSAI1 source as the 48 MHz clock is needed for the RNG
599
- * Linear Feedback Shift Register
600
- */
601
- LL_RCC_SetRNGClockSource (LL_RCC_RNG_CLKSOURCE_PLLSAI1 );
602
- #elif CONFIG_SOC_SERIES_STM32WLX || CONFIG_SOC_SERIES_STM32G0X
603
- LL_RCC_PLL_EnableDomain_RNG ();
604
- LL_RCC_SetRNGClockSource (LL_RCC_RNG_CLKSOURCE_PLL );
605
- #elif defined(RCC_CR2_HSI48ON ) || defined(RCC_CR_HSI48ON ) \
606
- || defined(RCC_CRRCR_HSI48ON )
607
- #if !STM32_HSI48_ENABLED
608
- /* Deprecated: enable HSI48 using device tree */
609
- #warning RNG requires HSI48 clock to be enabled using device tree
610
-
611
- /* Keeping this sequence for legacy: */
612
- #if CONFIG_SOC_SERIES_STM32L0X
613
- /* We need SYSCFG to control VREFINT, so make sure it is clocked */
614
- if (!LL_APB2_GRP1_IsEnabledClock (LL_APB2_GRP1_PERIPH_SYSCFG )) {
615
- return - EINVAL ;
616
- }
617
- /* HSI48 requires VREFINT (see RM0376 section 7.2.4). */
618
- LL_SYSCFG_VREFINT_EnableHSI48 ();
619
- #endif /* CONFIG_SOC_SERIES_STM32L0X */
620
-
621
- z_stm32_hsem_lock (CFG_HW_CLK48_CONFIG_SEMID , HSEM_LOCK_DEFAULT_RETRY );
622
- /* Use the HSI48 for the RNG */
623
- LL_RCC_HSI48_Enable ();
624
- while (!LL_RCC_HSI48_IsReady ()) {
625
- /* Wait for HSI48 to become ready */
626
- }
627
- #else /* !STM32_HSI48_ENABLED */
628
- /* HSI48 is enabled by the DTS : lock the HSI48 clock for RNG use */
629
- z_stm32_hsem_lock (CFG_HW_CLK48_CONFIG_SEMID , HSEM_LOCK_DEFAULT_RETRY );
630
- #endif /* !STM32_HSI48_ENABLED */
631
-
632
- /* HSI48 Clock is enabled through the DTS: set as RNG clock source */
633
- #if defined(CONFIG_SOC_SERIES_STM32WBX )
634
- LL_RCC_SetRNGClockSource (LL_RCC_RNG_CLKSOURCE_CLK48 );
635
- LL_RCC_SetCLK48ClockSource (LL_RCC_CLK48_CLKSOURCE_HSI48 );
636
-
637
- /* Don't unlock the HSEM to prevent M0 core
638
- * to disable HSI48 clock used for RNG.
639
- */
640
- #else
641
- LL_RCC_SetRNGClockSource (LL_RCC_RNG_CLKSOURCE_HSI48 );
581
+ #if (DT_INST_NUM_CLOCKS (0 ) == 1 )
582
+ /* No domain clock selected, let's check that the configuration is correct */
583
+
584
+ #if defined(CONFIG_SOC_SERIES_STM32L0X ) && \
585
+ (CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC * STM32_PLL_MULTIPLIER ) != MHZ (96 )
586
+ /* PLL used as RNG clock source (default), but its frequency doesn't fit */
587
+ /* Fix PLL freq or select HSI48 as RNG clock source */
588
+ #warning PLL clock not properly configured to be used as RNG clock. Configure another clock.
589
+ #elif !DT_NODE_HAS_COMPAT (DT_NODELABEL (clk_hsi48 ), fixed_clock )
590
+ /* No HSI48 available, a specific RNG domain clock has to be selected */
591
+ #warning RNG domain clock not configured
592
+ #endif
642
593
643
- /* Unlock the HSEM if it is not STM32WB */
644
- z_stm32_hsem_unlock (CFG_HW_CLK48_CONFIG_SEMID );
645
- #endif /* CONFIG_SOC_SERIES_STM32WBX */
594
+ #if DT_NODE_HAS_COMPAT (DT_NODELABEL (clk_hsi48 ), fixed_clock ) && !STM32_HSI48_ENABLED
595
+ /* On these series, HSI48 is available and set by default as RNG clock source */
596
+ /* HSI48 clock not enabled */
597
+ #warning HSI48 clock should be enabled or other domain clock selected
598
+ #endif
646
599
647
- #endif /* CONFIG_SOC_SERIES_STM32L4X */
600
+ #endif /* (DT_INST_NUM_CLOCKS(0) == 1) */
648
601
649
602
dev_data -> clock = DEVICE_DT_GET (STM32_CLOCK_CONTROL_NODE );
650
603
@@ -656,6 +609,14 @@ static int entropy_stm32_rng_init(const struct device *dev)
656
609
(clock_control_subsys_t * )& dev_cfg -> pclken [0 ]);
657
610
__ASSERT_NO_MSG (res == 0 );
658
611
612
+ /* Configure domain clock if any */
613
+ if (DT_INST_NUM_CLOCKS (0 ) > 1 ) {
614
+ res = clock_control_configure (dev_data -> clock ,
615
+ (clock_control_subsys_t * )& dev_cfg -> pclken [1 ],
616
+ NULL );
617
+ __ASSERT (res == 0 , "Could not select RNG domain clock" );
618
+ }
619
+
659
620
/* Locking semaphore initialized to 1 (unlocked) */
660
621
k_sem_init (& dev_data -> sem_lock , 1 , 1 );
661
622
0 commit comments