Skip to content

How to use RP2350 hardware TRNG? #2643

Answered by maxgerhardt
metehoca asked this question in Q&A
Discussion options

You must be logged in to vote

Note that if you want to get the TRNG output directly, you can also do that.

#include <Arduino.h>
#include "hardware/structs/trng.h"

void setup() {
  Serial.begin(115200);
  // initially reset TRNG
  trng_hw->trng_sw_reset = 1;
  delayMicroseconds(100);
  trng_hw->trng_sw_reset &= ~1;
}

uint32_t trng_sample_words[count_of(trng_hw->ehr_data)];
static_assert(count_of(trng_hw->ehr_data) >= 2 && count_of(trng_hw->ehr_data) < 255, "");
uint8_t trng_sample_word_count;

static uint64_t trng_get_64bits(void) {
  spin_lock_t *lock = spin_lock_instance(PICO_SPINLOCK_ID_RAND);
  uint32_t save = spin_lock_blocking(lock);
  if (trng_sample_word_count < 2) {
    // Sets the number of rng_clk cycles b…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@maxgerhardt
Comment options

Answer selected by metehoca
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants