Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nrfx_rng driver #43

Open
lilindian16 opened this issue Apr 9, 2024 · 1 comment
Open

nrfx_rng driver #43

lilindian16 opened this issue Apr 9, 2024 · 1 comment

Comments

@lilindian16
Copy link

lilindian16 commented Apr 9, 2024

Board: generic_nrf52840

This is a dumb question. How do I enable the RNG driver (cores/nRF5/nordic/nrfx/drivers/include/nrfx_rng.h)? I have included the driver in my source file. I have added -DNRFX_RNG_ENABLED to the build_flags in my platformio.ini

Building results in undefined reference to nrfx_rng_init and undefined reference to nrfx_rng_uninit

My current code:

bool rngGenerated = false;
uint8_t rngNumber;

void rngEventHandler(uint8_t randomNumber)
{
  rngGenerated = true;
  rngNumber = randomNumber;
}

void generateRandomNumber(uint8_t *dataBuffer, uint8_t bytesToGenerate)
{
  uint8_t numbersGenerated = 0;
  nrfx_rng_config_t config = NRFX_RNG_DEFAULT_CONFIG;
  nrfx_rng_evt_handler_t eventHandler = &rngEventHandler;
  nrfx_rng_init(&config, eventHandler);

  while (numbersGenerated < bytesToGenerate)
  {
    if (rngGenerated)
    {
      dataBuffer[numbersGenerated] = rngNumber;
      rngGenerated = false;
      numbersGenerated++;
    }
    delay(1);
  }
  nrfx_rng_uninit();
}

Any help would be much appreciated :)

@h2zero
Copy link
Owner

h2zero commented Apr 20, 2024

I don't think that code is included currently. I would need to add it, might be time to update nrfx as well. Any particular reason to use this over the other options?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants