[SOLVED] Arduino DUE 'pmc_enable_periph_clk' was not declared in this scope

Hi,

I'm trying to compile the following library for Arduino DUE:

GitHub - pmjdebruijn/Arduino-Entropy-Library: Arduino Entropy Library (Temporary Fork)

and i get the error:

sketch/Entropy.cpp: In member function 'void EntropyClass::initialize()':
Entropy.cpp:62:32: error: 'pmc_enable_periph_clk' was not declared in this scope
pmc_enable_periph_clk(ID_TRNG);
^

On the Arduino MEGA I found no problem.

I tried to install all the board manager versions for Arduino DUE.

I need a (almost) good generator of random bytes (uint8_t) without the need of external hardware, alternatives to this library and other solutions are welcome.
Thanks! :slight_smile:

The author of that fork of the Entropy library introduced a bug that broke Due compatibility with this commit:

I would recommend that you delete the fork from your computer and instead use the official version of the library:

I submitted a pull request to fix the bug in the fork:

Here is an example sketch to get a 32_bit true random number every us from a DUE:

/************************************************************************************/
/*     The True Random Number Generator (TRNG) on the DUE passes the American NIST  */
/*     Special Publication 800-22 and Diehard Random Tests Suites.                  */
/************************************************************************************/
#define TRNG_Key (0x524E47)
volatile uint32_t Random;

void setup() {
  PMC->PMC_PCER1 |= PMC_PCER1_PID41;                        // TRNG controller power ON
  TRNG->TRNG_CR = TRNG_CR_ENABLE | TRNG_CR_KEY(TRNG_Key);
  TRNG->TRNG_IER = TRNG_IER_DATRDY;
  NVIC_SetPriority(TRNG_IRQn, 0xFF);                        // Give TRNG interrupt the lowest urgency (if necessary )
  NVIC_EnableIRQ(TRNG_IRQn);

}

void loop() {
// Do something with Random, BUT do not Serial.print every Random 
// because any Serial.print takes several hundreds us !
}

/*     Fires every 1 us   ****/
void TRNG_Handler() {

  TRNG->TRNG_ISR;             // Clear status register
  Random = TRNG->TRNG_ODATA;  // Get 32_bit random value

}

I think the Entropy library is doing essentially the same thing. The advantage to using the library is that it also provides random number support for AVR and Teensy, making your code more portable.

Thanks to everyone for the help, I opted for the official version of the library to have more compatibility with other boards too.