STM32L443xx HAL User Manual
Functions
Peripheral Control functions
RNG Exported Functions

Peripheral Control functions. More...

Functions

HAL_StatusTypeDef HAL_RNG_GenerateRandomNumber (RNG_HandleTypeDef *hrng, uint32_t *random32bit)
 Generates a 32-bit random number.
HAL_StatusTypeDef HAL_RNG_GenerateRandomNumber_IT (RNG_HandleTypeDef *hrng)
 Generates a 32-bit random number in interrupt mode.
uint32_t HAL_RNG_GetRandomNumber (RNG_HandleTypeDef *hrng)
 Returns generated random number in polling mode (Obsolete) Use HAL_RNG_GenerateRandomNumber() API instead.
uint32_t HAL_RNG_GetRandomNumber_IT (RNG_HandleTypeDef *hrng)
 Returns a 32-bit random number with interrupt enabled (Obsolete), Use HAL_RNG_GenerateRandomNumber_IT() API instead.
void HAL_RNG_IRQHandler (RNG_HandleTypeDef *hrng)
 Handles RNG interrupt request.
uint32_t HAL_RNG_ReadLastRandomNumber (RNG_HandleTypeDef *hrng)
 Read latest generated random number.
__weak void HAL_RNG_ReadyDataCallback (RNG_HandleTypeDef *hrng, uint32_t random32bit)
 Data Ready callback in non-blocking mode.
__weak void HAL_RNG_ErrorCallback (RNG_HandleTypeDef *hrng)
 RNG error callbacks.

Detailed Description

Peripheral Control functions.

 ===============================================================================
                      ##### Peripheral Control functions #####
 ===============================================================================
    [..]  This section provides functions allowing to:
      (+) Get the 32 bit Random number
      (+) Get the 32 bit Random number with interrupt enabled
      (+) Handle RNG interrupt request


Function Documentation

RNG error callbacks.

Parameters:
hrngpointer to a RNG_HandleTypeDef structure that contains the configuration information for RNG.
Return values:
None

Definition at line 922 of file stm32l4xx_hal_rng.c.

Referenced by HAL_RNG_Init(), HAL_RNG_IRQHandler(), and HAL_RNG_UnRegisterCallback().

HAL_StatusTypeDef HAL_RNG_GenerateRandomNumber ( RNG_HandleTypeDef hrng,
uint32_t *  random32bit 
)

Generates a 32-bit random number.

Note:
When several random data are output at the same time in an output buffer, this function checks value of RNG_FLAG_DRDY flag to know if valid random number is available in the DR register (RNG_FLAG_DRDY flag set whenever a random number is available through the RNG_DR register). After transitioning from 0 to 1 (random number available), RNG_FLAG_DRDY flag remains high until output buffer becomes empty after reading four words from the RNG_DR register, i.e. further function calls will immediately return a new u32 random number (additional words are available and can be read by the application, till RNG_FLAG_DRDY flag remains high). When no more random number data is available in DR register, RNG_FLAG_DRDY flag is automatically cleared. When random number are out on a single sample basis, each time the random number data is read the RNG_FLAG_DRDY flag is automatically cleared.
Parameters:
hrngpointer to a RNG_HandleTypeDef structure that contains the configuration information for RNG.
random32bitpointer to generated random number variable if successful.
Return values:
HALstatus

Definition at line 667 of file stm32l4xx_hal_rng.c.

References __HAL_RNG_GET_FLAG, __RNG_HandleTypeDef::ErrorCode, HAL_GetTick(), HAL_RNG_ERROR_BUSY, HAL_RNG_ERROR_TIMEOUT, HAL_RNG_STATE_BUSY, HAL_RNG_STATE_READY, __RNG_HandleTypeDef::Instance, __RNG_HandleTypeDef::RandomNumber, RNG_FLAG_DRDY, RNG_TIMEOUT_VALUE, and __RNG_HandleTypeDef::State.

Referenced by HAL_RNG_GetRandomNumber().

HAL_StatusTypeDef HAL_RNG_GenerateRandomNumber_IT ( RNG_HandleTypeDef hrng)

Generates a 32-bit random number in interrupt mode.

Parameters:
hrngpointer to a RNG_HandleTypeDef structure that contains the configuration information for RNG.
Return values:
HALstatus

