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

TRNG on L4 pulls rug out from USB #8864

ghost opened this Issue Nov 25, 2018 · 3 comments


None yet
3 participants
Copy link

ghost commented Nov 25, 2018


Target: STM32L4x
Scope: USB and TRNG co-existence

In system_clock.c, the USB/SDMMC/TRNG source clock is set to either MSI or PLLSAI1, depending on the clock source (HSE/HSI use PLLSAI1 for 48MHz source, and MSI uses MSI for 48MHz source).

trng_api.c does not take this into account, and incorrectly sets the 48MHz clock source, in contradiction to what it was set to in system_clock.c

Bug Reproduction

  1. In json config, choose USE_PLL_MSI for clock source
  2. Use trng functionality (such as mbedtls_hardware_poll function call)
  3. USB operation ceases as soon as trng_init is called, as the 48MHz clock source is incorrectly changed to RCC_RNGCLKSOURCE_PLL, invalidating how it was set up in system_clock.c

Recommend a change in trng_api.c to choose the correct 48MHz source as it was set in system_clock.c, or remove this code as the 48MHz clock source was already set in system_clock.c, correct?

    PeriphClkInitStruct.RngClockSelection = RCC_RNGCLKSOURCE_MSI;
    PeriphClkInitStruct.RngClockSelection = RCC_RNGCLKSOURCE_PLLSAI1;

Issue request type

[ ] Question
[ ] Enhancement
[X] Bug

This comment has been minimized.

Copy link

ciarmcom commented Nov 25, 2018


This comment has been minimized.

Copy link

bcostm commented Nov 26, 2018

Thanks for this analysis and reporting

I also agree to remove the TRNG clock setting in the trng_api.c file and add it in the system_clock.c file instead (like we do for the USB). Just maybe add a "#ifdef DEVICE_TRNG". I will send a PR so you can test it and comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment