STM32L4xx_HAL_Driver  1.14.0
Initialization and de-initialization functions

Initialization and de-initialization functions. More...

Functions

HAL_StatusTypeDef HAL_RNG_Init (RNG_HandleTypeDef *hrng)
 Initialize the RNG peripheral and initialize the associated handle. More...
 
HAL_StatusTypeDef HAL_RNG_DeInit (RNG_HandleTypeDef *hrng)
 DeInitialize the RNG peripheral. More...
 
void HAL_RNG_MspInit (RNG_HandleTypeDef *hrng)
 Initialize the RNG MSP. More...
 
void HAL_RNG_MspDeInit (RNG_HandleTypeDef *hrng)
 DeInitialize the RNG MSP. More...
 
HAL_StatusTypeDef HAL_RNG_RegisterCallback (RNG_HandleTypeDef *hrng, HAL_RNG_CallbackIDTypeDef CallbackID, pRNG_CallbackTypeDef pCallback)
 Register a User RNG Callback To be used instead of the weak predefined callback. More...
 
HAL_StatusTypeDef HAL_RNG_UnRegisterCallback (RNG_HandleTypeDef *hrng, HAL_RNG_CallbackIDTypeDef CallbackID)
 Unregister an RNG Callback RNG callabck is redirected to the weak predefined callback. More...
 
HAL_StatusTypeDef HAL_RNG_RegisterReadyDataCallback (RNG_HandleTypeDef *hrng, pRNG_ReadyDataCallbackTypeDef pCallback)
 Register Data Ready RNG Callback To be used instead of the weak HAL_RNG_ReadyDataCallback() predefined callback. More...
 
HAL_StatusTypeDef HAL_RNG_UnRegisterReadyDataCallback (RNG_HandleTypeDef *hrng)
 UnRegister the Data Ready RNG Callback Data Ready RNG Callback is redirected to the weak HAL_RNG_ReadyDataCallback() predefined callback. More...
 

Detailed Description

Initialization and de-initialization functions.

 ===============================================================================
          ##### Initialization and de-initialization functions #####
 ===============================================================================
    [..]  This section provides functions allowing to:
      (+) Initialize the RNG according to the specified parameters 
          in the RNG_InitTypeDef and create the associated handle
      (+) DeInitialize the RNG peripheral
      (+) Initialize the RNG MSP (MCU Specific Package)
      (+) DeInitialize the RNG MSP 

Function Documentation

◆ HAL_RNG_DeInit()

HAL_StatusTypeDef HAL_RNG_DeInit ( RNG_HandleTypeDef hrng)

DeInitialize the RNG peripheral.

Parameters
hrngpointer to a RNG_HandleTypeDef structure.
Return values
HALstatus

Definition at line 221 of file stm32l4xx_hal_rng.c.

222 {
223  /* Check the RNG handle allocation */
224  if(hrng == NULL)
225  {
226  return HAL_ERROR;
227  }
228 
229 #if defined(RNG_CR_CED)
230  /* Clear Clock Error Detection bit */
231  CLEAR_BIT(hrng->Instance->CR, RNG_CR_CED);
232 #endif /* defined(RNG_CR_CED) */
233 
234  /* Disable the RNG Peripheral */
235  CLEAR_BIT(hrng->Instance->CR, RNG_CR_IE | RNG_CR_RNGEN);
236 
237  /* Clear RNG interrupt status flags */
238  CLEAR_BIT(hrng->Instance->SR, RNG_SR_CEIS | RNG_SR_SEIS);
239 
240 #if (USE_HAL_RNG_REGISTER_CALLBACKS == 1)
241  if(hrng->MspDeInitCallback == NULL)
242  {
243  hrng->MspDeInitCallback = HAL_RNG_MspDeInit; /* Legacy weak MspDeInit */
244  }
245 
246  /* DeInit the low level hardware */
247  hrng->MspDeInitCallback(hrng);
248 #else
249  /* DeInit the low level hardware */
250  HAL_RNG_MspDeInit(hrng);
251 #endif /* USE_HAL_RNG_REGISTER_CALLBACKS */
252 
253  /* Update the RNG state */
254  hrng->State = HAL_RNG_STATE_RESET;
255 
256  /* Initialise the error code */
257  hrng->ErrorCode = HAL_RNG_ERROR_NONE;
258 
259  /* Release Lock */
260  __HAL_UNLOCK(hrng);
261 
262  /* Return the function status */
263  return HAL_OK;
264 }
__IO HAL_RNG_StateTypeDef State
void HAL_RNG_MspDeInit(RNG_HandleTypeDef *hrng)
DeInitialize the RNG MSP.
__HAL_UNLOCK(hrtc)
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
void(* MspDeInitCallback)(struct __RNG_HandleTypeDef *hrng)
return HAL_OK
RNG_TypeDef * Instance
__IO uint32_t ErrorCode

