Very unusual behavior TRNG

Karol

Member
Hi,

I’m seeing very unusual behavior with the hardware TRNG on a Teensy 4.1 and I’m trying to determine whether this is a silicon issue, a marginal analog condition, or something configuration-related.

Summary of the issue:

  • Two Teensy 4.1 boards
  • Same firmware
  • Same CPU frequency
  • Same environment (no external hardware connected)
  • Same silicon revision (SRC_SBMR2 = 0x27 → Rev A)
On the “good” board:

  • TRNG works immediately at room temperature (~22–25°C)
  • MCTL reads ~0x00002602 at startup
  • ENT_VAL appears normally
On the “bad” board:

  • At room temperature, TRNG does not generate entropy
  • MCTL at boot: 0x00000202
  • After setting TSTART: 0x00003302
  • ENT_VAL never sets
  • ERR and FCT_FAIL remain 0
  • Clock gating (CCM_CCGR6) is enabled
Here is the critical observation:

If I heat the MCU (for example using warm air), once the internal temperature reaches approximately 36°C or higher (measured with TEMPMON), TRNG immediately starts working and ENT_VAL begins to assert normally.

Below ~36°C:

  • No entropy
  • No error flags
  • Digital control bits behave correctly
  • TSTART sets
  • But ENT_VAL never appears
Above ~36°C:

  • ENT_VAL appears
  • TRNG behaves normally
No glitching, no external load, no unusual power setup. USB-only power. Both boards behave consistently and repeatably.

This strongly suggests temperature-dependent analog behavior inside the TRNG (ring oscillators / noise source), possibly a marginal noise amplitude at lower temperatures causing the internal continuous test not to pass.

Questions:

  1. Has anyone seen temperature-dependent TRNG startup behavior on RT1062?
  2. Is there any known errata related to TRNG and temperature?
  3. Are there any documented configuration steps beyond SWR + TSTART required to fully reinitialize TRNG after reset?
  4. Could this be related to marginal silicon variation within spec?
The fact that it works perfectly once warmed up makes this particularly interesting.

Any insight would be greatly appreciated.
 
Thanks for asking.

Both boards were tested at the same CPU frequencies. I explicitly tested at:

  • 600 MHz
  • 150 MHz
The behavior is the same at both frequencies.

Good board (example at 150 MHz):

F_CPU: 150000000
Silicon revision: 27
Temperature ~22–23°C
TRNG outputs valid random values continuously.

Example:
Temperature 21.90 F3817AAC FFB33F3F 92F7A4AD
Temperature 23.14 3E09F090 A3B2317A 84F794EE

Bad board (150 MHz):

F_CPU: 150000000
Silicon revision: 27
Temperature ~35°C

Initially returns zeros from Entropy.random():

Temperature 35.25 00000000 00000000 00000000
Temperature 35.25 00000000 00000000 00000000

Then it may briefly start producing values:

Temperature 35.25 9B58B64A C177B70D B58D8B0E

And sometimes fall back to zeros again:

Temperature 35.25 00000000 00000000 00000000

Important details:

  • Same firmware on both boards
  • Same CPU frequency
  • Same silicon revision (SRC_SBMR2 = 27)
  • No external hardware connected
  • USB-powered only
  • Fully reproducible behavior
  • Both boards are secure locked
code:
#include "Arduino.h"
#include <Entropy.h>

extern float tempmonGetTemp(void);

void setup()
{
// --- Setup PC communication ---
Serial.begin(2000000);
Serial.setTimeout(2000);

Entropy.Initialize();
}

void loop()
{
while (!Serial || !Serial.dtr()) {
delay(10);
}

while(1)
{
Serial.printf("F_CPU: %lu\n", F_CPU);
Serial.printf("Silicon revision: %lu\n", SRC_SBMR2);
Serial.printf("Temperature %f %08X %08X %08X\n", tempmonGetTemp(),Entropy.random(),Entropy.random(),Entropy.random() );
Serial.println();
delay(1000);
}
}
 
On the one not working right try a "15 second Restore": Press Program Button ~15 secs until the RED LED flashes and release Button and wait for the RED LED to stop the processor restore.

I plugged in 5 T_4.1's here - only one is silicon REV #27 and four are REV #25, but all work.

