cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F207 RNG Interrupt

Anvi
Associate III

Hello,

I'm having trouble getting the interrupt for the RNG on the STM32F207 to trigger. Below is a code snippet of what I'm doing;.

void generate_rnd_num(uint32_t *rnd_num)
{
    RNG_HandleTypeDef rng_handler;
    rng_handler.Instance = RNG // Point to RNG Peripheral base addr (RNG_BASE  =  (AHB2PERIPH_BASE + 0x60800))
 
    __RNG_CLK_ENABLE();  // Enable RNG Clock: (RCC->AHB2ENR |= (RCC_AHB2ENR_RNGEN))
    __HAL_RNG_ENABLE(&rng_handler) // Enale RNG Peripheral: ((__HANDLE__)->Instance->CR |=  RNG_CR_RNGEN)
 
    __HAL_RNG_ENABLE_IT(&rng_handler) // Enable RNG Interrupts: ((__HANDLE__)->Instance->CR |=  RNG_CR_IE)
 
...
// Waiting for a sempahore to be released
...
}
 
/* --------------------------- STM HAL  --------------------------- */
void HAL_RNG_IRQHandler(RNG_HandleTypeDef *hrng)
{
 
    ...
 
  /* Check RNG data ready flag */    
  if(__HAL_RNG_GET_FLAG(hrng, RNG_FLAG_DRDY) != RESET)
  {
    /* Data Ready callback */ 
    HAL_RNG_ReadyCallback(hrng);
    
    /* Change RNG peripheral state */
    hrng->State = HAL_RNG_STATE_READY; 
      
    /* Clear the RNG Data Ready flag */
    __HAL_RNG_CLEAR_FLAG(hrng, RNG_FLAG_DRDY);
    
    /* Process Unlocked */
    __HAL_UNLOCK(hrng);
  }
} 
/* --------------------------- STM HAL  --------------------------- */
 
void HAL_RNG_ReadyCallback(RNG_HandleTypeDef* hrng)
{
 
    // Release semaphore
}

The IRQ handler (HAL_RNG_IRQHandler) is never reached. I should mention that polling for the random number works; the interrupt is just not triggering. The vector table also contains the correct IRQ handler and its definition calls HAL_RNG_ReadyCallback. Am I missing something?

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

You need to enable the interrupt in NVIC as well.

HAL_NVIC_EnableIRQ(RNG_IRQn);

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

2 REPLIES 2
TDK
Guru

You need to enable the interrupt in NVIC as well.

HAL_NVIC_EnableIRQ(RNG_IRQn);

If you feel a post has answered your question, please click "Accept as Solution".
Anvi
Associate III

😅 That was it! Thanks