◆ HAL_RNG_Init()

HAL_StatusTypeDef HAL_RNG_Init ( RNG_HandleTypeDef hrng)

Initialize the RNG peripheral and initialize the associated handle.

Parameters
hrngpointer to a RNG_HandleTypeDef structure.
Return values
HALstatus

Definition at line 154 of file stm32l4xx_hal_rng.c.

155 {
156  /* Check the RNG handle allocation */
157  if(hrng == NULL)
158  {
159  return HAL_ERROR;
160  }
161 
162  assert_param(IS_RNG_ALL_INSTANCE(hrng->Instance));
163 #if defined(RNG_CR_CED)
164  assert_param(IS_RNG_CED(hrng->Init.ClockErrorDetection));
165 #endif /* defined(RNG_CR_CED) */
166 
167 #if (USE_HAL_RNG_REGISTER_CALLBACKS == 1)
168  if(hrng->State == HAL_RNG_STATE_RESET)
169  {
170  /* Allocate lock resource and initialize it */
171  hrng->Lock = HAL_UNLOCKED;
172 
173  hrng->ReadyDataCallback = HAL_RNG_ReadyDataCallback; /* Legacy weak ReadyDataCallback */
174  hrng->ErrorCallback = HAL_RNG_ErrorCallback; /* Legacy weak ErrorCallback */
175 
176  if(hrng->MspInitCallback == NULL)
177  {
178  hrng->MspInitCallback = HAL_RNG_MspInit; /* Legacy weak MspInit */
179  }
180 
181  /* Init the low level hardware */
182  hrng->MspInitCallback(hrng);
183  }
184 #else
185  if(hrng->State == HAL_RNG_STATE_RESET)
186  {
187  /* Allocate lock resource and initialize it */
188  hrng->Lock = HAL_UNLOCKED;
189 
190  /* Init the low level hardware */
191  HAL_RNG_MspInit(hrng);
192  }
193 #endif /* USE_HAL_RNG_REGISTER_CALLBACKS */
194 
195  /* Change RNG peripheral state */
196  hrng->State = HAL_RNG_STATE_BUSY;
197 
198 #if defined(RNG_CR_CED)
199  /* Clock Error Detection configuration */
200  MODIFY_REG(hrng->Instance->CR, RNG_CR_CED, hrng->Init.ClockErrorDetection);
201 #endif /* defined(RNG_CR_CED) */
202 
203  /* Enable the RNG Peripheral */
204  __HAL_RNG_ENABLE(hrng);
205 
206  /* Initialize the RNG state */
207  hrng->State = HAL_RNG_STATE_READY;
208 
209  /* Initialise the error code */
210  hrng->ErrorCode = HAL_RNG_ERROR_NONE;
211 
212  /* Return function status */
213  return HAL_OK;
214 }
void(* ErrorCallback)(struct __RNG_HandleTypeDef *hrng)
void HAL_RNG_ReadyDataCallback(RNG_HandleTypeDef *hrng, uint32_t random32bit)
Data Ready callback in non-blocking mode.
void HAL_RNG_ErrorCallback(RNG_HandleTypeDef *hrng)
RNG error callback.
__IO HAL_RNG_StateTypeDef State
RNG_InitTypeDef Init
return HAL_OK
void(* MspInitCallback)(struct __RNG_HandleTypeDef *hrng)
RNG_TypeDef * Instance
HAL_LockTypeDef Lock
void HAL_RNG_MspInit(RNG_HandleTypeDef *hrng)
Initialize the RNG MSP.
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)
void(* ReadyDataCallback)(struct __RNG_HandleTypeDef *hrng, uint32_t random32bit)
__IO uint32_t ErrorCode
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_RNG_MspDeInit()

