Ring oscillator length configuration

nRF5340 Product Specification

The RNG engine must be configured with specific parameters to ensure correct operation in order to output random bits with sufficient entropy.

The noise source used for collecting entropy is based on inverter timing jitter that is collected from a dedicated on-chip free-running ring oscillator. The ring oscillator length, i.e. the number of inverters in the chain, can be configured using register TRNG_CONFIG.

In total there are four different ring oscillator lengths that can be selected, referred to as ROSC1 through ROSC4. For each of these four configurable lengths a corresponding sample count value is provided in register TRNG90B.ROSC1 through register TRNG90B.ROSC4.

The sampling frequency is configured using register SAMPLE_CNT, and the programmed value defines the number of CPU clock cycles between two consecutive ring oscillator samples. The configured sample count value is the minimum number of clock cycles that is enough to get independent outputs from the ring oscillator and must match that of the configured ROSC length.

The following steps describe how to set the RNG engine parameters described above:
  1. Enable RNG engine clock using register RNG_CLK.
  2. Reset the RNG engine using register RNG_SW_RESET.
  3. Re-enable RNG engine clock and select a device-specific sample count from registers TRNG90B.ROSC1 through TRNG90B.ROSC4 starting with the smallest one, and program the value into register SAMPLE_CNT.
  4. Perform a readback of the selected sample count value.
  5. Set the corresponding ROSC length in register TRNG_CONFIG to match the selected sample count selection.
  6. Enable the noise source using register NOISE_SOURCE.
  7. Wait until event EHR_VALID_INT in register RNG_ISR trigger to indicate successful collection of 192 bits of random data. The result can be read from registers EHR_DATA[n] (n=0..5).
  8. If events AUTOCORR_ERR_INT, CRNGT_ERR_INT, or VNC_ERR_INT in register RNG_ISR trigger, the RNG engine must be re-configured starting from step 2 above. Increase the ROSC length by a factor of one, and pick the corresponding sample count value from FICR. This step must be repeated until the collection of 192 bits of random data can be collected without an error event being triggered.

It is recommended to always try the shortest ROSC length first, allowing the RNG engine to complete the entropy collection in a shorter time and keep the ring oscillator turned off for longer periods in order to save power.