STM32L4xx_HAL_Driver  1.14.0
Initialization and de-initialization functions

Initialization and Configuration functions. More...

Functions

HAL_StatusTypeDef HAL_IRDA_Init (IRDA_HandleTypeDef *hirda)
 Initialize the IRDA mode according to the specified parameters in the IRDA_InitTypeDef and initialize the associated handle. More...
 
HAL_StatusTypeDef HAL_IRDA_DeInit (IRDA_HandleTypeDef *hirda)
 DeInitialize the IRDA peripheral. More...
 
void HAL_IRDA_MspInit (IRDA_HandleTypeDef *hirda)
 Initialize the IRDA MSP. More...
 
void HAL_IRDA_MspDeInit (IRDA_HandleTypeDef *hirda)
 DeInitialize the IRDA MSP. More...
 
HAL_StatusTypeDef HAL_IRDA_RegisterCallback (IRDA_HandleTypeDef *hirda, HAL_IRDA_CallbackIDTypeDef CallbackID, pIRDA_CallbackTypeDef pCallback)
 Register a User IRDA Callback To be used instead of the weak predefined callback. More...
 
HAL_StatusTypeDef HAL_IRDA_UnRegisterCallback (IRDA_HandleTypeDef *hirda, HAL_IRDA_CallbackIDTypeDef CallbackID)
 Unregister an IRDA callback IRDA callback is redirected to the weak predefined callback. More...
 

Detailed Description

Initialization and Configuration functions.

  ==============================================================================
              ##### Initialization and Configuration functions #####
  ==============================================================================
  [..]
  This subsection provides a set of functions allowing to initialize the USARTx
  in asynchronous IRDA mode.
  (+) For the asynchronous mode only these parameters can be configured:
      (++) Baud Rate
      (++) Word Length
      (++) Parity: If the parity is enabled, then the MSB bit of the data written
           in the data register is transmitted but is changed by the parity bit.
      (++) Power mode
      (++) Prescaler setting
      (++) Receiver/transmitter modes

  [..]
  The HAL_IRDA_Init() API follows the USART asynchronous configuration procedures
  (details for the procedures are available in reference manual).

Depending on the frame length defined by the M1 and M0 bits (7-bit, 8-bit or 9-bit), the possible IRDA frame formats are listed in the following table.

Table 1. IRDA frame format. +--------------------------------------------------------------------—+ | M1 bit | M0 bit | PCE bit | IRDA frame | |------—|------—|--------—|------------------------------------—| | 0 | 0 | 0 | | SB | 8 bit data | STB | | |------—|------—|--------—|------------------------------------—| | 0 | 0 | 1 | | SB | 7 bit data | PB | STB | | |------—|------—|--------—|------------------------------------—| | 0 | 1 | 0 | | SB | 9 bit data | STB | | |------—|------—|--------—|------------------------------------—| | 0 | 1 | 1 | | SB | 8 bit data | PB | STB | | |------—|------—|--------—|------------------------------------—| | 1 | 0 | 0 | | SB | 7 bit data | STB | | |------—|------—|--------—|------------------------------------—| | 1 | 0 | 1 | | SB | 6 bit data | PB | STB | | +--------------------------------------------------------------------—+

Function Documentation

◆ HAL_IRDA_DeInit()

HAL_StatusTypeDef HAL_IRDA_DeInit ( IRDA_HandleTypeDef hirda)

DeInitialize the IRDA peripheral.

Parameters
hirdaPointer to a IRDA_HandleTypeDef structure that contains the configuration information for the specified IRDA module.
Return values
HALstatus

Definition at line 401 of file stm32l4xx_hal_irda.c.

402 {
403  /* Check the IRDA handle allocation */
404  if (hirda == NULL)
405  {
406  return HAL_ERROR;
407  }
408 
409  /* Check the USART/UART associated to the IRDA handle */
410  assert_param(IS_IRDA_INSTANCE(hirda->Instance));
411 
412  hirda->gState = HAL_IRDA_STATE_BUSY;
413 
414  /* DeInit the low level hardware */
415 #if USE_HAL_IRDA_REGISTER_CALLBACKS == 1
416  if (hirda->MspDeInitCallback == NULL)
417  {
418  hirda->MspDeInitCallback = HAL_IRDA_MspDeInit;
419  }
420  /* DeInit the low level hardware */
421  hirda->MspDeInitCallback(hirda);
422 #else
423  HAL_IRDA_MspDeInit(hirda);
424 #endif /* USE_HAL_IRDA_REGISTER_CALLBACKS */
425  /* Disable the Peripheral */
426  __HAL_IRDA_DISABLE(hirda);
427 
428  hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
429  hirda->gState = HAL_IRDA_STATE_RESET;
430  hirda->RxState = HAL_IRDA_STATE_RESET;
431 
432  /* Process Unlock */
433  __HAL_UNLOCK(hirda);
434 
435  return HAL_OK;
436 }
__HAL_UNLOCK(hrtc)
void HAL_IRDA_MspDeInit(IRDA_HandleTypeDef *hirda)
DeInitialize the IRDA MSP.
return HAL_OK
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_IRDA_Init()

HAL_StatusTypeDef HAL_IRDA_Init ( IRDA_HandleTypeDef hirda)

Initialize the IRDA mode according to the specified parameters in the IRDA_InitTypeDef and initialize the associated handle.

Parameters
hirdaPointer to a IRDA_HandleTypeDef structure that contains the configuration information for the specified IRDA module.
Return values
HALstatus

Definition at line 336 of file stm32l4xx_hal_irda.c.

337 {
338  /* Check the IRDA handle allocation */
339  if (hirda == NULL)
340  {
341  return HAL_ERROR;
342  }
343 
344  /* Check the USART/UART associated to the IRDA handle */
345  assert_param(IS_IRDA_INSTANCE(hirda->Instance));
346 
347  if (hirda->gState == HAL_IRDA_STATE_RESET)
348  {
349  /* Allocate lock resource and initialize it */
350  hirda->Lock = HAL_UNLOCKED;
351 
352 #if USE_HAL_IRDA_REGISTER_CALLBACKS == 1
354 
355  if (hirda->MspInitCallback == NULL)
356  {
357  hirda->MspInitCallback = HAL_IRDA_MspInit;
358  }
359 
360  /* Init the low level hardware */
361  hirda->MspInitCallback(hirda);
362 #else
363  /* Init the low level hardware : GPIO, CLOCK */
364  HAL_IRDA_MspInit(hirda);
365 #endif /* USE_HAL_IRDA_REGISTER_CALLBACKS */
366  }
367 
368  hirda->gState = HAL_IRDA_STATE_BUSY;
369 
370  /* Disable the Peripheral to update the configuration registers */
371  __HAL_IRDA_DISABLE(hirda);
372 
373  /* Set the IRDA Communication parameters */
374  if (IRDA_SetConfig(hirda) == HAL_ERROR)
375  {
376  return HAL_ERROR;
377  }
378 
379  /* In IRDA mode, the following bits must be kept cleared:
380  - LINEN, STOP and CLKEN bits in the USART_CR2 register,
381  - SCEN and HDSEL bits in the USART_CR3 register.*/
382  CLEAR_BIT(hirda->Instance->CR2, (USART_CR2_LINEN | USART_CR2_CLKEN | USART_CR2_STOP));
383  CLEAR_BIT(hirda->Instance->CR3, (USART_CR3_SCEN | USART_CR3_HDSEL));
384 
385  /* set the UART/USART in IRDA mode */
386  hirda->Instance->CR3 |= USART_CR3_IREN;
387 
388  /* Enable the Peripheral */
389  __HAL_IRDA_ENABLE(hirda);
390 
391  /* TEACK and/or REACK to check before moving hirda->gState and hirda->RxState to Ready */
392  return (IRDA_CheckIdleState(hirda));
393 }
static HAL_StatusTypeDef IRDA_SetConfig(IRDA_HandleTypeDef *hirda)
Configure the IRDA peripheral.
void HAL_IRDA_MspInit(IRDA_HandleTypeDef *hirda)
Initialize the IRDA MSP.
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
void IRDA_InitCallbacksToDefault(IRDA_HandleTypeDef *hirda)
Initialize the callbacks to their default values.
static HAL_StatusTypeDef IRDA_CheckIdleState(IRDA_HandleTypeDef *hirda)
Check the IRDA Idle State.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_IRDA_MspDeInit()

__weak void HAL_IRDA_MspDeInit ( IRDA_HandleTypeDef hirda)

DeInitialize the IRDA MSP.

Parameters
hirdaPointer to a IRDA_HandleTypeDef structure that contains the configuration information for the specified IRDA module.
Return values
None

