I'm using a STM32F4 and I'm currently trying to get the build in RNG to work. Did any of you ever tried this before?
I used stm32f4xx.c and stm32f4xx.h and also added the corresponding stm32f4xx_rcc.c and stm32f4xx_rcc.h to get it to compile. (I also had to delete all the asset_param statements since they are undefined.)
But so far RNG_GetFlagStatus only returns RESET.
Do you have any ideas?
thanks,
kiwi
Code: Select all
#include "ch.h"
#include "hal.h"
/* RNGDriver */
#include "stm32f4xx_rng.h"
/* RNG Thread */
static WORKING_AREA(rngThreadWorkingArea, 128);
/* TODO: handle with interrupt */
static msg_t rngThread(void* arg) {
(void) arg;
while (TRUE) {
uint32_t random;
if(RNG_GetFlagStatus(RNG_FLAG_DRDY) == SET) {
palSetPad(GPIOG, GPIOG_LED4_RED);
random = RNG_GetRandomNumber();
} else if(RNG_GetFlagStatus(RNG_FLAG_CECS) == SET) {
RNG_ClearITPendingBit(RNG_IT_CEI);
} else if(RNG_GetFlagStatus(RNG_FLAG_SECS) == SET) {
RNG_ClearITPendingBit(RNG_IT_SEI);
}
// wait.
chThdSleepMilliseconds(500);
}
}
int main(void)
{
chSysInit();
halInit();
/* enable TRNG */
RNG_DeInit();
RNG_Cmd(ENABLE);
/* Start thread to read random numbers */
(void)chThdCreateStatic(rngThreadWorkingArea, sizeof(rngThreadWorkingArea),
NORMALPRIO, rngThread, NULL);
while(TRUE) {
}
/* Return success */
return 1;
}