Class library for using the true Random Number Generator on STM32F4xxx devices.

Dependents:   MCU-Benchmark-Sute Doom_Flame-F429ZI_v02 Wether_Meter

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers STM32F4_RNG.cpp Source File

STM32F4_RNG.cpp

00001 #include "STM32F4_RNG.h"
00002 #include "mbed.h"
00003 
00004 
00005 STM32F4_RNG::STM32F4_RNG() {
00006     RCC->AHB2ENR |= RCC_AHB2ENR_RNGEN;  /* Enable RNG clock source */
00007     RNG->CR |= RNG_CR_RNGEN;            /* RNG Peripheral enable */
00008 }
00009 
00010 
00011 unsigned long STM32F4_RNG::Get() {
00012     while (!(RNG->SR & (RNG_SR_DRDY))); /* Wait until one RNG number is ready */
00013 
00014     return RNG->DR;                     /* Get a 32-bit Random number */
00015 }