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

13.2.1 RNG configuration register (RNG_CR)

Address offset: 0x00

Reset value: 0x0000

This register configures the RNG.

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.TST_CLKRNG_DISRes.Res.
nwnw
Bits 31:4Reserved, must be kept at reset value.
Bit 3

TST_CLK: RNG 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 the 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 reasons, software should check that the RNGCLK is present before reading random values.

This bit is auto-cleared and always read as 0.

Bit 2

RNG_DIS: RNG disable bit.

This bit enables or disables the random number generator.

  • 0: RNG is enabled (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.
Bits 1:0Reserved, must be kept at reset value.

13.2.2 RNG status flag register (RNG_SR)

Address offset: 0x04

Reset value: 0x0000

This register provides status flags of the RNG.

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.FAULTREVCLKRNGRDY
rc_w1rr
Bits 31:3Reserved, must be kept at reset value.
Bit 2

FAULT: Fault 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 samevalue (0b or 1b)
  • Sequence of more than 16 consecutive alternation of 0band 1b (010101...01b).

Writing this bit with 1b clears it. Writing with 0b has no effect.

Bit 1REVCLK: RNGCLK 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 an AHB error response.
Bit 0RNGRDY: New random value ready.
  • 0: The RNG_VAL register value is not yet valid. If performing a read access to RNG_VAL, the host is 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)

13.2.3 RNG value register (RNG_VAL)

Address offset: 0x08

Reset value: 0xXXXX

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.

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
RANDOM_VALUE
rrrrrrrrrrrrrrrr
Bits 31:16Reserved, must be kept at reset value.
Bit 15:0RANDOM_VALUE: Random value.

13.2.4 RNG register map

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

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

Table 38. RNG register list

Address offsetNameRW (1)ResetDescription
0x00RNG_CRRW0x00000000RNG configuration register. See Section 13.2: RNG registers
0x04RNG_SRRO0x00000000RNG status register. See Section 13.2: RNG registers
0x08RNG_VALRO0x00000000RNG 16-bit random value. See Section 13.2: RNG registers

1. These acronyms have the following meaning: RW = read and write; RO = read only.