AnsweredAssumed Answered

K81 - TRNG_GetRandomData hanging

Question asked by Christian Nielsen on Jan 16, 2020
Latest reply on Jan 21, 2020 by Christian Nielsen

I am trying to get some random data from K81 hardware and I'm using TRNG_GetRandomData from fsl_trng.c.

I'm using it in connection with :



return_code = mbedtls_rsa_rsaes_pkcs1_v15_encrypt(key, trng_ctr_drbg_random, NULL, MBEDTLS_RSA_PUBLIC, sizeof(_pers_kbpk), (const uint8_t*)&, enc_pers_kbpk_ptr);


static int trng_ctr_drbg_random(void* notused, unsigned char* output, size_t output_len)
    return ( TRNG_GetRandomData(TRNG0, output, output_len) );



In TRNG_GetRandomData it hangs in the check while loop:


while ((TRNG_RD_MCTL_ENT_VAL(base) == 0) && (TRNG_RD_MCTL_ERR(base) == 0))

and never gets out.
If I run debug one step at a time it works perfect but if it runs normal it hangs.
Is there a workaround for this issue ?

It is configured with TRNG_Init and default config.


uint32_t trng_enable()
   trng_config_t trngConfig;

   trngConfig.sampleMode = kTRNG_SampleModeVonNeumann;

   return (TRNG_Init(TRNG0, &trngConfig));