stm32f4xx_hal_uart.c
Go to the documentation of this file.
1 
218 /* Includes ------------------------------------------------------------------*/
219 #include "stm32f4xx_hal.h"
220 
229 #ifdef HAL_UART_MODULE_ENABLED
230 
231 /* Private typedef -----------------------------------------------------------*/
232 /* Private define ------------------------------------------------------------*/
239 /* Private macro -------------------------------------------------------------*/
240 /* Private variables ---------------------------------------------------------*/
241 /* Private function prototypes -----------------------------------------------*/
246 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
247 void UART_InitCallbacksToDefault(UART_HandleTypeDef *huart);
248 #endif /* USE_HAL_UART_REGISTER_CALLBACKS */
249 static void UART_EndTxTransfer(UART_HandleTypeDef *huart);
250 static void UART_EndRxTransfer(UART_HandleTypeDef *huart);
251 static void UART_DMATransmitCplt(DMA_HandleTypeDef *hdma);
252 static void UART_DMAReceiveCplt(DMA_HandleTypeDef *hdma);
253 static void UART_DMATxHalfCplt(DMA_HandleTypeDef *hdma);
254 static void UART_DMARxHalfCplt(DMA_HandleTypeDef *hdma);
255 static void UART_DMAError(DMA_HandleTypeDef *hdma);
256 static void UART_DMAAbortOnError(DMA_HandleTypeDef *hdma);
257 static void UART_DMATxAbortCallback(DMA_HandleTypeDef *hdma);
258 static void UART_DMARxAbortCallback(DMA_HandleTypeDef *hdma);
259 static void UART_DMATxOnlyAbortCallback(DMA_HandleTypeDef *hdma);
260 static void UART_DMARxOnlyAbortCallback(DMA_HandleTypeDef *hdma);
261 static HAL_StatusTypeDef UART_Transmit_IT(UART_HandleTypeDef *huart);
262 static HAL_StatusTypeDef UART_EndTransmit_IT(UART_HandleTypeDef *huart);
263 static HAL_StatusTypeDef UART_Receive_IT(UART_HandleTypeDef *huart);
264 static HAL_StatusTypeDef UART_WaitOnFlagUntilTimeout(UART_HandleTypeDef *huart, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout);
266 
271 /* Exported functions ---------------------------------------------------------*/
318 {
319  /* Check the UART handle allocation */
320  if (huart == NULL)
321  {
322  return HAL_ERROR;
323  }
324 
325  /* Check the parameters */
327  {
328  /* The hardware flow control is available only for USART1, USART2, USART3 and USART6.
329  Except for STM32F446xx devices, that is available for USART1, USART2, USART3, USART6, UART4 and UART5.
330  */
333  }
334  else
335  {
337  }
340 
342  {
343  /* Allocate lock resource and initialize it */
345 
346 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
347  UART_InitCallbacksToDefault(huart);
348 
349  if (huart->MspInitCallback == NULL)
350  {
351  huart->MspInitCallback = HAL_UART_MspInit;
352  }
353 
354  /* Init the low level hardware */
355  huart->MspInitCallback(huart);
356 #else
357  /* Init the low level hardware : GPIO, CLOCK */
359 #endif /* (USE_HAL_UART_REGISTER_CALLBACKS) */
360  }
361 
363 
364  /* Disable the peripheral */
366 
367  /* Set the UART Communication parameters */
369 
370  /* In asynchronous mode, the following bits must be kept cleared:
371  - LINEN and CLKEN bits in the USART_CR2 register,
372  - SCEN, HDSEL and IREN bits in the USART_CR3 register.*/
375 
376  /* Enable the peripheral */
378 
379  /* Initialize the UART state */
383 
384  return HAL_OK;
385 }
386 
395 {
396  /* Check the UART handle allocation */
397  if (huart == NULL)
398  {
399  return HAL_ERROR;
400  }
401 
402  /* Check the parameters */
406 
408  {
409  /* Allocate lock resource and initialize it */
411 
412 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
413  UART_InitCallbacksToDefault(huart);
414 
415  if (huart->MspInitCallback == NULL)
416  {
417  huart->MspInitCallback = HAL_UART_MspInit;
418  }
419 
420  /* Init the low level hardware */
421  huart->MspInitCallback(huart);
422 #else
423  /* Init the low level hardware : GPIO, CLOCK */
425 #endif /* (USE_HAL_UART_REGISTER_CALLBACKS) */
426  }
427 
429 
430  /* Disable the peripheral */
432 
433  /* Set the UART Communication parameters */
435 
436  /* In half-duplex mode, the following bits must be kept cleared:
437  - LINEN and CLKEN bits in the USART_CR2 register,
438  - SCEN and IREN bits in the USART_CR3 register.*/
441 
442  /* Enable the Half-Duplex mode by setting the HDSEL bit in the CR3 register */
444 
445  /* Enable the peripheral */
447 
448  /* Initialize the UART state*/
452 
453  return HAL_OK;
454 }
455 
467 HAL_StatusTypeDef HAL_LIN_Init(UART_HandleTypeDef *huart, uint32_t BreakDetectLength)
468 {
469  /* Check the UART handle allocation */
470  if (huart == NULL)
471  {
472  return HAL_ERROR;
473  }
474 
475  /* Check the LIN UART instance */
477 
478  /* Check the Break detection length parameter */
479  assert_param(IS_UART_LIN_BREAK_DETECT_LENGTH(BreakDetectLength));
482 
484  {
485  /* Allocate lock resource and initialize it */
487 
488 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
489  UART_InitCallbacksToDefault(huart);
490 
491  if (huart->MspInitCallback == NULL)
492  {
493  huart->MspInitCallback = HAL_UART_MspInit;
494  }
495 
496  /* Init the low level hardware */
497  huart->MspInitCallback(huart);
498 #else
499  /* Init the low level hardware : GPIO, CLOCK */
501 #endif /* (USE_HAL_UART_REGISTER_CALLBACKS) */
502  }
503 
505 
506  /* Disable the peripheral */
508 
509  /* Set the UART Communication parameters */
511 
512  /* In LIN mode, the following bits must be kept cleared:
513  - CLKEN bits in the USART_CR2 register,
514  - SCEN, HDSEL and IREN bits in the USART_CR3 register.*/
517 
518  /* Enable the LIN mode by setting the LINEN bit in the CR2 register */
520 
521  /* Set the USART LIN Break detection length. */
523  SET_BIT(huart->Instance->CR2, BreakDetectLength);
524 
525  /* Enable the peripheral */
527 
528  /* Initialize the UART state*/
532 
533  return HAL_OK;
534 }
535 
548 HAL_StatusTypeDef HAL_MultiProcessor_Init(UART_HandleTypeDef *huart, uint8_t Address, uint32_t WakeUpMethod)
549 {
550  /* Check the UART handle allocation */
551  if (huart == NULL)
552  {
553  return HAL_ERROR;
554  }
555 
556  /* Check the parameters */
558 
559  /* Check the Address & wake up method parameters */
560  assert_param(IS_UART_WAKEUPMETHOD(WakeUpMethod));
561  assert_param(IS_UART_ADDRESS(Address));
564 
566  {
567  /* Allocate lock resource and initialize it */
569 
570 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
571  UART_InitCallbacksToDefault(huart);
572 
573  if (huart->MspInitCallback == NULL)
574  {
575  huart->MspInitCallback = HAL_UART_MspInit;
576  }
577 
578  /* Init the low level hardware */
579  huart->MspInitCallback(huart);
580 #else
581  /* Init the low level hardware : GPIO, CLOCK */
583 #endif /* (USE_HAL_UART_REGISTER_CALLBACKS) */
584  }
585 
587 
588  /* Disable the peripheral */
590 
591  /* Set the UART Communication parameters */
593 
594  /* In Multi-Processor mode, the following bits must be kept cleared:
595  - LINEN and CLKEN bits in the USART_CR2 register,
596  - SCEN, HDSEL and IREN bits in the USART_CR3 register */
599 
600  /* Set the USART address node */
602  SET_BIT(huart->Instance->CR2, Address);
603 
604  /* Set the wake up method by setting the WAKE bit in the CR1 register */
606  SET_BIT(huart->Instance->CR1, WakeUpMethod);
607 
608  /* Enable the peripheral */
610 
611  /* Initialize the UART state */
615 
616  return HAL_OK;
617 }
618 
626 {
627  /* Check the UART handle allocation */
628  if (huart == NULL)
629  {
630  return HAL_ERROR;
631  }
632 
633  /* Check the parameters */
635 
637 
638  /* Disable the Peripheral */
640 
641 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
642  if (huart->MspDeInitCallback == NULL)
643  {
644  huart->MspDeInitCallback = HAL_UART_MspDeInit;
645  }
646  /* DeInit the low level hardware */
647  huart->MspDeInitCallback(huart);
648 #else
649  /* DeInit the low level hardware */
651 #endif /* (USE_HAL_UART_REGISTER_CALLBACKS) */
652 
656 
657  /* Process Unlock */
659 
660  return HAL_OK;
661 }
662 
670 {
671  /* Prevent unused argument(s) compilation warning */
672  UNUSED(huart);
673  /* NOTE: This function should not be modified, when the callback is needed,
674  the HAL_UART_MspInit could be implemented in the user file
675  */
676 }
677 
685 {
686  /* Prevent unused argument(s) compilation warning */
687  UNUSED(huart);
688  /* NOTE: This function should not be modified, when the callback is needed,
689  the HAL_UART_MspDeInit could be implemented in the user file
690  */
691 }
692 
693 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
694 
713 HAL_StatusTypeDef HAL_UART_RegisterCallback(UART_HandleTypeDef *huart, HAL_UART_CallbackIDTypeDef CallbackID, pUART_CallbackTypeDef pCallback)
714 {
715  HAL_StatusTypeDef status = HAL_OK;
716 
717  if (pCallback == NULL)
718  {
719  /* Update the error code */
720  huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK;
721 
722  return HAL_ERROR;
723  }
724  /* Process locked */
725  __HAL_LOCK(huart);
726 
728  {
729  switch (CallbackID)
730  {
731  case HAL_UART_TX_HALFCOMPLETE_CB_ID :
732  huart->TxHalfCpltCallback = pCallback;
733  break;
734 
735  case HAL_UART_TX_COMPLETE_CB_ID :
736  huart->TxCpltCallback = pCallback;
737  break;
738 
739  case HAL_UART_RX_HALFCOMPLETE_CB_ID :
740  huart->RxHalfCpltCallback = pCallback;
741  break;
742 
743  case HAL_UART_RX_COMPLETE_CB_ID :
744  huart->RxCpltCallback = pCallback;
745  break;
746 
747  case HAL_UART_ERROR_CB_ID :
748  huart->ErrorCallback = pCallback;
749  break;
750 
751  case HAL_UART_ABORT_COMPLETE_CB_ID :
752  huart->AbortCpltCallback = pCallback;
753  break;
754 
755  case HAL_UART_ABORT_TRANSMIT_COMPLETE_CB_ID :
756  huart->AbortTransmitCpltCallback = pCallback;
757  break;
758 
759  case HAL_UART_ABORT_RECEIVE_COMPLETE_CB_ID :
760  huart->AbortReceiveCpltCallback = pCallback;
761  break;
762 
763  case HAL_UART_MSPINIT_CB_ID :
764  huart->MspInitCallback = pCallback;
765  break;
766 
767  case HAL_UART_MSPDEINIT_CB_ID :
768  huart->MspDeInitCallback = pCallback;
769  break;
770 
771  default :
772  /* Update the error code */
773  huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK;
774 
775  /* Return error status */
776  status = HAL_ERROR;
777  break;
778  }
779  }
780  else if (huart->gState == HAL_UART_STATE_RESET)
781  {
782  switch (CallbackID)
783  {
784  case HAL_UART_MSPINIT_CB_ID :
785  huart->MspInitCallback = pCallback;
786  break;
787 
788  case HAL_UART_MSPDEINIT_CB_ID :
789  huart->MspDeInitCallback = pCallback;
790  break;
791 
792  default :
793  /* Update the error code */
794  huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK;
795 
796  /* Return error status */
797  status = HAL_ERROR;
798  break;
799  }
800  }
801  else
802  {
803  /* Update the error code */
804  huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK;
805 
806  /* Return error status */
807  status = HAL_ERROR;
808  }
809 
810  /* Release Lock */
812 
813  return status;
814 }
815 
834 HAL_StatusTypeDef HAL_UART_UnRegisterCallback(UART_HandleTypeDef *huart, HAL_UART_CallbackIDTypeDef CallbackID)
835 {
836  HAL_StatusTypeDef status = HAL_OK;
837 
838  /* Process locked */
839  __HAL_LOCK(huart);
840 
842  {
843  switch (CallbackID)
844  {
845  case HAL_UART_TX_HALFCOMPLETE_CB_ID :
846  huart->TxHalfCpltCallback = HAL_UART_TxHalfCpltCallback; /* Legacy weak TxHalfCpltCallback */
847  break;
848 
849  case HAL_UART_TX_COMPLETE_CB_ID :
850  huart->TxCpltCallback = HAL_UART_TxCpltCallback; /* Legacy weak TxCpltCallback */
851  break;
852 
853  case HAL_UART_RX_HALFCOMPLETE_CB_ID :
854  huart->RxHalfCpltCallback = HAL_UART_RxHalfCpltCallback; /* Legacy weak RxHalfCpltCallback */
855  break;
856 
857  case HAL_UART_RX_COMPLETE_CB_ID :
858  huart->RxCpltCallback = HAL_UART_RxCpltCallback; /* Legacy weak RxCpltCallback */
859  break;
860 
861  case HAL_UART_ERROR_CB_ID :
862  huart->ErrorCallback = HAL_UART_ErrorCallback; /* Legacy weak ErrorCallback */
863  break;
864 
865  case HAL_UART_ABORT_COMPLETE_CB_ID :
866  huart->AbortCpltCallback = HAL_UART_AbortCpltCallback; /* Legacy weak AbortCpltCallback */
867  break;
868 
869  case HAL_UART_ABORT_TRANSMIT_COMPLETE_CB_ID :
870  huart->AbortTransmitCpltCallback = HAL_UART_AbortTransmitCpltCallback; /* Legacy weak AbortTransmitCpltCallback */
871  break;
872 
873  case HAL_UART_ABORT_RECEIVE_COMPLETE_CB_ID :
874  huart->AbortReceiveCpltCallback = HAL_UART_AbortReceiveCpltCallback; /* Legacy weak AbortReceiveCpltCallback */
875  break;
876 
877  case HAL_UART_MSPINIT_CB_ID :
878  huart->MspInitCallback = HAL_UART_MspInit; /* Legacy weak MspInitCallback */
879  break;
880 
881  case HAL_UART_MSPDEINIT_CB_ID :
882  huart->MspDeInitCallback = HAL_UART_MspDeInit; /* Legacy weak MspDeInitCallback */
883  break;
884 
885  default :
886  /* Update the error code */
887  huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK;
888 
889  /* Return error status */
890  status = HAL_ERROR;
891  break;
892  }
893  }
894  else if (HAL_UART_STATE_RESET == huart->gState)
895  {
896  switch (CallbackID)
897  {
898  case HAL_UART_MSPINIT_CB_ID :
899  huart->MspInitCallback = HAL_UART_MspInit;
900  break;
901 
902  case HAL_UART_MSPDEINIT_CB_ID :
903  huart->MspDeInitCallback = HAL_UART_MspDeInit;
904  break;
905 
906  default :
907  /* Update the error code */
908  huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK;
909 
910  /* Return error status */
911  status = HAL_ERROR;
912  break;
913  }
914  }
915  else
916  {
917  /* Update the error code */
918  huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK;
919 
920  /* Return error status */
921  status = HAL_ERROR;
922  }
923 
924  /* Release Lock */
926 
927  return status;
928 }
929 #endif /* USE_HAL_UART_REGISTER_CALLBACKS */
930 
1024 HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout)
1025 {
1026  uint16_t *tmp;
1027  uint32_t tickstart = 0U;
1028 
1029  /* Check that a Tx process is not already ongoing */
1031  {
1032  if ((pData == NULL) || (Size == 0U))
1033  {
1034  return HAL_ERROR;
1035  }
1036 
1037  /* Process Locked */
1038  __HAL_LOCK(huart);
1039 
1042 
1043  /* Init tickstart for timeout managment */
1044  tickstart = HAL_GetTick();
1045 
1046  huart->TxXferSize = Size;
1047  huart->TxXferCount = Size;
1048 
1049  /* Process Unlocked */
1051 
1052  while (huart->TxXferCount > 0U)
1053  {
1054  huart->TxXferCount--;
1056  {
1057  if (UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK)
1058  {
1059  return HAL_TIMEOUT;
1060  }
1061  tmp = (uint16_t *) pData;
1062  huart->Instance->DR = (*tmp & (uint16_t)0x01FF);
1064  {
1065  pData += 2U;
1066  }
1067  else
1068  {
1069  pData += 1U;
1070  }
1071  }
1072  else
1073  {
1074  if (UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK)
1075  {
1076  return HAL_TIMEOUT;
1077  }
1078  huart->Instance->DR = (*pData++ & (uint8_t)0xFF);
1079  }
1080  }
1081 
1082  if (UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_TC, RESET, tickstart, Timeout) != HAL_OK)
1083  {
1084  return HAL_TIMEOUT;
1085  }
1086 
1087  /* At end of Tx process, restore huart->gState to Ready */
1089 
1090  return HAL_OK;
1091  }
1092  else
1093  {
1094  return HAL_BUSY;
1095  }
1096 }
1097 
1110 HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout)
1111 {
1112  uint16_t *tmp;
1113  uint32_t tickstart = 0U;
1114 
1115  /* Check that a Rx process is not already ongoing */
1117  {
1118  if ((pData == NULL) || (Size == 0U))
1119  {
1120  return HAL_ERROR;
1121  }
1122 
1123  /* Process Locked */
1124  __HAL_LOCK(huart);
1125 
1128 
1129  /* Init tickstart for timeout managment */
1130  tickstart = HAL_GetTick();
1131 
1132  huart->RxXferSize = Size;
1133  huart->RxXferCount = Size;
1134 
1135  /* Process Unlocked */
1137 
1138  /* Check the remain data to be received */
1139  while (huart->RxXferCount > 0U)
1140  {
1141  huart->RxXferCount--;
1143  {
1144  if (UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK)
1145  {
1146  return HAL_TIMEOUT;
1147  }
1148  tmp = (uint16_t *) pData;
1150  {
1151  *tmp = (uint16_t)(huart->Instance->DR & (uint16_t)0x01FF);
1152  pData += 2U;
1153  }
1154  else
1155  {
1156  *tmp = (uint16_t)(huart->Instance->DR & (uint16_t)0x00FF);
1157  pData += 1U;
1158  }
1159 
1160  }
1161  else
1162  {
1163  if (UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK)
1164  {
1165  return HAL_TIMEOUT;
1166  }
1168  {
1169  *pData++ = (uint8_t)(huart->Instance->DR & (uint8_t)0x00FF);
1170  }
1171  else
1172  {
1173  *pData++ = (uint8_t)(huart->Instance->DR & (uint8_t)0x007F);
1174  }
1175 
1176  }
1177  }
1178 
1179  /* At end of Rx process, restore huart->RxState to Ready */
1181 
1182  return HAL_OK;
1183  }
1184  else
1185  {
1186  return HAL_BUSY;
1187  }
1188 }
1189 
1201 HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
1202 {
1203  /* Check that a Tx process is not already ongoing */
1205  {
1206  if ((pData == NULL) || (Size == 0U))
1207  {
1208  return HAL_ERROR;
1209  }
1210 
1211  /* Process Locked */
1212  __HAL_LOCK(huart);
1213 
1214  huart->pTxBuffPtr = pData;
1215  huart->TxXferSize = Size;
1216  huart->TxXferCount = Size;
1217 
1220 
1221  /* Process Unlocked */
1223 
1224  /* Enable the UART Transmit data register empty Interrupt */
1226 
1227  return HAL_OK;
1228  }
1229  else
1230  {
1231  return HAL_BUSY;
1232  }
1233 }
1234 
1246 HAL_StatusTypeDef HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
1247 {
1248  /* Check that a Rx process is not already ongoing */
1250  {
1251  if ((pData == NULL) || (Size == 0U))
1252  {
1253  return HAL_ERROR;
1254  }
1255 
1256  /* Process Locked */
1257  __HAL_LOCK(huart);
1258 
1259  huart->pRxBuffPtr = pData;
1260  huart->RxXferSize = Size;
1261  huart->RxXferCount = Size;
1262 
1265 
1266  /* Process Unlocked */
1268 
1269  /* Enable the UART Parity Error Interrupt */
1271 
1272  /* Enable the UART Error Interrupt: (Frame error, noise error, overrun error) */
1274 
1275  /* Enable the UART Data Register not empty Interrupt */
1277 
1278  return HAL_OK;
1279  }
1280  else
1281  {
1282  return HAL_BUSY;
1283  }
1284 }
1285 
1297 HAL_StatusTypeDef HAL_UART_Transmit_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
1298 {
1299  uint32_t *tmp;
1300 
1301  /* Check that a Tx process is not already ongoing */
1303  {
1304  if ((pData == NULL) || (Size == 0U))
1305  {
1306  return HAL_ERROR;
1307  }
1308 
1309  /* Process Locked */
1310  __HAL_LOCK(huart);
1311 
1312  huart->pTxBuffPtr = pData;
1313  huart->TxXferSize = Size;
1314  huart->TxXferCount = Size;
1315 
1318 
1319  /* Set the UART DMA transfer complete callback */
1320  huart->hdmatx->XferCpltCallback = UART_DMATransmitCplt;
1321 
1322  /* Set the UART DMA Half transfer complete callback */
1323  huart->hdmatx->XferHalfCpltCallback = UART_DMATxHalfCplt;
1324 
1325  /* Set the DMA error callback */
1326  huart->hdmatx->XferErrorCallback = UART_DMAError;
1327 
1328  /* Set the DMA abort callback */
1330 
1331  /* Enable the UART transmit DMA stream */
1332  tmp = (uint32_t *)&pData;
1333  HAL_DMA_Start_IT(huart->hdmatx, *(uint32_t *)tmp, (uint32_t)&huart->Instance->DR, Size);
1334 
1335  /* Clear the TC flag in the SR register by writing 0 to it */
1337 
1338  /* Process Unlocked */
1340 
1341  /* Enable the DMA transfer for transmit request by setting the DMAT bit
1342  in the UART CR3 register */
1344 
1345  return HAL_OK;
1346  }
1347  else
1348  {
1349  return HAL_BUSY;
1350  }
1351 }
1352 
1365 HAL_StatusTypeDef HAL_UART_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
1366 {
1367  uint32_t *tmp;
1368 
1369  /* Check that a Rx process is not already ongoing */
1371  {
1372  if ((pData == NULL) || (Size == 0U))
1373  {
1374  return HAL_ERROR;
1375  }
1376 
1377  /* Process Locked */
1378  __HAL_LOCK(huart);
1379 
1380  huart->pRxBuffPtr = pData;
1381  huart->RxXferSize = Size;
1382 
1385 
1386  /* Set the UART DMA transfer complete callback */
1387  huart->hdmarx->XferCpltCallback = UART_DMAReceiveCplt;
1388 
1389  /* Set the UART DMA Half transfer complete callback */
1390  huart->hdmarx->XferHalfCpltCallback = UART_DMARxHalfCplt;
1391 
1392  /* Set the DMA error callback */
1393  huart->hdmarx->XferErrorCallback = UART_DMAError;
1394 
1395  /* Set the DMA abort callback */
1397 
1398  /* Enable the DMA stream */
1399  tmp = (uint32_t *)&pData;
1400  HAL_DMA_Start_IT(huart->hdmarx, (uint32_t)&huart->Instance->DR, *(uint32_t *)tmp, Size);
1401 
1402  /* Clear the Overrun flag just before enabling the DMA Rx request: can be mandatory for the second transfer */
1404 
1405  /* Process Unlocked */
1407 
1408  /* Enable the UART Parity Error Interrupt */
1410 
1411  /* Enable the UART Error Interrupt: (Frame error, noise error, overrun error) */
1413 
1414  /* Enable the DMA transfer for the receiver request by setting the DMAR bit
1415  in the UART CR3 register */
1417 
1418  return HAL_OK;
1419  }
1420  else
1421  {
1422  return HAL_BUSY;
1423  }
1424 }
1425 
1433 {
1434  uint32_t dmarequest = 0x00U;
1435 
1436  /* Process Locked */
1437  __HAL_LOCK(huart);
1438 
1439  dmarequest = HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAT);
1440  if ((huart->gState == HAL_UART_STATE_BUSY_TX) && dmarequest)
1441  {
1442  /* Disable the UART DMA Tx request */
1444  }
1445 
1446  dmarequest = HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR);
1447  if ((huart->RxState == HAL_UART_STATE_BUSY_RX) && dmarequest)
1448  {
1449  /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
1452 
1453  /* Disable the UART DMA Rx request */
1455  }
1456 
1457  /* Process Unlocked */
1459 
1460  return HAL_OK;
1461 }
1462 
1470 {
1471  /* Process Locked */
1472  __HAL_LOCK(huart);
1473 
1475  {
1476  /* Enable the UART DMA Tx request */
1478  }
1479 
1481  {
1482  /* Clear the Overrun flag before resuming the Rx transfer*/
1484 
1485  /* Reenable PE and ERR (Frame error, noise error, overrun error) interrupts */
1488 
1489  /* Enable the UART DMA Rx request */
1491  }
1492 
1493  /* Process Unlocked */
1495 
1496  return HAL_OK;
1497 }
1498 
1506 {
1507  uint32_t dmarequest = 0x00U;
1508  /* The Lock is not implemented on this API to allow the user application
1509  to call the HAL UART API under callbacks HAL_UART_TxCpltCallback() / HAL_UART_RxCpltCallback():
1510  when calling HAL_DMA_Abort() API the DMA TX/RX Transfer complete interrupt is generated
1511  and the correspond call back is executed HAL_UART_TxCpltCallback() / HAL_UART_RxCpltCallback()
1512  */
1513 
1514  /* Stop UART DMA Tx request if ongoing */
1515  dmarequest = HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAT);
1516  if ((huart->gState == HAL_UART_STATE_BUSY_TX) && dmarequest)
1517  {
1519 
1520  /* Abort the UART DMA Tx stream */
1521  if (huart->hdmatx != NULL)
1522  {
1524  }
1525  UART_EndTxTransfer(huart);
1526  }
1527 
1528  /* Stop UART DMA Rx request if ongoing */
1529  dmarequest = HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR);
1530  if ((huart->RxState == HAL_UART_STATE_BUSY_RX) && dmarequest)
1531  {
1533 
1534  /* Abort the UART DMA Rx stream */
1535  if (huart->hdmarx != NULL)
1536  {
1538  }
1539  UART_EndRxTransfer(huart);
1540  }
1541 
1542  return HAL_OK;
1543 }
1544 
1558 {
1559  /* Disable TXEIE, TCIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
1562 
1563  /* Disable the UART DMA Tx request if enabled */
1565  {
1567 
1568  /* Abort the UART DMA Tx stream: use blocking DMA Abort API (no callback) */
1569  if (huart->hdmatx != NULL)
1570  {
1571  /* Set the UART DMA Abort callback to Null.
1572  No call back execution at end of DMA abort procedure */
1574 
1575  if (HAL_DMA_Abort(huart->hdmatx) != HAL_OK)
1576  {
1578  {
1579  /* Set error code to DMA */
1581 
1582  return HAL_TIMEOUT;
1583  }
1584  }
1585  }
1586  }
1587 
1588  /* Disable the UART DMA Rx request if enabled */
1590  {
1592 
1593  /* Abort the UART DMA Rx stream: use blocking DMA Abort API (no callback) */
1594  if (huart->hdmarx != NULL)
1595  {
1596  /* Set the UART DMA Abort callback to Null.
1597  No call back execution at end of DMA abort procedure */
1599 
1600  if (HAL_DMA_Abort(huart->hdmarx) != HAL_OK)
1601  {
1603  {
1604  /* Set error code to DMA */
1606 
1607  return HAL_TIMEOUT;
1608  }
1609  }
1610  }
1611  }
1612 
1613  /* Reset Tx and Rx transfer counters */
1614  huart->TxXferCount = 0x00U;
1615  huart->RxXferCount = 0x00U;
1616 
1617  /* Reset ErrorCode */
1619 
1620  /* Restore huart->RxState and huart->gState to Ready */
1623 
1624  return HAL_OK;
1625 }
1626 
1640 {
1641  /* Disable TXEIE and TCIE interrupts */
1643 
1644  /* Disable the UART DMA Tx request if enabled */
1646  {
1648 
1649  /* Abort the UART DMA Tx stream : use blocking DMA Abort API (no callback) */
1650  if (huart->hdmatx != NULL)
1651  {
1652  /* Set the UART DMA Abort callback to Null.
1653  No call back execution at end of DMA abort procedure */
1655 
1656  if (HAL_DMA_Abort(huart->hdmatx) != HAL_OK)
1657  {
1659  {
1660  /* Set error code to DMA */
1662 
1663  return HAL_TIMEOUT;
1664  }
1665  }
1666  }
1667  }
1668 
1669  /* Reset Tx transfer counter */
1670  huart->TxXferCount = 0x00U;
1671 
1672  /* Restore huart->gState to Ready */
1674 
1675  return HAL_OK;
1676 }
1677 
1691 {
1692  /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
1695 
1696  /* Disable the UART DMA Rx request if enabled */
1698  {
1700 
1701  /* Abort the UART DMA Rx stream : use blocking DMA Abort API (no callback) */
1702  if (huart->hdmarx != NULL)
1703  {
1704  /* Set the UART DMA Abort callback to Null.
1705  No call back execution at end of DMA abort procedure */
1707 
1708  if (HAL_DMA_Abort(huart->hdmarx) != HAL_OK)
1709  {
1711  {
1712  /* Set error code to DMA */
1714 
1715  return HAL_TIMEOUT;
1716  }
1717  }
1718  }
1719  }
1720 
1721  /* Reset Rx transfer counter */
1722  huart->RxXferCount = 0x00U;
1723 
1724  /* Restore huart->RxState to Ready */
1726 
1727  return HAL_OK;
1728 }
1729 
1745 {
1746  uint32_t AbortCplt = 0x01U;
1747 
1748  /* Disable TXEIE, TCIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
1751 
1752  /* If DMA Tx and/or DMA Rx Handles are associated to UART Handle, DMA Abort complete callbacks should be initialised
1753  before any call to DMA Abort functions */
1754  /* DMA Tx Handle is valid */
1755  if (huart->hdmatx != NULL)
1756  {
1757  /* Set DMA Abort Complete callback if UART DMA Tx request if enabled.
1758  Otherwise, set it to NULL */
1760  {
1761  huart->hdmatx->XferAbortCallback = UART_DMATxAbortCallback;
1762  }
1763  else
1764  {
1766  }
1767  }
1768  /* DMA Rx Handle is valid */
1769  if (huart->hdmarx != NULL)
1770  {
1771  /* Set DMA Abort Complete callback if UART DMA Rx request if enabled.
1772  Otherwise, set it to NULL */
1774  {
1775  huart->hdmarx->XferAbortCallback = UART_DMARxAbortCallback;
1776  }
1777  else
1778  {
1780  }
1781  }
1782 
1783  /* Disable the UART DMA Tx request if enabled */
1785  {
1786  /* Disable DMA Tx at UART level */
1788 
1789  /* Abort the UART DMA Tx stream : use non blocking DMA Abort API (callback) */
1790  if (huart->hdmatx != NULL)
1791  {
1792  /* UART Tx DMA Abort callback has already been initialised :
1793  will lead to call HAL_UART_AbortCpltCallback() at end of DMA abort procedure */
1794 
1795  /* Abort DMA TX */
1797  {
1799  }
1800  else
1801  {
1802  AbortCplt = 0x00U;
1803  }
1804  }
1805  }
1806 
1807  /* Disable the UART DMA Rx request if enabled */
1809  {
1811 
1812  /* Abort the UART DMA Rx stream : use non blocking DMA Abort API (callback) */
1813  if (huart->hdmarx != NULL)
1814  {
1815  /* UART Rx DMA Abort callback has already been initialised :
1816  will lead to call HAL_UART_AbortCpltCallback() at end of DMA abort procedure */
1817 
1818  /* Abort DMA RX */
1820  {
1822  AbortCplt = 0x01U;
1823  }
1824  else
1825  {
1826  AbortCplt = 0x00U;
1827  }
1828  }
1829  }
1830 
1831  /* if no DMA abort complete callback execution is required => call user Abort Complete callback */
1832  if (AbortCplt == 0x01U)
1833  {
1834  /* Reset Tx and Rx transfer counters */
1835  huart->TxXferCount = 0x00U;
1836  huart->RxXferCount = 0x00U;
1837 
1838  /* Reset ErrorCode */
1840 
1841  /* Restore huart->gState and huart->RxState to Ready */
1844 
1845  /* As no DMA to be aborted, call directly user Abort complete callback */
1846 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
1847  /* Call registered Abort complete callback */
1848  huart->AbortCpltCallback(huart);
1849 #else
1850  /* Call legacy weak Abort complete callback */
1852 #endif /* USE_HAL_UART_REGISTER_CALLBACKS */
1853  }
1854 
1855  return HAL_OK;
1856 }
1857 
1873 {
1874  /* Disable TXEIE and TCIE interrupts */
1876 
1877  /* Disable the UART DMA Tx request if enabled */
1879  {
1881 
1882  /* Abort the UART DMA Tx stream : use blocking DMA Abort API (no callback) */
1883  if (huart->hdmatx != NULL)
1884  {
1885  /* Set the UART DMA Abort callback :
1886  will lead to call HAL_UART_AbortCpltCallback() at end of DMA abort procedure */
1887  huart->hdmatx->XferAbortCallback = UART_DMATxOnlyAbortCallback;
1888 
1889  /* Abort DMA TX */
1891  {
1892  /* Call Directly huart->hdmatx->XferAbortCallback function in case of error */
1894  }
1895  }
1896  else
1897  {
1898  /* Reset Tx transfer counter */
1899  huart->TxXferCount = 0x00U;
1900 
1901  /* Restore huart->gState to Ready */
1903 
1904  /* As no DMA to be aborted, call directly user Abort complete callback */
1905 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
1906  /* Call registered Abort Transmit Complete Callback */
1907  huart->AbortTransmitCpltCallback(huart);
1908 #else
1909  /* Call legacy weak Abort Transmit Complete Callback */
1911 #endif /* USE_HAL_UART_REGISTER_CALLBACKS */
1912  }
1913  }
1914  else
1915  {
1916  /* Reset Tx transfer counter */
1917  huart->TxXferCount = 0x00U;
1918 
1919  /* Restore huart->gState to Ready */
1921 
1922  /* As no DMA to be aborted, call directly user Abort complete callback */
1923 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
1924  /* Call registered Abort Transmit Complete Callback */
1925  huart->AbortTransmitCpltCallback(huart);
1926 #else
1927  /* Call legacy weak Abort Transmit Complete Callback */
1929 #endif /* USE_HAL_UART_REGISTER_CALLBACKS */
1930  }
1931 
1932  return HAL_OK;
1933 }
1934 
1950 {
1951  /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
1954 
1955  /* Disable the UART DMA Rx request if enabled */
1957  {
1959 
1960  /* Abort the UART DMA Rx stream : use blocking DMA Abort API (no callback) */
1961  if (huart->hdmarx != NULL)
1962  {
1963  /* Set the UART DMA Abort callback :
1964  will lead to call HAL_UART_AbortCpltCallback() at end of DMA abort procedure */
1965  huart->hdmarx->XferAbortCallback = UART_DMARxOnlyAbortCallback;
1966 
1967  /* Abort DMA RX */
1969  {
1970  /* Call Directly huart->hdmarx->XferAbortCallback function in case of error */
1972  }
1973  }
1974  else
1975  {
1976  /* Reset Rx transfer counter */
1977  huart->RxXferCount = 0x00U;
1978 
1979  /* Restore huart->RxState to Ready */
1981 
1982  /* As no DMA to be aborted, call directly user Abort complete callback */
1983 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
1984  /* Call registered Abort Receive Complete Callback */
1985  huart->AbortReceiveCpltCallback(huart);
1986 #else
1987  /* Call legacy weak Abort Receive Complete Callback */
1989 #endif /* USE_HAL_UART_REGISTER_CALLBACKS */
1990  }
1991  }
1992  else
1993  {
1994  /* Reset Rx transfer counter */
1995  huart->RxXferCount = 0x00U;
1996 
1997  /* Restore huart->RxState to Ready */
1999 
2000  /* As no DMA to be aborted, call directly user Abort complete callback */
2001 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
2002  /* Call registered Abort Receive Complete Callback */
2003  huart->AbortReceiveCpltCallback(huart);
2004 #else
2005  /* Call legacy weak Abort Receive Complete Callback */
2007 #endif /* USE_HAL_UART_REGISTER_CALLBACKS */
2008  }
2009 
2010  return HAL_OK;
2011 }
2012 
2020 {
2021  uint32_t isrflags = READ_REG(huart->Instance->SR);
2022  uint32_t cr1its = READ_REG(huart->Instance->CR1);
2023  uint32_t cr3its = READ_REG(huart->Instance->CR3);
2024  uint32_t errorflags = 0x00U;
2025  uint32_t dmarequest = 0x00U;
2026 
2027  /* If no error occurs */
2028  errorflags = (isrflags & (uint32_t)(USART_SR_PE | USART_SR_FE | USART_SR_ORE | USART_SR_NE));
2029  if (errorflags == RESET)
2030  {
2031  /* UART in mode Receiver -------------------------------------------------*/
2032  if (((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET))
2033  {
2034  UART_Receive_IT(huart);
2035  return;
2036  }
2037  }
2038 
2039  /* If some errors occur */
2040  if ((errorflags != RESET) && (((cr3its & USART_CR3_EIE) != RESET) || ((cr1its & (USART_CR1_RXNEIE | USART_CR1_PEIE)) != RESET)))
2041  {
2042  /* UART parity error interrupt occurred ----------------------------------*/
2043  if (((isrflags & USART_SR_PE) != RESET) && ((cr1its & USART_CR1_PEIE) != RESET))
2044  {
2046  }
2047 
2048  /* UART noise error interrupt occurred -----------------------------------*/
2049  if (((isrflags & USART_SR_NE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET))
2050  {
2052  }
2053 
2054  /* UART frame error interrupt occurred -----------------------------------*/
2055  if (((isrflags & USART_SR_FE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET))
2056  {
2058  }
2059 
2060  /* UART Over-Run interrupt occurred --------------------------------------*/
2061  if (((isrflags & USART_SR_ORE) != RESET) && (((cr1its & USART_CR1_RXNEIE) != RESET) || ((cr3its & USART_CR3_EIE) != RESET)))
2062  {
2064  }
2065 
2066  /* Call UART Error Call back function if need be --------------------------*/
2068  {
2069  /* UART in mode Receiver -----------------------------------------------*/
2070  if (((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET))
2071  {
2072  UART_Receive_IT(huart);
2073  }
2074 
2075  /* If Overrun error occurs, or if any error occurs in DMA mode reception,
2076  consider error as blocking */
2077  dmarequest = HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR);
2078  if (((huart->ErrorCode & HAL_UART_ERROR_ORE) != RESET) || dmarequest)
2079  {
2080  /* Blocking error : transfer is aborted
2081  Set the UART state ready to be able to start again the process,
2082  Disable Rx Interrupts, and disable Rx DMA request, if ongoing */
2083  UART_EndRxTransfer(huart);
2084 
2085  /* Disable the UART DMA Rx request if enabled */
2087  {
2089 
2090  /* Abort the UART DMA Rx stream */
2091  if (huart->hdmarx != NULL)
2092  {
2093  /* Set the UART DMA Abort callback :
2094  will lead to call HAL_UART_ErrorCallback() at end of DMA abort procedure */
2095  huart->hdmarx->XferAbortCallback = UART_DMAAbortOnError;
2097  {
2098  /* Call Directly XferAbortCallback function in case of error */
2100  }
2101  }
2102  else
2103  {
2104  /* Call user error callback */
2105 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
2106  /*Call registered error callback*/
2107  huart->ErrorCallback(huart);
2108 #else
2109  /*Call legacy weak error callback*/
2111 #endif /* USE_HAL_UART_REGISTER_CALLBACKS */
2112  }
2113  }
2114  else
2115  {
2116  /* Call user error callback */
2117 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
2118  /*Call registered error callback*/
2119  huart->ErrorCallback(huart);
2120 #else
2121  /*Call legacy weak error callback*/
2123 #endif /* USE_HAL_UART_REGISTER_CALLBACKS */
2124  }
2125  }
2126  else
2127  {
2128  /* Non Blocking error : transfer could go on.
2129  Error is notified to user through user error callback */
2130 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
2131  /*Call registered error callback*/
2132  huart->ErrorCallback(huart);
2133 #else
2134  /*Call legacy weak error callback*/
2136 #endif /* USE_HAL_UART_REGISTER_CALLBACKS */
2137 
2139  }
2140  }
2141  return;
2142  } /* End if some error occurs */
2143 
2144  /* UART in mode Transmitter ------------------------------------------------*/
2145  if (((isrflags & USART_SR_TXE) != RESET) && ((cr1its & USART_CR1_TXEIE) != RESET))
2146  {
2147  UART_Transmit_IT(huart);
2148  return;
2149  }
2150 
2151  /* UART in mode Transmitter end --------------------------------------------*/
2152  if (((isrflags & USART_SR_TC) != RESET) && ((cr1its & USART_CR1_TCIE) != RESET))
2153  {
2154  UART_EndTransmit_IT(huart);
2155  return;
2156  }
2157 }
2158 
2166 {
2167  /* Prevent unused argument(s) compilation warning */
2168  UNUSED(huart);
2169  /* NOTE: This function should not be modified, when the callback is needed,
2170  the HAL_UART_TxCpltCallback could be implemented in the user file
2171  */
2172 }
2173 
2181 {
2182  /* Prevent unused argument(s) compilation warning */
2183  UNUSED(huart);
2184  /* NOTE: This function should not be modified, when the callback is needed,
2185  the HAL_UART_TxHalfCpltCallback could be implemented in the user file
2186  */
2187 }
2188 
2196 {
2197  /* Prevent unused argument(s) compilation warning */
2198  UNUSED(huart);
2199  /* NOTE: This function should not be modified, when the callback is needed,
2200  the HAL_UART_RxCpltCallback could be implemented in the user file
2201  */
2202 }
2203 
2211 {
2212  /* Prevent unused argument(s) compilation warning */
2213  UNUSED(huart);
2214  /* NOTE: This function should not be modified, when the callback is needed,
2215  the HAL_UART_RxHalfCpltCallback could be implemented in the user file
2216  */
2217 }
2218 
2226 {
2227  /* Prevent unused argument(s) compilation warning */
2228  UNUSED(huart);
2229  /* NOTE: This function should not be modified, when the callback is needed,
2230  the HAL_UART_ErrorCallback could be implemented in the user file
2231  */
2232 }
2233 
2240 {
2241  /* Prevent unused argument(s) compilation warning */
2242  UNUSED(huart);
2243 
2244  /* NOTE : This function should not be modified, when the callback is needed,
2245  the HAL_UART_AbortCpltCallback can be implemented in the user file.
2246  */
2247 }
2248 
2255 {
2256  /* Prevent unused argument(s) compilation warning */
2257  UNUSED(huart);
2258 
2259  /* NOTE : This function should not be modified, when the callback is needed,
2260  the HAL_UART_AbortTransmitCpltCallback can be implemented in the user file.
2261  */
2262 }
2263 
2270 {
2271  /* Prevent unused argument(s) compilation warning */
2272  UNUSED(huart);
2273 
2274  /* NOTE : This function should not be modified, when the callback is needed,
2275  the HAL_UART_AbortReceiveCpltCallback can be implemented in the user file.
2276  */
2277 }
2278 
2309 {
2310  /* Check the parameters */
2312 
2313  /* Process Locked */
2314  __HAL_LOCK(huart);
2315 
2317 
2318  /* Send break characters */
2320 
2322 
2323  /* Process Unlocked */
2325 
2326  return HAL_OK;
2327 }
2328 
2336 {
2337  /* Check the parameters */
2339 
2340  /* Process Locked */
2341  __HAL_LOCK(huart);
2342 
2344 
2345  /* Enable the USART mute mode by setting the RWU bit in the CR1 register */
2347 
2349 
2350  /* Process Unlocked */
2352 
2353  return HAL_OK;
2354 }
2355 
2363 {
2364  /* Check the parameters */
2366 
2367  /* Process Locked */
2368  __HAL_LOCK(huart);
2369 
2371 
2372  /* Disable the USART mute mode by clearing the RWU bit in the CR1 register */
2374 
2376 
2377  /* Process Unlocked */
2379 
2380  return HAL_OK;
2381 }
2382 
2390 {
2391  uint32_t tmpreg = 0x00U;
2392 
2393  /* Process Locked */
2394  __HAL_LOCK(huart);
2395 
2397 
2398  /*-------------------------- USART CR1 Configuration -----------------------*/
2399  tmpreg = huart->Instance->CR1;
2400 
2401  /* Clear TE and RE bits */
2402  tmpreg &= (uint32_t)~((uint32_t)(USART_CR1_TE | USART_CR1_RE));
2403 
2404  /* Enable the USART's transmit interface by setting the TE bit in the USART CR1 register */
2405  tmpreg |= (uint32_t)USART_CR1_TE;
2406 
2407  /* Write to USART CR1 */
2408  WRITE_REG(huart->Instance->CR1, (uint32_t)tmpreg);
2409 
2411 
2412  /* Process Unlocked */
2414 
2415  return HAL_OK;
2416 }
2417 
2425 {
2426  uint32_t tmpreg = 0x00U;
2427 
2428  /* Process Locked */
2429  __HAL_LOCK(huart);
2430 
2432 
2433  /*-------------------------- USART CR1 Configuration -----------------------*/
2434  tmpreg = huart->Instance->CR1;
2435 
2436  /* Clear TE and RE bits */
2437  tmpreg &= (uint32_t)~((uint32_t)(USART_CR1_TE | USART_CR1_RE));
2438 
2439  /* Enable the USART's receive interface by setting the RE bit in the USART CR1 register */
2440  tmpreg |= (uint32_t)USART_CR1_RE;
2441 
2442  /* Write to USART CR1 */
2443  WRITE_REG(huart->Instance->CR1, (uint32_t)tmpreg);
2444 
2446 
2447  /* Process Unlocked */
2449 
2450  return HAL_OK;
2451 }
2452 
2482 {
2483  uint32_t temp1 = 0x00U, temp2 = 0x00U;
2484  temp1 = huart->gState;
2485  temp2 = huart->RxState;
2486 
2487  return (HAL_UART_StateTypeDef)(temp1 | temp2);
2488 }
2489 
2497 {
2498  return huart->ErrorCode;
2499 }
2500 
2518 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
2519 void UART_InitCallbacksToDefault(UART_HandleTypeDef *huart)
2520 {
2521  /* Init the UART Callback settings */
2522  huart->TxHalfCpltCallback = HAL_UART_TxHalfCpltCallback; /* Legacy weak TxHalfCpltCallback */
2523  huart->TxCpltCallback = HAL_UART_TxCpltCallback; /* Legacy weak TxCpltCallback */
2524  huart->RxHalfCpltCallback = HAL_UART_RxHalfCpltCallback; /* Legacy weak RxHalfCpltCallback */
2525  huart->RxCpltCallback = HAL_UART_RxCpltCallback; /* Legacy weak RxCpltCallback */
2526  huart->ErrorCallback = HAL_UART_ErrorCallback; /* Legacy weak ErrorCallback */
2527  huart->AbortCpltCallback = HAL_UART_AbortCpltCallback; /* Legacy weak AbortCpltCallback */
2528  huart->AbortTransmitCpltCallback = HAL_UART_AbortTransmitCpltCallback; /* Legacy weak AbortTransmitCpltCallback */
2529  huart->AbortReceiveCpltCallback = HAL_UART_AbortReceiveCpltCallback; /* Legacy weak AbortReceiveCpltCallback */
2530 
2531 }
2532 #endif /* USE_HAL_UART_REGISTER_CALLBACKS */
2533 
2540 static void UART_DMATransmitCplt(DMA_HandleTypeDef *hdma)
2541 {
2543  /* DMA Normal mode*/
2544  if ((hdma->Instance->CR & DMA_SxCR_CIRC) == 0U)
2545  {
2546  huart->TxXferCount = 0x00U;
2547 
2548  /* Disable the DMA transfer for transmit request by setting the DMAT bit
2549  in the UART CR3 register */
2551 
2552  /* Enable the UART Transmit Complete Interrupt */
2554 
2555  }
2556  /* DMA Circular mode */
2557  else
2558  {
2559 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
2560  /*Call registered Tx complete callback*/
2561  huart->TxCpltCallback(huart);
2562 #else
2563  /*Call legacy weak Tx complete callback*/
2565 #endif /* USE_HAL_UART_REGISTER_CALLBACKS */
2566  }
2567 }
2568 
2575 static void UART_DMATxHalfCplt(DMA_HandleTypeDef *hdma)
2576 {
2578 
2579 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
2580  /*Call registered Tx complete callback*/
2581  huart->TxHalfCpltCallback(huart);
2582 #else
2583  /*Call legacy weak Tx complete callback*/
2585 #endif /* USE_HAL_UART_REGISTER_CALLBACKS */
2586 }
2587 
2594 static void UART_DMAReceiveCplt(DMA_HandleTypeDef *hdma)
2595 {
2597  /* DMA Normal mode*/
2598  if ((hdma->Instance->CR & DMA_SxCR_CIRC) == 0U)
2599  {
2600  huart->RxXferCount = 0U;
2601 
2602  /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
2605 
2606  /* Disable the DMA transfer for the receiver request by setting the DMAR bit
2607  in the UART CR3 register */
2609 
2610  /* At end of Rx process, restore huart->RxState to Ready */
2612  }
2613 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
2614  /*Call registered Rx complete callback*/
2615  huart->RxCpltCallback(huart);
2616 #else
2617  /*Call legacy weak Rx complete callback*/
2619 #endif /* USE_HAL_UART_REGISTER_CALLBACKS */
2620 }
2621 
2628 static void UART_DMARxHalfCplt(DMA_HandleTypeDef *hdma)
2629 {
2631 
2632 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
2633  /*Call registered Rx Half complete callback*/
2634  huart->RxHalfCpltCallback(huart);
2635 #else
2636  /*Call legacy weak Rx Half complete callback*/
2638 #endif /* USE_HAL_UART_REGISTER_CALLBACKS */
2639 }
2640 
2647 static void UART_DMAError(DMA_HandleTypeDef *hdma)
2648 {
2649  uint32_t dmarequest = 0x00U;
2651 
2652  /* Stop UART DMA Tx request if ongoing */
2653  dmarequest = HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAT);
2654  if ((huart->gState == HAL_UART_STATE_BUSY_TX) && dmarequest)
2655  {
2656  huart->TxXferCount = 0x00U;
2657  UART_EndTxTransfer(huart);
2658  }
2659 
2660  /* Stop UART DMA Rx request if ongoing */
2661  dmarequest = HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR);
2662  if ((huart->RxState == HAL_UART_STATE_BUSY_RX) && dmarequest)
2663  {
2664  huart->RxXferCount = 0x00U;
2665  UART_EndRxTransfer(huart);
2666  }
2667 
2669 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
2670  /*Call registered error callback*/
2671  huart->ErrorCallback(huart);
2672 #else
2673  /*Call legacy weak error callback*/
2675 #endif /* USE_HAL_UART_REGISTER_CALLBACKS */
2676 }
2677 
2688 static HAL_StatusTypeDef UART_WaitOnFlagUntilTimeout(UART_HandleTypeDef *huart, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout)
2689 {
2690  /* Wait until flag is set */
2691  while ((__HAL_UART_GET_FLAG(huart, Flag) ? SET : RESET) == Status)
2692  {
2693  /* Check for the Timeout */
2694  if (Timeout != HAL_MAX_DELAY)
2695  {
2696  if ((Timeout == 0U) || ((HAL_GetTick() - Tickstart) > Timeout))
2697  {
2698  /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */
2701 
2704 
2705  /* Process Unlocked */
2707 
2708  return HAL_TIMEOUT;
2709  }
2710  }
2711  }
2712  return HAL_OK;
2713 }
2714 
2720 static void UART_EndTxTransfer(UART_HandleTypeDef *huart)
2721 {
2722  /* Disable TXEIE and TCIE interrupts */
2724 
2725  /* At end of Tx process, restore huart->gState to Ready */
2727 }
2728 
2734 static void UART_EndRxTransfer(UART_HandleTypeDef *huart)
2735 {
2736  /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
2739 
2740  /* At end of Rx process, restore huart->RxState to Ready */
2742 }
2743 
2751 static void UART_DMAAbortOnError(DMA_HandleTypeDef *hdma)
2752 {
2754  huart->RxXferCount = 0x00U;
2755  huart->TxXferCount = 0x00U;
2756 
2757 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
2758  /*Call registered error callback*/
2759  huart->ErrorCallback(huart);
2760 #else
2761  /*Call legacy weak error callback*/
2763 #endif /* USE_HAL_UART_REGISTER_CALLBACKS */
2764 }
2765 
2775 static void UART_DMATxAbortCallback(DMA_HandleTypeDef *hdma)
2776 {
2778 
2780 
2781  /* Check if an Abort process is still ongoing */
2782  if (huart->hdmarx != NULL)
2783  {
2785  {
2786  return;
2787  }
2788  }
2789 
2790  /* No Abort process still ongoing : All DMA channels are aborted, call user Abort Complete callback */
2791  huart->TxXferCount = 0x00U;
2792  huart->RxXferCount = 0x00U;
2793 
2794  /* Reset ErrorCode */
2796 
2797  /* Restore huart->gState and huart->RxState to Ready */
2800 
2801  /* Call user Abort complete callback */
2802 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
2803  /* Call registered Abort complete callback */
2804  huart->AbortCpltCallback(huart);
2805 #else
2806  /* Call legacy weak Abort complete callback */
2808 #endif /* USE_HAL_UART_REGISTER_CALLBACKS */
2809 }
2810 
2820 static void UART_DMARxAbortCallback(DMA_HandleTypeDef *hdma)
2821 {
2823 
2825 
2826  /* Check if an Abort process is still ongoing */
2827  if (huart->hdmatx != NULL)
2828  {
2830  {
2831  return;
2832  }
2833  }
2834 
2835  /* No Abort process still ongoing : All DMA channels are aborted, call user Abort Complete callback */
2836  huart->TxXferCount = 0x00U;
2837  huart->RxXferCount = 0x00U;
2838 
2839  /* Reset ErrorCode */
2841 
2842  /* Restore huart->gState and huart->RxState to Ready */
2845 
2846  /* Call user Abort complete callback */
2847 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
2848  /* Call registered Abort complete callback */
2849  huart->AbortCpltCallback(huart);
2850 #else
2851  /* Call legacy weak Abort complete callback */
2853 #endif /* USE_HAL_UART_REGISTER_CALLBACKS */
2854 }
2855 
2865 static void UART_DMATxOnlyAbortCallback(DMA_HandleTypeDef *hdma)
2866 {
2868 
2869  huart->TxXferCount = 0x00U;
2870 
2871  /* Restore huart->gState to Ready */
2873 
2874  /* Call user Abort complete callback */
2875 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
2876  /* Call registered Abort Transmit Complete Callback */
2877  huart->AbortTransmitCpltCallback(huart);
2878 #else
2879  /* Call legacy weak Abort Transmit Complete Callback */
2881 #endif /* USE_HAL_UART_REGISTER_CALLBACKS */
2882 }
2883 
2893 static void UART_DMARxOnlyAbortCallback(DMA_HandleTypeDef *hdma)
2894 {
2896 
2897  huart->RxXferCount = 0x00U;
2898 
2899  /* Restore huart->RxState to Ready */
2901 
2902  /* Call user Abort complete callback */
2903 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
2904  /* Call registered Abort Receive Complete Callback */
2905  huart->AbortReceiveCpltCallback(huart);
2906 #else
2907  /* Call legacy weak Abort Receive Complete Callback */
2909 #endif /* USE_HAL_UART_REGISTER_CALLBACKS */
2910 }
2911 
2918 static HAL_StatusTypeDef UART_Transmit_IT(UART_HandleTypeDef *huart)
2919 {
2920  uint16_t *tmp;
2921 
2922  /* Check that a Tx process is ongoing */
2924  {
2926  {
2927  tmp = (uint16_t *) huart->pTxBuffPtr;
2928  huart->Instance->DR = (uint16_t)(*tmp & (uint16_t)0x01FF);
2930  {
2931  huart->pTxBuffPtr += 2U;
2932  }
2933  else
2934  {
2935  huart->pTxBuffPtr += 1U;
2936  }
2937  }
2938  else
2939  {
2940  huart->Instance->DR = (uint8_t)(*huart->pTxBuffPtr++ & (uint8_t)0x00FF);
2941  }
2942 
2943  if (--huart->TxXferCount == 0U)
2944  {
2945  /* Disable the UART Transmit Complete Interrupt */
2947 
2948  /* Enable the UART Transmit Complete Interrupt */
2950  }
2951  return HAL_OK;
2952  }
2953  else
2954  {
2955  return HAL_BUSY;
2956  }
2957 }
2958 
2965 static HAL_StatusTypeDef UART_EndTransmit_IT(UART_HandleTypeDef *huart)
2966 {
2967  /* Disable the UART Transmit Complete Interrupt */
2969 
2970  /* Tx process is ended, restore huart->gState to Ready */
2972 
2973 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
2974  /*Call registered Tx complete callback*/
2975  huart->TxCpltCallback(huart);
2976 #else
2977  /*Call legacy weak Tx complete callback*/
2979 #endif /* USE_HAL_UART_REGISTER_CALLBACKS */
2980 
2981  return HAL_OK;
2982 }
2983 
2990 static HAL_StatusTypeDef UART_Receive_IT(UART_HandleTypeDef *huart)
2991 {
2992  uint16_t *tmp;
2993 
2994  /* Check that a Rx process is ongoing */
2996  {
2998  {
2999  tmp = (uint16_t *) huart->pRxBuffPtr;
3001  {
3002  *tmp = (uint16_t)(huart->Instance->DR & (uint16_t)0x01FF);
3003  huart->pRxBuffPtr += 2U;
3004  }
3005  else
3006  {
3007  *tmp = (uint16_t)(huart->Instance->DR & (uint16_t)0x00FF);
3008  huart->pRxBuffPtr += 1U;
3009  }
3010  }
3011  else
3012  {
3014  {
3015  *huart->pRxBuffPtr++ = (uint8_t)(huart->Instance->DR & (uint8_t)0x00FF);
3016  }
3017  else
3018  {
3019  *huart->pRxBuffPtr++ = (uint8_t)(huart->Instance->DR & (uint8_t)0x007F);
3020  }
3021  }
3022 
3023  if (--huart->RxXferCount == 0U)
3024  {
3025  /* Disable the UART Data Register not empty Interrupt */
3027 
3028  /* Disable the UART Parity Error Interrupt */
3030 
3031  /* Disable the UART Error Interrupt: (Frame error, noise error, overrun error) */
3033 
3034  /* Rx process is completed, restore huart->RxState to Ready */
3036 
3037 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
3038  /*Call registered Rx complete callback*/
3039  huart->RxCpltCallback(huart);
3040 #else
3041  /*Call legacy weak Rx complete callback*/
3043 #endif /* USE_HAL_UART_REGISTER_CALLBACKS */
3044 
3045  return HAL_OK;
3046  }
3047  return HAL_OK;
3048  }
3049  else
3050  {
3051  return HAL_BUSY;
3052  }
3053 }
3054 
3062 {
3063  uint32_t tmpreg;
3064  uint32_t pclk;
3065 
3066  /* Check the parameters */
3071 
3072  /*-------------------------- USART CR2 Configuration -----------------------*/
3073  /* Configure the UART Stop Bits: Set STOP[13:12] bits
3074  according to huart->Init.StopBits value */
3076 
3077  /*-------------------------- USART CR1 Configuration -----------------------*/
3078  /* Configure the UART Word Length, Parity and mode:
3079  Set the M bits according to huart->Init.WordLength value
3080  Set PCE and PS bits according to huart->Init.Parity value
3081  Set TE and RE bits according to huart->Init.Mode value
3082  Set OVER8 bit according to huart->Init.OverSampling value */
3083 
3084  tmpreg = (uint32_t)huart->Init.WordLength | huart->Init.Parity | huart->Init.Mode | huart->Init.OverSampling;
3087  tmpreg);
3088 
3089  /*-------------------------- USART CR3 Configuration -----------------------*/
3090  /* Configure the UART HFC: Set CTSE and RTSE bits according to huart->Init.HwFlowCtl value */
3092 
3093  /* Check the Over Sampling */
3095  {
3096  /*-------------------------- USART BRR Configuration ---------------------*/
3097 #if defined(USART6) && defined(UART9) && defined(UART10)
3098  if ((huart->Instance == USART1) || (huart->Instance == USART6) || (huart->Instance == UART9) || (huart->Instance == UART10))
3099  {
3100  pclk = HAL_RCC_GetPCLK2Freq();
3102  }
3103 #elif defined(USART6)
3104  if ((huart->Instance == USART1) || (huart->Instance == USART6))
3105  {
3106  pclk = HAL_RCC_GetPCLK2Freq();
3108  }
3109 #else
3110  if (huart->Instance == USART1)
3111  {
3112  pclk = HAL_RCC_GetPCLK2Freq();
3114  }
3115 #endif /* USART6 */
3116  else
3117  {
3118  pclk = HAL_RCC_GetPCLK1Freq();
3120  }
3121  }
3122  else
3123  {
3124  /*-------------------------- USART BRR Configuration ---------------------*/
3125 #if defined(USART6) && defined(UART9) && defined(UART10)
3126  if ((huart->Instance == USART1) || (huart->Instance == USART6) || (huart->Instance == UART9) || (huart->Instance == UART10))
3127  {
3128  pclk = HAL_RCC_GetPCLK2Freq();
3130  }
3131 #elif defined(USART6)
3132  if ((huart->Instance == USART1) || (huart->Instance == USART6))
3133  {
3134  pclk = HAL_RCC_GetPCLK2Freq();
3136  }
3137 #else
3138  if (huart->Instance == USART1)
3139  {
3140  pclk = HAL_RCC_GetPCLK2Freq();
3142  }
3143 #endif /* USART6 */
3144  else
3145  {
3146  pclk = HAL_RCC_GetPCLK1Freq();
3148  }
3149  }
3150 }
3151 
3156 #endif /* HAL_UART_MODULE_ENABLED */
3157 
3165 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
HAL_UART_ErrorCallback
void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
assert_param
#define assert_param(expr)
Include module's header file.
Definition: stm32f407/stm32f407g-disc1/Inc/stm32f4xx_hal_conf.h:353
USART_SR_PE
#define USART_SR_PE
Definition: stm32f407xx.h:12460
HAL_UART_Transmit_IT
HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
HAL_MultiProcessor_ExitMuteMode
HAL_StatusTypeDef HAL_MultiProcessor_ExitMuteMode(UART_HandleTypeDef *huart)
USART_CR1_OVER8
#define USART_CR1_OVER8
Definition: stm32f407xx.h:12547
UART9
#define UART9
Definition: stm32h735xx.h:2562
USART_CR1_M
#define USART_CR1_M
Definition: stm32f407xx.h:12541
HAL_StatusTypeDef
HAL_StatusTypeDef
HAL Status structures definition
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:40
HAL_UART_TxCpltCallback
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
__UART_HandleTypeDef::Init
UART_InitTypeDef Init
Definition: stm32f4xx_hal_uart.h:145
HAL_UART_StateTypeDef
HAL_UART_StateTypeDef
HAL UART State structures definition.
Definition: stm32f4xx_hal_uart.h:117
HAL_UART_AbortReceive
HAL_StatusTypeDef HAL_UART_AbortReceive(UART_HandleTypeDef *huart)
HAL_UART_ERROR_NE
#define HAL_UART_ERROR_NE
Definition: stm32f4xx_hal_uart.h:233
HAL_LIN_SendBreak
HAL_StatusTypeDef HAL_LIN_SendBreak(UART_HandleTypeDef *huart)
HAL_UART_Transmit
HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout)
__DMA_HandleTypeDef::XferHalfCpltCallback
void(* XferHalfCpltCallback)(struct __DMA_HandleTypeDef *hdma)
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h:153
IS_UART_HWFLOW_INSTANCE
#define IS_UART_HWFLOW_INSTANCE(INSTANCE)
Definition: stm32f407xx.h:15483
HAL_UART_ERROR_FE
#define HAL_UART_ERROR_FE
Definition: stm32f4xx_hal_uart.h:234
USART_CR3_SCEN
#define USART_CR3_SCEN
Definition: stm32f407xx.h:12600
__DMA_HandleTypeDef
DMA handle Structure definition.
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h:139
NULL
#define NULL
Definition: porcupine/demo/c/dr_libs/tests/external/miniaudio/extras/speex_resampler/thirdparty/resample.c:92
HAL_UART_Transmit_DMA
HAL_StatusTypeDef HAL_UART_Transmit_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
IS_UART_HALFDUPLEX_INSTANCE
#define IS_UART_HALFDUPLEX_INSTANCE(INSTANCE)
Definition: stm32f407xx.h:15472
HAL_DMA_ERROR_TIMEOUT
#define HAL_DMA_ERROR_TIMEOUT
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h:190
USART_CR2_ADD
#define USART_CR2_ADD
Definition: stm32f407xx.h:12552
HAL_UNLOCKED
@ HAL_UNLOCKED
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:53
UART_BRR_SAMPLING8
#define UART_BRR_SAMPLING8(_PCLK_, _BAUD_)
Definition: stm32f4xx_hal_uart.h:815
UART_FLAG_TC
#define UART_FLAG_TC
Definition: stm32f4xx_hal_uart.h:337
USART_CR3_HDSEL
#define USART_CR3_HDSEL
Definition: stm32f407xx.h:12594
USART_TypeDef::SR
__IO uint32_t SR
Definition: stm32f407xx.h:760
huart
UART_HandleTypeDef huart
Definition: pv_stm32f469.c:31
HAL_DMA_Abort_IT
HAL_StatusTypeDef HAL_DMA_Abort_IT(DMA_HandleTypeDef *hdma)
IS_UART_ADDRESS
#define IS_UART_ADDRESS(ADDRESS)
Definition: stm32f4xx_hal_uart.h:799
IS_UART_MODE
#define IS_UART_MODE(MODE)
Definition: stm32f4xx_hal_uart.h:788
USART_CR1_TXEIE
#define USART_CR1_TXEIE
Definition: stm32f407xx.h:12526
UART_InitTypeDef::OverSampling
uint32_t OverSampling
Definition: stm32f4xx_hal_uart.h:74
__UART_HandleTypeDef::TxXferCount
__IO uint16_t TxXferCount
Definition: stm32f4xx_hal_uart.h:151
HAL_UART_DMAStop
HAL_StatusTypeDef HAL_UART_DMAStop(UART_HandleTypeDef *huart)
HAL_UART_Abort_IT
HAL_StatusTypeDef HAL_UART_Abort_IT(UART_HandleTypeDef *huart)
HAL_RCC_GetPCLK2Freq
uint32_t HAL_RCC_GetPCLK2Freq(void)
USART_TypeDef::DR
__IO uint32_t DR
Definition: stm32f407xx.h:761
__DMA_HandleTypeDef::XferAbortCallback
void(* XferAbortCallback)(struct __DMA_HandleTypeDef *hdma)
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h:161
UART_InitTypeDef::WordLength
uint32_t WordLength
Definition: stm32f4xx_hal_uart.h:55
__UART_HandleTypeDef
UART handle Structure definition.
Definition: stm32f4xx_hal_uart.h:141
__HAL_UART_ENABLE
#define __HAL_UART_ENABLE(__HANDLE__)
Enable UART.
Definition: stm32f4xx_hal_uart.h:652
UART_InitTypeDef::BaudRate
uint32_t BaudRate
Definition: stm32f4xx_hal_uart.h:49
USART_CR3_DMAT
#define USART_CR3_DMAT
Definition: stm32f407xx.h:12606
USART_TypeDef::CR1
__IO uint32_t CR1
Definition: stm32f407xx.h:763
HAL_ERROR
@ HAL_ERROR
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:43
UART_WORDLENGTH_9B
#define UART_WORDLENGTH_9B
Definition: stm32f4xx_hal_uart.h:248
__HAL_UART_GET_FLAG
#define __HAL_UART_GET_FLAG(__HANDLE__, __FLAG__)
Checks whether the specified UART flag is set or not.
Definition: stm32f4xx_hal_uart.h:426
__HAL_UART_DISABLE
#define __HAL_UART_DISABLE(__HANDLE__)
Disable UART.
Definition: stm32f4xx_hal_uart.h:658
CLEAR_BIT
#define CLEAR_BIT(REG, BIT)
Definition: stm32f407/stm32f407g-disc1/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h:214
HAL_GetTick
uint32_t HAL_GetTick(void)
Provides a tick value in millisecond.
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c:323
IS_UART_WAKEUPMETHOD
#define IS_UART_WAKEUPMETHOD(WAKEUP)
Definition: stm32f4xx_hal_uart.h:796
HAL_UART_ERROR_PE
#define HAL_UART_ERROR_PE
Definition: stm32f4xx_hal_uart.h:232
USART_CR3_RTSE
#define USART_CR3_RTSE
Definition: stm32f407xx.h:12609
HAL_UART_DMAResume
HAL_StatusTypeDef HAL_UART_DMAResume(UART_HandleTypeDef *huart)
IS_UART_LIN_WORD_LENGTH
#define IS_UART_LIN_WORD_LENGTH(LENGTH)
Definition: stm32f4xx_hal_uart.h:777
DMA_Stream_TypeDef::CR
__IO uint32_t CR
Definition: stm32f407xx.h:348
HAL_UART_STATE_BUSY_TX
@ HAL_UART_STATE_BUSY_TX
Definition: stm32f4xx_hal_uart.h:125
HAL_UART_MspInit
void HAL_UART_MspInit(UART_HandleTypeDef *huart)
UART MSP Initialization This function configures the hardware resources used in this example.
Definition: stm32h7xx_hal_msp.c:320
USART_CR3_CTSE
#define USART_CR3_CTSE
Definition: stm32f407xx.h:12612
UART_IT_TC
#define UART_IT_TC
Definition: stm32f4xx_hal_uart.h:360
USART_CR1_RWU
#define USART_CR1_RWU
Definition: stm32f407xx.h:12508
UART_HWCONTROL_NONE
#define UART_HWCONTROL_NONE
Definition: stm32f4xx_hal_uart.h:275
HAL_OK
@ HAL_OK
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:42
UART_InitTypeDef::StopBits
uint32_t StopBits
Definition: stm32f4xx_hal_uart.h:58
UART_OVERSAMPLING_8
#define UART_OVERSAMPLING_8
Definition: stm32f4xx_hal_uart.h:306
HAL_HalfDuplex_EnableReceiver
HAL_StatusTypeDef HAL_HalfDuplex_EnableReceiver(UART_HandleTypeDef *huart)
HAL_UART_RxCpltCallback
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
UART_IT_RXNE
#define UART_IT_RXNE
Definition: stm32f4xx_hal_uart.h:361
UNUSED
#define UNUSED(x)
Definition: porcupine/demo/c/dr_libs/old/dr.h:92
__HAL_UART_DISABLE_IT
#define __HAL_UART_DISABLE_IT(__HANDLE__, __INTERRUPT__)
Disable the specified UART interrupt.
Definition: stm32f4xx_hal_uart.h:534
IS_UART_PARITY
#define IS_UART_PARITY(PARITY)
Definition: stm32f4xx_hal_uart.h:780
USART_CR1_PCE
#define USART_CR1_PCE
Definition: stm32f407xx.h:12535
USART_SR_ORE
#define USART_SR_ORE
Definition: stm32f407xx.h:12469
USART_CR2_STOP
#define USART_CR2_STOP
Definition: stm32f407xx.h:12574
IS_UART_LIN_BREAK_DETECT_LENGTH
#define IS_UART_LIN_BREAK_DETECT_LENGTH(LENGTH)
Definition: stm32f4xx_hal_uart.h:794
HAL_UART_RxHalfCpltCallback
void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart)
USART_CR2_CLKEN
#define USART_CR2_CLKEN
Definition: stm32f407xx.h:12570
__UART_HandleTypeDef::hdmatx
DMA_HandleTypeDef * hdmatx
Definition: stm32f4xx_hal_uart.h:159
__HAL_LOCK
#define __HAL_LOCK(__HANDLE__)
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:93
HAL_UART_GetState
HAL_UART_StateTypeDef HAL_UART_GetState(UART_HandleTypeDef *huart)
USART_CR1_RXNEIE
#define USART_CR1_RXNEIE
Definition: stm32f407xx.h:12520
__DMA_HandleTypeDef::Instance
DMA_Stream_TypeDef * Instance
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h:141
IS_UART_LIN_OVERSAMPLING
#define IS_UART_LIN_OVERSAMPLING(SAMPLING)
Definition: stm32f4xx_hal_uart.h:793
HAL_UART_AbortReceive_IT
HAL_StatusTypeDef HAL_UART_AbortReceive_IT(UART_HandleTypeDef *huart)
MODIFY_REG
#define MODIFY_REG(REG, CLEARMASK, SETMASK)
Definition: stm32f407/stm32f407g-disc1/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h:224
HAL_UART_ERROR_DMA
#define HAL_UART_ERROR_DMA
Definition: stm32f4xx_hal_uart.h:236
UART_BRR_SAMPLING16
#define UART_BRR_SAMPLING16(_PCLK_, _BAUD_)
Definition: stm32f4xx_hal_uart.h:806
HAL_UART_Init
HAL_StatusTypeDef HAL_UART_Init(UART_HandleTypeDef *huart)
UART_IT_PE
#define UART_IT_PE
Definition: stm32f4xx_hal_uart.h:358
HAL_UART_ERROR_ORE
#define HAL_UART_ERROR_ORE
Definition: stm32f4xx_hal_uart.h:235
HAL_UART_AbortTransmit_IT
HAL_StatusTypeDef HAL_UART_AbortTransmit_IT(UART_HandleTypeDef *huart)
USART_SR_NE
#define USART_SR_NE
Definition: stm32f407xx.h:12466
RESET
@ RESET
Definition: stm32f407/stm32f407g-disc1/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h:187
__UART_HandleTypeDef::Lock
HAL_LockTypeDef Lock
Definition: stm32f4xx_hal_uart.h:163
__HAL_UART_CLEAR_OREFLAG
#define __HAL_UART_CLEAR_OREFLAG(__HANDLE__)
Clears the UART ORE pending flag.
Definition: stm32f4xx_hal_uart.h:488
HAL_BUSY
@ HAL_BUSY
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:44
HAL_DMA_Start_IT
HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
HAL_UART_Receive_DMA
HAL_StatusTypeDef HAL_UART_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
USART_SR_RXNE
#define USART_SR_RXNE
Definition: stm32f407xx.h:12475
UART_FLAG_RXNE
#define UART_FLAG_RXNE
Definition: stm32f4xx_hal_uart.h:338
__UART_HandleTypeDef::RxState
__IO HAL_UART_StateTypeDef RxState
Definition: stm32f4xx_hal_uart.h:169
HAL_UART_STATE_BUSY_RX
@ HAL_UART_STATE_BUSY_RX
Definition: stm32f4xx_hal_uart.h:127
USART_TypeDef::CR3
__IO uint32_t CR3
Definition: stm32f407xx.h:765
USART_CR1_PEIE
#define USART_CR1_PEIE
Definition: stm32f407xx.h:12529
USART_TypeDef::CR2
__IO uint32_t CR2
Definition: stm32f407xx.h:764
__HAL_UNLOCK
#define __HAL_UNLOCK(__HANDLE__)
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:105
HAL_MAX_DELAY
#define HAL_MAX_DELAY
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:61
HAL_DMA_Abort
HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma)
__UART_HandleTypeDef::TxXferSize
uint16_t TxXferSize
Definition: stm32f4xx_hal_uart.h:149
__UART_HandleTypeDef::pTxBuffPtr
uint8_t * pTxBuffPtr
Definition: stm32f4xx_hal_uart.h:147
HAL_UART_Receive
HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout)
__UART_HandleTypeDef::gState
__IO HAL_UART_StateTypeDef gState
Definition: stm32f4xx_hal_uart.h:165
HAL_UART_ERROR_NONE
#define HAL_UART_ERROR_NONE
Definition: stm32f4xx_hal_uart.h:231
IS_UART_INSTANCE
#define IS_UART_INSTANCE
Definition: stm32f407xx.h:15480
__UART_HandleTypeDef::hdmarx
DMA_HandleTypeDef * hdmarx
Definition: stm32f4xx_hal_uart.h:161
__UART_HandleTypeDef::RxXferSize
uint16_t RxXferSize
Definition: stm32f4xx_hal_uart.h:155
UART_SetConfig
HAL_StatusTypeDef UART_SetConfig(UART_HandleTypeDef *huart)
USART_CR1_TCIE
#define USART_CR1_TCIE
Definition: stm32f407xx.h:12523
USART_TypeDef::BRR
__IO uint32_t BRR
Definition: stm32f407xx.h:762
USART_CR3_EIE
#define USART_CR3_EIE
Definition: stm32f407xx.h:12585
__UART_HandleTypeDef::pRxBuffPtr
uint8_t * pRxBuffPtr
Definition: stm32f4xx_hal_uart.h:153
__UART_HandleTypeDef::ErrorCode
__IO uint32_t ErrorCode
Definition: stm32f4xx_hal_uart.h:172
HAL_TIMEOUT
@ HAL_TIMEOUT
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:45
UART_IT_TXE
#define UART_IT_TXE
Definition: stm32f4xx_hal_uart.h:359
USART_CR2_LBDL
#define USART_CR2_LBDL
Definition: stm32f407xx.h:12555
__HAL_UART_ENABLE_IT
#define __HAL_UART_ENABLE_IT(__HANDLE__, __INTERRUPT__)
Enable the specified UART interrupt.
Definition: stm32f4xx_hal_uart.h:514
USART1
#define USART1
Definition: stm32f407xx.h:1088
IS_UART_LIN_INSTANCE
#define IS_UART_LIN_INSTANCE
Definition: stm32f407xx.h:15488
HAL_HalfDuplex_EnableTransmitter
HAL_StatusTypeDef HAL_HalfDuplex_EnableTransmitter(UART_HandleTypeDef *huart)
__DMA_HandleTypeDef::XferCpltCallback
void(* XferCpltCallback)(struct __DMA_HandleTypeDef *hdma)
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h:151
USART_SR_TXE
#define USART_SR_TXE
Definition: stm32f407xx.h:12481
IS_UART_HARDWARE_FLOW_CONTROL
#define IS_UART_HARDWARE_FLOW_CONTROL(CONTROL)
Definition: stm32f4xx_hal_uart.h:783
UART_WaitOnFlagUntilTimeout
HAL_StatusTypeDef UART_WaitOnFlagUntilTimeout(UART_HandleTypeDef *huart, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout)
HAL_RCC_GetPCLK1Freq
uint32_t HAL_RCC_GetPCLK1Freq(void)
USART_CR1_WAKE
#define USART_CR1_WAKE
Definition: stm32f407xx.h:12538
SET
@ SET
Definition: stm32f407/stm32f407g-disc1/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h:188
UART_InitTypeDef::Mode
uint32_t Mode
Definition: stm32f4xx_hal_uart.h:68
UART_IT_ERR
#define UART_IT_ERR
Definition: stm32f4xx_hal_uart.h:367
HAL_MultiProcessor_Init
HAL_StatusTypeDef HAL_MultiProcessor_Init(UART_HandleTypeDef *huart, uint8_t Address, uint32_t WakeUpMethod)
HAL_UART_AbortTransmit
HAL_StatusTypeDef HAL_UART_AbortTransmit(UART_HandleTypeDef *huart)
HAL_UART_STATE_RESET
@ HAL_UART_STATE_RESET
Definition: stm32f4xx_hal_uart.h:119
HAL_LIN_Init
HAL_StatusTypeDef HAL_LIN_Init(UART_HandleTypeDef *huart, uint32_t BreakDetectLength)
FlagStatus
FlagStatus
Definition: stm32f407/stm32f407g-disc1/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h:185
HAL_UART_AbortReceiveCpltCallback
void HAL_UART_AbortReceiveCpltCallback(UART_HandleTypeDef *huart)
HAL_UART_IRQHandler
void HAL_UART_IRQHandler(UART_HandleTypeDef *huart)
UART_InitTypeDef::HwFlowCtl
uint32_t HwFlowCtl
Definition: stm32f4xx_hal_uart.h:71
USART_CR1_RE
#define USART_CR1_RE
Definition: stm32f407xx.h:12511
HAL_HalfDuplex_Init
HAL_StatusTypeDef HAL_HalfDuplex_Init(UART_HandleTypeDef *huart)
UART_PARITY_NONE
#define UART_PARITY_NONE
Definition: stm32f4xx_hal_uart.h:265
HAL_IS_BIT_SET
#define HAL_IS_BIT_SET(REG, BIT)
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:63
WRITE_REG
#define WRITE_REG(REG, VAL)
Definition: stm32f407/stm32f407g-disc1/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h:220
IS_UART_STOPBITS
#define IS_UART_STOPBITS(STOPBITS)
Definition: stm32f4xx_hal_uart.h:778
USART6
#define USART6
Definition: stm32f407xx.h:1089
HAL_DMA_GetError
uint32_t HAL_DMA_GetError(DMA_HandleTypeDef *hdma)
HAL_UART_DeInit
HAL_StatusTypeDef HAL_UART_DeInit(UART_HandleTypeDef *huart)
IS_UART_WORD_LENGTH
#define IS_UART_WORD_LENGTH(LENGTH)
Definition: stm32f4xx_hal_uart.h:775
READ_REG
#define READ_REG(REG)
Definition: stm32f407/stm32f407g-disc1/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h:222
SET_BIT
#define SET_BIT(REG, BIT)
Definition: stm32f407/stm32f407g-disc1/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h:212
HAL_UART_AbortTransmitCpltCallback
void HAL_UART_AbortTransmitCpltCallback(UART_HandleTypeDef *huart)
IS_UART_OVERSAMPLING
#define IS_UART_OVERSAMPLING(SAMPLING)
Definition: stm32f4xx_hal_uart.h:791
HAL_UART_TxHalfCpltCallback
void HAL_UART_TxHalfCpltCallback(UART_HandleTypeDef *huart)
USART_CR2_LINEN
#define USART_CR2_LINEN
Definition: stm32f407xx.h:12580
USART_CR1_SBK
#define USART_CR1_SBK
Definition: stm32f407xx.h:12505
USART_CR3_DMAR
#define USART_CR3_DMAR
Definition: stm32f407xx.h:12603
HAL_UART_Receive_IT
HAL_StatusTypeDef HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
HAL_MultiProcessor_EnterMuteMode
HAL_StatusTypeDef HAL_MultiProcessor_EnterMuteMode(UART_HandleTypeDef *huart)
DMA_SxCR_CIRC
#define DMA_SxCR_CIRC
Definition: stm32f407xx.h:5852
USART_CR3_IREN
#define USART_CR3_IREN
Definition: stm32f407xx.h:12588
__UART_HandleTypeDef::Instance
USART_TypeDef * Instance
Definition: stm32f4xx_hal_uart.h:143
USART_SR_TC
#define USART_SR_TC
Definition: stm32f407xx.h:12478
HAL_UART_AbortCpltCallback
void HAL_UART_AbortCpltCallback(UART_HandleTypeDef *huart)
USART_CR1_TE
#define USART_CR1_TE
Definition: stm32f407xx.h:12514
__HAL_UART_CLEAR_FLAG
#define __HAL_UART_CLEAR_FLAG(__HANDLE__, __FLAG__)
Clears the specified UART pending flag.
Definition: stm32f4xx_hal_uart.h:450
UART_FLAG_TXE
#define UART_FLAG_TXE
Definition: stm32f4xx_hal_uart.h:336
USART_CR1_PS
#define USART_CR1_PS
Definition: stm32f407xx.h:12532
HAL_UART_STATE_BUSY
@ HAL_UART_STATE_BUSY
Definition: stm32f4xx_hal_uart.h:123
__UART_HandleTypeDef::RxXferCount
__IO uint16_t RxXferCount
Definition: stm32f4xx_hal_uart.h:157
HAL_UART_MspDeInit
void HAL_UART_MspDeInit(UART_HandleTypeDef *huart)
UART MSP De-Initialization This function freeze the hardware resources used in this example.
Definition: stm32h7xx_hal_msp.c:369
USART_SR_FE
#define USART_SR_FE
Definition: stm32f407xx.h:12463
HAL_UART_DMAPause
HAL_StatusTypeDef HAL_UART_DMAPause(UART_HandleTypeDef *huart)
HAL_UART_Abort
HAL_StatusTypeDef HAL_UART_Abort(UART_HandleTypeDef *huart)
__DMA_HandleTypeDef::XferErrorCallback
void(* XferErrorCallback)(struct __DMA_HandleTypeDef *hdma)
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h:159
UART_InitTypeDef::Parity
uint32_t Parity
Definition: stm32f4xx_hal_uart.h:61
IS_UART_BAUDRATE
#define IS_UART_BAUDRATE(BAUDRATE)
Definition: stm32f4xx_hal_uart.h:798
HAL_UART_STATE_READY
@ HAL_UART_STATE_READY
Definition: stm32f4xx_hal_uart.h:121
HAL_UART_GetError
uint32_t HAL_UART_GetError(UART_HandleTypeDef *huart)


picovoice_driver
Author(s):
autogenerated on Fri Apr 1 2022 02:14:52