TRNG driver working.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@12343 110e8d01-0319-4d1e-a829-52ad28d1bb01
This commit is contained in:
parent
e72ef8c943
commit
0f2e8f0b01
|
@ -277,6 +277,11 @@
|
|||
#define STM32_ST_IRQ_PRIORITY 8
|
||||
#define STM32_ST_USE_TIMER 2
|
||||
|
||||
/*
|
||||
* TRNG driver system settings.
|
||||
*/
|
||||
#define STM32_TRNG_USE_RNG1 FALSE
|
||||
|
||||
/*
|
||||
* UART driver system settings.
|
||||
*/
|
||||
|
|
|
@ -277,6 +277,11 @@
|
|||
#define STM32_ST_IRQ_PRIORITY 8
|
||||
#define STM32_ST_USE_TIMER 2
|
||||
|
||||
/*
|
||||
* TRNG driver system settings.
|
||||
*/
|
||||
#define STM32_TRNG_USE_RNG1 FALSE
|
||||
|
||||
/*
|
||||
* UART driver system settings.
|
||||
*/
|
||||
|
|
|
@ -152,7 +152,7 @@ bool trng_lld_generate(TRNGDriver *trngp, size_t size, uint8_t *out) {
|
|||
|
||||
/* Waiting for a random number in data register.*/
|
||||
tmo = STM32_DATA_FETCH_ATTEMPTS;
|
||||
while ((tmo > 0) && ((trngp->rng->SR & RNG_SR_DRDY) != 0)) {
|
||||
while ((tmo > 0) && ((trngp->rng->SR & RNG_SR_DRDY) == 0)) {
|
||||
tmo--;
|
||||
if (tmo == 0) {
|
||||
return true;
|
||||
|
|
|
@ -85,7 +85,8 @@
|
|||
to eight data lines so "quad" was no more appropriate.
|
||||
- NEW: Added a new SIO driver model to HAL, it is a low level abstraction of
|
||||
an UART.
|
||||
- NEW: Independent TRNG driver model added to HAL.
|
||||
- NEW: Independent TRNG driver model added to HAL. Implemented a RNGv1 driver
|
||||
for STM32, added test application.
|
||||
- NEW: Added a new "pipes" subsystem to the OS library.
|
||||
- NEW: Added mcuconf.h generators for STM32L432xx, STM32L476xx, STM32L496xx,
|
||||
STM32L4R5xx, STM32F72x/73x, STM32F746/756 and STM32F76x/77x devices.
|
||||
|
|
|
@ -277,6 +277,11 @@
|
|||
#define STM32_ST_IRQ_PRIORITY 8
|
||||
#define STM32_ST_USE_TIMER 2
|
||||
|
||||
/*
|
||||
* TRNG driver system settings.
|
||||
*/
|
||||
#define STM32_TRNG_USE_RNG1 FALSE
|
||||
|
||||
/*
|
||||
* UART driver system settings.
|
||||
*/
|
||||
|
|
|
@ -277,6 +277,11 @@
|
|||
#define STM32_ST_IRQ_PRIORITY 8
|
||||
#define STM32_ST_USE_TIMER 2
|
||||
|
||||
/*
|
||||
* TRNG driver system settings.
|
||||
*/
|
||||
#define STM32_TRNG_USE_RNG1 FALSE
|
||||
|
||||
/*
|
||||
* UART driver system settings.
|
||||
*/
|
||||
|
|
|
@ -277,6 +277,11 @@
|
|||
#define STM32_ST_IRQ_PRIORITY 8
|
||||
#define STM32_ST_USE_TIMER 2
|
||||
|
||||
/*
|
||||
* TRNG driver system settings.
|
||||
*/
|
||||
#define STM32_TRNG_USE_RNG1 FALSE
|
||||
|
||||
/*
|
||||
* UART driver system settings.
|
||||
*/
|
||||
|
|
|
@ -277,6 +277,11 @@
|
|||
#define STM32_ST_IRQ_PRIORITY 8
|
||||
#define STM32_ST_USE_TIMER 2
|
||||
|
||||
/*
|
||||
* TRNG driver system settings.
|
||||
*/
|
||||
#define STM32_TRNG_USE_RNG1 FALSE
|
||||
|
||||
/*
|
||||
* UART driver system settings.
|
||||
*/
|
||||
|
|
|
@ -277,6 +277,11 @@
|
|||
#define STM32_ST_IRQ_PRIORITY 8
|
||||
#define STM32_ST_USE_TIMER 2
|
||||
|
||||
/*
|
||||
* TRNG driver system settings.
|
||||
*/
|
||||
#define STM32_TRNG_USE_RNG1 FALSE
|
||||
|
||||
/*
|
||||
* UART driver system settings.
|
||||
*/
|
||||
|
|
|
@ -277,6 +277,11 @@
|
|||
#define STM32_ST_IRQ_PRIORITY 8
|
||||
#define STM32_ST_USE_TIMER 2
|
||||
|
||||
/*
|
||||
* TRNG driver system settings.
|
||||
*/
|
||||
#define STM32_TRNG_USE_RNG1 FALSE
|
||||
|
||||
/*
|
||||
* UART driver system settings.
|
||||
*/
|
||||
|
|
|
@ -277,6 +277,11 @@
|
|||
#define STM32_ST_IRQ_PRIORITY 8
|
||||
#define STM32_ST_USE_TIMER 2
|
||||
|
||||
/*
|
||||
* TRNG driver system settings.
|
||||
*/
|
||||
#define STM32_TRNG_USE_RNG1 FALSE
|
||||
|
||||
/*
|
||||
* UART driver system settings.
|
||||
*/
|
||||
|
|
|
@ -277,6 +277,11 @@
|
|||
#define STM32_ST_IRQ_PRIORITY 8
|
||||
#define STM32_ST_USE_TIMER 2
|
||||
|
||||
/*
|
||||
* TRNG driver system settings.
|
||||
*/
|
||||
#define STM32_TRNG_USE_RNG1 FALSE
|
||||
|
||||
/*
|
||||
* UART driver system settings.
|
||||
*/
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="2"/>
|
||||
<stringAttribute key="org.eclipse.cdt.launch.COREFILE_PATH" value=""/>
|
||||
<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_REGISTER_GROUPS" value=""/>
|
||||
<stringAttribute key="org.eclipse.cdt.launch.FORMAT" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?><contentList><content id="xPSR-(format)" val="4"/><content id="mfs_buffer[447]-null-mfs_test_001_005_execute-(format)" val="0"/><content id="mfs_buffer[507]-null-mfs_test_001_005_execute-(format)" val="0"/><content id="rp[506]-rp-mfs_flash_read-(format)" val="0"/><content id="rp[507]-rp-mfs_flash_read-(format)" val="0"/><content id="rp-mfs_flash_read-(cast_to_array)" val="0:511"/></contentList>"/>
|
||||
<stringAttribute key="org.eclipse.cdt.launch.FORMAT" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?><contentList><content id="rand-main-(format)" val="4"/><content id="rp-mfs_flash_read-(cast_to_array)" val="0:511"/><content id="rp[507]-rp-mfs_flash_read-(format)" val="0"/><content id="rp[506]-rp-mfs_flash_read-(format)" val="0"/><content id="mfs_buffer[507]-null-mfs_test_001_005_execute-(format)" val="0"/><content id="mfs_buffer[447]-null-mfs_test_001_005_execute-(format)" val="0"/><content id="xPSR-(format)" val="4"/><content id="rand[0]-rand-main-(format)" val="4"/><content id="rand[1]-rand-main-(format)" val="4"/><content id="rand[2]-rand-main-(format)" val="4"/><content id="rand[3]-rand-main-(format)" val="4"/><content id="rand[4]-rand-main-(format)" val="4"/><content id="rand[5]-rand-main-(format)" val="4"/><content id="rand[6]-rand-main-(format)" val="4"/><content id="rand[7]-rand-main-(format)" val="4"/><content id="rand[8]-rand-main-(format)" val="4"/><content id="rand[9]-rand-main-(format)" val="4"/><content id="rand[10]-rand-main-(format)" val="4"/><content id="rand[11]-rand-main-(format)" val="4"/><content id="rand[12]-rand-main-(format)" val="4"/><content id="rand[13]-rand-main-(format)" val="4"/><content id="rand[14]-rand-main-(format)" val="4"/><content id="rand[15]-rand-main-(format)" val="4"/><content id="rand[16]-rand-main-(format)" val="4"/><content id="rand[17]-rand-main-(format)" val="4"/><content id="rand[18]-rand-main-(format)" val="4"/><content id="rand[19]-rand-main-(format)" val="4"/><content id="rand[20]-rand-main-(format)" val="4"/><content id="rand[21]-rand-main-(format)" val="4"/><content id="rand[22]-rand-main-(format)" val="4"/><content id="rand[23]-rand-main-(format)" val="4"/><content id="rand[24]-rand-main-(format)" val="4"/><content id="rand[25]-rand-main-(format)" val="4"/><content id="rand[26]-rand-main-(format)" val="4"/><content id="rand[27]-rand-main-(format)" val="4"/><content id="rand[28]-rand-main-(format)" val="4"/><content id="rand[29]-rand-main-(format)" val="4"/><content id="rand[30]-rand-main-(format)" val="4"/><content id="rand[31]-rand-main-(format)" val="4"/></contentList>"/>
|
||||
<stringAttribute key="org.eclipse.cdt.launch.GLOBAL_VARIABLES" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <globalVariableList/> "/>
|
||||
<stringAttribute key="org.eclipse.cdt.launch.MEMORY_BLOCKS" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <memoryBlockExpressionList> <memoryBlockExpressionItem> <expression text="0x20000c34"/> </memoryBlockExpressionItem> </memoryBlockExpressionList> "/>
|
||||
<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="${selected_resource_loc}"/>
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
# Compiler options here.
|
||||
ifeq ($(USE_OPT),)
|
||||
USE_OPT = -O2 -ggdb -fomit-frame-pointer -falign-functions=16
|
||||
USE_OPT = -O0 -ggdb -fomit-frame-pointer -falign-functions=16
|
||||
endif
|
||||
|
||||
# C specific options here (added to USE_OPT).
|
||||
|
@ -112,6 +112,7 @@ include $(CHIBIOS)/tools/mk/autobuild.mk
|
|||
include $(CHIBIOS)/test/lib/test.mk
|
||||
include $(CHIBIOS)/test/rt/rt_test.mk
|
||||
include $(CHIBIOS)/test/oslib/oslib_test.mk
|
||||
include $(CHIBIOS)/os/hal/lib/streams/streams.mk
|
||||
|
||||
# Define linker script file here.
|
||||
LDSCRIPT= $(STARTUPLD)/STM32L476xG.ld
|
||||
|
|
|
@ -277,6 +277,11 @@
|
|||
#define STM32_ST_IRQ_PRIORITY 8
|
||||
#define STM32_ST_USE_TIMER 2
|
||||
|
||||
/*
|
||||
* TRNG driver system settings.
|
||||
*/
|
||||
#define STM32_TRNG_USE_RNG1 FALSE
|
||||
|
||||
/*
|
||||
* UART driver system settings.
|
||||
*/
|
||||
|
|
|
@ -277,6 +277,11 @@
|
|||
#define STM32_ST_IRQ_PRIORITY 8
|
||||
#define STM32_ST_USE_TIMER 2
|
||||
|
||||
/*
|
||||
* TRNG driver system settings.
|
||||
*/
|
||||
#define STM32_TRNG_USE_RNG1 FALSE
|
||||
|
||||
/*
|
||||
* UART driver system settings.
|
||||
*/
|
||||
|
|
|
@ -288,6 +288,11 @@
|
|||
#define STM32_ST_IRQ_PRIORITY ${doc.STM32_ST_IRQ_PRIORITY!"8"}
|
||||
#define STM32_ST_USE_TIMER ${doc.STM32_ST_USE_TIMER!"2"}
|
||||
|
||||
/*
|
||||
* TRNG driver system settings.
|
||||
*/
|
||||
#define STM32_TRNG_USE_RNG1 ${doc.STM32_TRNG_USE_RNG1!"FALSE"}
|
||||
|
||||
/*
|
||||
* UART driver system settings.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue