William Easdown investigates using the True Random Number Generator (TRNG) in the Microchip SAMD51 microcontroller:
Lately, I’ve been wanting to learn how to do direct register access on the SAM family of microcontrollers. I have a SAMD51-based Adafruit Feather M4 Express board, so was looking through the SAMD51’s datasheet to work out which registers I could do something useful with while not having to dive too deep into the microcontroller.
Looking down the extensive list of peripherals, I came across the True Random Number Generator (TRNG). This seems to be a relatively rare feature for a microcontroller – I haven’t seen any others with one – and it struck me that it should be fairly simple to get going because it shouldn’t need to interface with too many other peripherals or central parts of the chip.
Indeed, reading its description revealed it just need a clock source from the Main Clock (MCLK) and an interrupt setting up and I’d be ready to go. This involved setting three registers in total: the first to send the MCLK to the TRNG, the second to enable the TRNG and the third to enable interrupts from the TRNG when a new random number is available.
The SAMD51 datasheet states that the TRNG “passes the American NIST Special Publication 800-22 and Diehard Random Tests Suites”. William uses Arduino code to test the TRNG and a Python program to generate the results in the plot below.
You can read the details in the blog post here.