STM32F4xx HAL Driver master
STM32CubeF4 HAL / LL Drivers API Reference
Loading...
Searching...
No Matches
stm32f4xx_hal_irda.c
Go to the documentation of this file.
1
201
202/* Includes ------------------------------------------------------------------*/
203#include "stm32f4xx_hal.h"
204
208
213
214#ifdef HAL_IRDA_MODULE_ENABLED
215
216/* Private typedef -----------------------------------------------------------*/
217/* Private define ------------------------------------------------------------*/
218/* Private constants ---------------------------------------------------------*/
219/* Private macro -------------------------------------------------------------*/
220/* Private variables ---------------------------------------------------------*/
221/* Private function prototypes -----------------------------------------------*/
225#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
226void IRDA_InitCallbacksToDefault(IRDA_HandleTypeDef *hirda);
227#endif /* USE_HAL_IRDA_REGISTER_CALLBACKS */
228static void IRDA_SetConfig(IRDA_HandleTypeDef *hirda);
229static HAL_StatusTypeDef IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda);
230static HAL_StatusTypeDef IRDA_EndTransmit_IT(IRDA_HandleTypeDef *hirda);
231static HAL_StatusTypeDef IRDA_Receive_IT(IRDA_HandleTypeDef *hirda);
232static void IRDA_DMATransmitCplt(DMA_HandleTypeDef *hdma);
233static void IRDA_DMATransmitHalfCplt(DMA_HandleTypeDef *hdma);
234static void IRDA_DMAReceiveCplt(DMA_HandleTypeDef *hdma);
235static void IRDA_DMAReceiveHalfCplt(DMA_HandleTypeDef *hdma);
236static void IRDA_DMAError(DMA_HandleTypeDef *hdma);
237static void IRDA_DMAAbortOnError(DMA_HandleTypeDef *hdma);
238static void IRDA_DMATxAbortCallback(DMA_HandleTypeDef *hdma);
239static void IRDA_DMARxAbortCallback(DMA_HandleTypeDef *hdma);
240static void IRDA_DMATxOnlyAbortCallback(DMA_HandleTypeDef *hdma);
241static void IRDA_DMARxOnlyAbortCallback(DMA_HandleTypeDef *hdma);
242static HAL_StatusTypeDef IRDA_WaitOnFlagUntilTimeout(IRDA_HandleTypeDef *hirda, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout);
243static void IRDA_EndTxTransfer(IRDA_HandleTypeDef *hirda);
244static void IRDA_EndRxTransfer(IRDA_HandleTypeDef *hirda);
248
249/* Exported functions --------------------------------------------------------*/
253
285
294{
295 /* Check the IRDA handle allocation */
296 if (hirda == NULL)
297 {
298 return HAL_ERROR;
299 }
300
301 /* Check the IRDA instance parameters */
302 assert_param(IS_IRDA_INSTANCE(hirda->Instance));
303 /* Check the IRDA mode parameter in the IRDA handle */
305
306 if (hirda->gState == HAL_IRDA_STATE_RESET)
307 {
308 /* Allocate lock resource and initialize it */
309 hirda->Lock = HAL_UNLOCKED;
310
311#if USE_HAL_IRDA_REGISTER_CALLBACKS == 1
312 IRDA_InitCallbacksToDefault(hirda);
313
314 if (hirda->MspInitCallback == NULL)
315 {
316 hirda->MspInitCallback = HAL_IRDA_MspInit;
317 }
318
319 /* Init the low level hardware */
320 hirda->MspInitCallback(hirda);
321#else
322 /* Init the low level hardware : GPIO, CLOCK */
323 HAL_IRDA_MspInit(hirda);
324#endif /* USE_HAL_IRDA_REGISTER_CALLBACKS */
325 }
326
328
329 /* Disable the IRDA peripheral */
330 __HAL_IRDA_DISABLE(hirda);
331
332 /* Set the IRDA communication parameters */
333 IRDA_SetConfig(hirda);
334
335 /* In IrDA mode, the following bits must be kept cleared:
336 - LINEN, STOP and CLKEN bits in the USART_CR2 register,
337 - SCEN and HDSEL bits in the USART_CR3 register.*/
338 CLEAR_BIT(hirda->Instance->CR2, (USART_CR2_LINEN | USART_CR2_STOP | USART_CR2_CLKEN));
339 CLEAR_BIT(hirda->Instance->CR3, (USART_CR3_SCEN | USART_CR3_HDSEL));
340
341 /* Enable the IRDA peripheral */
342 __HAL_IRDA_ENABLE(hirda);
343
344 /* Set the prescaler */
345 MODIFY_REG(hirda->Instance->GTPR, USART_GTPR_PSC, hirda->Init.Prescaler);
346
347 /* Configure the IrDA mode */
348 MODIFY_REG(hirda->Instance->CR3, USART_CR3_IRLP, hirda->Init.IrDAMode);
349
350 /* Enable the IrDA mode by setting the IREN bit in the CR3 register */
351 SET_BIT(hirda->Instance->CR3, USART_CR3_IREN);
352
353 /* Initialize the IRDA state*/
357
358 return HAL_OK;
359}
360
368{
369 /* Check the IRDA handle allocation */
370 if (hirda == NULL)
371 {
372 return HAL_ERROR;
373 }
374
375 /* Check the parameters */
376 assert_param(IS_IRDA_INSTANCE(hirda->Instance));
377
379
380 /* Disable the Peripheral */
381 __HAL_IRDA_DISABLE(hirda);
382
383 /* DeInit the low level hardware */
384#if USE_HAL_IRDA_REGISTER_CALLBACKS == 1
385 if (hirda->MspDeInitCallback == NULL)
386 {
387 hirda->MspDeInitCallback = HAL_IRDA_MspDeInit;
388 }
389 /* DeInit the low level hardware */
390 hirda->MspDeInitCallback(hirda);
391#else
392 HAL_IRDA_MspDeInit(hirda);
393#endif /* USE_HAL_IRDA_REGISTER_CALLBACKS */
394
396
399
400 /* Release Lock */
401 __HAL_UNLOCK(hirda);
402
403 return HAL_OK;
404}
405
412__weak void HAL_IRDA_MspInit(IRDA_HandleTypeDef *hirda)
413{
414 /* Prevent unused argument(s) compilation warning */
415 UNUSED(hirda);
416
417 /* NOTE: This function should not be modified, when the callback is needed,
418 the HAL_IRDA_MspInit can be implemented in the user file
419 */
420}
421
428__weak void HAL_IRDA_MspDeInit(IRDA_HandleTypeDef *hirda)
429{
430 /* Prevent unused argument(s) compilation warning */
431 UNUSED(hirda);
432
433 /* NOTE: This function should not be modified, when the callback is needed,
434 the HAL_IRDA_MspDeInit can be implemented in the user file
435 */
436}
437
438#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
460HAL_StatusTypeDef HAL_IRDA_RegisterCallback(IRDA_HandleTypeDef *hirda, HAL_IRDA_CallbackIDTypeDef CallbackID, pIRDA_CallbackTypeDef pCallback)
461{
462 HAL_StatusTypeDef status = HAL_OK;
463
464 if (pCallback == NULL)
465 {
466 /* Update the error code */
467 hirda->ErrorCode |= HAL_IRDA_ERROR_INVALID_CALLBACK;
468
469 return HAL_ERROR;
470 }
471
472 if (hirda->gState == HAL_IRDA_STATE_READY)
473 {
474 switch (CallbackID)
475 {
476 case HAL_IRDA_TX_HALFCOMPLETE_CB_ID :
477 hirda->TxHalfCpltCallback = pCallback;
478 break;
479
480 case HAL_IRDA_TX_COMPLETE_CB_ID :
481 hirda->TxCpltCallback = pCallback;
482 break;
483
484 case HAL_IRDA_RX_HALFCOMPLETE_CB_ID :
485 hirda->RxHalfCpltCallback = pCallback;
486 break;
487
488 case HAL_IRDA_RX_COMPLETE_CB_ID :
489 hirda->RxCpltCallback = pCallback;
490 break;
491
492 case HAL_IRDA_ERROR_CB_ID :
493 hirda->ErrorCallback = pCallback;
494 break;
495
496 case HAL_IRDA_ABORT_COMPLETE_CB_ID :
497 hirda->AbortCpltCallback = pCallback;
498 break;
499
500 case HAL_IRDA_ABORT_TRANSMIT_COMPLETE_CB_ID :
501 hirda->AbortTransmitCpltCallback = pCallback;
502 break;
503
504 case HAL_IRDA_ABORT_RECEIVE_COMPLETE_CB_ID :
505 hirda->AbortReceiveCpltCallback = pCallback;
506 break;
507
508 case HAL_IRDA_MSPINIT_CB_ID :
509 hirda->MspInitCallback = pCallback;
510 break;
511
512 case HAL_IRDA_MSPDEINIT_CB_ID :
513 hirda->MspDeInitCallback = pCallback;
514 break;
515
516 default :
517 /* Update the error code */
518 hirda->ErrorCode |= HAL_IRDA_ERROR_INVALID_CALLBACK;
519
520 /* Return error status */
521 status = HAL_ERROR;
522 break;
523 }
524 }
525 else if (hirda->gState == HAL_IRDA_STATE_RESET)
526 {
527 switch (CallbackID)
528 {
529 case HAL_IRDA_MSPINIT_CB_ID :
530 hirda->MspInitCallback = pCallback;
531 break;
532
533 case HAL_IRDA_MSPDEINIT_CB_ID :
534 hirda->MspDeInitCallback = pCallback;
535 break;
536
537 default :
538 /* Update the error code */
539 hirda->ErrorCode |= HAL_IRDA_ERROR_INVALID_CALLBACK;
540
541 /* Return error status */
542 status = HAL_ERROR;
543 break;
544 }
545 }
546 else
547 {
548 /* Update the error code */
549 hirda->ErrorCode |= HAL_IRDA_ERROR_INVALID_CALLBACK;
550
551 /* Return error status */
552 status = HAL_ERROR;
553 }
554
555 return status;
556}
557
578HAL_StatusTypeDef HAL_IRDA_UnRegisterCallback(IRDA_HandleTypeDef *hirda, HAL_IRDA_CallbackIDTypeDef CallbackID)
579{
580 HAL_StatusTypeDef status = HAL_OK;
581
582 if (HAL_IRDA_STATE_READY == hirda->gState)
583 {
584 switch (CallbackID)
585 {
586 case HAL_IRDA_TX_HALFCOMPLETE_CB_ID :
587 hirda->TxHalfCpltCallback = HAL_IRDA_TxHalfCpltCallback; /* Legacy weak TxHalfCpltCallback */
588 break;
589
590 case HAL_IRDA_TX_COMPLETE_CB_ID :
591 hirda->TxCpltCallback = HAL_IRDA_TxCpltCallback; /* Legacy weak TxCpltCallback */
592 break;
593
594 case HAL_IRDA_RX_HALFCOMPLETE_CB_ID :
595 hirda->RxHalfCpltCallback = HAL_IRDA_RxHalfCpltCallback; /* Legacy weak RxHalfCpltCallback */
596 break;
597
598 case HAL_IRDA_RX_COMPLETE_CB_ID :
599 hirda->RxCpltCallback = HAL_IRDA_RxCpltCallback; /* Legacy weak RxCpltCallback */
600 break;
601
602 case HAL_IRDA_ERROR_CB_ID :
603 hirda->ErrorCallback = HAL_IRDA_ErrorCallback; /* Legacy weak ErrorCallback */
604 break;
605
606 case HAL_IRDA_ABORT_COMPLETE_CB_ID :
607 hirda->AbortCpltCallback = HAL_IRDA_AbortCpltCallback; /* Legacy weak AbortCpltCallback */
608 break;
609
610 case HAL_IRDA_ABORT_TRANSMIT_COMPLETE_CB_ID :
611 hirda->AbortTransmitCpltCallback = HAL_IRDA_AbortTransmitCpltCallback; /* Legacy weak AbortTransmitCpltCallback */
612 break;
613
614 case HAL_IRDA_ABORT_RECEIVE_COMPLETE_CB_ID :
615 hirda->AbortReceiveCpltCallback = HAL_IRDA_AbortReceiveCpltCallback; /* Legacy weak AbortReceiveCpltCallback */
616 break;
617
618 case HAL_IRDA_MSPINIT_CB_ID :
619 hirda->MspInitCallback = HAL_IRDA_MspInit; /* Legacy weak MspInitCallback */
620 break;
621
622 case HAL_IRDA_MSPDEINIT_CB_ID :
623 hirda->MspDeInitCallback = HAL_IRDA_MspDeInit; /* Legacy weak MspDeInitCallback */
624 break;
625
626 default :
627 /* Update the error code */
628 hirda->ErrorCode |= HAL_IRDA_ERROR_INVALID_CALLBACK;
629
630 /* Return error status */
631 status = HAL_ERROR;
632 break;
633 }
634 }
635 else if (HAL_IRDA_STATE_RESET == hirda->gState)
636 {
637 switch (CallbackID)
638 {
639 case HAL_IRDA_MSPINIT_CB_ID :
640 hirda->MspInitCallback = HAL_IRDA_MspInit;
641 break;
642
643 case HAL_IRDA_MSPDEINIT_CB_ID :
644 hirda->MspDeInitCallback = HAL_IRDA_MspDeInit;
645 break;
646
647 default :
648 /* Update the error code */
649 hirda->ErrorCode |= HAL_IRDA_ERROR_INVALID_CALLBACK;
650
651 /* Return error status */
652 status = HAL_ERROR;
653 break;
654 }
655 }
656 else
657 {
658 /* Update the error code */
659 hirda->ErrorCode |= HAL_IRDA_ERROR_INVALID_CALLBACK;
660
661 /* Return error status */
662 status = HAL_ERROR;
663 }
664
665 return status;
666}
667#endif /* USE_HAL_IRDA_REGISTER_CALLBACKS */
668
672
751
764HAL_StatusTypeDef HAL_IRDA_Transmit(IRDA_HandleTypeDef *hirda, const uint8_t *pData, uint16_t Size, uint32_t Timeout)
765{
766 const uint16_t *tmp;
767 uint32_t tickstart = 0U;
768
769 /* Check that a Tx process is not already ongoing */
770 if (hirda->gState == HAL_IRDA_STATE_READY)
771 {
772 if ((pData == NULL) || (Size == 0U))
773 {
774 return HAL_ERROR;
775 }
776
777 /* Process Locked */
778 __HAL_LOCK(hirda);
779
782
783 /* Init tickstart for timeout management*/
784 tickstart = HAL_GetTick();
785
786 hirda->TxXferSize = Size;
787 hirda->TxXferCount = Size;
788 while (hirda->TxXferCount > 0U)
789 {
790 hirda->TxXferCount--;
791 if (hirda->Init.WordLength == IRDA_WORDLENGTH_9B)
792 {
793 if (IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK)
794 {
795 return HAL_TIMEOUT;
796 }
797 tmp = (const uint16_t *) pData;
798 hirda->Instance->DR = (*tmp & (uint16_t)0x01FF);
799 if (hirda->Init.Parity == IRDA_PARITY_NONE)
800 {
801 pData += 2U;
802 }
803 else
804 {
805 pData += 1U;
806 }
807 }
808 else
809 {
810 if (IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK)
811 {
812 return HAL_TIMEOUT;
813 }
814 hirda->Instance->DR = (*pData++ & (uint8_t)0xFF);
815 }
816 }
817
818 if (IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_TC, RESET, tickstart, Timeout) != HAL_OK)
819 {
820 return HAL_TIMEOUT;
821 }
822
823 /* At end of Tx process, restore hirda->gState to Ready */
825
826 /* Process Unlocked */
827 __HAL_UNLOCK(hirda);
828
829 return HAL_OK;
830 }
831 else
832 {
833 return HAL_BUSY;
834 }
835}
836
849HAL_StatusTypeDef HAL_IRDA_Receive(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size, uint32_t Timeout)
850{
851 uint16_t *tmp;
852 uint32_t tickstart = 0U;
853
854 /* Check that a Rx process is not already ongoing */
855 if (hirda->RxState == HAL_IRDA_STATE_READY)
856 {
857 if ((pData == NULL) || (Size == 0U))
858 {
859 return HAL_ERROR;
860 }
861
862 /* Process Locked */
863 __HAL_LOCK(hirda);
864
867
868 /* Init tickstart for timeout management*/
869 tickstart = HAL_GetTick();
870
871 hirda->RxXferSize = Size;
872 hirda->RxXferCount = Size;
873
874 /* Check the remain data to be received */
875 while (hirda->RxXferCount > 0U)
876 {
877 hirda->RxXferCount--;
878
879 if (hirda->Init.WordLength == IRDA_WORDLENGTH_9B)
880 {
881 if (IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK)
882 {
883 return HAL_TIMEOUT;
884 }
885 tmp = (uint16_t *) pData ;
886 if (hirda->Init.Parity == IRDA_PARITY_NONE)
887 {
888 *tmp = (uint16_t)(hirda->Instance->DR & (uint16_t)0x01FF);
889 pData += 2U;
890 }
891 else
892 {
893 *tmp = (uint16_t)(hirda->Instance->DR & (uint16_t)0x00FF);
894 pData += 1U;
895 }
896 }
897 else
898 {
899 if (IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK)
900 {
901 return HAL_TIMEOUT;
902 }
903 if (hirda->Init.Parity == IRDA_PARITY_NONE)
904 {
905 *pData++ = (uint8_t)(hirda->Instance->DR & (uint8_t)0x00FF);
906 }
907 else
908 {
909 *pData++ = (uint8_t)(hirda->Instance->DR & (uint8_t)0x007F);
910 }
911 }
912 }
913
914 /* At end of Rx process, restore hirda->RxState to Ready */
916
917 /* Process Unlocked */
918 __HAL_UNLOCK(hirda);
919
920 return HAL_OK;
921 }
922 else
923 {
924 return HAL_BUSY;
925 }
926}
927
939HAL_StatusTypeDef HAL_IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda, const uint8_t *pData, uint16_t Size)
940{
941 /* Check that a Tx process is not already ongoing */
942 if (hirda->gState == HAL_IRDA_STATE_READY)
943 {
944 if ((pData == NULL) || (Size == 0U))
945 {
946 return HAL_ERROR;
947 }
948
949 /* Process Locked */
950 __HAL_LOCK(hirda);
951
952 hirda->pTxBuffPtr = pData;
953 hirda->TxXferSize = Size;
954 hirda->TxXferCount = Size;
955
958
959 /* Process Unlocked */
960 __HAL_UNLOCK(hirda);
961
962 /* Enable the IRDA Transmit Data Register Empty Interrupt */
963 SET_BIT(hirda->Instance->CR1, USART_CR1_TXEIE);
964
965 return HAL_OK;
966 }
967 else
968 {
969 return HAL_BUSY;
970 }
971}
972
984HAL_StatusTypeDef HAL_IRDA_Receive_IT(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size)
985{
986 /* Check that a Rx process is not already ongoing */
987 if (hirda->RxState == HAL_IRDA_STATE_READY)
988 {
989 if ((pData == NULL) || (Size == 0U))
990 {
991 return HAL_ERROR;
992 }
993
994 /* Process Locked */
995 __HAL_LOCK(hirda);
996
997 hirda->pRxBuffPtr = pData;
998 hirda->RxXferSize = Size;
999 hirda->RxXferCount = Size;
1000
1003
1004 /* Process Unlocked */
1005 __HAL_UNLOCK(hirda);
1006
1007 if (hirda->Init.Parity != IRDA_PARITY_NONE)
1008 {
1009 /* Enable the IRDA Parity Error and Data Register Not Empty Interrupts */
1010 SET_BIT(hirda->Instance->CR1, USART_CR1_PEIE | USART_CR1_RXNEIE);
1011 }
1012 else
1013 {
1014 /* Enable the IRDA Data Register Not Empty Interrupts */
1015 SET_BIT(hirda->Instance->CR1, USART_CR1_RXNEIE);
1016 }
1017
1018 /* Enable the IRDA Error Interrupt: (Frame error, Noise error, Overrun error) */
1019 SET_BIT(hirda->Instance->CR3, USART_CR3_EIE);
1020
1021 return HAL_OK;
1022 }
1023 else
1024 {
1025 return HAL_BUSY;
1026 }
1027}
1028
1040HAL_StatusTypeDef HAL_IRDA_Transmit_DMA(IRDA_HandleTypeDef *hirda, const uint8_t *pData, uint16_t Size)
1041{
1042 const uint32_t *tmp;
1043
1044 /* Check that a Tx process is not already ongoing */
1045 if (hirda->gState == HAL_IRDA_STATE_READY)
1046 {
1047 if ((pData == NULL) || (Size == 0U))
1048 {
1049 return HAL_ERROR;
1050 }
1051
1052 /* Process Locked */
1053 __HAL_LOCK(hirda);
1054
1055 hirda->pTxBuffPtr = pData;
1056 hirda->TxXferSize = Size;
1057 hirda->TxXferCount = Size;
1058
1061
1062 /* Set the IRDA DMA transfer complete callback */
1063 hirda->hdmatx->XferCpltCallback = IRDA_DMATransmitCplt;
1064
1065 /* Set the IRDA DMA half transfer complete callback */
1066 hirda->hdmatx->XferHalfCpltCallback = IRDA_DMATransmitHalfCplt;
1067
1068 /* Set the DMA error callback */
1069 hirda->hdmatx->XferErrorCallback = IRDA_DMAError;
1070
1071 /* Set the DMA abort callback */
1072 hirda->hdmatx->XferAbortCallback = NULL;
1073
1074 /* Enable the IRDA transmit DMA stream */
1075 tmp = (const uint32_t *)&pData;
1076 if (HAL_DMA_Start_IT(hirda->hdmatx, *(const uint32_t *)tmp, (uint32_t)&hirda->Instance->DR, Size) == HAL_OK)
1077 {
1078 /* Clear the TC flag in the SR register by writing 0 to it */
1080
1081 /* Process Unlocked */
1082 __HAL_UNLOCK(hirda);
1083
1084 /* Enable the DMA transfer for transmit request by setting the DMAT bit
1085 in the USART CR3 register */
1086 SET_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
1087
1088 return HAL_OK;
1089 }
1090 else
1091 {
1092 /* Set error code to DMA */
1094
1095 /* Process Unlocked */
1096 __HAL_UNLOCK(hirda);
1097
1098 /* Restore hirda->gState to ready */
1100
1101 return HAL_ERROR;
1102 }
1103 }
1104 else
1105 {
1106 return HAL_BUSY;
1107 }
1108}
1109
1122HAL_StatusTypeDef HAL_IRDA_Receive_DMA(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size)
1123{
1124 uint32_t *tmp;
1125
1126 /* Check that a Rx process is not already ongoing */
1127 if (hirda->RxState == HAL_IRDA_STATE_READY)
1128 {
1129 if ((pData == NULL) || (Size == 0U))
1130 {
1131 return HAL_ERROR;
1132 }
1133
1134 /* Process Locked */
1135 __HAL_LOCK(hirda);
1136
1137 hirda->pRxBuffPtr = pData;
1138 hirda->RxXferSize = Size;
1139
1142
1143 /* Set the IRDA DMA transfer complete callback */
1144 hirda->hdmarx->XferCpltCallback = IRDA_DMAReceiveCplt;
1145
1146 /* Set the IRDA DMA half transfer complete callback */
1147 hirda->hdmarx->XferHalfCpltCallback = IRDA_DMAReceiveHalfCplt;
1148
1149 /* Set the DMA error callback */
1150 hirda->hdmarx->XferErrorCallback = IRDA_DMAError;
1151
1152 /* Set the DMA abort callback */
1153 hirda->hdmarx->XferAbortCallback = NULL;
1154
1155 /* Enable the DMA stream */
1156 tmp = (uint32_t *)&pData;
1157 if (HAL_DMA_Start_IT(hirda->hdmarx, (uint32_t)&hirda->Instance->DR, *(uint32_t *)tmp, Size) == HAL_OK)
1158 {
1159 /* Clear the Overrun flag just before enabling the DMA Rx request: can be mandatory for the second transfer */
1161
1162 /* Process Unlocked */
1163 __HAL_UNLOCK(hirda);
1164
1165 if (hirda->Init.Parity != IRDA_PARITY_NONE)
1166 {
1167 /* Enable the IRDA Parity Error Interrupt */
1168 SET_BIT(hirda->Instance->CR1, USART_CR1_PEIE);
1169 }
1170
1171 /* Enable the IRDA Error Interrupt: (Frame error, Noise error, Overrun error) */
1172 SET_BIT(hirda->Instance->CR3, USART_CR3_EIE);
1173
1174 /* Enable the DMA transfer for the receiver request by setting the DMAR bit
1175 in the USART CR3 register */
1176 SET_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
1177
1178 return HAL_OK;
1179 }
1180 else
1181 {
1182 /* Set error code to DMA */
1184
1185 /* Process Unlocked */
1186 __HAL_UNLOCK(hirda);
1187
1188 /* Restore hirda->RxState to ready */
1190
1191 return HAL_ERROR;
1192 }
1193 }
1194 else
1195 {
1196 return HAL_BUSY;
1197 }
1198}
1199
1207{
1208 uint32_t dmarequest = 0x00U;
1209
1210 /* Process Locked */
1211 __HAL_LOCK(hirda);
1212
1213 dmarequest = HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT);
1214 if ((hirda->gState == HAL_IRDA_STATE_BUSY_TX) && dmarequest)
1215 {
1216 /* Disable the IRDA DMA Tx request */
1217 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
1218 }
1219
1220 dmarequest = HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR);
1221 if ((hirda->RxState == HAL_IRDA_STATE_BUSY_RX) && dmarequest)
1222 {
1223 /* Disable PE and ERR (Frame error, noise error, overrun error) interrupts */
1224 CLEAR_BIT(hirda->Instance->CR1, USART_CR1_PEIE);
1225 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
1226
1227 /* Disable the IRDA DMA Rx request */
1228 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
1229 }
1230
1231 /* Process Unlocked */
1232 __HAL_UNLOCK(hirda);
1233
1234 return HAL_OK;
1235}
1236
1244{
1245 /* Process Locked */
1246 __HAL_LOCK(hirda);
1247
1248 if (hirda->gState == HAL_IRDA_STATE_BUSY_TX)
1249 {
1250 /* Enable the IRDA DMA Tx request */
1251 SET_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
1252 }
1253
1254 if (hirda->RxState == HAL_IRDA_STATE_BUSY_RX)
1255 {
1256 /* Clear the Overrun flag before resuming the Rx transfer */
1258
1259 /* Re-enable PE and ERR (Frame error, noise error, overrun error) interrupts */
1260 if (hirda->Init.Parity != IRDA_PARITY_NONE)
1261 {
1262 SET_BIT(hirda->Instance->CR1, USART_CR1_PEIE);
1263 }
1264 SET_BIT(hirda->Instance->CR3, USART_CR3_EIE);
1265
1266 /* Enable the IRDA DMA Rx request */
1267 SET_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
1268 }
1269
1270 /* Process Unlocked */
1271 __HAL_UNLOCK(hirda);
1272
1273 return HAL_OK;
1274}
1275
1283{
1284 uint32_t dmarequest = 0x00U;
1285 /* The Lock is not implemented on this API to allow the user application
1286 to call the HAL IRDA API under callbacks HAL_IRDA_TxCpltCallback() / HAL_IRDA_RxCpltCallback():
1287 when calling HAL_DMA_Abort() API the DMA TX/RX Transfer complete interrupt is generated
1288 and the correspond call back is executed HAL_IRDA_TxCpltCallback() / HAL_IRDA_RxCpltCallback()
1289 */
1290
1291 /* Stop IRDA DMA Tx request if ongoing */
1292 dmarequest = HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT);
1293 if ((hirda->gState == HAL_IRDA_STATE_BUSY_TX) && dmarequest)
1294 {
1295 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
1296
1297 /* Abort the IRDA DMA Tx channel */
1298 if (hirda->hdmatx != NULL)
1299 {
1300 HAL_DMA_Abort(hirda->hdmatx);
1301 }
1302 IRDA_EndTxTransfer(hirda);
1303 }
1304
1305 /* Stop IRDA DMA Rx request if ongoing */
1306 dmarequest = HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR);
1307 if ((hirda->RxState == HAL_IRDA_STATE_BUSY_RX) && dmarequest)
1308 {
1309 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
1310
1311 /* Abort the IRDA DMA Rx channel */
1312 if (hirda->hdmarx != NULL)
1313 {
1314 HAL_DMA_Abort(hirda->hdmarx);
1315 }
1316 IRDA_EndRxTransfer(hirda);
1317 }
1318
1319 return HAL_OK;
1320}
1321
1335{
1336 /* Disable TXEIE, TCIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
1337 CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE));
1338 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
1339
1340 /* Disable the IRDA DMA Tx request if enabled */
1341 if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT))
1342 {
1343 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
1344
1345 /* Abort the IRDA DMA Tx channel : use blocking DMA Abort API (no callback) */
1346 if (hirda->hdmatx != NULL)
1347 {
1348 /* Set the IRDA DMA Abort callback to Null.
1349 No call back execution at end of DMA abort procedure */
1350 hirda->hdmatx->XferAbortCallback = NULL;
1351
1352 HAL_DMA_Abort(hirda->hdmatx);
1353 }
1354 }
1355
1356 /* Disable the IRDA DMA Rx request if enabled */
1357 if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
1358 {
1359 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
1360
1361 /* Abort the IRDA DMA Rx channel : use blocking DMA Abort API (no callback) */
1362 if (hirda->hdmarx != NULL)
1363 {
1364 /* Set the IRDA DMA Abort callback to Null.
1365 No call back execution at end of DMA abort procedure */
1366 hirda->hdmarx->XferAbortCallback = NULL;
1367
1368 HAL_DMA_Abort(hirda->hdmarx);
1369 }
1370 }
1371
1372 /* Reset Tx and Rx transfer counters */
1373 hirda->TxXferCount = 0x00U;
1374 hirda->RxXferCount = 0x00U;
1375
1376 /* Reset ErrorCode */
1378
1379 /* Restore hirda->RxState and hirda->gState to Ready */
1382
1383 return HAL_OK;
1384}
1385
1399{
1400 /* Disable TXEIE and TCIE interrupts */
1401 CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE));
1402
1403 /* Disable the IRDA DMA Tx request if enabled */
1404 if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT))
1405 {
1406 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
1407
1408 /* Abort the IRDA DMA Tx channel : use blocking DMA Abort API (no callback) */
1409 if (hirda->hdmatx != NULL)
1410 {
1411 /* Set the IRDA DMA Abort callback to Null.
1412 No call back execution at end of DMA abort procedure */
1413 hirda->hdmatx->XferAbortCallback = NULL;
1414
1415 HAL_DMA_Abort(hirda->hdmatx);
1416 }
1417 }
1418
1419 /* Reset Tx transfer counter */
1420 hirda->TxXferCount = 0x00U;
1421
1422 /* Restore hirda->gState to Ready */
1424
1425 return HAL_OK;
1426}
1427
1441{
1442 /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
1443 CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
1444 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
1445
1446 /* Disable the IRDA DMA Rx request if enabled */
1447 if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
1448 {
1449 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
1450
1451 /* Abort the IRDA DMA Rx channel : use blocking DMA Abort API (no callback) */
1452 if (hirda->hdmarx != NULL)
1453 {
1454 /* Set the IRDA DMA Abort callback to Null.
1455 No call back execution at end of DMA abort procedure */
1456 hirda->hdmarx->XferAbortCallback = NULL;
1457
1458 HAL_DMA_Abort(hirda->hdmarx);
1459 }
1460 }
1461
1462 /* Reset Rx transfer counter */
1463 hirda->RxXferCount = 0x00U;
1464
1465 /* Restore hirda->RxState to Ready */
1467
1468 return HAL_OK;
1469}
1470
1486{
1487 uint32_t AbortCplt = 0x01U;
1488
1489 /* Disable TXEIE, TCIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
1490 CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE));
1491 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
1492
1493 /* If DMA Tx and/or DMA Rx Handles are associated to IRDA Handle, DMA Abort complete callbacks should be initialised
1494 before any call to DMA Abort functions */
1495 /* DMA Tx Handle is valid */
1496 if (hirda->hdmatx != NULL)
1497 {
1498 /* Set DMA Abort Complete callback if IRDA DMA Tx request if enabled.
1499 Otherwise, set it to NULL */
1500 if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT))
1501 {
1502 hirda->hdmatx->XferAbortCallback = IRDA_DMATxAbortCallback;
1503 }
1504 else
1505 {
1506 hirda->hdmatx->XferAbortCallback = NULL;
1507 }
1508 }
1509 /* DMA Rx Handle is valid */
1510 if (hirda->hdmarx != NULL)
1511 {
1512 /* Set DMA Abort Complete callback if IRDA DMA Rx request if enabled.
1513 Otherwise, set it to NULL */
1514 if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
1515 {
1516 hirda->hdmarx->XferAbortCallback = IRDA_DMARxAbortCallback;
1517 }
1518 else
1519 {
1520 hirda->hdmarx->XferAbortCallback = NULL;
1521 }
1522 }
1523
1524 /* Disable the IRDA DMA Tx request if enabled */
1525 if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT))
1526 {
1527 /* Disable DMA Tx at IRDA level */
1528 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
1529
1530 /* Abort the IRDA DMA Tx channel : use non blocking DMA Abort API (callback) */
1531 if (hirda->hdmatx != NULL)
1532 {
1533 /* IRDA Tx DMA Abort callback has already been initialised :
1534 will lead to call HAL_IRDA_AbortCpltCallback() at end of DMA abort procedure */
1535
1536 /* Abort DMA TX */
1537 if (HAL_DMA_Abort_IT(hirda->hdmatx) != HAL_OK)
1538 {
1539 hirda->hdmatx->XferAbortCallback = NULL;
1540 }
1541 else
1542 {
1543 AbortCplt = 0x00U;
1544 }
1545 }
1546 }
1547
1548 /* Disable the IRDA DMA Rx request if enabled */
1549 if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
1550 {
1551 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
1552
1553 /* Abort the IRDA DMA Rx channel : use non blocking DMA Abort API (callback) */
1554 if (hirda->hdmarx != NULL)
1555 {
1556 /* IRDA Rx DMA Abort callback has already been initialised :
1557 will lead to call HAL_IRDA_AbortCpltCallback() at end of DMA abort procedure */
1558
1559 /* Abort DMA RX */
1560 if (HAL_DMA_Abort_IT(hirda->hdmarx) != HAL_OK)
1561 {
1562 hirda->hdmarx->XferAbortCallback = NULL;
1563 AbortCplt = 0x01U;
1564 }
1565 else
1566 {
1567 AbortCplt = 0x00U;
1568 }
1569 }
1570 }
1571
1572 /* if no DMA abort complete callback execution is required => call user Abort Complete callback */
1573 if (AbortCplt == 0x01U)
1574 {
1575 /* Reset Tx and Rx transfer counters */
1576 hirda->TxXferCount = 0x00U;
1577 hirda->RxXferCount = 0x00U;
1578
1579 /* Reset ErrorCode */
1581
1582 /* Restore hirda->gState and hirda->RxState to Ready */
1585
1586 /* As no DMA to be aborted, call directly user Abort complete callback */
1587#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
1588 /* Call registered Abort complete callback */
1589 hirda->AbortCpltCallback(hirda);
1590#else
1591 /* Call legacy weak Abort complete callback */
1593#endif /* USE_HAL_IRDA_REGISTER_CALLBACK */
1594 }
1595
1596 return HAL_OK;
1597}
1598
1614{
1615 /* Disable TXEIE and TCIE interrupts */
1616 CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE));
1617
1618 /* Disable the IRDA DMA Tx request if enabled */
1619 if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT))
1620 {
1621 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
1622
1623 /* Abort the IRDA DMA Tx channel : use non blocking DMA Abort API (callback) */
1624 if (hirda->hdmatx != NULL)
1625 {
1626 /* Set the IRDA DMA Abort callback :
1627 will lead to call HAL_IRDA_AbortCpltCallback() at end of DMA abort procedure */
1628 hirda->hdmatx->XferAbortCallback = IRDA_DMATxOnlyAbortCallback;
1629
1630 /* Abort DMA TX */
1631 if (HAL_DMA_Abort_IT(hirda->hdmatx) != HAL_OK)
1632 {
1633 /* Call Directly hirda->hdmatx->XferAbortCallback function in case of error */
1634 hirda->hdmatx->XferAbortCallback(hirda->hdmatx);
1635 }
1636 }
1637 else
1638 {
1639 /* Reset Tx transfer counter */
1640 hirda->TxXferCount = 0x00U;
1641
1642 /* Restore hirda->gState to Ready */
1644
1645 /* As no DMA to be aborted, call directly user Abort complete callback */
1646#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
1647 /* Call registered Abort Transmit Complete Callback */
1648 hirda->AbortTransmitCpltCallback(hirda);
1649#else
1650 /* Call legacy weak Abort Transmit Complete Callback */
1652#endif /* USE_HAL_IRDA_REGISTER_CALLBACK */
1653 }
1654 }
1655 else
1656 {
1657 /* Reset Tx transfer counter */
1658 hirda->TxXferCount = 0x00U;
1659
1660 /* Restore hirda->gState to Ready */
1662
1663 /* As no DMA to be aborted, call directly user Abort complete callback */
1664#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
1665 /* Call registered Abort Transmit Complete Callback */
1666 hirda->AbortTransmitCpltCallback(hirda);
1667#else
1668 /* Call legacy weak Abort Transmit Complete Callback */
1670#endif /* USE_HAL_IRDA_REGISTER_CALLBACK */
1671 }
1672
1673 return HAL_OK;
1674}
1675
1691{
1692 /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
1693 CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
1694 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
1695
1696 /* Disable the IRDA DMA Rx request if enabled */
1697 if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
1698 {
1699 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
1700
1701 /* Abort the IRDA DMA Rx channel : use non blocking DMA Abort API (callback) */
1702 if (hirda->hdmarx != NULL)
1703 {
1704 /* Set the IRDA DMA Abort callback :
1705 will lead to call HAL_IRDA_AbortCpltCallback() at end of DMA abort procedure */
1706 hirda->hdmarx->XferAbortCallback = IRDA_DMARxOnlyAbortCallback;
1707
1708 /* Abort DMA RX */
1709 if (HAL_DMA_Abort_IT(hirda->hdmarx) != HAL_OK)
1710 {
1711 /* Call Directly hirda->hdmarx->XferAbortCallback function in case of error */
1712 hirda->hdmarx->XferAbortCallback(hirda->hdmarx);
1713 }
1714 }
1715 else
1716 {
1717 /* Reset Rx transfer counter */
1718 hirda->RxXferCount = 0x00U;
1719
1720 /* Restore hirda->RxState to Ready */
1722
1723 /* As no DMA to be aborted, call directly user Abort complete callback */
1724#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
1725 /* Call registered Abort Receive Complete Callback */
1726 hirda->AbortReceiveCpltCallback(hirda);
1727#else
1728 /* Call legacy weak Abort Receive Complete Callback */
1730#endif /* USE_HAL_IRDA_REGISTER_CALLBACK */
1731 }
1732 }
1733 else
1734 {
1735 /* Reset Rx transfer counter */
1736 hirda->RxXferCount = 0x00U;
1737
1738 /* Restore hirda->RxState to Ready */
1740
1741 /* As no DMA to be aborted, call directly user Abort complete callback */
1742#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
1743 /* Call registered Abort Receive Complete Callback */
1744 hirda->AbortReceiveCpltCallback(hirda);
1745#else
1746 /* Call legacy weak Abort Receive Complete Callback */
1748#endif /* USE_HAL_IRDA_REGISTER_CALLBACK */
1749 }
1750
1751 return HAL_OK;
1752}
1753
1761{
1762 uint32_t isrflags = READ_REG(hirda->Instance->SR);
1763 uint32_t cr1its = READ_REG(hirda->Instance->CR1);
1764 uint32_t cr3its = READ_REG(hirda->Instance->CR3);
1765 uint32_t errorflags = 0x00U;
1766 uint32_t dmarequest = 0x00U;
1767
1768 /* If no error occurs */
1769 errorflags = (isrflags & (uint32_t)(USART_SR_PE | USART_SR_FE | USART_SR_ORE | USART_SR_NE));
1770 if (errorflags == RESET)
1771 {
1772 /* IRDA in mode Receiver -----------------------------------------------*/
1773 if (((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET))
1774 {
1775 IRDA_Receive_IT(hirda);
1776 return;
1777 }
1778 }
1779
1780 /* If some errors occur */
1781 if ((errorflags != RESET) && (((cr3its & USART_CR3_EIE) != RESET) || ((cr1its & (USART_CR1_RXNEIE | USART_CR1_PEIE)) != RESET)))
1782 {
1783 /* IRDA parity error interrupt occurred -------------------------------*/
1784 if (((isrflags & USART_SR_PE) != RESET) && ((cr1its & USART_CR1_PEIE) != RESET))
1785 {
1786 hirda->ErrorCode |= HAL_IRDA_ERROR_PE;
1787 }
1788
1789 /* IRDA noise error interrupt occurred --------------------------------*/
1790 if (((isrflags & USART_SR_NE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET))
1791 {
1792 hirda->ErrorCode |= HAL_IRDA_ERROR_NE;
1793 }
1794
1795 /* IRDA frame error interrupt occurred --------------------------------*/
1796 if (((isrflags & USART_SR_FE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET))
1797 {
1798 hirda->ErrorCode |= HAL_IRDA_ERROR_FE;
1799 }
1800
1801 /* IRDA Over-Run interrupt occurred -----------------------------------*/
1802 if (((isrflags & USART_SR_ORE) != RESET) && (((cr1its & USART_CR1_RXNEIE) != RESET) || ((cr3its & USART_CR3_EIE) != RESET)))
1803 {
1804 hirda->ErrorCode |= HAL_IRDA_ERROR_ORE;
1805 }
1806 /* Call IRDA Error Call back function if need be -----------------------*/
1807 if (hirda->ErrorCode != HAL_IRDA_ERROR_NONE)
1808 {
1809 /* IRDA in mode Receiver ---------------------------------------------*/
1810 if (((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET))
1811 {
1812 IRDA_Receive_IT(hirda);
1813 }
1814
1815 /* If Overrun error occurs, or if any error occurs in DMA mode reception,
1816 consider error as blocking */
1817 dmarequest = HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR);
1818 if (((hirda->ErrorCode & HAL_IRDA_ERROR_ORE) != RESET) || dmarequest)
1819 {
1820 /* Blocking error : transfer is aborted
1821 Set the IRDA state ready to be able to start again the process,
1822 Disable Rx Interrupts, and disable Rx DMA request, if ongoing */
1823 IRDA_EndRxTransfer(hirda);
1824
1825 /* Disable the IRDA DMA Rx request if enabled */
1826 if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
1827 {
1828 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
1829
1830 /* Abort the IRDA DMA Rx channel */
1831 if (hirda->hdmarx != NULL)
1832 {
1833 /* Set the IRDA DMA Abort callback :
1834 will lead to call HAL_IRDA_ErrorCallback() at end of DMA abort procedure */
1835 hirda->hdmarx->XferAbortCallback = IRDA_DMAAbortOnError;
1836
1837 /* Abort DMA RX */
1838 if (HAL_DMA_Abort_IT(hirda->hdmarx) != HAL_OK)
1839 {
1840 /* Call Directly XferAbortCallback function in case of error */
1841 hirda->hdmarx->XferAbortCallback(hirda->hdmarx);
1842 }
1843 }
1844 else
1845 {
1846#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
1847 /* Call registered user error callback */
1848 hirda->ErrorCallback(hirda);
1849#else
1850 /* Call legacy weak user error callback */
1852#endif /* USE_HAL_IRDA_REGISTER_CALLBACK */
1853 }
1854 }
1855 else
1856 {
1857#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
1858 /* Call registered user error callback */
1859 hirda->ErrorCallback(hirda);
1860#else
1861 /* Call legacy weak user error callback */
1863#endif /* USE_HAL_IRDA_REGISTER_CALLBACK */
1864 }
1865 }
1866 else
1867 {
1868 /* Non Blocking error : transfer could go on.
1869 Error is notified to user through user error callback */
1870#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
1871 /* Call registered user error callback */
1872 hirda->ErrorCallback(hirda);
1873#else
1874 /* Call legacy weak user error callback */
1876#endif /* USE_HAL_IRDA_REGISTER_CALLBACK */
1877
1879 }
1880 }
1881 return;
1882 } /* End if some error occurs */
1883
1884 /* IRDA in mode Transmitter ------------------------------------------------*/
1885 if (((isrflags & USART_SR_TXE) != RESET) && ((cr1its & USART_CR1_TXEIE) != RESET))
1886 {
1887 IRDA_Transmit_IT(hirda);
1888 return;
1889 }
1890
1891 /* IRDA in mode Transmitter end --------------------------------------------*/
1892 if (((isrflags & USART_SR_TC) != RESET) && ((cr1its & USART_CR1_TCIE) != RESET))
1893 {
1894 IRDA_EndTransmit_IT(hirda);
1895 return;
1896 }
1897}
1898
1906{
1907 /* Prevent unused argument(s) compilation warning */
1908 UNUSED(hirda);
1909
1910 /* NOTE : This function should not be modified, when the callback is needed,
1911 the HAL_IRDA_TxCpltCallback can be implemented in the user file.
1912 */
1913}
1914
1922{
1923 /* Prevent unused argument(s) compilation warning */
1924 UNUSED(hirda);
1925
1926 /* NOTE : This function should not be modified, when the callback is needed,
1927 the HAL_IRDA_TxHalfCpltCallback can be implemented in the user file.
1928 */
1929}
1930
1938{
1939 /* Prevent unused argument(s) compilation warning */
1940 UNUSED(hirda);
1941
1942 /* NOTE : This function should not be modified, when the callback is needed,
1943 the HAL_IRDA_RxCpltCallback can be implemented in the user file.
1944 */
1945}
1946
1954{
1955 /* Prevent unused argument(s) compilation warning */
1956 UNUSED(hirda);
1957
1958 /* NOTE : This function should not be modified, when the callback is needed,
1959 the HAL_IRDA_RxHalfCpltCallback can be implemented in the user file.
1960 */
1961}
1962
1970{
1971 /* Prevent unused argument(s) compilation warning */
1972 UNUSED(hirda);
1973
1974 /* NOTE : This function should not be modified, when the callback is needed,
1975 the HAL_IRDA_ErrorCallback can be implemented in the user file.
1976 */
1977}
1978
1986{
1987 /* Prevent unused argument(s) compilation warning */
1988 UNUSED(hirda);
1989
1990 /* NOTE : This function should not be modified, when the callback is needed,
1991 the HAL_IRDA_AbortCpltCallback can be implemented in the user file.
1992 */
1993}
1994
2002{
2003 /* Prevent unused argument(s) compilation warning */
2004 UNUSED(hirda);
2005
2006 /* NOTE : This function should not be modified, when the callback is needed,
2007 the HAL_IRDA_AbortTransmitCpltCallback can be implemented in the user file.
2008 */
2009}
2010
2018{
2019 /* Prevent unused argument(s) compilation warning */
2020 UNUSED(hirda);
2021
2022 /* NOTE : This function should not be modified, when the callback is needed,
2023 the HAL_IRDA_AbortReceiveCpltCallback can be implemented in the user file.
2024 */
2025}
2026
2030
2047
2055{
2056 uint32_t temp1 = 0x00U, temp2 = 0x00U;
2057 temp1 = hirda->gState;
2058 temp2 = hirda->RxState;
2059
2060 return (HAL_IRDA_StateTypeDef)(temp1 | temp2);
2061}
2062
2069uint32_t HAL_IRDA_GetError(const IRDA_HandleTypeDef *hirda)
2070{
2071 return hirda->ErrorCode;
2072}
2073
2077
2081
2085
2086#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
2092void IRDA_InitCallbacksToDefault(IRDA_HandleTypeDef *hirda)
2093{
2094 /* Init the IRDA Callback settings */
2095 hirda->TxHalfCpltCallback = HAL_IRDA_TxHalfCpltCallback; /* Legacy weak TxHalfCpltCallback */
2096 hirda->TxCpltCallback = HAL_IRDA_TxCpltCallback; /* Legacy weak TxCpltCallback */
2097 hirda->RxHalfCpltCallback = HAL_IRDA_RxHalfCpltCallback; /* Legacy weak RxHalfCpltCallback */
2098 hirda->RxCpltCallback = HAL_IRDA_RxCpltCallback; /* Legacy weak RxCpltCallback */
2099 hirda->ErrorCallback = HAL_IRDA_ErrorCallback; /* Legacy weak ErrorCallback */
2100 hirda->AbortCpltCallback = HAL_IRDA_AbortCpltCallback; /* Legacy weak AbortCpltCallback */
2101 hirda->AbortTransmitCpltCallback = HAL_IRDA_AbortTransmitCpltCallback; /* Legacy weak AbortTransmitCpltCallback */
2102 hirda->AbortReceiveCpltCallback = HAL_IRDA_AbortReceiveCpltCallback; /* Legacy weak AbortReceiveCpltCallback */
2103
2104}
2105#endif /* USE_HAL_IRDA_REGISTER_CALLBACKS */
2106
2113static void IRDA_DMATransmitCplt(DMA_HandleTypeDef *hdma)
2114{
2115 IRDA_HandleTypeDef *hirda = (IRDA_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
2116 /* DMA Normal mode */
2117 if ((hdma->Instance->CR & DMA_SxCR_CIRC) == 0U)
2118 {
2119 hirda->TxXferCount = 0U;
2120
2121 /* Disable the DMA transfer for transmit request by resetting the DMAT bit
2122 in the IRDA CR3 register */
2123 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
2124
2125 /* Enable the IRDA Transmit Complete Interrupt */
2126 SET_BIT(hirda->Instance->CR1, USART_CR1_TCIE);
2127 }
2128 /* DMA Circular mode */
2129 else
2130 {
2131#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
2132 /* Call registered Tx complete callback */
2133 hirda->TxCpltCallback(hirda);
2134#else
2135 /* Call legacy weak Tx complete callback */
2137#endif /* USE_HAL_IRDA_REGISTER_CALLBACK */
2138 }
2139}
2140
2147static void IRDA_DMATransmitHalfCplt(DMA_HandleTypeDef *hdma)
2148{
2149 IRDA_HandleTypeDef *hirda = (IRDA_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
2150
2151#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
2152 /* Call registered Tx Half complete callback */
2153 hirda->TxHalfCpltCallback(hirda);
2154#else
2155 /* Call legacy weak Tx complete callback */
2157#endif /* USE_HAL_IRDA_REGISTER_CALLBACK */
2158}
2159
2166static void IRDA_DMAReceiveCplt(DMA_HandleTypeDef *hdma)
2167{
2168 IRDA_HandleTypeDef *hirda = (IRDA_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
2169
2170 /* DMA Normal mode */
2171 if ((hdma->Instance->CR & DMA_SxCR_CIRC) == 0U)
2172 {
2173 hirda->RxXferCount = 0U;
2174
2175 /* Disable PE and ERR (Frame error, noise error, overrun error) interrupts */
2176 CLEAR_BIT(hirda->Instance->CR1, USART_CR1_PEIE);
2177 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
2178
2179 /* Disable the DMA transfer for the receiver request by resetting the DMAR bit
2180 in the IRDA CR3 register */
2181 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
2182
2183 /* At end of Rx process, restore hirda->RxState to Ready */
2185 }
2186
2187#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
2188 /* Call registered Rx complete callback */
2189 hirda->RxCpltCallback(hirda);
2190#else
2191 /* Call legacy weak Rx complete callback */
2193#endif /* USE_HAL_IRDA_REGISTER_CALLBACKS */
2194}
2195
2202static void IRDA_DMAReceiveHalfCplt(DMA_HandleTypeDef *hdma)
2203{
2204 IRDA_HandleTypeDef *hirda = (IRDA_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
2205
2206#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
2207 /*Call registered Rx Half complete callback*/
2208 hirda->RxHalfCpltCallback(hirda);
2209#else
2210 /* Call legacy weak Rx Half complete callback */
2212#endif /* USE_HAL_IRDA_REGISTER_CALLBACK */
2213}
2214
2221static void IRDA_DMAError(DMA_HandleTypeDef *hdma)
2222{
2223 uint32_t dmarequest = 0x00U;
2224 IRDA_HandleTypeDef *hirda = (IRDA_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
2225
2226 /* Stop IRDA DMA Tx request if ongoing */
2227 dmarequest = HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT);
2228 if ((hirda->gState == HAL_IRDA_STATE_BUSY_TX) && dmarequest)
2229 {
2230 hirda->TxXferCount = 0U;
2231 IRDA_EndTxTransfer(hirda);
2232 }
2233
2234 /* Stop IRDA DMA Rx request if ongoing */
2235 dmarequest = HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR);
2236 if ((hirda->RxState == HAL_IRDA_STATE_BUSY_RX) && dmarequest)
2237 {
2238 hirda->RxXferCount = 0U;
2239 IRDA_EndRxTransfer(hirda);
2240 }
2241
2242 hirda->ErrorCode |= HAL_IRDA_ERROR_DMA;
2243
2244#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
2245 /* Call registered user error callback */
2246 hirda->ErrorCallback(hirda);
2247#else
2248 /* Call legacy weak user error callback */
2250#endif /* USE_HAL_IRDA_REGISTER_CALLBACK */
2251}
2252
2264static HAL_StatusTypeDef IRDA_WaitOnFlagUntilTimeout(IRDA_HandleTypeDef *hirda, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout)
2265{
2266 /* Wait until flag is set */
2267 while ((__HAL_IRDA_GET_FLAG(hirda, Flag) ? SET : RESET) == Status)
2268 {
2269 /* Check for the Timeout */
2270 if (Timeout != HAL_MAX_DELAY)
2271 {
2272 if ((Timeout == 0U) || ((HAL_GetTick() - Tickstart) > Timeout))
2273 {
2274 /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */
2275 CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE));
2276 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
2277
2280
2281 /* Process Unlocked */
2282 __HAL_UNLOCK(hirda);
2283
2284 return HAL_TIMEOUT;
2285 }
2286 }
2287 }
2288 return HAL_OK;
2289}
2290
2296static void IRDA_EndTxTransfer(IRDA_HandleTypeDef *hirda)
2297{
2298 /* Disable TXEIE and TCIE interrupts */
2299 CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE));
2300
2301 /* At end of Tx process, restore hirda->gState to Ready */
2303}
2304
2310static void IRDA_EndRxTransfer(IRDA_HandleTypeDef *hirda)
2311{
2312 /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
2313 CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
2314 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
2315
2316 /* At end of Rx process, restore hirda->RxState to Ready */
2318}
2319
2326static void IRDA_DMAAbortOnError(DMA_HandleTypeDef *hdma)
2327{
2328 IRDA_HandleTypeDef *hirda = (IRDA_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
2329 hirda->RxXferCount = 0x00U;
2330 hirda->TxXferCount = 0x00U;
2331
2332#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
2333 /* Call registered user error callback */
2334 hirda->ErrorCallback(hirda);
2335#else
2336 /* Call legacy weak user error callback */
2338#endif /* USE_HAL_IRDA_REGISTER_CALLBACK */
2339}
2340
2349static void IRDA_DMATxAbortCallback(DMA_HandleTypeDef *hdma)
2350{
2351 IRDA_HandleTypeDef *hirda = (IRDA_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
2352
2353 hirda->hdmatx->XferAbortCallback = NULL;
2354
2355 /* Check if an Abort process is still ongoing */
2356 if (hirda->hdmarx != NULL)
2357 {
2358 if (hirda->hdmarx->XferAbortCallback != NULL)
2359 {
2360 return;
2361 }
2362 }
2363
2364 /* No Abort process still ongoing : All DMA channels are aborted, call user Abort Complete callback */
2365 hirda->TxXferCount = 0x00U;
2366 hirda->RxXferCount = 0x00U;
2367
2368 /* Reset ErrorCode */
2370
2371 /* Restore hirda->gState and hirda->RxState to Ready */
2374
2375 /* Call user Abort complete callback */
2376#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
2377 /* Call registered Abort complete callback */
2378 hirda->AbortCpltCallback(hirda);
2379#else
2380 /* Call legacy weak Abort complete callback */
2382#endif /* USE_HAL_IRDA_REGISTER_CALLBACK */
2383}
2384
2393static void IRDA_DMARxAbortCallback(DMA_HandleTypeDef *hdma)
2394{
2395 IRDA_HandleTypeDef *hirda = (IRDA_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
2396
2397 hirda->hdmarx->XferAbortCallback = NULL;
2398
2399 /* Check if an Abort process is still ongoing */
2400 if (hirda->hdmatx != NULL)
2401 {
2402 if (hirda->hdmatx->XferAbortCallback != NULL)
2403 {
2404 return;
2405 }
2406 }
2407
2408 /* No Abort process still ongoing : All DMA channels are aborted, call user Abort Complete callback */
2409 hirda->TxXferCount = 0x00U;
2410 hirda->RxXferCount = 0x00U;
2411
2412 /* Reset ErrorCode */
2414
2415 /* Restore hirda->gState and hirda->RxState to Ready */
2418
2419 /* Call user Abort complete callback */
2420#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
2421 /* Call registered Abort complete callback */
2422 hirda->AbortCpltCallback(hirda);
2423#else
2424 /* Call legacy weak Abort complete callback */
2426#endif /* USE_HAL_IRDA_REGISTER_CALLBACK */
2427}
2428
2437static void IRDA_DMATxOnlyAbortCallback(DMA_HandleTypeDef *hdma)
2438{
2439 IRDA_HandleTypeDef *hirda = (IRDA_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
2440
2441 hirda->TxXferCount = 0x00U;
2442
2443 /* Restore hirda->gState to Ready */
2445
2446 /* Call user Abort complete callback */
2447#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
2448 /* Call registered Abort Transmit Complete Callback */
2449 hirda->AbortTransmitCpltCallback(hirda);
2450#else
2451 /* Call legacy weak Abort Transmit Complete Callback */
2453#endif /* USE_HAL_IRDA_REGISTER_CALLBACK */
2454}
2455
2464static void IRDA_DMARxOnlyAbortCallback(DMA_HandleTypeDef *hdma)
2465{
2466 IRDA_HandleTypeDef *hirda = (IRDA_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
2467
2468 hirda->RxXferCount = 0x00U;
2469
2470 /* Restore hirda->RxState to Ready */
2472
2473 /* Call user Abort complete callback */
2474#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
2475 /* Call registered Abort Receive Complete Callback */
2476 hirda->AbortReceiveCpltCallback(hirda);
2477#else
2478 /* Call legacy weak Abort Receive Complete Callback */
2480#endif /* USE_HAL_IRDA_REGISTER_CALLBACK */
2481}
2482
2489static HAL_StatusTypeDef IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda)
2490{
2491 const uint16_t *tmp;
2492
2493 /* Check that a Tx process is ongoing */
2494 if (hirda->gState == HAL_IRDA_STATE_BUSY_TX)
2495 {
2496 if (hirda->Init.WordLength == IRDA_WORDLENGTH_9B)
2497 {
2498 tmp = (const uint16_t *) hirda->pTxBuffPtr;
2499 hirda->Instance->DR = (uint16_t)(*tmp & (uint16_t)0x01FF);
2500 if (hirda->Init.Parity == IRDA_PARITY_NONE)
2501 {
2502 hirda->pTxBuffPtr += 2U;
2503 }
2504 else
2505 {
2506 hirda->pTxBuffPtr += 1U;
2507 }
2508 }
2509 else
2510 {
2511 hirda->Instance->DR = (uint8_t)(*hirda->pTxBuffPtr++ & (uint8_t)0x00FF);
2512 }
2513
2514 if (--hirda->TxXferCount == 0U)
2515 {
2516 /* Disable the IRDA Transmit Data Register Empty Interrupt */
2517 CLEAR_BIT(hirda->Instance->CR1, USART_CR1_TXEIE);
2518
2519 /* Enable the IRDA Transmit Complete Interrupt */
2520 SET_BIT(hirda->Instance->CR1, USART_CR1_TCIE);
2521 }
2522
2523 return HAL_OK;
2524 }
2525 else
2526 {
2527 return HAL_BUSY;
2528 }
2529}
2530
2537static HAL_StatusTypeDef IRDA_EndTransmit_IT(IRDA_HandleTypeDef *hirda)
2538{
2539 /* Disable the IRDA Transmit Complete Interrupt */
2540 CLEAR_BIT(hirda->Instance->CR1, USART_CR1_TCIE);
2541
2542 /* Disable the IRDA Error Interrupt: (Frame error, noise error, overrun error) */
2543 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
2544
2545 /* Tx process is ended, restore hirda->gState to Ready */
2547
2548#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
2549 /* Call registered Tx complete callback */
2550 hirda->TxCpltCallback(hirda);
2551#else
2552 /* Call legacy weak Tx complete callback */
2554#endif /* USE_HAL_IRDA_REGISTER_CALLBACK */
2555
2556 return HAL_OK;
2557}
2558
2565static HAL_StatusTypeDef IRDA_Receive_IT(IRDA_HandleTypeDef *hirda)
2566{
2567 uint16_t *tmp;
2568 uint16_t uhdata;
2569
2570 /* Check that a Rx process is ongoing */
2571 if (hirda->RxState == HAL_IRDA_STATE_BUSY_RX)
2572 {
2573 uhdata = (uint16_t) READ_REG(hirda->Instance->DR);
2574 if (hirda->Init.WordLength == IRDA_WORDLENGTH_9B)
2575 {
2576 tmp = (uint16_t *) hirda->pRxBuffPtr;
2577 if (hirda->Init.Parity == IRDA_PARITY_NONE)
2578 {
2579 *tmp = (uint16_t)(uhdata & (uint16_t)0x01FF);
2580 hirda->pRxBuffPtr += 2U;
2581 }
2582 else
2583 {
2584 *tmp = (uint16_t)(uhdata & (uint16_t)0x00FF);
2585 hirda->pRxBuffPtr += 1U;
2586 }
2587 }
2588 else
2589 {
2590 if (hirda->Init.Parity == IRDA_PARITY_NONE)
2591 {
2592 *hirda->pRxBuffPtr++ = (uint8_t)(uhdata & (uint8_t)0x00FF);
2593 }
2594 else
2595 {
2596 *hirda->pRxBuffPtr++ = (uint8_t)(uhdata & (uint8_t)0x007F);
2597 }
2598 }
2599
2600 if (--hirda->RxXferCount == 0U)
2601 {
2602 /* Disable the IRDA Data Register not empty Interrupt */
2603 CLEAR_BIT(hirda->Instance->CR1, USART_CR1_RXNEIE);
2604
2605 /* Disable the IRDA Parity Error Interrupt */
2606 CLEAR_BIT(hirda->Instance->CR1, USART_CR1_PEIE);
2607
2608 /* Disable the IRDA Error Interrupt: (Frame error, noise error, overrun error) */
2609 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
2610
2611 /* Rx process is completed, restore hirda->RxState to Ready */
2613
2614#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
2615 /* Call registered Rx complete callback */
2616 hirda->RxCpltCallback(hirda);
2617#else
2618 /* Call legacy weak Rx complete callback */
2620#endif /* USE_HAL_IRDA_REGISTER_CALLBACKS */
2621
2622 return HAL_OK;
2623 }
2624 return HAL_OK;
2625 }
2626 else
2627 {
2628 return HAL_BUSY;
2629 }
2630}
2631
2638static void IRDA_SetConfig(IRDA_HandleTypeDef *hirda)
2639{
2640 uint32_t pclk;
2641
2642 /* Check the parameters */
2643 assert_param(IS_IRDA_INSTANCE(hirda->Instance));
2649
2650 /*-------------------------- USART CR2 Configuration ------------------------*/
2651 /* Clear STOP[13:12] bits */
2652 CLEAR_BIT(hirda->Instance->CR2, USART_CR2_STOP);
2653
2654 /*-------------------------- USART CR1 Configuration -----------------------*/
2655 /* Clear M, PCE, PS, TE and RE bits */
2656 CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_M | USART_CR1_PCE | USART_CR1_PS | USART_CR1_TE | USART_CR1_RE));
2657
2658 /* Configure the USART Word Length, Parity and mode:
2659 Set the M bits according to hirda->Init.WordLength value
2660 Set PCE and PS bits according to hirda->Init.Parity value
2661 Set TE and RE bits according to hirda->Init.Mode value */
2662 /* Write to USART CR1 */
2663 SET_BIT(hirda->Instance->CR1, (hirda->Init.WordLength | hirda->Init.Parity | hirda->Init.Mode));
2664
2665 /*-------------------------- USART CR3 Configuration -----------------------*/
2666 /* Clear CTSE and RTSE bits */
2667 CLEAR_BIT(hirda->Instance->CR3, (USART_CR3_RTSE | USART_CR3_CTSE));
2668
2669 /*-------------------------- USART BRR Configuration -----------------------*/
2670#if defined(USART6) && defined(UART9) && defined(UART10)
2671 if ((hirda->Instance == USART1) || (hirda->Instance == USART6) || (hirda->Instance == UART9) || (hirda->Instance == UART10))
2672 {
2673 pclk = HAL_RCC_GetPCLK2Freq();
2674 SET_BIT(hirda->Instance->BRR, IRDA_BRR(pclk, hirda->Init.BaudRate));
2675 }
2676#elif defined(USART6)
2677 if((hirda->Instance == USART1) || (hirda->Instance == USART6))
2678 {
2679 pclk = HAL_RCC_GetPCLK2Freq();
2680 SET_BIT(hirda->Instance->BRR, IRDA_BRR(pclk, hirda->Init.BaudRate));
2681 }
2682#else
2683 if(hirda->Instance == USART1)
2684 {
2685 pclk = HAL_RCC_GetPCLK2Freq();
2686 SET_BIT(hirda->Instance->BRR, IRDA_BRR(pclk, hirda->Init.BaudRate));
2687 }
2688#endif /* USART6 */
2689 else
2690 {
2691 pclk = HAL_RCC_GetPCLK1Freq();
2692 SET_BIT(hirda->Instance->BRR, IRDA_BRR(pclk, hirda->Init.BaudRate));
2693 }
2694}
2695
2699
2700#endif /* HAL_IRDA_MODULE_ENABLED */
2704
2708
HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma)
HAL_StatusTypeDef HAL_DMA_Abort_IT(DMA_HandleTypeDef *hdma)
HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
struct __DMA_HandleTypeDef DMA_HandleTypeDef
DMA handle Structure definition.
uint32_t HAL_GetTick(void)
Provides a tick value in millisecond.
#define HAL_IRDA_ERROR_DMA
#define HAL_IRDA_ERROR_ORE
#define HAL_IRDA_ERROR_NONE
#define HAL_IRDA_ERROR_PE
#define HAL_IRDA_ERROR_NE
#define HAL_IRDA_ERROR_FE
void HAL_IRDA_MspDeInit(IRDA_HandleTypeDef *hirda)
HAL_StatusTypeDef HAL_IRDA_DeInit(IRDA_HandleTypeDef *hirda)
HAL_StatusTypeDef HAL_IRDA_Init(IRDA_HandleTypeDef *hirda)
void HAL_IRDA_MspInit(IRDA_HandleTypeDef *hirda)
void HAL_IRDA_AbortReceiveCpltCallback(IRDA_HandleTypeDef *hirda)
HAL_StatusTypeDef HAL_IRDA_Receive_IT(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size)
HAL_StatusTypeDef HAL_IRDA_Transmit(IRDA_HandleTypeDef *hirda, const uint8_t *pData, uint16_t Size, uint32_t Timeout)
HAL_StatusTypeDef HAL_IRDA_DMAStop(IRDA_HandleTypeDef *hirda)
HAL_StatusTypeDef HAL_IRDA_Receive(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size, uint32_t Timeout)
HAL_StatusTypeDef HAL_IRDA_DMAPause(IRDA_HandleTypeDef *hirda)
HAL_StatusTypeDef HAL_IRDA_AbortTransmit_IT(IRDA_HandleTypeDef *hirda)
void HAL_IRDA_AbortTransmitCpltCallback(IRDA_HandleTypeDef *hirda)
void HAL_IRDA_AbortCpltCallback(IRDA_HandleTypeDef *hirda)
void HAL_IRDA_IRQHandler(IRDA_HandleTypeDef *hirda)
HAL_StatusTypeDef HAL_IRDA_AbortReceive_IT(IRDA_HandleTypeDef *hirda)
void HAL_IRDA_ErrorCallback(IRDA_HandleTypeDef *hirda)
HAL_StatusTypeDef HAL_IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda, const uint8_t *pData, uint16_t Size)
HAL_StatusTypeDef HAL_IRDA_AbortTransmit(IRDA_HandleTypeDef *hirda)
void HAL_IRDA_TxCpltCallback(IRDA_HandleTypeDef *hirda)
void HAL_IRDA_RxHalfCpltCallback(IRDA_HandleTypeDef *hirda)
void HAL_IRDA_TxHalfCpltCallback(IRDA_HandleTypeDef *hirda)
HAL_StatusTypeDef HAL_IRDA_Receive_DMA(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size)
HAL_StatusTypeDef HAL_IRDA_AbortReceive(IRDA_HandleTypeDef *hirda)
HAL_StatusTypeDef HAL_IRDA_Transmit_DMA(IRDA_HandleTypeDef *hirda, const uint8_t *pData, uint16_t Size)
HAL_StatusTypeDef HAL_IRDA_Abort(IRDA_HandleTypeDef *hirda)
HAL_StatusTypeDef HAL_IRDA_DMAResume(IRDA_HandleTypeDef *hirda)
HAL_StatusTypeDef HAL_IRDA_Abort_IT(IRDA_HandleTypeDef *hirda)
void HAL_IRDA_RxCpltCallback(IRDA_HandleTypeDef *hirda)
uint32_t HAL_IRDA_GetError(const IRDA_HandleTypeDef *hirda)
HAL_IRDA_StateTypeDef HAL_IRDA_GetState(const IRDA_HandleTypeDef *hirda)
#define __HAL_IRDA_GET_FLAG(__HANDLE__, __FLAG__)
Check whether the specified IRDA flag is set or not.
#define __HAL_IRDA_CLEAR_OREFLAG(__HANDLE__)
Clear the IRDA ORE pending flag.
#define __HAL_IRDA_CLEAR_FLAG(__HANDLE__, __FLAG__)
Clear the specified IRDA pending flag.
#define __HAL_IRDA_ENABLE(__HANDLE__)
Enable UART/USART associated to IRDA Handle.
#define __HAL_IRDA_DISABLE(__HANDLE__)
Disable UART/USART associated to IRDA Handle.
HAL_IRDA_StateTypeDef
HAL IRDA State structures definition.
@ HAL_IRDA_STATE_BUSY_RX
@ HAL_IRDA_STATE_BUSY_TX
@ HAL_IRDA_STATE_BUSY
@ HAL_IRDA_STATE_READY
@ HAL_IRDA_STATE_RESET
#define IRDA_FLAG_RXNE
#define IRDA_FLAG_TXE
#define IRDA_FLAG_TC
#define IRDA_PARITY_NONE
#define IS_IRDA_MODE(MODE)
#define IS_IRDA_PARITY(PARITY)
#define IRDA_BRR(_PCLK_, _BAUD_)
#define IS_IRDA_BAUDRATE(BAUDRATE)
#define IS_IRDA_WORD_LENGTH(LENGTH)
#define IS_IRDA_POWERMODE(MODE)
#define IRDA_WORDLENGTH_9B
uint32_t HAL_RCC_GetPCLK1Freq(void)
uint32_t HAL_RCC_GetPCLK2Freq(void)
#define assert_param(expr)
This file contains all the functions prototypes for the HAL module driver.
#define HAL_IS_BIT_SET(REG, BIT)
HAL_StatusTypeDef
HAL Status structures definition.
@ HAL_TIMEOUT
@ HAL_ERROR
@ HAL_OK
@ HAL_BUSY
#define __HAL_UNLOCK(__HANDLE__)
#define HAL_MAX_DELAY
@ HAL_UNLOCKED
#define __HAL_LOCK(__HANDLE__)
IRDA handle Structure definition.
DMA_HandleTypeDef * hdmarx
volatile uint32_t ErrorCode
volatile HAL_IRDA_StateTypeDef gState
USART_TypeDef * Instance
volatile HAL_IRDA_StateTypeDef RxState
const uint8_t * pTxBuffPtr
IRDA_InitTypeDef Init
volatile uint16_t TxXferCount
volatile uint16_t RxXferCount
DMA_HandleTypeDef * hdmatx
void(* XferAbortCallback)(struct __DMA_HandleTypeDef *hdma)
void(* XferCpltCallback)(struct __DMA_HandleTypeDef *hdma)
void(* XferErrorCallback)(struct __DMA_HandleTypeDef *hdma)
void(* XferHalfCpltCallback)(struct __DMA_HandleTypeDef *hdma)
DMA_Stream_TypeDef * Instance