/* To generate entropy from hardware entropy source (TRNG)  */
int32_t RNG_EntropyPoll(uint8_t *pu8Out, int32_t i32Len)
/* To generate entropy from hardware entropy source (TRNG)  */
int32_t RNG_EntropyPoll(uint8_t *pu8Out, int32_t i32Len)
{
    int32_t timeout;
    int32_t i;
    if ((TRNG->CTL & TRNG_CTL_READY_Msk) == 0)
    {
        printf("trng is not active\n");
        return -1;
    }
    TRNG->CTL |= TRNG_CTL_TRNGEN_Msk;
    for (i = 0; i < i32Len; i++)
    {
        timeout = SystemCoreClock;
        while ((TRNG->CTL & TRNG_CTL_DVIF_Msk) == 0)
        {
            if (timeout-- <= 0)
            {
                printf("timeout\n");
                return -1;
            }
        }
        *pu8Out++ = TRNG->DATA;
    }
    return i32Len;
}