Class library for using the true Random Number Generator on STM32F4xxx devices.
Dependents: MCU-Benchmark-Sute Doom_Flame-F429ZI_v02 Wether_Meter
STM32F4_RNG.cpp@0:1c605984e361, 2016-02-08 (annotated)
- Committer:
- grantphillips
- Date:
- Mon Feb 08 20:15:12 2016 +0000
- Revision:
- 0:1c605984e361
v1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
grantphillips | 0:1c605984e361 | 1 | #include "STM32F4_RNG.h" |
grantphillips | 0:1c605984e361 | 2 | #include "mbed.h" |
grantphillips | 0:1c605984e361 | 3 | |
grantphillips | 0:1c605984e361 | 4 | |
grantphillips | 0:1c605984e361 | 5 | STM32F4_RNG::STM32F4_RNG() { |
grantphillips | 0:1c605984e361 | 6 | RCC->AHB2ENR |= RCC_AHB2ENR_RNGEN; /* Enable RNG clock source */ |
grantphillips | 0:1c605984e361 | 7 | RNG->CR |= RNG_CR_RNGEN; /* RNG Peripheral enable */ |
grantphillips | 0:1c605984e361 | 8 | } |
grantphillips | 0:1c605984e361 | 9 | |
grantphillips | 0:1c605984e361 | 10 | |
grantphillips | 0:1c605984e361 | 11 | unsigned long STM32F4_RNG::Get() { |
grantphillips | 0:1c605984e361 | 12 | while (!(RNG->SR & (RNG_SR_DRDY))); /* Wait until one RNG number is ready */ |
grantphillips | 0:1c605984e361 | 13 | |
grantphillips | 0:1c605984e361 | 14 | return RNG->DR; /* Get a 32-bit Random number */ |
grantphillips | 0:1c605984e361 | 15 | } |