Skip to content

TRNG on L4 pulls rug out from USB #8864

@ghost

Description

Description

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?

#if ((CLOCK_SOURCE) & USE_PLL_MSI)
    PeriphClkInitStruct.RngClockSelection = RCC_RNGCLKSOURCE_MSI;
#else
    PeriphClkInitStruct.RngClockSelection = RCC_RNGCLKSOURCE_PLLSAI1;
#endif

Issue request type

[ ] Question
[ ] Enhancement
[X] Bug

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions