GD32W51x User Manual
311
chapter), so that the quality of the
generated random number depends on TRNG_CLK exclusively, no matter what HCLK
frequency was set or not.
The 32-bit value of LFSR will transfer into TRNG_DATA register after a sufficient number of
seeds have been sent to the LFSR.
At the same time, the analog seed and TRNG_CLK clock are monitored. When an analog
seed error or a clock error occurs, the corresponding status bit in TRNG_STAT will be set and
an interrupt will generate if the IE bit in TRNG_CTL is set.
11.3.1.
Operation flow
The following steps are recommended for using TRNG block:
1). Enable the interrupt as necessary, so that when a random number or an error occurs, an
interrupt will be generated.
2). Enable the TRNGEN bit.
3). When an interrupt occurs, check the status register TRGN_STAT, if SEIF=0, CEIF=0 and
DRDY=1, then the random value in the data register could be read.
As required by the FIPS PUB 140-2, the first random data in data register should be saved
but not be used. Every subsequent new random data should be compared to the previously
random data. The data can only be used if it is not equal to the previously one.
11.3.2.
Error flags
(1) Clock error
When the TRNG_CLK frequency is lower than the 1/16 of HCLK, the CECS and CEIF bit will
be set. In this case, the application should check TRNG_CLK and HCLK frequency
configurations and then clear CEIF bit. Clock error will not impact the previous random data.
(2) Seed error
When the analog seed is not changed or always changing during 64 TRNG_CLK periods, the
SECS and SEIF bit will be set. In this case, the random data in data register should not be
used. The application needs to clear the SEIF bit, then clear and set TRNGEN bit for restarting
the TRNG.