Definition at line 460 of file stm32l4xx_hal_irda.c.

461 {
462  /* Prevent unused argument(s) compilation warning */
463  UNUSED(hirda);
464 
465  /* NOTE: This function should not be modified, when the callback is needed,
466  the HAL_IRDA_MspDeInit can be implemented in the user file
467  */
468 }

◆ HAL_IRDA_MspInit()

__weak void HAL_IRDA_MspInit ( IRDA_HandleTypeDef hirda)

Initialize the IRDA MSP.

Parameters
hirdaPointer to a IRDA_HandleTypeDef structure that contains the configuration information for the specified IRDA module.
Return values
None

Definition at line 444 of file stm32l4xx_hal_irda.c.

445 {
446  /* Prevent unused argument(s) compilation warning */
447  UNUSED(hirda);
448 
449  /* NOTE: This function should not be modified, when the callback is needed,
450  the HAL_IRDA_MspInit can be implemented in the user file
451  */
452 }

◆ HAL_IRDA_RegisterCallback()

HAL_StatusTypeDef HAL_IRDA_RegisterCallback ( IRDA_HandleTypeDef hirda,
HAL_IRDA_CallbackIDTypeDef  CallbackID,
pIRDA_CallbackTypeDef  pCallback 
)

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

Parameters
hirdairda 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 490 of file stm32l4xx_hal_irda.c.

492 {
493  HAL_StatusTypeDef status = HAL_OK;
494 
495  if (pCallback == NULL)
496  {
497  /* Update the error code */
498  hirda->ErrorCode |= HAL_IRDA_ERROR_INVALID_CALLBACK;
499 
500  return HAL_ERROR;
501  }
502  /* Process locked */
503  __HAL_LOCK(hirda);
504 
505  if (hirda->gState == HAL_IRDA_STATE_READY)
506  {
507  switch (CallbackID)
508  {
510  hirda->TxHalfCpltCallback = pCallback;
511  break;
512 
514  hirda->TxCpltCallback = pCallback;
515  break;
516 
518  hirda->RxHalfCpltCallback = pCallback;
519  break;
520 
522  hirda->RxCpltCallback = pCallback;
523  break;
524 
525  case HAL_IRDA_ERROR_CB_ID :
526  hirda->ErrorCallback = pCallback;
527  break;
528 
530  hirda->AbortCpltCallback = pCallback;
531  break;
532 
534  hirda->AbortTransmitCpltCallback = pCallback;
535  break;
536 
538  hirda->AbortReceiveCpltCallback = pCallback;
539  break;
540 
542  hirda->MspInitCallback = pCallback;
543  break;
544 
546  hirda->MspDeInitCallback = pCallback;
547  break;
548 
549  default :
550  /* Update the error code */
551  hirda->ErrorCode |= HAL_IRDA_ERROR_INVALID_CALLBACK;
552 
553  /* Return error status */
554  status = HAL_ERROR;
555  break;
556  }
557  }
558  else if (hirda->gState == HAL_IRDA_STATE_RESET)
559  {
560  switch (CallbackID)
561  {
563  hirda->MspInitCallback = pCallback;
564  break;
565 
567  hirda->MspDeInitCallback = pCallback;
568  break;
569 
570  default :
571  /* Update the error code */
572  hirda->ErrorCode |= HAL_IRDA_ERROR_INVALID_CALLBACK;
573 
574  /* Return error status */
575  status = HAL_ERROR;
576  break;
577  }
578  }
579  else
580  {
581  /* Update the error code */
582  hirda->ErrorCode |= HAL_IRDA_ERROR_INVALID_CALLBACK;
583 
584  /* Return error status */
585  status = HAL_ERROR;
586  }
587 
588  /* Release Lock */
589  __HAL_UNLOCK(hirda);
590 
591  return status;
592 }
__HAL_UNLOCK(hrtc)
__HAL_LOCK(hrtc)
return HAL_OK

◆ HAL_IRDA_UnRegisterCallback()

HAL_StatusTypeDef HAL_IRDA_UnRegisterCallback ( IRDA_HandleTypeDef hirda,
HAL_IRDA_CallbackIDTypeDef  CallbackID 
)

Unregister an IRDA callback IRDA callback is redirected to the weak predefined callback.

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

Definition at line 612 of file stm32l4xx_hal_irda.c.

