Here is my function to generate random numbers of desired length.
#define TRNG_BASE 0x4000D000
#define TRNG_TASKS_START (*(volatile uint32_t *)(TRNG_BASE + 0x000))
#define TRNG_TASKS_STOP (*(volatile uint32_t *)(TRNG_BASE + 0x004))
#define TRNG_EV_VALRDY (*(volatile uint32_t *)(TRNG_BASE + 0x100))
#define TRNG_VALUE (*(volatile uint32_t *)(TRNG_BASE + 0x508))
void sys_random(uint8_t *buf, int len)
{
volatile uint8_t val;
volatile int i = 0;
/* Clear VALRDY */
TRNG_EV_VALRDY = 0;
/* Start TRNG */
TRNG_TASKS_START = 1;
for (i = 0; i < len; i++)
{
printf("Generating random #%d\r\n", i);
/* Wait until value ready */
while (TRNG_EV_VALRDY == 0);
TRNG_EV_VALRDY = 0;
buf[i] = (uint8_t)(TRNG_VALUE & 0x000000FF);
}
TRNG_TASKS_STOP |= 1;
}
After generating a few(5 to 6) random numbers the function hangs at
while (TRNG_EV_VALRDY == 0).
I am using RIOT OS on nrf52832. What could be the issue here?