This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TRNG (True Random Number Generator) need to wait a long time before number is ready

Other Parts Discussed in Thread: CC1350

Hi,

I am using the CC1350 7x7 package and are trying to get the TRNG from driverlib/trng.h to work as it should.

Right now it do work, but it takes aproximately 345 ms to get the random number. I have tried on another chip (CC1350 EM module from TI) where almost all of the code is similar and my trng code works there.

The code shall generate a random reconnect timeout, thus I want speed over entropy.

void TRNG_Init(void)
{
  PRCMPowerDomainOn(PRCM_DOMAIN_PERIPH);
  while ((PRCMPowerDomainStatus(PRCM_DOMAIN_PERIPH) != PRCM_DOMAIN_POWER_ON));

  PRCMPeripheralRunEnable(PRCM_PERIPH_TRNG);
  PRCMLoadSet();
  while( ! PRCMLoadGet() );

  TRNGConfigure(0, 2^8, 0);
  TRNGEnable();
}

void TRNG_Deinit(void)
{
  TRNGDisable();

  PRCMPeripheralRunDisable(PRCM_PERIPH_TRNG);
  PRCMLoadSet();
  while( ! PRCMLoadGet() );
}


uint32_t TRNG_GetRandomNumber(void)
{
  while (!(TRNGStatusGet() & TRNG_NUMBER_READY))
  {
    WATCHDOG_Kick();
  }

  return TRNGNumberGet(DTTRNG_HI_OR_LOW_WORD);
}

From application:

TRNG_Init();
uint32_t reconnect = TRNG_GetRandomNumber(); // This call takes 345 ms


All help appreciated
Best regard Kai André  

  • Hi,

    first of all, when you implement your own driver in TI-RTOS, I highly recommend using the power driver API to control the peripheral:

    // Ensures that TRNG is on when the CPU is in running state
    Power_setDependency(PowerCC26XX_PERIPH_TRNG);
    // Let's the TRNG power down if nobody else is using it
    Power_releaseDependency(PowerCC26XX_PERIPH_TRNG);
    
    // Needed if not using the TRNG in polling mode
    // Prevents the CPU from going to standby and switching off peripherals
    Power_setConstraint(PowerCC26XX_SB_DISALLOW);

    The problem in your above code snippet is "2^8". This doesn't produce the intended value 256 as "^" in C means "XOR". Just use 256 and the TRNG response time will go down to a few microseconds.