Inserting code with toolbar " </> " presents as below with formatting preserved.
Code modified to test more and print less and Pause when .random() is ZERO
Also 4 of temps here are 40°C or higher (except one at 37°) so not helpful to OP case.
Code:
#include "Arduino.h"
#include <Entropy.h>
// https://forum.pjrc.com/index.php?threads/very-unusual-behavior-trng.77733/#post-366092

extern float tempmonGetTemp(void);

void setup()
{
  // --- Setup PC communication ---
  Serial.begin(2000000);
  Serial.setTimeout(2000);
  Entropy.Initialize();
  Serial.println("\n Startup");
}

void loop()
{
  while (!Serial || !Serial.dtr()) {
    delay(10);
  }

  while (1)
  {
    Serial.printf("\nF_CPU: %lu\tF_CPU_ACTUAL: %lu\n", F_CPU, F_CPU_ACTUAL);
    Serial.printf("Silicon revision: %lu\n", SRC_SBMR2);
    Serial.printf("Temperature %f %08X %08X %08X\t", tempmonGetTemp(), Entropy.random(), Entropy.random(), Entropy.random() );
    int ii = 0;
    while ( ii < 1000 ) {
      int jj = Entropy.random();
      if ( 0 == jj ) {
        Serial.printf("\n>>>>>>>   Temperature %f jj==%08X %08X %08X\n", tempmonGetTemp(), jj, Entropy.random(), Entropy.random() );
        delay(10000);
      }
      if ( !(ii%100) ) Serial.print(". ");
      delay(10);
      ii++;
    }
    Serial.println();
    delay(1000);
  }
}
 
Hi,

I conducted a series of tests on 18 different Teensy 4.1 boards to investigate temperature-related behavior of the TRNG.

Each board was connected via USB and running a simple test firmware that continuously generated random numbers. I then cooled the MCU using compressed air spray and observed whether random numbers were still being produced.

For identification purposes:
  • I added the unique serial number read from HW_OCOTP_MAC0 to the firmware output.
  • I also recorded the markings printed directly on each MCU package.
This allowed me to clearly track individual boards during testing.

What I observed is a noticeable hysteresis effect in operation. Some boards stop generating random numbers below a certain temperature threshold, but once reheated, they resume normal operation — and the temperature at which they recover is different from the temperature at which they initially stopped.

The behavior is consistent across multiple units, although the exact temperature threshold varies slightly between boards.
MASK SRC_SBMR2 HW_OCOTP_MAC0 TEMPERATURE
-------------------------------------------------------------------------------------------
WORKING..
MIMXRT1026 DVJ6B 1N00X CTBP2117D revision 25, 0xE50FFA82 -4.272728 OK, with ETHERNET

MIMXRT1026 DVJ6B 1N00X CTGB2211A revision 27, 0xE512BCAD 0.59632 OK, without ETHERNET
MIMXRT1026 DVJ6B 1N00X CTGB2211A revision 27, 0xE512BCC4 -7.454544 OK, without ETHERNET
MIMXRT1026 DVJ6B 1N00X CTGB2211A revision 25, 0xE512BCCF -5.462959 OK, without ETHERNET
MIMXRT1026 DVJ6B 1N00X CTGB2211A revision 27, 0xE512BCAB -6.818184 OK, without ETHERNET
MIMXRT1026 DVJ6B 1N00X CTGB2211A revision 27, 0xE512BCEA -10.945946 OK, without ETHERNET
MIMXRT1026 DVJ6B 1N00X CTGB2211A revision 27, 0xE512BCE3 -9.375000 OK, without ETHERNET

MIMXRT1026 DVJ6B 1N00X CTDV2144J revision 25, 0xE5124FC0 -14.099098 OK, with ETHERNET
MIMXRT1026 DVJ6B 1N00X CTDV2144J revision 25, 0xE5124FE2 -6.875000 OK, with ETHERNET
MIMXRT1026 DVJ6B 1N00X CTDV2144J revision 25, 0xE5124FE1 -7.454544 OK, with ETHERNET

MIMXRT1026 DVJ6B 1N00X CTDP2138G revision 25, 0xE51188AF -3.495575 OK, with ETHERNET
MIMXRT1026 DVJ6B 1N00X CTDP2138G revision 27, 0xE5118899 -1.017700 OK, with ETHERNET

MIMXRT1026 DVJ6B 1N00X CTEB2151E revision 27, 0xE51283F2 -9.684685 OK, without ETHERNET
-------------------------------------------------------------------------------------------------
NOT WORKING...
MIMXRT1026 DVJ6B 1N00X CTDP2138G revision 25, 0xE51188B0 with ETHERNET, start above Temperature 45.442478 jj==00000000 00000000 7B003AD2
MIMXRT1026 DVJ6B 1N00X CTDP2138G revision 25, 0xE511889B with ETHERNET, stop below 4' then start above 10
MIMXRT1026 DVJ6B 1N00X CTDV2144J revision 25, 0xE5124FC2 with ETHERNET, start about 50.0
MIMXRT1026 DVJ6B 1N00X CTDP2138G revision 27, 0xE51188A5 with ETHERNET, start above 35.25862
MIMXRT1026 DVJ6B 1N00X CTDP2138G revision 27, 0xE5118891 with ETHERNET, start above 4.557522
 
I tested one Teensy 4.1 board and captured the startup log while monitoring TRNG output during temperature increase.
Markdown (GitHub flavored):
Startup

F_CPU: 150000000    F_CPU_ACTUAL: 151200000
Silicon revision: 27
Serial : E51188A5
Temperature 31.637932 00000000 00000000 00000000
>>>>>>>   Temperature 31.637932 jj==00000000 00000000 00000000
.
>>>>>>>   Temperature 34.051723 jj==00000000 00000000 00000000
>>>>>>>   Temperature 35.258621 jj==00000000 00000000 00000000
>>>>>>>   Temperature 36.465519 jj==00000000 00000000 00000000
>>>>>>>   Temperature 37.068966 jj==00000000 00000000 00000000
>>>>>>>   Temperature 37.672413 jj==00000000 00000000 00000000
>>>>>>>   Temperature 37.672413 jj==00000000 00000000 00000000
>>>>>>>   Temperature 37.672413 jj==00000000 00000000 00000000
>>>>>>>   Temperature 38.275864 jj==00000000 00000000 00000000
>>>>>>>   Temperature 38.275864 jj==00000000 00000000 D26702E2
. . . . . . . . .

F_CPU: 150000000    F_CPU_ACTUAL: 151200000
Silicon revision: 27
Serial : E51188A5
Temperature 38.879311 CDEDB976 2A72EAF6 DADEA6C8    . . . . . . .
 
Was the 15s Restore attempted?
Interesting - and after getting hot it got properly Random. Some rev #25's and #27's "NOT WORKING" and +/- ethernet
... from above
>> MIMXRT1026 DVJ6B 1N00X CTDP2138G revision 27, 0xE51188A5 with ETHERNET, start above 35.25862
and
>>>>>>> Temperature 38.275864 jj==00000000 00000000 D26702E2
. . . . . . . . .
Serial : E51188A5


So, it might start at 35+ or not until 38+
 
As suggested, I performed the 15-second restore (holding the PROGRAM button).
The board reset correctly but the TRNG behavior remains the same.

For reference, this board is running in secure mode with JTAG disabled.

I slightly modified the test program to also print TRNG_ENT0, TRNG_MCTL, and TRNG_STATUS along with the Entropy.random() output.


Relevant code snippet:
C++:
Serial.printf(
"Temperature %f %08X %08X %08X TRNG_ENT0:%08X; TRNG_MCTL:%08X; TRNG_STATUS:%08X\n",
tempmonGetTemp(),
Entropy.random(),
Entropy.random(),
Entropy.random(),
TRNG_ENT0,
TRNG_MCTL,
TRNG_STATUS
);
Example log from one board (silicon revision 27):
Markdown (GitHub flavored):
Startup

F_CPU: 150000000    F_CPU_ACTUAL: 151200000
Silicon revision: 27
Serial : E51188A5
Temperature 33.448277 00000000 00000000 00000000 TRNG_ENT0:00000000; TRNG_MCTL:00000202; TRNG_STATUS:0001EBFF

>>>>>>>   Temperature 33.448277 jj==00000000 00000000 00000000 TRNG_ENT0:00000000; TRNG_MCTL:00000202; TRNG_STATUS:0001E403
.
>>>>>>>   Temperature 35.258621 jj==00000000 00000000 00000000 TRNG_ENT0:00000000; TRNG_MCTL:00003302; TRNG_STATUS:0001CFFF