Definition at line 721 of file stm32l4xx_hal_rng.c.

References __HAL_RNG_ENABLE_IT, __RNG_HandleTypeDef::ErrorCode, HAL_RNG_ERROR_BUSY, HAL_RNG_STATE_BUSY, HAL_RNG_STATE_READY, and __RNG_HandleTypeDef::State.

Returns generated random number in polling mode (Obsolete) Use HAL_RNG_GenerateRandomNumber() API instead.

Parameters:
hrngpointer to a RNG_HandleTypeDef structure that contains the configuration information for RNG.
Return values:
Randomvalue

Definition at line 756 of file stm32l4xx_hal_rng.c.

References HAL_RNG_GenerateRandomNumber(), and __RNG_HandleTypeDef::RandomNumber.

Returns a 32-bit random number with interrupt enabled (Obsolete), Use HAL_RNG_GenerateRandomNumber_IT() API instead.

Parameters:
hrngpointer to a RNG_HandleTypeDef structure that contains the configuration information for RNG.
Return values:
32-bitrandom number

Definition at line 775 of file stm32l4xx_hal_rng.c.

References __HAL_RNG_ENABLE_IT, HAL_RNG_STATE_BUSY, __RNG_HandleTypeDef::Instance, and __RNG_HandleTypeDef::State.

Handles RNG interrupt request.

Note:
In the case of a clock error, the RNG is no more able to generate random numbers because the PLL48CLK clock is not correct. User has to check that the clock controller is correctly configured to provide the RNG clock and clear the CEIS bit using __HAL_RNG_CLEAR_IT(). The clock error has no impact on the previously generated random numbers, and the RNG_DR register contents can be used.
In the case of a seed error, the generation of random numbers is interrupted as long as the SECS bit is '1'. If a number is available in the RNG_DR register, it must not be used because it may not have enough entropy. In this case, it is recommended to clear the SEIS bit using __HAL_RNG_CLEAR_IT(), then disable and enable the RNG peripheral to reinitialize and restart the RNG.
User-written HAL_RNG_ErrorCallback() API is called once whether SEIS or CEIS are set.
Parameters:
hrngpointer to a RNG_HandleTypeDef structure that contains the configuration information for RNG.
Return values:
None

Definition at line 816 of file stm32l4xx_hal_rng.c.

References __HAL_RNG_CLEAR_IT, __HAL_RNG_DISABLE_IT, __HAL_RNG_GET_IT, __RNG_HandleTypeDef::ErrorCallback, __RNG_HandleTypeDef::ErrorCode, HAL_RNG_ERROR_CLOCK, HAL_RNG_ERROR_SEED, HAL_RNG_ErrorCallback(), HAL_RNG_ReadyDataCallback(), HAL_RNG_STATE_ERROR, HAL_RNG_STATE_READY, __RNG_HandleTypeDef::Instance, __RNG_HandleTypeDef::RandomNumber, __RNG_HandleTypeDef::ReadyDataCallback, RNG_IT_CEI, RNG_IT_DRDY, RNG_IT_SEI, and __RNG_HandleTypeDef::State.

Read latest generated random number.

Parameters:
hrngpointer to a RNG_HandleTypeDef structure that contains the configuration information for RNG.
Return values:
randomvalue

Definition at line 888 of file stm32l4xx_hal_rng.c.

References __RNG_HandleTypeDef::RandomNumber.

void HAL_RNG_ReadyDataCallback ( RNG_HandleTypeDef hrng,
uint32_t  random32bit 
)

Data Ready callback in non-blocking mode.

Note:
When several random data are output at the same time in an output buffer, When RNG_FLAG_DRDY flag value is set, first random number has been read from DR register in IRQ Handler and is provided as callback parameter. Depending on valid data available in the conditioning output buffer, additional words can be read by the application from DR register till DRDY bit remains high.
Parameters:
hrngpointer to a RNG_HandleTypeDef structure that contains the configuration information for RNG.
random32bitgenerated random number.
Return values:
None

Definition at line 906 of file stm32l4xx_hal_rng.c.

Referenced by HAL_RNG_Init(), HAL_RNG_IRQHandler(), and HAL_RNG_UnRegisterReadyDataCallback().