Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STM32WB0: add TRNG support #83152

Merged
merged 7 commits into from
Jan 22, 2025
Merged

Conversation

mathieuchopstm
Copy link
Collaborator

Add support for TRNG of STM32WB0 series to existing STM32 driver. Test overlay for Nucleo-WB05KZ and Nucleo-WB09KE is also added so that correct behavior can be verified.

Tested OK using standard tests/drivers/entropy/api and modified version that also verifies entropy_get_entropy_from_isr and large buffer sizes. Also tested on Nucleo-WB07CC, but board is not upstream yet.

Potentially supersedes #83109 - driver modification is split in two commits and PR is marked as draft for this reason.

@mathieuchopstm
Copy link
Collaborator Author

  • Mark cross-LL wrappers as inline to silence -Wunused-function (should fix CI failures)
  • Improved readability by factoring in and indenting preprocessor checks better
  • Corrected a typo in a comment

@@ -124,6 +140,68 @@ static struct entropy_stm32_rng_dev_data entropy_stm32_rng_data = {
.rng = (RNG_TypeDef *)DT_INST_REG_ADDR(0),
};

/* Cross-series LL compatibility wrappers */
static inline void ll_rng_EnableIT(RNG_TypeDef *RNGx)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use rather: ll_rng_enable_it

@@ -124,6 +140,68 @@ static struct entropy_stm32_rng_dev_data entropy_stm32_rng_data = {
.rng = (RNG_TypeDef *)DT_INST_REG_ADDR(0),
};

/* Cross-series LL compatibility wrappers */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move wrappers in a header file

Comment on lines 39 to 44
#else /* DT_INST_NUM_IRQS(0) == 0 */
/* DT_PROP_OR is used to remove noise from error message */
BUILD_ASSERT(DT_INST_NODE_HAS_PROP(0, generation_delay_ns),
"RNG '" DT_NODE_FULL_NAME(DT_DRV_INST(0)) "' has no interrupt line "
"but lacks the mandatory 'generation-delay-ns' property");
#define TRNG_GENERATION_DELAY K_NSEC(DT_INST_PROP_OR(0, generation_delay_ns, 0))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please modify bindings so they can catch this issue and get rid of this

Add a new binding for STM32 RNG instances without interrupt lines,
such as the one present in the STM32WB05/06/07 SoCs.

Signed-off-by: Mathieu Choplain <mathieu.choplain@st.com>
Add Device Tree nodes corresponding to TRNG of STM32WB0 series SoCs.

Signed-off-by: Mathieu Choplain <mathieu.choplain@st.com>
Add support for TRNG peripherals that lack interrupt lines in the STM32
entropy driver.

This enables usage of the TRNG of STM32WB05/06/07 SoCs with the driver.

Signed-off-by: Mathieu Choplain <mathieu.choplain@st.com>
Add overlay to allow testing of RNG driver on STM32WB0 hardware.

Signed-off-by: Mathieu Choplain <mathieu.choplain@st.com>
Copy link
Member

@erwango erwango left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise LGTM

Comment on lines 32 to 37
#if defined(CONFIG_SOC_STM32WB09XX)
LL_RNG_EnableEnErrorIrq(RNGx);
LL_RNG_EnableEnFfFullIrq(RNGx);
#else /* !CONFIG_SOC_SERIES_STM32WB0X */
LL_RNG_EnableIT(RNGx);
#endif /* CONFIG_SOC_SERIES_STM32WB0X */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use consistent style in the file.

Add support for the STM32WB09-specific TRNG IP in STM32 entropy driver.

Signed-off-by: Mathieu Choplain <mathieu.choplain@st.com>
Add overlay to allow testing of RNG driver on STM32WB0 hardware.

Signed-off-by: Mathieu Choplain <mathieu.choplain@st.com>
Add overlay to allow testing of TRNG on STM32WB07.

Signed-off-by: Mathieu Choplain <mathieu.choplain@st.com>
Copy link
Collaborator

@djiatsaf-st djiatsaf-st left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise LGTM

Copy link
Collaborator

@tomi-font tomi-font left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't check the entropy driver source changes but the rest looks good!

* This node is valid for STM32WB05, STM32WB06 and
* STM32WB07, all equipped with the same IRQ-less
* TRNG instance. Since all those properties are
* also valid on STM32SWB09, except "compatible",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* also valid on STM32SWB09, except "compatible",
* also valid on STM32SWB09 except "compatible",

@erwango
Copy link
Member

erwango commented Jan 21, 2025

@ceolin PTAL

Copy link
Member

@ceolin ceolin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kartben kartben merged commit 26b0058 into zephyrproject-rtos:main Jan 22, 2025
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants