Skip to content

nrfx_rng driver #43

Open
Open

Description

@lilindian16

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 :)

Activity

  1. h2zero commented on Apr 20, 2024

    @h2zero
    Owner

    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?

  2. tsl0922 commented on Dec 31, 2024

    @tsl0922
    Contributor

    @h2zero Any reason you just included the header without code? I'd like to use the rtc driver, but it's code is missing too.

  3. h2zero commented on Jan 2, 2025

    @h2zero
    Owner

    It was required by another file, no sure which. I will be looking to update the nrfx version soon and will include this as well.

  4. h2zero commented on Jan 16, 2025

    @h2zero
    Owner

    @tsl0922 @lilindian16 I was looking into this today and the reason it is not included is because the NimBLE core defines the RNG ISR so there is a conflict. However this actually simplifies things because you can simply do this:

    #include "nimble/nimble/controller/include/controller/ble_hw.h"
    
    uint8_t randomNumber = ble_hw_rng_read();
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions