aboutsummaryrefslogtreecommitdiffstats
path: root/testhal/STM32/multi/TRNG/main.c
diff options
context:
space:
mode:
authorGiovanni Di Sirio <gdisirio@gmail.com>2018-10-07 08:56:43 +0000
committerGiovanni Di Sirio <gdisirio@gmail.com>2018-10-07 08:56:43 +0000
commit0f2e8f0b01edd1a0389426b316f491acf49af596 (patch)
tree78d608ed936ff7f1c5fc20c21fcbb68a717ea837 /testhal/STM32/multi/TRNG/main.c
parente72ef8c943b3a335fe4354e6451be99ab1346081 (diff)
downloadChibiOS-0f2e8f0b01edd1a0389426b316f491acf49af596.tar.gz
ChibiOS-0f2e8f0b01edd1a0389426b316f491acf49af596.tar.bz2
ChibiOS-0f2e8f0b01edd1a0389426b316f491acf49af596.zip
TRNG driver working.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@12343 110e8d01-0319-4d1e-a829-52ad28d1bb01
Diffstat (limited to 'testhal/STM32/multi/TRNG/main.c')
-rw-r--r--testhal/STM32/multi/TRNG/main.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/testhal/STM32/multi/TRNG/main.c b/testhal/STM32/multi/TRNG/main.c
index 83edb3e63..51d03718d 100644
--- a/testhal/STM32/multi/TRNG/main.c
+++ b/testhal/STM32/multi/TRNG/main.c
@@ -16,6 +16,7 @@
#include "ch.h"
#include "hal.h"
+#include "chprintf.h"
#include "portab.h"
@@ -61,6 +62,53 @@ int main(void) {
/* Normal main() thread activity, in this demo it does nothing.*/
while (true) {
+ if (palReadLine(PORTAB_LINE_BUTTON) == PORTAB_BUTTON_PRESSED) {
+ bool err;
+ uint8_t rand[32];
+
+ trngStart(&TRNGD1, NULL);
+
+ err = trngGenerate(&TRNGD1, 32, rand);
+ if (err) {
+ chprintf((BaseSequentialStream *)&PORTAB_SD1, "Error!\r\n");
+ }
+ else {
+ unsigned i;
+
+ for (i = 0; i < 32; i++) {
+ chprintf((BaseSequentialStream *)&PORTAB_SD1, "%02x", rand[i]);
+ }
+ chprintf((BaseSequentialStream *)&PORTAB_SD1, "\r\n");
+ }
+
+ err = trngGenerate(&TRNGD1, 15, rand);
+ if (err) {
+ chprintf((BaseSequentialStream *)&PORTAB_SD1, "Error!\r\n");
+ }
+ else {
+ unsigned i;
+
+ for (i = 0; i < 15; i++) {
+ chprintf((BaseSequentialStream *)&PORTAB_SD1, "%02x", rand[i]);
+ }
+ chprintf((BaseSequentialStream *)&PORTAB_SD1, "\r\n");
+ }
+
+ err = trngGenerate(&TRNGD1, 2, rand);
+ if (err) {
+ chprintf((BaseSequentialStream *)&PORTAB_SD1, "Error!\r\n");
+ }
+ else {
+ unsigned i;
+
+ for (i = 0; i < 2; i++) {
+ chprintf((BaseSequentialStream *)&PORTAB_SD1, "%02x", rand[i]);
+ }
+ chprintf((BaseSequentialStream *)&PORTAB_SD1, "\r\n");
+ }
+
+ trngStop(&TRNGD1);
+ }
chThdSleepMilliseconds(500);
}
return 0;