Class library for using the true Random Number Generator on STM32F4xxx devices.
Dependents: MCU-Benchmark-Sute Doom_Flame-F429ZI_v02 Wether_Meter
STM32F4_RNG.h@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 | /* STM32F4_RNG Library v1.0 |
grantphillips | 0:1c605984e361 | 2 | * Copyright (c) 2016 Grant Phillips |
grantphillips | 0:1c605984e361 | 3 | * grant.phillips@nmmu.ac.za |
grantphillips | 0:1c605984e361 | 4 | * |
grantphillips | 0:1c605984e361 | 5 | * This library was adapted from tm_stm32f4_rng written by Tilen Majerle. |
grantphillips | 0:1c605984e361 | 6 | * (http://stm32f4-discovery.com/2014/07/library-22-true-random-number-generator-stm32f4xx/) |
grantphillips | 0:1c605984e361 | 7 | * |
grantphillips | 0:1c605984e361 | 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
grantphillips | 0:1c605984e361 | 9 | * of this software and associated documentation files (the "Software"), to deal |
grantphillips | 0:1c605984e361 | 10 | * in the Software without restriction, including without limitation the rights |
grantphillips | 0:1c605984e361 | 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
grantphillips | 0:1c605984e361 | 12 | * copies of the Software, and to permit persons to whom the Software is |
grantphillips | 0:1c605984e361 | 13 | * furnished to do so, subject to the following conditions: |
grantphillips | 0:1c605984e361 | 14 | * |
grantphillips | 0:1c605984e361 | 15 | * The above copyright notice and this permission notice shall be included in |
grantphillips | 0:1c605984e361 | 16 | * all copies or substantial portions of the Software. |
grantphillips | 0:1c605984e361 | 17 | * |
grantphillips | 0:1c605984e361 | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
grantphillips | 0:1c605984e361 | 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
grantphillips | 0:1c605984e361 | 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
grantphillips | 0:1c605984e361 | 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
grantphillips | 0:1c605984e361 | 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
grantphillips | 0:1c605984e361 | 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
grantphillips | 0:1c605984e361 | 24 | * THE SOFTWARE. |
grantphillips | 0:1c605984e361 | 25 | */ |
grantphillips | 0:1c605984e361 | 26 | |
grantphillips | 0:1c605984e361 | 27 | #ifndef STM32F4_RNG_H |
grantphillips | 0:1c605984e361 | 28 | #define STM32F4_RNG_H |
grantphillips | 0:1c605984e361 | 29 | |
grantphillips | 0:1c605984e361 | 30 | #include "mbed.h" |
grantphillips | 0:1c605984e361 | 31 | |
grantphillips | 0:1c605984e361 | 32 | /** Class library for using the true Random Number Generator on STM32F4xxx devices. |
grantphillips | 0:1c605984e361 | 33 | * |
grantphillips | 0:1c605984e361 | 34 | * Example: |
grantphillips | 0:1c605984e361 | 35 | * @code |
grantphillips | 0:1c605984e361 | 36 | * #include "mbed.h" |
grantphillips | 0:1c605984e361 | 37 | * #include "STM32F4_RNG.h" |
grantphillips | 0:1c605984e361 | 38 | * #include "SWO.h" |
grantphillips | 0:1c605984e361 | 39 | * |
grantphillips | 0:1c605984e361 | 40 | * STM32F4_RNG rnd; |
grantphillips | 0:1c605984e361 | 41 | * |
grantphillips | 0:1c605984e361 | 42 | * int main() { |
grantphillips | 0:1c605984e361 | 43 | * // create a 32-bit unsigned variable |
grantphillips | 0:1c605984e361 | 44 | * unsigned long num; //or uint32_t num |
grantphillips | 0:1c605984e361 | 45 | * |
grantphillips | 0:1c605984e361 | 46 | * while(1) { |
grantphillips | 0:1c605984e361 | 47 | * num = rnd.Get(); |
grantphillips | 0:1c605984e361 | 48 | * printf("%u\n", num); |
grantphillips | 0:1c605984e361 | 49 | * wait(1.0); |
grantphillips | 0:1c605984e361 | 50 | * } |
grantphillips | 0:1c605984e361 | 51 | * } |
grantphillips | 0:1c605984e361 | 52 | * @endcode |
grantphillips | 0:1c605984e361 | 53 | */ |
grantphillips | 0:1c605984e361 | 54 | |
grantphillips | 0:1c605984e361 | 55 | class STM32F4_RNG { |
grantphillips | 0:1c605984e361 | 56 | public: |
grantphillips | 0:1c605984e361 | 57 | /** Create a STM32F4_RNG object. |
grantphillips | 0:1c605984e361 | 58 | * |
grantphillips | 0:1c605984e361 | 59 | */ |
grantphillips | 0:1c605984e361 | 60 | STM32F4_RNG(); |
grantphillips | 0:1c605984e361 | 61 | |
grantphillips | 0:1c605984e361 | 62 | /** Gets a 32-bit random number. |
grantphillips | 0:1c605984e361 | 63 | * @param |
grantphillips | 0:1c605984e361 | 64 | * None |
grantphillips | 0:1c605984e361 | 65 | * @return |
grantphillips | 0:1c605984e361 | 66 | * 32-bit random number. |
grantphillips | 0:1c605984e361 | 67 | */ |
grantphillips | 0:1c605984e361 | 68 | unsigned long Get(); |
grantphillips | 0:1c605984e361 | 69 | }; |
grantphillips | 0:1c605984e361 | 70 | |
grantphillips | 0:1c605984e361 | 71 | #endif |