>>>>>>>   Temperature 36.465519 jj==00000000 00000000 00000000 TRNG_ENT0:00000000; TRNG_MCTL:00003302; TRNG_STATUS:0001CFFF

>>>>>>>   Temperature 37.068966 jj==00000000 00000000 00000000 TRNG_ENT0:00000000; TRNG_MCTL:00003302; TRNG_STATUS:0001CFFF

>>>>>>>   Temperature 37.068966 jj==00000000 00000000 00000000 TRNG_ENT0:00000000; TRNG_MCTL:00000202; TRNG_STATUS:0001EBFF

>>>>>>>   Temperature 37.672413 jj==00000000 00000000 00000000 TRNG_ENT0:E000911B; TRNG_MCTL:00002602; TRNG_STATUS:00010000

>>>>>>>   Temperature 37.672413 jj==00000000 00000000 00000000 TRNG_ENT0:E000911B; TRNG_MCTL:00002602; TRNG_STATUS:00010000

>>>>>>>   Temperature 37.672413 jj==00000000 00000000 00000000 TRNG_ENT0:E000911B; TRNG_MCTL:00002602; TRNG_STATUS:00010000

>>>>>>>   Temperature 38.275864 jj==00000000 00000000 00000000 TRNG_ENT0:E000911B; TRNG_MCTL:00002602; TRNG_STATUS:00010000

>>>>>>>   Temperature 37.672413 jj==00000000 00000000 E000911B TRNG_ENT0:00000000; TRNG_MCTL:00000202; TRNG_STATUS:0001EFFF
. . . . . . . . .

F_CPU: 150000000    F_CPU_ACTUAL: 151200000
Silicon revision: 27
Serial : E51188A5
Temperature 38.275864 0F281D55 9B2DE889 7A4287EB TRNG_ENT0:00000000; TRNG_MCTL:00000202; TRNG_STATUS:0001EFFF
. . . . . . . . . .

F_CPU: 150000000    F_CPU_ACTUAL: 151200000
Silicon revision: 27
Serial : E51188A5
Temperature 38.879311 FDA75A9E 993C9965 D1294F8F TRNG_ENT0:0E15B926; TRNG_MCTL:00002602; TRNG_STATUS:00010000
. . . . . . . . . .

F_CPU: 150000000    F_CPU_ACTUAL: 151200000
Silicon revision: 27
Serial : E51188A5
Temperature 38.879311 5256ECCA 80CB3710 92D17C61 TRNG_ENT0:BCA638B2; TRNG_MCTL:00002602; TRNG_STATUS:00010000
. . . . . . . . . .

F_CPU: 150000000    F_CPU_ACTUAL: 151200000
Silicon revision: 27
Serial : E51188A5
Temperature 38.879311 2C420C4D 0FD33FDD 36A009CF TRNG_ENT0:00000000; TRNG_MCTL:00000202; TRNG_STATUS:0001EBFF
. . . . . . . . . .

F_CPU: 150000000    F_CPU_ACTUAL: 151200000
Silicon revision: 27
Serial : E51188A5
Temperature 38.879311 C944A41B 86D1D542 4A0BEEE1 TRNG_ENT0:AE2CD510; TRNG_MCTL:00002602; TRNG_STATUS:00010000
. . . . . . . . . .
 
15s Restore was just a hope it might ...

Yes, 5 here are on various PCB and 1 not - the temps on the same desk are all over the place with some few degrees spread.

Wonder if repeat of { Entropy.Initialize(); jj=Entropy.random(); } until JJ not zero might do anything?
 
I performed additional tests on 13 more Teensy 4.1 boards marked:

MIMXRT1062 1N00X CTDV2144J

Out of these boards, only two started generating random numbers immediately after power-up.
The remaining boards required heating with warm air before the TRNG began producing values.

On some boards the TRNG only started working when the MCU temperature exceeded about 40 °C (according to the internal temperature sensor).