__weak void HAL_RNG_MspDeInit ( RNG_HandleTypeDef hrng)

DeInitialize the RNG MSP.

Parameters
hrngpointer to a RNG_HandleTypeDef structure.
Return values
None

Definition at line 286 of file stm32l4xx_hal_rng.c.

287 {
288  /* Prevent unused argument(s) compilation warning */
289  UNUSED(hrng);
290 
291  /* NOTE : This function should not be modified. When the callback is needed,
292  function HAL_RNG_MspDeInit must be implemented in the user file.
293  */
294 }

◆ HAL_RNG_MspInit()

__weak void HAL_RNG_MspInit ( RNG_HandleTypeDef hrng)

Initialize the RNG MSP.

Parameters
hrngpointer to a RNG_HandleTypeDef structure.
Return values
None

Definition at line 271 of file stm32l4xx_hal_rng.c.

272 {
273  /* Prevent unused argument(s) compilation warning */
274  UNUSED(hrng);
275 
276  /* NOTE : This function should not be modified. When the callback is needed,
277  function HAL_RNG_MspInit must be implemented in the user file.
278  */
279 }

◆ HAL_RNG_RegisterCallback()

HAL_StatusTypeDef HAL_RNG_RegisterCallback ( RNG_HandleTypeDef hrng,
HAL_RNG_CallbackIDTypeDef  CallbackID,
pRNG_CallbackTypeDef  pCallback 
)

Register a User RNG Callback To be used instead of the weak predefined callback.

Parameters
hrngRNG handle
CallbackIDID of the callback to be registered This parameter can be one of the following values:
pCallbackpointer to the Callback function
Return values
HALstatus

Definition at line 309 of file stm32l4xx_hal_rng.c.

310 {
311  HAL_StatusTypeDef status = HAL_OK;
312 
313  if(pCallback == NULL)
314  {
315  /* Update the error code */
316  hrng->ErrorCode |= HAL_RNG_ERROR_INVALID_CALLBACK;
317  return HAL_ERROR;
318  }
319  /* Process locked */
320  __HAL_LOCK(hrng);
321 
322  if(HAL_RNG_STATE_READY == hrng->State)
323  {
324  switch (CallbackID)
325  {
326  case HAL_RNG_ERROR_CB_ID :
327  hrng->ErrorCallback = pCallback;
328  break;
329 
330  case HAL_RNG_MSPINIT_CB_ID :
331  hrng->MspInitCallback = pCallback;
332  break;
333 
335  hrng->MspDeInitCallback = pCallback;
336  break;
337 
338  default :
339  /* Update the error code */
340  hrng->ErrorCode |= HAL_RNG_ERROR_INVALID_CALLBACK;
341  /* Return error status */
342  status = HAL_ERROR;
343  break;
344  }
345  }
346  else if(HAL_RNG_STATE_RESET == hrng->State)
347  {
348  switch (CallbackID)
349  {
350  case HAL_RNG_MSPINIT_CB_ID :
351  hrng->MspInitCallback = pCallback;
352  break;
353 
355  hrng->MspDeInitCallback = pCallback;
356  break;
357 
358  default :
359  /* Update the error code */
360  hrng->ErrorCode |= HAL_RNG_ERROR_INVALID_CALLBACK;
361  /* Return error status */
362  status = HAL_ERROR;
363  break;
364  }
365  }
366  else
367  {
368  /* Update the error code */
369  hrng->ErrorCode |= HAL_RNG_ERROR_INVALID_CALLBACK;
370  /* Return error status */
371  status = HAL_ERROR;
372  }
373 
374  /* Release Lock */
375  __HAL_UNLOCK(hrng);
376  return status;
377 }
void(* ErrorCallback)(struct __RNG_HandleTypeDef *hrng)
__IO HAL_RNG_StateTypeDef State
__HAL_UNLOCK(hrtc)
__HAL_LOCK(hrtc)
void(* MspDeInitCallback)(struct __RNG_HandleTypeDef *hrng)
return HAL_OK
void(* MspInitCallback)(struct __RNG_HandleTypeDef *hrng)
__IO uint32_t ErrorCode

