13. Random number generator (RNG)

The RNG is a random number generator based on a continuous analog noise that provides a 16-bit value to the host when read.

13.1 Features

Power consumption and RNG:

The internal free-running oscillators are quite power consuming. It is possible to stop them when the RNG is not used.

13.2 RNG registers map

Refer to Section 2.2.2: Memory map and register boundary addresses for the register boundary addresses.

Note: Despite RNG registers are addressed through AHB, only 32-bit accesses are allowed. Any 8-bit or 16-bit access generate an AHB error leading to a hard fault on Cortex-M0+.

Table 35. RNG register list

Address offsetNameRW(1)ResetDescription
0x00RNG_CRRW0x00000000RNG Configuration register. See Table 36: RNG_CR register description on page 270
0x04RNG_SRRO0x00000000RNG Status register. See Table 37: RNG_SR register description on page 271
0x08RNG_VALRO0x00000000RNG 16-bit random value. See Table 38: RNG_VAL register description on page 271

1. These acronyms have the following meaning:

RW = Read and Write

RO = Read Only

13.3 RNG registers description

RNG_CR

This register configures the RNG.

Table 36. RNG_CR register description

Address: RNG_BASE + 0x00
BitField nameResetR/WDescription
1:0RESERVED2'h0RWRESERVED
2RNG_DIS1'h0RWRNG Disable bit.
This bit enables or disables the random number generator.
– 0: RNG is enable (default)
– 1: RNG is disabled. The internal free-running oscillators are put in power-down mode and the RNG clock is stopped at the input of the block.
3TST_CLK1'h0RWRNG Test Clock bit.
Writing this bit with 1b starts the logic that detects the presence of the RNG_CLK. Then wait (with a timeout of at least four RNGCLK cycles) for REVCLK = 1b in RNG_SR register. If REVCLK = 0b after timeout elapsed, it means that RNGCLK is not present and reading RNG_VAL register triggers an AHB error response.
For security reason, software should check before reading random values that the RNGCLK is present.
This bit is auto-cleared and always read as 0.
31:4RESERVED28'h0000000RRESERVED

RNG_SR

This register provides status flags of the RNG.

Table 37. RNG_SR register description

Address: RNG_BASE + 0x04
BitField nameResetR/WDescription
0RNGRDY1'h0RNew Random Value Ready.
– 0: the RNG_VAL register value is not yet valid. If performing a read access to RNG_VAL, the host is put on hold (by wait-states insertion on the AHB bus) until a random value is available.
– 1: the RNG_VAL register contains a valid random number.
This bit remains at 0b when the RNG is disabled (RNGDIS bit = 1b in RNG_CR)
1REVCLK1'h0RRNGCLK Clock Reveal bit.
A write with 1b to bit TSTCLK in RNG_CR resets this bit. If the RNGCLK is present, this bit is 1b after four RNGCLK cycles after the end of the write to RNG_CR. If REVCLK = 0b after this period, it means the RNGCLK is not present and reading RNG_VAL triggers a AHB error response.
2FAULT1'h0RC_W1Fault Reveal bit.
This bit is set by hardware when a faulty sequence of bits occurs. The faulty sequences are:
– sequence of more than 32 consecutive bits of same value (0b or 1b)
– sequence of more than 16 consecutive alternation of 0b and 1b (010101...01b).
Writing this bit with 1b clear it. Writing with 0b has no effect.
31:3RESERVED29'h00000000RRESERVED

RNG_VAL

This register delivers a 16-bit random value when read. After being read, this register delivers a new random value only after 20 cycles of RNGCLK. If the host performs a new read before the period has elapsed, the RNG inserts a wait-state on the AHB bus.

Table 38. RNG_VAL register description

Address: RNG_BASE + 0x08
BitField nameResetR/WDescription
15:0RANDOM_VALUE16'h----RRandom Value.
31:16RESERVED16'h0000RRESERVED