For these tests I slightly modified the code so that the TRNG is reinitialized before each attempt:
C++:
     Entropy.Initialize();
      int jj = Entropy.random();
      if ( 0 == jj ) { ...

For example, one board (silicon revision 25, serial E5124FB3, lockable but not locked) was cooled down to -8 °C.
After each temperature step I cycled the USB power and checked whether the TRNG started generating values.
In this case the generator started producing values when the temperature reached approximately 14–16 °C.
Markdown (GitHub flavored):
 Startup

F_CPU: 150000000    F_CPU_ACTUAL: 151200000
Silicon revision: 25
Serial : E5124FB3
Temperature -8.125000 00000000 00000000 00000000 TRNG_ENT0:00000000; TRNG_MCTL:00000202; TRNG_STATUS:0001EBFF

>>>>>>>   Temperature -8.125000 jj==00000000 00000000 00000000 TRNG_ENT0:00000000; TRNG_MCTL:00000202; TRNG_STATUS:0001EBFF

 Startup

F_CPU: 150000000    F_CPU_ACTUAL: 151200000
Silicon revision: 25
Serial : E5124FB3
Temperature 0.625000 00000000 00000000 00000000 TRNG_ENT0:00000000; TRNG_MCTL:00000202; TRNG_STATUS:0001EBFF

>>>>>>>   Temperature 0.625000 jj==00000000 00000000 00000000 TRNG_ENT0:00000000; TRNG_MCTL:00000202; TRNG_STATUS:0001EBFF

 Startup

F_CPU: 150000000    F_CPU_ACTUAL: 151200000
Silicon revision: 25
Serial : E5124FB3
Temperature 3.750000 00000000 00000000 00000000 TRNG_ENT0:00000000; TRNG_MCTL:00000202; TRNG_STATUS:0001EBFF

>>>>>>>   Temperature 3.750000 jj==00000000 00000000 00000000 TRNG_ENT0:00000000; TRNG_MCTL:00000202; TRNG_STATUS:0001EBFF

 Startup

F_CPU: 150000000    F_CPU_ACTUAL: 151200000
Silicon revision: 25
Serial : E5124FB3
Temperature 6.875000 00000000 00000000 00000000 TRNG_ENT0:00000000; TRNG_MCTL:00000202; TRNG_STATUS:0001EBFF

>>>>>>>   Temperature 7.500000 jj==00000000 00000000 00000000 TRNG_ENT0:00000000; TRNG_MCTL:00000202; TRNG_STATUS:0001EBFF

 Startup

F_CPU: 150000000    F_CPU_ACTUAL: 151200000
Silicon revision: 25
Serial : E5124FB3
Temperature 9.375000 00000000 00000000 00000000 TRNG_ENT0:00000000; TRNG_MCTL:00000202; TRNG_STATUS:0001EBFF

>>>>>>>   Temperature 9.375000 jj==00000000 00000000 00000000 TRNG_ENT0:00000000; TRNG_MCTL:00000202; TRNG_STATUS:0001E2FF

 Startup

F_CPU: 150000000    F_CPU_ACTUAL: 151200000
Silicon revision: 25
Serial : E5124FB3
Temperature 11.250000 00000000 00000000 00000000 TRNG_ENT0:00000000; TRNG_MCTL:00000202; TRNG_STATUS:0001EBFF

>>>>>>>   Temperature 11.250000 jj==00000000 00000000 00000000 TRNG_ENT0:00000000; TRNG_MCTL:00000202; TRNG_STATUS:0001EBFF

 Startup

F_CPU: 150000000    F_CPU_ACTUAL: 151200000
Silicon revision: 25
Serial : E5124FB3
Temperature 11.875000 00000000 00000000 00000000 TRNG_ENT0:00000000; TRNG_MCTL:00000202; TRNG_STATUS:0001EBFF

>>>>>>>   Temperature 11.875000 jj==00000000 00000000 00000000 TRNG_ENT0:00000000; TRNG_MCTL:00000202; TRNG_STATUS:0001EBFF

 Startup

F_CPU: 150000000    F_CPU_ACTUAL: 151200000
Silicon revision: 25
Serial : E5124FB3
Temperature 13.125000 00000000 00000000 00000000 TRNG_ENT0:00000000; TRNG_MCTL:00000202; TRNG_STATUS:0001EBFF

>>>>>>>   Temperature 13.125000 jj==00000000 00000000 00000000 TRNG_ENT0:00000000; TRNG_MCTL:00000202; TRNG_STATUS:0001EBFF

 Startup

F_CPU: 150000000    F_CPU_ACTUAL: 151200000
Silicon revision: 25
Serial : E5124FB3
Temperature 14.375000 00000000 00000000 00000000 TRNG_ENT0:00000000; TRNG_MCTL:00000202; TRNG_STATUS:0001EBFF

>>>>>>>   Temperature 13.750000 jj==00000000 00000000 00000000 TRNG_ENT0:00000000; TRNG_MCTL:00000202; TRNG_STATUS:0001EBFF

 Startup

F_CPU: 150000000    F_CPU_ACTUAL: 151200000
Silicon revision: 25
Serial : E5124FB3
Temperature 14.375000 00000000 00000000 00000000 TRNG_ENT0:00000000; TRNG_MCTL:00000202; TRNG_STATUS:0001EBFF

>>>>>>>   Temperature 15.000000 jj==00000000 00000000 00000000 TRNG_ENT0:00000000; TRNG_MCTL:00000202; TRNG_STATUS:0001EBFF

 Startup

F_CPU: 150000000    F_CPU_ACTUAL: 151200000
Silicon revision: 25
Serial : E5124FB3
Temperature 15.625000 00000000 00000000 00000000 TRNG_ENT0:00000000; TRNG_MCTL:00000202; TRNG_STATUS:0001EBFF

>>>>>>>   Temperature 15.625000 jj==00000000 00000000 00000000 TRNG_ENT0:00000000; TRNG_MCTL:00000202; TRNG_STATUS:0001EBFF

 Startup

F_CPU: 150000000    F_CPU_ACTUAL: 151200000
Silicon revision: 25
Serial : E5124FB3
Temperature 16.250000 00000000 00000000 00000000 TRNG_ENT0:00000000; TRNG_MCTL:00000202; TRNG_STATUS:0001EBFF

>>>>>>>   Temperature 15.625000 jj==00000000 00000000 00000000 TRNG_ENT0:00000000; TRNG_MCTL:00000202; TRNG_STATUS:0001EBFF

 Startup

F_CPU: 150000000    F_CPU_ACTUAL: 151200000
Silicon revision: 25
Serial : E5124FB3
Temperature 16.875000 547DBE38 C7E322E5 5CCC643E TRNG_ENT0:00000000; TRNG_MCTL:00000202; TRNG_STATUS:0001EBFF
. . . . . . . . . .

F_CPU: 150000000    F_CPU_ACTUAL: 151200000
Silicon revision: 25
Serial : E5124FB3
Temperature 21.250000 4B211133 C70FEEF6 66F00857 TRNG_ENT0:F8A24C0C; TRNG_MCTL:00002602; TRNG_STATUS:00010000
.

The same Teensy board was then cooled again, but this time without disconnecting USB during warm-up.
In this case the TRNG started generating values at around 20–24 °C.

Markdown (GitHub flavored):
 Startup

F_CPU: 150000000    F_CPU_ACTUAL: 151200000
Silicon revision: 25
Serial : E5124FB3
Temperature -6.875000 00000000 00000000 00000000 TRNG_ENT0:00000000; TRNG_MCTL:00000202; TRNG_STATUS:0001EBFF

>>>>>>>   Temperature -6.875000 jj==00000000 00000000 00000000 TRNG_ENT0:00000000; TRNG_MCTL:00000202; TRNG_STATUS:0001EBFF
.
>>>>>>>   Temperature 1.875000 jj==00000000 00000000 00000000 TRNG_ENT0:00000000; TRNG_MCTL:00000302; TRNG_STATUS:0001EBFF

>>>>>>>   Temperature 7.500000 jj==00000000 00000000 00000000 TRNG_ENT0:00000000; TRNG_MCTL:00000302; TRNG_STATUS:0001EBFF

>>>>>>>   Temperature 10.625000 jj==00000000 00000000 00000000 TRNG_ENT0:00000000; TRNG_MCTL:00000302; TRNG_STATUS:0001EBFF

>>>>>>>   Temperature 13.750000 jj==00000000 00000000 00000000 TRNG_ENT0:00000000; TRNG_MCTL:00000202; TRNG_STATUS:0001EBFF

>>>>>>>   Temperature 15.000000 jj==00000000 00000000 00000000 TRNG_ENT0:00000000; TRNG_MCTL:00000202; TRNG_STATUS:0001EBFF

>>>>>>>   Temperature 16.875000 jj==00000000 00000000 00000000 TRNG_ENT0:00000000; TRNG_MCTL:00000202; TRNG_STATUS:0001EBFF

>>>>>>>   Temperature 18.125000 jj==00000000 00000000 00000000 TRNG_ENT0:00000000; TRNG_MCTL:00000202; TRNG_STATUS:0001EBFF

>>>>>>>   Temperature 19.375000 jj==00000000 00000000 00000000 TRNG_ENT0:00000000; TRNG_MCTL:00000202; TRNG_STATUS:0001EBFF

>>>>>>>   Temperature 20.000000 jj==00000000 00000000 8A80730B TRNG_ENT0:00000000; TRNG_MCTL:00000202; TRNG_STATUS:0001EFFF
. . . . . . . . .

F_CPU: 150000000    F_CPU_ACTUAL: 151200000
Silicon revision: 25
Serial : E5124FB3
Temperature 22.500000 82727BA1 F9A8B64E AD63722E TRNG_ENT0:00000000; TRNG_MCTL:00000202; TRNG_STATUS:0001EFFF
. . . . . . . . . .

F_CPU: 150000000    F_CPU_ACTUAL: 151200000
Silicon revision: 25
Serial : E5124FB3
Temperature 23.750000 7453B36A AD5922FA AB4759C6 TRNG_ENT0:DA52B9D8; TRNG_MCTL:00002602; TRNG_STATUS:00010000
. . . . . . . . . .
 
After some more testing I think I may have found the reason for the TRNG behaviour I described earlier.

While looking at the initialization code in Entropy.cpp I noticed that the library explicitly overrides the value of TRNG_DEFAULT_ENTROPY_DELAY:

#undef TRNG_DEFAULT_ENTROPY_DELAY
#define TRNG_DEFAULT_ENTROPY_DELAY 0x320 // not 3200 as is in imxrt.h

TRNG_SDCTL = TRNG_SDCTL_ENT_DLY(TRNG_DEFAULT_ENTROPY_DELAY) |
TRNG_SDCTL_SAMP_SIZE(TRNG_DEFAULT_SAMPLE_SIZE);
In imxrt.h however the value is defined as:

#define TRNG_DEFAULT_ENTROPY_DELAY 3200

To understand which value is actually correct I reset the TRNG configuration to hardware defaults using:
TRNG_MCTL |= TRNG_MCTL_RST_DEF;
After this reset the value of TRNG_SDCTL is: 0x032009C4
When using 0x320, the TRNG starts producing random numbers immediately and continues to work reliably even at sub-zero temperatures.
 
TD 1.60 Code search here doesn't show override and the #undef and re - #define in the cpp?

Great though if that change results in proper function independent of temp/device.

Code:
T:\T_Drive\arduino-1.8.19\hardware\teensy\avr\cores\teensy4\imxrt.h:
 9049  #define TRNG_SCR6PL_RUN6P_MAX(n)    ((uint32_t)(((n) & 0x07FF) << 0))
 9050  // defaults from NXP's SDK (fsl_trng.c)
 9051: #define TRNG_DEFAULT_ENTROPY_DELAY    3200
 9052  #define TRNG_DEFAULT_SAMPLE_SIZE    2500
 9053  #define TRNG_DEFAULT_SPARSE_BIT_LIMIT    63

T:\T_Drive\arduino-1.8.19\hardware\teensy\avr\libraries\Entropy\Entropy.cpp:
  121    TRNG_FRQMAX = TRNG_DEFAULT_FREQUENCY_MAXIMUM;
  122    TRNG_FRQMIN = TRNG_DEFAULT_FREQUENCY_MINIMUM;
  123:   TRNG_SDCTL = TRNG_SDCTL_ENT_DLY(TRNG_DEFAULT_ENTROPY_DELAY) |
  124                  TRNG_SDCTL_SAMP_SIZE(TRNG_DEFAULT_SAMPLE_SIZE);
  125    TRNG_SBLIM = TRNG_DEFAULT_SPARSE_BIT_LIMIT;
 
After some more testing I think I may have found the reason for the TRNG behaviour I described earlier.

While looking at the initialization code in Entropy.cpp I noticed that the library explicitly overrides the value of TRNG_DEFAULT_ENTROPY_DELAY:

#undef TRNG_DEFAULT_ENTROPY_DELAY
#define TRNG_DEFAULT_ENTROPY_DELAY 0x320 // not 3200 as is in imxrt.h

TRNG_SDCTL = TRNG_SDCTL_ENT_DLY(TRNG_DEFAULT_ENTROPY_DELAY) |
TRNG_SDCTL_SAMP_SIZE(TRNG_DEFAULT_SAMPLE_SIZE);
In imxrt.h however the value is defined as:

#define TRNG_DEFAULT_ENTROPY_DELAY 3200

To understand which value is actually correct I reset the TRNG configuration to hardware defaults using:
TRNG_MCTL |= TRNG_MCTL_RST_DEF;
After this reset the value of TRNG_SDCTL is: 0x032009C4
When using 0x320, the TRNG starts producing random numbers immediately and continues to work reliably even at sub-zero temperatures.
Difficult question : are the numbers really random? Off course all zeroes is the worst...
 
TD 1.60 Code search here doesn't show override and the #undef and re - #define in the cpp?

Great though if that change results in proper function independent of temp/device.

Code:
T:\T_Drive\arduino-1.8.19\hardware\teensy\avr\cores\teensy4\imxrt.h:
 9049  #define TRNG_SCR6PL_RUN6P_MAX(n)    ((uint32_t)(((n) & 0x07FF) << 0))
 9050  // defaults from NXP's SDK (fsl_trng.c)
 9051: #define TRNG_DEFAULT_ENTROPY_DELAY    3200
 9052  #define TRNG_DEFAULT_SAMPLE_SIZE    2500
 9053  #define TRNG_DEFAULT_SPARSE_BIT_LIMIT    63

T:\T_Drive\arduino-1.8.19\hardware\teensy\avr\libraries\Entropy\Entropy.cpp:
  121    TRNG_FRQMAX = TRNG_DEFAULT_FREQUENCY_MAXIMUM;
  122    TRNG_FRQMIN = TRNG_DEFAULT_FREQUENCY_MINIMUM;
  123:   TRNG_SDCTL = TRNG_SDCTL_ENT_DLY(TRNG_DEFAULT_ENTROPY_DELAY) |
  124                  TRNG_SDCTL_SAMP_SIZE(TRNG_DEFAULT_SAMPLE_SIZE);
  125    TRNG_SBLIM = TRNG_DEFAULT_SPARSE_BIT_LIMIT;
Difficult question : are the numbers really random? Off course all zeroes is the worst...
I modified Entropy.cpp to test whether it works. Below is the code I added:
#undef TRNG_DEFAULT_ENTROPY_DELAY
#define TRNG_DEFAULT_ENTROPY_DELAY 0x320 // not 3200 as is in imxrt.h
by the way comment out line
123: TRNG_SDCTL = TRNG_SDCTL_ENT_DLY(TRNG_DEFAULT_ENTROPY_DELAY) |
124 TRNG_SDCTL_SAMP_SIZE(TRNG_DEFAULT_SAMPLE_SIZE);
it also works.
 
This seems... feasible. This is also from NXP's source code (found on the net, I have not signed any NDA!):
/*******************************************************************************
* TRNG_SDCTL - RNG Seed Control Register
******************************************************************************/
/*!
* @brief TRNG_SDCTL - RNG Seed Control Register (RW)
*
* Reset value: 0x0C8009C4U
*
* The RNG Seed Control Register contains two fields. One field defines the
* length (in system clocks) of each Entropy sample (ENT_DLY), and the other field
* indicates the number of samples that will taken during each TRNG Entropy
* generation (SAMP_SIZE).
*/
/*!
* @name Register TRNG_SDCTL, field ENT_DLY[31:16] (RW)
*
* Entropy Delay. Defines the length (in system clocks) of each Entropy sample
* taken. This field is writable only if MCTL[PRGM] bit is 1. This field will read
* zeroes if MCTL[PRGM] = 0. This field is cleared to 0C80h (decimal 3200) by
* writing the MCTL[RST_DEF] bit to 1.
*/
Note the listed reset value: 0x0C80 matches their #define of 3200, but apparently this is not the correct reset value for this hardware.
 
Back
Top