K70 - HW Random Number Generator Example

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

K70 - HW Random Number Generator Example

2,006 Views
chrisc
Contributor II

Hi,

Is there a code example of how to obtain a seed from the hardware random number generator accelerator on the Kinetis K70 board?  I've found Chapter 37 (Random Number Generator Accelerator) from the following document, but wasn't able to find an example of this being used anywhere.

http://cache.freescale.com/files/microcontrollers/doc/ref_manual/K70P256M150SF3RM.pdf

Thanks,

Chris

Labels (1)
Tags (4)
0 Kudos
1 Reply

670 Views
mjbcswitzerland
Specialist V

Hi Chris

The following code is from the uTasker project:

Initialisation:

POWER_UP(3, SIM_SCGC3_RNGB);     // power up the RNG   

RNG_CR = (RNG_CR_FUFMODE_TE | RNG_CR_AR);   // automatic reseed mode and generate a bus error on FIFO underrun  

RNG_CMD = (RNG_CMD_GS | RNG_CMD_CI | RNG_CMD_CE);    // start the initial seed process // the initial seeding takes some time but we don't wait for it to complete here - if it hasn't completed when we first need a value we will wait for it then

Getting a random number:

  

while (RNG_SR & RNG_SR_BUSY) {}    // wait for the RNG to become ready (it may be seeding)    

while ((RNG_SR & RNG_SR_FIFO_LVL_MASK) == 0) { }  // wait for at least one output word to become available

return RNG_OUT;            // read from the FIFO and return 32 bits of output


Regards

Mark

http://www.uTasker.com