This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

RNG interrupt handler not called

RNG interrupt handler is not called.

Using nrfx_rng library to generate random numbers.

VALRDY event is generated but interrupt handler nrfx_rng_irq_handler in library is not called.

Breakpoint not hit.

Despite EVENTS_VALRDY being set.

and INTENSET/ NVIC_ISER0 having correct values.

Code which sets up RNG using nrfx_rng library

ren_status_t generateRand(uint8_t * p_challenge)
{
ren_status_t return_value = RAND_ERROR;

static const nrfx_rng_config_t RNG_CONFIG = {
.error_correction = true,
.interrupt_priority = RNG_INTERRUPT_PRIORITY
};

assert(p_challenge != NULL);

challenge_pointer = p_challenge;

/* Reset random number counter. */
random_number_index = 0U;

/* Initialise random number generator. */
if (NRF_SUCCESS == nrfx_rng_init(&RNG_CONFIG, randomNumberEventHandler))
{
/* Start random number generator. */
nrfx_rng_start();

/* Wait for required number of random numbers to be generated. */
while(random_number_index < RAND_SIZE);

/* Stop random number generator. */
nrfx_rng_stop();

/* Uninitialise random number generator. */
nrfx_rng_uninit();

return_value = RAND_SUCCESS;
}

return return_value;
}



static void randomNumberEventHandler(uint8_t rng_data)
{
assert(challenge_pointer != NULL);

/* Store random number in appropriate location in challenge. */
rand_pointer[random_number_index] = rng_data;

/* Move on to next location. */
random_number_index++;
}

Any ideas ?

Parents Reply Children
  • In the end, as this is a relatively simple peripheral, I decided to access the hardware directly. Works fine.

    void generateRandomNumbers(uint8_t * p_random_numbers)
    {
       assert(p_random_numbers != NULL);
    
       random_number_pointer = p_random_numbers;
    
       /* Reset random number counter. */
       random_number_index = 0U;
    
       /* Initialise random number generator. */
    
       /* Configure for bias correction. */
       NRF_RNG->CONFIG = RNG_CONFIG_DERCEN_Enabled << RNG_CONFIG_DERCEN_Pos;
    
       /* Enable value ready interrupt. */
       sd_nvic_EnableIRQ(RNG_IRQn);
    
       NRF_RNG->INTENSET = RNG_INTENSET_VALRDY_Enabled << RNG_INTENSET_VALRDY_Pos;
    
       /* Start random number generation. */
       NRF_RNG->TASKS_START = 1U;
    
       /* Wait for required number of random numbers to be generated. */
       while(random_number_index < CHALLENGE_LEN);
    
       /* Stop random number generator. */
       NRF_RNG->TASKS_STOP = 1U;
    }
    
    
    void RNG_IRQHandler(void)
    {
       /* Random value ready. */
    
       /* Clear event. */
       NRF_RNG->EVENTS_VALRDY = 0U;
    
       random_number_pointer[random_number_index] = NRF_RNG->VALUE;
    
       /* Move on to next location. */
       random_number_index++;
    }
    

Related