◆ HAL_RNG_RegisterReadyDataCallback()

HAL_StatusTypeDef HAL_RNG_RegisterReadyDataCallback ( RNG_HandleTypeDef hrng,
pRNG_ReadyDataCallbackTypeDef  pCallback 
)

Register Data Ready RNG Callback To be used instead of the weak HAL_RNG_ReadyDataCallback() predefined callback.

Parameters
hrngRNG handle
pCallbackpointer to the Data Ready Callback function
Return values
HALstatus

Definition at line 461 of file stm32l4xx_hal_rng.c.

462 {
463  HAL_StatusTypeDef status = HAL_OK;
464 
465  if(pCallback == NULL)
466  {
467  /* Update the error code */
468  hrng->ErrorCode |= HAL_RNG_ERROR_INVALID_CALLBACK;
469  return HAL_ERROR;
470  }
471  /* Process locked */
472  __HAL_LOCK(hrng);
473 
474  if(HAL_RNG_STATE_READY == hrng->State)
475  {
476  hrng->ReadyDataCallback = pCallback;
477  }
478  else
479  {
480  /* Update the error code */
481  hrng->ErrorCode |= HAL_RNG_ERROR_INVALID_CALLBACK;
482  /* Return error status */
483  status = HAL_ERROR;
484  }
485 
486  /* Release Lock */
487  __HAL_UNLOCK(hrng);
488  return status;
489 }
__IO HAL_RNG_StateTypeDef State
__HAL_UNLOCK(hrtc)
__HAL_LOCK(hrtc)
return HAL_OK
void(* ReadyDataCallback)(struct __RNG_HandleTypeDef *hrng, uint32_t random32bit)
__IO uint32_t ErrorCode

◆ HAL_RNG_UnRegisterCallback()

HAL_StatusTypeDef HAL_RNG_UnRegisterCallback ( RNG_HandleTypeDef hrng,
HAL_RNG_CallbackIDTypeDef  CallbackID 
)

Unregister an RNG Callback RNG callabck is redirected to the weak predefined callback.

Parameters
hrngRNG handle
CallbackIDID of the callback to be unregistered This parameter can be one of the following values:
Return values
HALstatus

Definition at line 390 of file stm32l4xx_hal_rng.c.

391 {
392 HAL_StatusTypeDef status = HAL_OK;
393 
394  /* Process locked */
395  __HAL_LOCK(hrng);
396 
397  if(HAL_RNG_STATE_READY == hrng->State)
398  {
399  switch (CallbackID)
400  {
401  case HAL_RNG_ERROR_CB_ID :
402  hrng->ErrorCallback = HAL_RNG_ErrorCallback; /* Legacy weak ErrorCallback */
403  break;
404 
405  case HAL_RNG_MSPINIT_CB_ID :
406  hrng->MspInitCallback = HAL_RNG_MspInit; /* Legacy weak MspInit */
407  break;
408 
410  hrng->MspDeInitCallback = HAL_RNG_MspDeInit; /* Legacy weak MspDeInit */
411  break;
412 
413  default :
414  /* Update the error code */
415  hrng->ErrorCode |= HAL_RNG_ERROR_INVALID_CALLBACK;
416  /* Return error status */
417  status = HAL_ERROR;
418  break;
419  }
420  }
421  else if(HAL_RNG_STATE_RESET == hrng->State)
422  {
423  switch (CallbackID)
424  {
425  case HAL_RNG_MSPINIT_CB_ID :
426  hrng->MspInitCallback = HAL_RNG_MspInit; /* Legacy weak MspInit */
427  break;
428 
430  hrng->MspDeInitCallback = HAL_RNG_MspDeInit; /* Legacy weak MspInit */
431  break;
432 
433  default :
434  /* Update the error code */
435  hrng->ErrorCode |= HAL_RNG_ERROR_INVALID_CALLBACK;
436  /* Return error status */
437  status = HAL_ERROR;
438  break;
439  }
440  }
441  else
442  {
443  /* Update the error code */
444  hrng->ErrorCode |= HAL_RNG_ERROR_INVALID_CALLBACK;
445  /* Return error status */
446  status = HAL_ERROR;
447  }
448 
449  /* Release Lock */
450  __HAL_UNLOCK(hrng);
451  return status;
452 }
void(* ErrorCallback)(struct __RNG_HandleTypeDef *hrng)
void HAL_RNG_ErrorCallback(RNG_HandleTypeDef *hrng)
RNG error callback.
__IO HAL_RNG_StateTypeDef State
void HAL_RNG_MspDeInit(RNG_HandleTypeDef *hrng)
DeInitialize the RNG MSP.
__HAL_UNLOCK(hrtc)
__HAL_LOCK(hrtc)
void(* MspDeInitCallback)(struct __RNG_HandleTypeDef *hrng)
return HAL_OK
void(* MspInitCallback)(struct __RNG_HandleTypeDef *hrng)
void HAL_RNG_MspInit(RNG_HandleTypeDef *hrng)
Initialize the RNG MSP.
__IO uint32_t ErrorCode

◆ HAL_RNG_UnRegisterReadyDataCallback()

HAL_StatusTypeDef HAL_RNG_UnRegisterReadyDataCallback ( RNG_HandleTypeDef hrng)

UnRegister the Data Ready RNG Callback Data Ready RNG Callback is redirected to the weak HAL_RNG_ReadyDataCallback() predefined callback.

Parameters
hrngRNG handle
Return values
HALstatus

Definition at line 497 of file stm32l4xx_hal_rng.c.

498 {
499  HAL_StatusTypeDef status = HAL_OK;
500 
501  /* Process locked */
502  __HAL_LOCK(hrng);
503 
504  if(HAL_RNG_STATE_READY == hrng->State)
505  {
506  hrng->ReadyDataCallback = HAL_RNG_ReadyDataCallback; /* Legacy weak ReadyDataCallback */
507  }
508  else
509  {
510  /* Update the error code */
511  hrng->ErrorCode |= HAL_RNG_ERROR_INVALID_CALLBACK;
512  /* Return error status */
513  status = HAL_ERROR;
514  }
515 
516  /* Release Lock */
517  __HAL_UNLOCK(hrng);
518  return status;
519 }
void HAL_RNG_ReadyDataCallback(RNG_HandleTypeDef *hrng, uint32_t random32bit)
Data Ready callback in non-blocking mode.
__IO HAL_RNG_StateTypeDef State
__HAL_UNLOCK(hrtc)
__HAL_LOCK(hrtc)
return HAL_OK
void(* ReadyDataCallback)(struct __RNG_HandleTypeDef *hrng, uint32_t random32bit)
__IO uint32_t ErrorCode