613 {
614  HAL_StatusTypeDef status = HAL_OK;
615 
616  /* Process locked */
617  __HAL_LOCK(hirda);
618 
619  if (HAL_IRDA_STATE_READY == hirda->gState)
620  {
621  switch (CallbackID)
622  {
624  hirda->TxHalfCpltCallback = HAL_IRDA_TxHalfCpltCallback; /* Legacy weak TxHalfCpltCallback */
625  break;
626 
628  hirda->TxCpltCallback = HAL_IRDA_TxCpltCallback; /* Legacy weak TxCpltCallback */
629  break;
630 
632  hirda->RxHalfCpltCallback = HAL_IRDA_RxHalfCpltCallback; /* Legacy weak RxHalfCpltCallback */
633  break;
634 
636  hirda->RxCpltCallback = HAL_IRDA_RxCpltCallback; /* Legacy weak RxCpltCallback */
637  break;
638 
639  case HAL_IRDA_ERROR_CB_ID :
640  hirda->ErrorCallback = HAL_IRDA_ErrorCallback; /* Legacy weak ErrorCallback */
641  break;
642 
644  hirda->AbortCpltCallback = HAL_IRDA_AbortCpltCallback; /* Legacy weak AbortCpltCallback */
645  break;
646 
648  hirda->AbortTransmitCpltCallback = HAL_IRDA_AbortTransmitCpltCallback; /* Legacy weak AbortTransmitCpltCallback */
649  break;
650 
652  hirda->AbortReceiveCpltCallback = HAL_IRDA_AbortReceiveCpltCallback; /* Legacy weak AbortReceiveCpltCallback */
653  break;
654 
656  hirda->MspInitCallback = HAL_IRDA_MspInit; /* Legacy weak MspInitCallback */
657  break;
658 
660  hirda->MspDeInitCallback = HAL_IRDA_MspDeInit; /* Legacy weak MspDeInitCallback */
661  break;
662 
663  default :
664  /* Update the error code */
665  hirda->ErrorCode |= HAL_IRDA_ERROR_INVALID_CALLBACK;
666 
667  /* Return error status */
668  status = HAL_ERROR;
669  break;
670  }
671  }
672  else if (HAL_IRDA_STATE_RESET == hirda->gState)
673  {
674  switch (CallbackID)
675  {
677  hirda->MspInitCallback = HAL_IRDA_MspInit;
678  break;
679 
681  hirda->MspDeInitCallback = HAL_IRDA_MspDeInit;
682  break;
683 
684  default :
685  /* Update the error code */
686  hirda->ErrorCode |= HAL_IRDA_ERROR_INVALID_CALLBACK;
687 
688  /* Return error status */
689  status = HAL_ERROR;
690  break;
691  }
692  }
693  else
694  {
695  /* Update the error code */
696  hirda->ErrorCode |= HAL_IRDA_ERROR_INVALID_CALLBACK;
697 
698  /* Return error status */
699  status = HAL_ERROR;
700  }
701 
702  /* Release Lock */
703  __HAL_UNLOCK(hirda);
704 
705  return status;
706 }
void HAL_IRDA_AbortReceiveCpltCallback(IRDA_HandleTypeDef *hirda)
IRDA Abort Receive Complete callback.
void HAL_IRDA_MspInit(IRDA_HandleTypeDef *hirda)
Initialize the IRDA MSP.
void HAL_IRDA_RxHalfCpltCallback(IRDA_HandleTypeDef *hirda)
Rx Half Transfer complete callback.
__HAL_UNLOCK(hrtc)
void HAL_IRDA_ErrorCallback(IRDA_HandleTypeDef *hirda)
IRDA error callback.
void HAL_IRDA_MspDeInit(IRDA_HandleTypeDef *hirda)
DeInitialize the IRDA MSP.
__HAL_LOCK(hrtc)
void HAL_IRDA_TxCpltCallback(IRDA_HandleTypeDef *hirda)
Tx Transfer completed callback.
void HAL_IRDA_TxHalfCpltCallback(IRDA_HandleTypeDef *hirda)
Tx Half Transfer completed callback.
return HAL_OK
void HAL_IRDA_AbortCpltCallback(IRDA_HandleTypeDef *hirda)
IRDA Abort Complete callback.
void HAL_IRDA_RxCpltCallback(IRDA_HandleTypeDef *hirda)
Rx Transfer completed callback.
void HAL_IRDA_AbortTransmitCpltCallback(IRDA_HandleTypeDef *hirda)
IRDA Abort Complete callback.