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

Incorrect STM32L4P5xx and STM32L4Q5xx RNG Initialisation in Low Level API #14

Open
badcf00d opened this issue Jan 16, 2024 · 3 comments
Assignees
Labels
bug Something isn't working hal HAL-LL driver-related issue or pull-request. internal bug tracker Issue confirmed and reported into a ticket in the internal bug tracking system question Further information is requested st community Also reported by users on the community.st.com

Comments

@badcf00d
Copy link

In a post here https://community.st.com/t5/stm32-mcus-security/why-am-i-getting-an-rng-failure-on-the-stm32l4p5/m-p/203250. It was recognised that the HAL was initialising the RNG peripheral incorrectly.

The HAL function HAL_RNG_Init seems to have been corrected to set the correct CONFIG[1,2,3] and HTCR.

However the LL version of this function doesn't include any of this, so the CONFIG[1,2,3] and HTCR will all contain the wrong values when using this function.

ErrorStatus LL_RNG_Init(RNG_TypeDef *RNGx, LL_RNG_InitTypeDef *RNG_InitStruct)
{
/* Check the parameters */
assert_param(IS_RNG_ALL_INSTANCE(RNGx));
assert_param(IS_LL_RNG_CED(RNG_InitStruct->ClockErrorDetection));
#if defined(RNG_CR_CONDRST)
/* Clock Error Detection Configuration when CONDRT bit is set to 1 */
MODIFY_REG(RNGx->CR, RNG_CR_CED | RNG_CR_CONDRST, RNG_InitStruct->ClockErrorDetection | RNG_CR_CONDRST);
/* Writing bits CONDRST=0*/
CLEAR_BIT(RNGx->CR, RNG_CR_CONDRST);
#else
/* Clock Error Detection configuration */
MODIFY_REG(RNGx->CR, RNG_CR_CED, RNG_InitStruct->ClockErrorDetection);
#endif /* RNG_CR_CONDRST */
return (SUCCESS);
}

Could this function be updated to set the correct values, as described in Table 225. RNG configurations
of RM0432?

@badcf00d
Copy link
Author

badcf00d commented Jan 16, 2024

Another suggestion, it would be useful if LL_RNG_SetHealthconfiguration and LL_RNG_GetHealthconfiguration was modified to write the magic bytes 0x17590ABC to unlock the HTCR register before reading / writing as specified in RM0432

__STATIC_INLINE void LL_RNG_SetHealthconfiguration(RNG_TypeDef *RNGx, uint32_t HTCFG)
{
WRITE_REG(RNGx->HTCR, HTCFG);
}
/**
* @brief Get RNG Health Test Control
* @rmtoll HTCR HTCFG LL_RNG_GetHealthconfiguration
* @param RNGx RNG Instance
* @retval Return 32-bit RNG Health Test configuration
*/
__STATIC_INLINE uint32_t LL_RNG_GetHealthconfiguration(RNG_TypeDef *RNGx)
{
return (uint32_t)READ_REG(RNGx->HTCR);
}

Currently the write function will have no effect if the user just calls it with the value they want in the HTCR e.g.

LL_RNG_SetHealthconfiguration(0x00007274);

@ALABSTM ALABSTM added st community Also reported by users on the community.st.com hal HAL-LL driver-related issue or pull-request. bug Something isn't working labels Jan 17, 2024
@ALABSTM ALABSTM added this to To do in stm32cube-mcu-hal-dashboard via automation Jan 17, 2024
@RJMSTM
Copy link
Contributor

RJMSTM commented Jan 19, 2024

Hello @badcf00d,

Thank you for your contribution. Your report will be forwarded to our development team for analysis.
We will get back to you as soon as we have an answer.

As a first answer, it's Cleary mentioned in Reference manual to unlock the HCR register before reading or writing in the register in this case you can call the function LL_RNG_SetHealthconfiguration two times firstly write the magic bytes 0x17590ABC to unlock the HTCR register and then you can read or write this register.

Thanks in advance for your patience and understanding.

With Regards,

@RJMSTM RJMSTM added the question Further information is requested label Jan 19, 2024
@RJMSTM RJMSTM moved this from To do to Analyzed in stm32cube-mcu-hal-dashboard Jan 19, 2024
@STMicroelectronics STMicroelectronics deleted a comment from RJMSTM Feb 5, 2024
@RJMSTM
Copy link
Contributor

RJMSTM commented Feb 9, 2024

ST Internal Reference: 173093

@RJMSTM RJMSTM added the internal bug tracker Issue confirmed and reported into a ticket in the internal bug tracking system label Feb 9, 2024
@RJMSTM RJMSTM moved this from Analyzed to In progress in stm32cube-mcu-hal-dashboard Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working hal HAL-LL driver-related issue or pull-request. internal bug tracker Issue confirmed and reported into a ticket in the internal bug tracking system question Further information is requested st community Also reported by users on the community.st.com
Projects
Development

No branches or pull requests

3 participants