Use the following procedure to start the TRNG:
- Enable the TRNG by setting the ENABLE bit together with the KEY in the TRNG PWREN register.
- Configure the TRNG clock divider to ensure that the TRNG functional clock is within the allowable range (10MHz typical, see the device data sheet for additional detail). The clock divider is configured by programming
the required value to the RATIO field of the CLKDIVIDE register. As an example, if MCLK is 80MHz, the RATIO field shall be set to 0x7 (divide-by-8) to provide a 10MHz functional clock to the TRNG module.
- Verify that the TRNG interrupts are disabled (interrupt mask bits are cleared to mask interrupts).
- Move the TRNG from the default OFF state to the NORM_FUNC state by writing the NORM_FUNC command (0x3) to the CMD field in the CTL register of the TRNG. Wait for the IRQ_CMD_DONE interrupt
flag to be set, indicating that the CMD completed.
- Run the digital block start-up self-test routine to ensure the TRNG digital is functioning properly:
- Move the TRNG from the NORM_FUNC state to the TEST_DIG state by writing the TEST_DIG command (0x1) to the CMD field in the CTL register. Wait for the IRQ_CMD_DONE interrupt flag to be
set, indicating that the digital self-test has completed.
- Check that all 8 digital tests passed be ensuring the DIG_TEST field in the TEST_RESULTS register are set (DIG_TEST=0xFF).
- After the digital test, the TRNG will return to the NORM_FUNC state automatically.
- Run the analog block start-up self-test routine to ensure that the TRNG analog is functioning properly:
- Move the TRNG from the NORM_FUNC state to the TEST_ANA state by writing the TEST_ANA command (0x2) to the CMD field in the CTL register. Wait for the IRQ_CMD_DONE interrupt flag to be
set, indicating that the analog self-test has completed.
- Check that the analog test passed by verifying that the ANA_TEST bit in the TEST_RESULTS register was set.
- After the analog test, if the test passed the TRNG will return to the NORM_FUNC state automatically. If the test failed, the TRNG enters the ERR state and must be brought to the OFF
state before attempting to use it again.
- Configure the TRNG for normal operation after running start-up self-tests:
- Clear the IRQ_CAPTURED_RDY_IRQ status by setting the
corresponding ICLR bit, as this may have been set during the self-tests
performed earlier.
- Set the decimation rate to the desired value by programming the new decimation rate into the DECIM_RATE field of the CTL register, followed by sending the NORM_FUNC command again (by writing 0x3 to the CMD field
in the CTL register). A decimation rate of 4 (DECIM_RATE=0x3) or greater is recommended.
- Enable the health fail interrupt by setting the IRQ_HEALTH_FAIL bit in the IMASK register.
- Enable the data captured interrupt by setting the IRQ_CAPTURED_RDY bit in the IMASK register.
- Wait for the first
IRQ_CAPTURED_RDY IRQ, and read the DATA_CAPTURE register. This value (the first
value read from DATA_CAPTURE after running a startup self-test) is not a true
random value and must be read and discarded before collecting true random data
from the DATA_CAPTURE register.
- When the IRQ_CAPTURED_RDY IRQ is
again asserted, random bits are available for read-out in the DATA_CAPTURE
register.
- If the IRQ_HEALTH_FAIL IRQ is asserted, a low entropy condition was found and the TRNG will have automatically switched to the ERR state to stop operation. To exit the ERR state, clear the
IRQ_HEALTH_FAIL interrupt. Then, transition the TRNG to the OFF state by sending an OFF command (0x0) to the CMD field in the CTL register. Wait for the IRQ_CMD_DONE interrupt flag to be set, then return to step #2 to power up the TRNG
again to test if sufficient entropy is again available.