diff --git a/boards/arm/olimex_stm32_e407/olimex_stm32_e407.dts b/boards/arm/olimex_stm32_e407/olimex_stm32_e407.dts index 4adc2d2c16a..eaca8dde941 100644 --- a/boards/arm/olimex_stm32_e407/olimex_stm32_e407.dts +++ b/boards/arm/olimex_stm32_e407/olimex_stm32_e407.dts @@ -60,6 +60,10 @@ status = "okay"; }; +&rng { + status = "okay"; +}; + /* Only one interface should be enabled at a time: usbotg_fs or usbotg_hs */ usb_otg1: &usbotg_fs { status = "disabled"; diff --git a/boards/arm/olimex_stm32_e407/olimex_stm32_e407_defconfig b/boards/arm/olimex_stm32_e407/olimex_stm32_e407_defconfig index 0f9922d6a20..dd207468ca2 100644 --- a/boards/arm/olimex_stm32_e407/olimex_stm32_e407_defconfig +++ b/boards/arm/olimex_stm32_e407/olimex_stm32_e407_defconfig @@ -36,5 +36,3 @@ CONFIG_CLOCK_STM32_PLL_Q_DIVISOR=7 CONFIG_CLOCK_STM32_AHB_PRESCALER=1 CONFIG_CLOCK_STM32_APB1_PRESCALER=4 CONFIG_CLOCK_STM32_APB2_PRESCALER=2 - -CONFIG_ENTROPY_GENERATOR=y diff --git a/boards/arm/olimex_stm32_h407/olimex_stm32_h407.dts b/boards/arm/olimex_stm32_h407/olimex_stm32_h407.dts index 41adfc99cd4..50cd9d26283 100644 --- a/boards/arm/olimex_stm32_h407/olimex_stm32_h407.dts +++ b/boards/arm/olimex_stm32_h407/olimex_stm32_h407.dts @@ -59,3 +59,7 @@ &rtc { status = "okay"; }; + +&rng { + status = "okay"; +}; diff --git a/boards/arm/olimex_stm32_h407/olimex_stm32_h407_defconfig b/boards/arm/olimex_stm32_h407/olimex_stm32_h407_defconfig index b52339333e5..dd207468ca2 100644 --- a/boards/arm/olimex_stm32_h407/olimex_stm32_h407_defconfig +++ b/boards/arm/olimex_stm32_h407/olimex_stm32_h407_defconfig @@ -36,8 +36,3 @@ CONFIG_CLOCK_STM32_PLL_Q_DIVISOR=7 CONFIG_CLOCK_STM32_AHB_PRESCALER=1 CONFIG_CLOCK_STM32_APB1_PRESCALER=4 CONFIG_CLOCK_STM32_APB2_PRESCALER=2 - -CONFIG_ENTROPY_GENERATOR=y -CONFIG_ENTROPY_NAME="ENTROPY_0" -CONFIG_TEST_RANDOM_GENERATOR=y -CONFIG_TIMER_RANDOM_GENERATOR=y diff --git a/boards/arm/olimex_stm32_p405/olimex_stm32_p405.dts b/boards/arm/olimex_stm32_p405/olimex_stm32_p405.dts index 92465e845d7..b28eb6abc69 100644 --- a/boards/arm/olimex_stm32_p405/olimex_stm32_p405.dts +++ b/boards/arm/olimex_stm32_p405/olimex_stm32_p405.dts @@ -55,3 +55,7 @@ bus-speed = <125000>; status = "okay"; }; + +&rng { + status = "okay"; +}; diff --git a/drivers/entropy/Kconfig.stm32 b/drivers/entropy/Kconfig.stm32 index 42cfc416209..2e34a724fce 100644 --- a/drivers/entropy/Kconfig.stm32 +++ b/drivers/entropy/Kconfig.stm32 @@ -8,6 +8,7 @@ config ENTROPY_STM32_RNG depends on SOC_FAMILY_STM32 select ENTROPY_HAS_DRIVER select USE_STM32_LL_RNG + select HAS_DTS_ENTROPY help This option enables the RNG processor, which is a entropy number generator, based on a continuous analog noise, that provides diff --git a/drivers/entropy/entropy_stm32.c b/drivers/entropy/entropy_stm32.c index fffe6113c76..f986c30c618 100644 --- a/drivers/entropy/entropy_stm32.c +++ b/drivers/entropy/entropy_stm32.c @@ -4,6 +4,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +#define DT_DRV_COMPAT st_stm32_rng + #include #include #include @@ -17,14 +19,6 @@ #include #include -#if !defined(CONFIG_SOC_SERIES_STM32L4X) && !defined(CONFIG_SOC_SERIES_STM32F4X) && !defined(CONFIG_SOC_SERIES_STM32F7X) && !defined(CONFIG_SOC_SERIES_STM32G4X) -#error RNG only available on STM32F4, STM32F7, STM32L4 and STM32G4 series -#elif defined(CONFIG_SOC_STM32F401XE) -#error RNG not available on STM32F401 based SoCs -#elif defined(CONFIG_SOC_STM32F411XE) -#error RNG not available on STM32F411 based SoCs -#else - struct entropy_stm32_rng_dev_cfg { struct stm32_pclken pclken; }; @@ -209,18 +203,16 @@ static const struct entropy_driver_api entropy_stm32_rng_api = { }; static const struct entropy_stm32_rng_dev_cfg entropy_stm32_rng_config = { - .pclken = { .bus = STM32_CLOCK_BUS_AHB2, - .enr = LL_AHB2_GRP1_PERIPH_RNG }, + .pclken = { .bus = DT_INST_CLOCKS_CELL(0, bus), + .enr = DT_INST_CLOCKS_CELL(0, bits) }, }; static struct entropy_stm32_rng_dev_data entropy_stm32_rng_data = { - .rng = RNG, + .rng = (RNG_TypeDef *)DT_INST_REG_ADDR(0), }; -DEVICE_AND_API_INIT(entropy_stm32_rng, CONFIG_ENTROPY_NAME, +DEVICE_AND_API_INIT(entropy_stm32_rng, DT_INST_LABEL(0), entropy_stm32_rng_init, &entropy_stm32_rng_data, &entropy_stm32_rng_config, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &entropy_stm32_rng_api); - -#endif diff --git a/soc/arm/st_stm32/stm32f4/dts_fixup.h b/soc/arm/st_stm32/stm32f4/dts_fixup.h index 8d877c1245f..ab6811c0586 100644 --- a/soc/arm/st_stm32/stm32f4/dts_fixup.h +++ b/soc/arm/st_stm32/stm32f4/dts_fixup.h @@ -210,4 +210,8 @@ #define DT_FLASH_DEV_NAME DT_LABEL(DT_INST(0, st_stm32f4_flash_controller)) +#ifndef CONFIG_ENTROPY_NAME +#define CONFIG_ENTROPY_NAME DT_LABEL(DT_INST(0, st_stm32_rng)) +#endif + /* End of SoC Level DTS fixup file */ diff --git a/soc/arm/st_stm32/stm32f7/dts_fixup.h b/soc/arm/st_stm32/stm32f7/dts_fixup.h index 760bcae6728..f4899998bd6 100644 --- a/soc/arm/st_stm32/stm32f7/dts_fixup.h +++ b/soc/arm/st_stm32/stm32f7/dts_fixup.h @@ -69,4 +69,8 @@ #define DT_ADC_1_NAME DT_ST_STM32_ADC_40012000_LABEL +#ifndef CONFIG_ENTROPY_NAME +#define CONFIG_ENTROPY_NAME DT_LABEL(DT_INST(0, st_stm32_rng)) +#endif + /* End of SoC Level DTS fixup file */ diff --git a/soc/arm/st_stm32/stm32g4/dts_fixup.h b/soc/arm/st_stm32/stm32g4/dts_fixup.h index 59fbd5fa463..1fa36c5bba3 100644 --- a/soc/arm/st_stm32/stm32g4/dts_fixup.h +++ b/soc/arm/st_stm32/stm32g4/dts_fixup.h @@ -44,4 +44,8 @@ #define DT_WDT_0_NAME DT_LABEL(DT_INST(0, st_stm32_watchdog)) +#ifndef CONFIG_ENTROPY_NAME +#define CONFIG_ENTROPY_NAME DT_LABEL(DT_INST(0, st_stm32_rng)) +#endif + /* End of SoC Level DTS fixup file */ diff --git a/soc/arm/st_stm32/stm32l4/dts_fixup.h b/soc/arm/st_stm32/stm32l4/dts_fixup.h index 9df71cdf5ff..95bffda9caa 100644 --- a/soc/arm/st_stm32/stm32l4/dts_fixup.h +++ b/soc/arm/st_stm32/stm32l4/dts_fixup.h @@ -74,4 +74,8 @@ #define DT_LPTIM_1_CLOCK_BITS DT_ST_STM32_TIMERS_40007C00_CLOCK_BITS_0 #define DT_LPTIM_1_CLOCK_BUS DT_ST_STM32_TIMERS_40007C00_CLOCK_BUS_0 +#ifndef CONFIG_ENTROPY_NAME +#define CONFIG_ENTROPY_NAME DT_LABEL(DT_INST(0, st_stm32_rng)) +#endif + /* End of SoC Level DTS fixup file */