Skip to main content
Anvi
Associate III
September 10, 2021
Solved

STM32F207 RNG Interrupt

  • September 10, 2021
  • 1 reply
  • 1752 views

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

This topic has been closed for replies.
Best answer by TDK

You need to enable the interrupt in NVIC as well.

HAL_NVIC_EnableIRQ(RNG_IRQn);

1 reply

TDK
TDKBest answer
Super User
September 11, 2021

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
AnviAuthor
Associate III
September 11, 2021

:grinning_face_with_sweat: That was it! Thanks