Random Numbers : Teensy 4.0 and Entropy Library

Status
Not open for further replies.

JupiterMoll

Member
Hallo,

I,m trying to compile the example Seed_PRNG included in the Entropy library of Teensyduino for generating random Numbers with Teensy 4.0

Code:
#include <Entropy.h>

#define randomSeed(s) srandom(s)

void setup()
{
  uint32_t seed_value;

  Serial.begin(9600);
  while (!Serial) {
    ;
  }

  Entropy.initialize();
  seed_value = Entropy.random();
  
  Serial.print("Seed value = ");
  Serial.println(seed_value);
  
  randomSeed(seed_value);
  

}

void loop()
{
}

I got this error message during compiling::(

Code:
Arduino: 1.8.9 (Linux), TD: 1.48, Board: "Teensy 4.0, Serial, 600 MHz, Faster, US English"

/home/alphi/Arduino/libraries/Entropy/Entropy.cpp: In member function 'void EntropyClass::initialize()':
/home/alphi/Arduino/libraries/Entropy/Entropy.cpp:67:3: error: 'SIM_SCGC5' was not declared in this scope
   SIM_SCGC5 |= SIM_SCGC5_LPTIMER;
   ^
/home/alphi/Arduino/libraries/Entropy/Entropy.cpp:67:16: error: 'SIM_SCGC5_LPTIMER' was not declared in this scope
   SIM_SCGC5 |= SIM_SCGC5_LPTIMER;
                ^
/home/alphi/Arduino/libraries/Entropy/Entropy.cpp:68:3: error: 'LPTMR0_CSR' was not declared in this scope
   LPTMR0_CSR = 0b10000100;
   ^
/home/alphi/Arduino/libraries/Entropy/Entropy.cpp:69:3: error: 'LPTMR0_PSR' was not declared in this scope
   LPTMR0_PSR = 0b00000101;  // PCS=01 : 1 kHz clock
   ^
/home/alphi/Arduino/libraries/Entropy/Entropy.cpp:70:3: error: 'LPTMR0_CMR' was not declared in this scope
   LPTMR0_CMR = 0x0006;      // smaller number = faster random numbers...
   ^
In file included from /home/alphi/Downloads/arduino-1.8.9-linux64/arduino-1.8.9/hardware/teensy/avr/cores/teensy4/core_pins.h:32:0,
                 from /home/alphi/Downloads/arduino-1.8.9-linux64/arduino-1.8.9/hardware/teensy/avr/cores/teensy4/wiring.h:38,
                 from /home/alphi/Downloads/arduino-1.8.9-linux64/arduino-1.8.9/hardware/teensy/avr/cores/teensy4/WProgram.h:45,
                 from /tmp/arduino_build_981811/pch/Arduino.h:6:
/home/alphi/Arduino/libraries/Entropy/Entropy.cpp:72:19: error: 'IRQ_LPTMR' was not declared in this scope
   NVIC_ENABLE_IRQ(IRQ_LPTMR);
                   ^
/home/alphi/Downloads/arduino-1.8.9-linux64/arduino-1.8.9/hardware/teensy/avr/cores/teensy4/imxrt.h:8296:52: note: in definition of macro 'NVIC_ENABLE_IRQ'
 #define NVIC_ENABLE_IRQ(n)      (*(&NVIC_ISER0 + ((n) >> 5)) = (1 << ((n) & 31)))
                                                    ^
/home/alphi/Arduino/libraries/Entropy/Entropy.cpp: In function 'void lptmr_isr()':
/home/alphi/Arduino/libraries/Entropy/Entropy.cpp:336:3: error: 'LPTMR0_CSR' was not declared in this scope
   LPTMR0_CSR = 0b10000100;
   ^
Multiple libraries were found for "Entropy.h"
 Used: /home/alphi/Arduino/libraries/Entropy
 Not used: /home/alphi/Downloads/arduino-1.8.9-linux64/arduino-1.8.9/hardware/teensy/avr/libraries/Entropy
Using library Entropy in folder: /home/alphi/Arduino/libraries/Entropy (legacy)
Error compiling for board Teensy 4.0.

It seems that the Entropy Library is not compatible with Teensy 4.0.
Is there a workarround to create random Numbers or can somebody help me to updated this library to work with Teensy 4.0 ???

Thx...
 
entropy lib is based on "duelling clocks" and has not been ported to T4, but T3.5, T3.6, and T4.0 have hardware random number generators. The T4 generator is discussed in this thread:
https://forum.pjrc.com/threads/54711-Teensy-4-0-First-Beta-Test?p=195000&viewfull=1#post195000
It is slow compared to T3.5/3.6 TRNG.
https://github.com/manitou48/teensy4/blob/master/trng.ino

if you don't need crypto-strength random numbers, there is always random()

EDIT: T4 and T3.5/T3.6 have been added to Entropy lib
see https://forum.pjrc.com/threads/61125-Teensy-4-1-Random-Number-Generator
 
Last edited:
Status
Not open for further replies.
Back
Top