Library 22- True random number generator for STM32F4

STM32F4 devices (in most cases) have True Random Number Generator (or RNG). This peripheral can provide 32bit random number. I made a small library, that you can enable and use it very quickly.

RNG on STM32F4 is based on analog circuitry. It makes analog noise and that noice is connected to linear shift register. Analog circuitry is designed from ring oscillators whose outputs are XORed. For RNG circuitry is also separate LFSR clock and is independent from System clock. This allows RNG to be independent from system clock between different STM32F4 devices.

RNG Library


  • True random number generator
  • Supports 32-bit numbers


    • STM32F4xx
    • STM32F4xx RCC
    • STM32F4xx RNG
  • TM
    • defines.h

How to use it

After you set up your files, include it into your project and use function to initialize RNG peripheral:

After you set it up, you are ready to use. When you need your number, just call function below:


Bottom example produces this

RNG Result on STM32F429 Discovery board

RNG Result

Project available on my Github account, download library below.


Owner of this site. Application engineer, currently employed by STMicroelectronics. Exploring latest technologies and owner of different libraries posted on Github.

You may also like...