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

Features

  • True random number generator
  • Supports 32-bit numbers

Dependencies

  • CMSIS
    • 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:

Example

Bottom example produces this

RNG Result on STM32F429 Discovery board

RNG Result



Project available on my Github account, download library below.

Icon
TM STM32F4 RNG Library

True random number generator for STM32F4xx devices

tilz0R

Owner of this site. Also electronic enthusiasts, web developer, 3D printer fan, handball player and more. Big fan of STM32F4 devices. In anticipation of the new Discovery board for STM32F7 lines.

You may also like...

Read before commenting!

Before you make a new comment, make sure you agree with things listed below:

  • - Read post to make sure if it is already posted what you are asking for,
  • - Make sure you have the latest version of libraries used in your project,
  • - Make a clean and grammatically correct written message,
  • - Report as many details as possible, including what have you done so far,
  • - Do NOT post any code here. Use Pastebin,
  • - Do NOT post any error codes here. Use Pastebin,
  • - Specify STM32Fxxx family and used Discovery/EVAL/Nucleo or custom made board,
  • - Make sure your clock is set correct for PLL,
  • - If you are using my HAL drivers, please check this post how to start.
Comment will be deleted on breaking these rules without notification!
  • Christian Julius

    Got an error during compilation: Function is missing

    debugramtmlibsrctm_stm32f4_rng.o: In function TM_RNG_Init':
    D:emblocksstm32f429_project/TMLIBsrc/tm_stm32f4_rng.c:26: undefined reference to
    RNG_Cmd’
    collect2.exe: error: ld returned 1 exit status
    Process terminated with status 1 (0 minutes, 5 seconds)

    • Guest

      Sorry, old version, new download works.

    • Hi,

      works old version too, but you have to include “stm32f4xx_rng.h/c” file to your project from standard periph drivers.
      In new version, I’ve made update to be independent from STD libraries, that’s why it worked 🙂

      • Christian Julius

        Yeah, got it! Used the StdPeriph Libs, because it is so simple. “Game of Life” now works perfect with true Random Scenerys at startup and my “Digital” Population is alive for more than 10.000 generations 🙂

  • vanaja

    Hi MajerleTelin,

    Do you have Cryptographic implementation on stm32f407.