Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 2 | Rev 6 | ||
|---|---|---|---|
| Line 37... | Line 37... | ||
| 37 | (+++) Declare a DMA handle structure for the Tx/Rx channel. |
37 | (+++) Declare a DMA handle structure for the Tx/Rx channel. |
| 38 | (+++) Enable the DMAx interface clock. |
38 | (+++) Enable the DMAx interface clock. |
| 39 | (+++) Configure the declared DMA handle structure with the required Tx/Rx parameters. |
39 | (+++) Configure the declared DMA handle structure with the required Tx/Rx parameters. |
| 40 | (+++) Configure the DMA Tx/Rx channel. |
40 | (+++) Configure the DMA Tx/Rx channel. |
| 41 | (+++) Associate the initialized DMA handle to the USART DMA Tx/Rx handle. |
41 | (+++) Associate the initialized DMA handle to the USART DMA Tx/Rx handle. |
| 42 | (+++) Configure the priority and enable the NVIC for the transfer complete interrupt on the DMA Tx/Rx channel. |
42 | (+++) Configure the priority and enable the NVIC for the transfer |
| - | 43 | complete interrupt on the DMA Tx/Rx channel. |
|
| 43 | 44 | ||
| 44 | (#) Program the Baud Rate, Word Length, Stop Bit, Parity, and Mode |
45 | (#) Program the Baud Rate, Word Length, Stop Bit, Parity, and Mode |
| 45 | (Receiver/Transmitter) in the husart handle Init structure. |
46 | (Receiver/Transmitter) in the husart handle Init structure. |
| 46 | 47 | ||
| 47 | (#) Initialize the USART registers by calling the HAL_USART_Init() API: |
48 | (#) Initialize the USART registers by calling the HAL_USART_Init() API: |
| Line 59... | Line 60... | ||
| 59 | [..] |
60 | [..] |
| 60 | The compilation define USE_HAL_USART_REGISTER_CALLBACKS when set to 1 |
61 | The compilation define USE_HAL_USART_REGISTER_CALLBACKS when set to 1 |
| 61 | allows the user to configure dynamically the driver callbacks. |
62 | allows the user to configure dynamically the driver callbacks. |
| 62 | 63 | ||
| 63 | [..] |
64 | [..] |
| 64 | Use Function @ref HAL_USART_RegisterCallback() to register a user callback. |
65 | Use Function HAL_USART_RegisterCallback() to register a user callback. |
| 65 | Function @ref HAL_USART_RegisterCallback() allows to register following callbacks: |
66 | Function HAL_USART_RegisterCallback() allows to register following callbacks: |
| 66 | (+) TxHalfCpltCallback : Tx Half Complete Callback. |
67 | (+) TxHalfCpltCallback : Tx Half Complete Callback. |
| 67 | (+) TxCpltCallback : Tx Complete Callback. |
68 | (+) TxCpltCallback : Tx Complete Callback. |
| 68 | (+) RxHalfCpltCallback : Rx Half Complete Callback. |
69 | (+) RxHalfCpltCallback : Rx Half Complete Callback. |
| 69 | (+) RxCpltCallback : Rx Complete Callback. |
70 | (+) RxCpltCallback : Rx Complete Callback. |
| 70 | (+) TxRxCpltCallback : Tx Rx Complete Callback. |
71 | (+) TxRxCpltCallback : Tx Rx Complete Callback. |
| Line 74... | Line 75... | ||
| 74 | (+) MspDeInitCallback : USART MspDeInit. |
75 | (+) MspDeInitCallback : USART MspDeInit. |
| 75 | This function takes as parameters the HAL peripheral handle, the Callback ID |
76 | This function takes as parameters the HAL peripheral handle, the Callback ID |
| 76 | and a pointer to the user callback function. |
77 | and a pointer to the user callback function. |
| 77 | 78 | ||
| 78 | [..] |
79 | [..] |
| 79 | Use function @ref HAL_USART_UnRegisterCallback() to reset a callback to the default |
80 | Use function HAL_USART_UnRegisterCallback() to reset a callback to the default |
| 80 | weak (surcharged) function. |
81 | weak (surcharged) function. |
| 81 | @ref HAL_USART_UnRegisterCallback() takes as parameters the HAL peripheral handle, |
82 | HAL_USART_UnRegisterCallback() takes as parameters the HAL peripheral handle, |
| 82 | and the Callback ID. |
83 | and the Callback ID. |
| 83 | This function allows to reset following callbacks: |
84 | This function allows to reset following callbacks: |
| 84 | (+) TxHalfCpltCallback : Tx Half Complete Callback. |
85 | (+) TxHalfCpltCallback : Tx Half Complete Callback. |
| 85 | (+) TxCpltCallback : Tx Complete Callback. |
86 | (+) TxCpltCallback : Tx Complete Callback. |
| 86 | (+) RxHalfCpltCallback : Rx Half Complete Callback. |
87 | (+) RxHalfCpltCallback : Rx Half Complete Callback. |
| Line 90... | Line 91... | ||
| 90 | (+) AbortCpltCallback : Abort Complete Callback. |
91 | (+) AbortCpltCallback : Abort Complete Callback. |
| 91 | (+) MspInitCallback : USART MspInit. |
92 | (+) MspInitCallback : USART MspInit. |
| 92 | (+) MspDeInitCallback : USART MspDeInit. |
93 | (+) MspDeInitCallback : USART MspDeInit. |
| 93 | 94 | ||
| 94 | [..] |
95 | [..] |
| 95 | By default, after the @ref HAL_USART_Init() and when the state is HAL_USART_STATE_RESET |
96 | By default, after the HAL_USART_Init() and when the state is HAL_USART_STATE_RESET |
| 96 | all callbacks are set to the corresponding weak (surcharged) functions: |
97 | all callbacks are set to the corresponding weak (surcharged) functions: |
| 97 | examples @ref HAL_USART_TxCpltCallback(), @ref HAL_USART_RxHalfCpltCallback(). |
98 | examples HAL_USART_TxCpltCallback(), HAL_USART_RxHalfCpltCallback(). |
| 98 | Exception done for MspInit and MspDeInit functions that are respectively |
99 | Exception done for MspInit and MspDeInit functions that are respectively |
| 99 | reset to the legacy weak (surcharged) functions in the @ref HAL_USART_Init() |
100 | reset to the legacy weak (surcharged) functions in the HAL_USART_Init() |
| 100 | and @ref HAL_USART_DeInit() only when these callbacks are null (not registered beforehand). |
101 | and HAL_USART_DeInit() only when these callbacks are null (not registered beforehand). |
| 101 | If not, MspInit or MspDeInit are not null, the @ref HAL_USART_Init() and @ref HAL_USART_DeInit() |
102 | If not, MspInit or MspDeInit are not null, the HAL_USART_Init() and HAL_USART_DeInit() |
| 102 | keep and use the user MspInit/MspDeInit callbacks (registered beforehand). |
103 | keep and use the user MspInit/MspDeInit callbacks (registered beforehand). |
| 103 | 104 | ||
| 104 | [..] |
105 | [..] |
| 105 | Callbacks can be registered/unregistered in HAL_USART_STATE_READY state only. |
106 | Callbacks can be registered/unregistered in HAL_USART_STATE_READY state only. |
| 106 | Exception done MspInit/MspDeInit that can be registered/unregistered |
107 | Exception done MspInit/MspDeInit that can be registered/unregistered |
| 107 | in HAL_USART_STATE_READY or HAL_USART_STATE_RESET state, thus registered (user) |
108 | in HAL_USART_STATE_READY or HAL_USART_STATE_RESET state, thus registered (user) |
| 108 | MspInit/DeInit callbacks can be used during the Init/DeInit. |
109 | MspInit/DeInit callbacks can be used during the Init/DeInit. |
| 109 | In that case first register the MspInit/MspDeInit user callbacks |
110 | In that case first register the MspInit/MspDeInit user callbacks |
| 110 | using @ref HAL_USART_RegisterCallback() before calling @ref HAL_USART_DeInit() |
111 | using HAL_USART_RegisterCallback() before calling HAL_USART_DeInit() |
| 111 | or @ref HAL_USART_Init() function. |
112 | or HAL_USART_Init() function. |
| 112 | 113 | ||
| 113 | [..] |
114 | [..] |
| 114 | When The compilation define USE_HAL_USART_REGISTER_CALLBACKS is set to 0 or |
115 | When The compilation define USE_HAL_USART_REGISTER_CALLBACKS is set to 0 or |
| 115 | not defined, the callback registration feature is not available |
116 | not defined, the callback registration feature is not available |
| 116 | and weak (surcharged) callbacks are used. |
117 | and weak (surcharged) callbacks are used. |
| Line 313... | Line 314... | ||
| 313 | return HAL_ERROR; |
314 | return HAL_ERROR; |
| 314 | } |
315 | } |
| 315 | 316 | ||
| 316 | /* In Synchronous mode, the following bits must be kept cleared: |
317 | /* In Synchronous mode, the following bits must be kept cleared: |
| 317 | - LINEN bit (if LIN is supported) in the USART_CR2 register |
318 | - LINEN bit (if LIN is supported) in the USART_CR2 register |
| 318 | - SCEN (if Smartcard is supported), HDSEL and IREN (if IrDA is supported) bits in the USART_CR3 register. |
319 | - SCEN (if Smartcard is supported), HDSEL and IREN (if IrDA is supported) bits in the USART_CR3 register. |
| 319 | */ |
320 | */ |
| 320 | #if defined (USART_CR2_LINEN) |
321 | #if defined (USART_CR2_LINEN) |
| 321 | husart->Instance->CR2 &= ~USART_CR2_LINEN; |
322 | husart->Instance->CR2 &= ~USART_CR2_LINEN; |
| 322 | #endif /* USART_CR2_LINEN */ |
323 | #endif /* USART_CR2_LINEN */ |
| 323 | #if defined (USART_CR3_SCEN) |
324 | #if defined (USART_CR3_SCEN) |
| Line 533... | Line 534... | ||
| 533 | 534 | ||
| 534 | return status; |
535 | return status; |
| 535 | } |
536 | } |
| 536 | 537 | ||
| 537 | /** |
538 | /** |
| 538 | * @brief Unregister an UART Callback |
539 | * @brief Unregister an USART Callback |
| 539 | * UART callaback is redirected to the weak predefined callback |
540 | * USART callaback is redirected to the weak predefined callback |
| 540 | * @param husart uart handle |
541 | * @param husart usart handle |
| 541 | * @param CallbackID ID of the callback to be unregistered |
542 | * @param CallbackID ID of the callback to be unregistered |
| 542 | * This parameter can be one of the following values: |
543 | * This parameter can be one of the following values: |
| 543 | * @arg @ref HAL_USART_TX_HALFCOMPLETE_CB_ID Tx Half Complete Callback ID |
544 | * @arg @ref HAL_USART_TX_HALFCOMPLETE_CB_ID Tx Half Complete Callback ID |
| 544 | * @arg @ref HAL_USART_TX_COMPLETE_CB_ID Tx Complete Callback ID |
545 | * @arg @ref HAL_USART_TX_COMPLETE_CB_ID Tx Complete Callback ID |
| 545 | * @arg @ref HAL_USART_RX_HALFCOMPLETE_CB_ID Rx Half Complete Callback ID |
546 | * @arg @ref HAL_USART_RX_HALFCOMPLETE_CB_ID Rx Half Complete Callback ID |
| Line 561... | Line 562... | ||
| 561 | if (HAL_USART_STATE_READY == husart->State) |
562 | if (HAL_USART_STATE_READY == husart->State) |
| 562 | { |
563 | { |
| 563 | switch (CallbackID) |
564 | switch (CallbackID) |
| 564 | { |
565 | { |
| 565 | case HAL_USART_TX_HALFCOMPLETE_CB_ID : |
566 | case HAL_USART_TX_HALFCOMPLETE_CB_ID : |
| 566 | husart->TxHalfCpltCallback = HAL_USART_TxHalfCpltCallback; /* Legacy weak TxHalfCpltCallback */ |
567 | husart->TxHalfCpltCallback = HAL_USART_TxHalfCpltCallback; /* Legacy weak TxHalfCpltCallback */ |
| 567 | break; |
568 | break; |
| 568 | 569 | ||
| 569 | case HAL_USART_TX_COMPLETE_CB_ID : |
570 | case HAL_USART_TX_COMPLETE_CB_ID : |
| 570 | husart->TxCpltCallback = HAL_USART_TxCpltCallback; /* Legacy weak TxCpltCallback */ |
571 | husart->TxCpltCallback = HAL_USART_TxCpltCallback; /* Legacy weak TxCpltCallback */ |
| 571 | break; |
572 | break; |
| 572 | 573 | ||
| 573 | case HAL_USART_RX_HALFCOMPLETE_CB_ID : |
574 | case HAL_USART_RX_HALFCOMPLETE_CB_ID : |
| 574 | husart->RxHalfCpltCallback = HAL_USART_RxHalfCpltCallback; /* Legacy weak RxHalfCpltCallback */ |
575 | husart->RxHalfCpltCallback = HAL_USART_RxHalfCpltCallback; /* Legacy weak RxHalfCpltCallback */ |
| 575 | break; |
576 | break; |
| 576 | 577 | ||
| 577 | case HAL_USART_RX_COMPLETE_CB_ID : |
578 | case HAL_USART_RX_COMPLETE_CB_ID : |
| 578 | husart->RxCpltCallback = HAL_USART_RxCpltCallback; /* Legacy weak RxCpltCallback */ |
579 | husart->RxCpltCallback = HAL_USART_RxCpltCallback; /* Legacy weak RxCpltCallback */ |
| 579 | break; |
580 | break; |
| 580 | 581 | ||
| 581 | case HAL_USART_TX_RX_COMPLETE_CB_ID : |
582 | case HAL_USART_TX_RX_COMPLETE_CB_ID : |
| 582 | husart->TxRxCpltCallback = HAL_USART_TxRxCpltCallback; /* Legacy weak TxRxCpltCallback */ |
583 | husart->TxRxCpltCallback = HAL_USART_TxRxCpltCallback; /* Legacy weak TxRxCpltCallback */ |
| 583 | break; |
584 | break; |
| 584 | 585 | ||
| 585 | case HAL_USART_ERROR_CB_ID : |
586 | case HAL_USART_ERROR_CB_ID : |
| 586 | husart->ErrorCallback = HAL_USART_ErrorCallback; /* Legacy weak ErrorCallback */ |
587 | husart->ErrorCallback = HAL_USART_ErrorCallback; /* Legacy weak ErrorCallback */ |
| 587 | break; |
588 | break; |
| 588 | 589 | ||
| 589 | case HAL_USART_ABORT_COMPLETE_CB_ID : |
590 | case HAL_USART_ABORT_COMPLETE_CB_ID : |
| 590 | husart->AbortCpltCallback = HAL_USART_AbortCpltCallback; /* Legacy weak AbortCpltCallback */ |
591 | husart->AbortCpltCallback = HAL_USART_AbortCpltCallback; /* Legacy weak AbortCpltCallback */ |
| 591 | break; |
592 | break; |
| 592 | 593 | ||
| 593 | 594 | ||
| 594 | case HAL_USART_MSPINIT_CB_ID : |
595 | case HAL_USART_MSPINIT_CB_ID : |
| 595 | husart->MspInitCallback = HAL_USART_MspInit; /* Legacy weak MspInitCallback */ |
596 | husart->MspInitCallback = HAL_USART_MspInit; /* Legacy weak MspInitCallback */ |
| 596 | break; |
597 | break; |
| 597 | 598 | ||
| 598 | case HAL_USART_MSPDEINIT_CB_ID : |
599 | case HAL_USART_MSPDEINIT_CB_ID : |
| 599 | husart->MspDeInitCallback = HAL_USART_MspDeInit; /* Legacy weak MspDeInitCallback */ |
600 | husart->MspDeInitCallback = HAL_USART_MspDeInit; /* Legacy weak MspDeInitCallback */ |
| 600 | break; |
601 | break; |
| 601 | 602 | ||
| 602 | default : |
603 | default : |
| 603 | /* Update the error code */ |
604 | /* Update the error code */ |
| 604 | husart->ErrorCode |= HAL_USART_ERROR_INVALID_CALLBACK; |
605 | husart->ErrorCode |= HAL_USART_ERROR_INVALID_CALLBACK; |
| Line 713... | Line 714... | ||
| 713 | (++) HAL_USART_AbortCpltCallback() |
714 | (++) HAL_USART_AbortCpltCallback() |
| 714 | 715 | ||
| 715 | (#) In Non-Blocking mode transfers, possible errors are split into 2 categories. |
716 | (#) In Non-Blocking mode transfers, possible errors are split into 2 categories. |
| 716 | Errors are handled as follows : |
717 | Errors are handled as follows : |
| 717 | (++) Error is considered as Recoverable and non blocking : Transfer could go till end, but error severity is |
718 | (++) Error is considered as Recoverable and non blocking : Transfer could go till end, but error severity is |
| - | 719 | to be evaluated by user : this concerns Frame Error, |
|
| 718 | to be evaluated by user : this concerns Frame Error, Parity Error or Noise Error in Interrupt mode reception . |
720 | Parity Error or Noise Error in Interrupt mode reception . |
| 719 | Received character is then retrieved and stored in Rx buffer, Error code is set to allow user to identify error type, |
721 | Received character is then retrieved and stored in Rx buffer, Error code is set to allow user to identify |
| 720 | and HAL_USART_ErrorCallback() user callback is executed. Transfer is kept ongoing on USART side. |
722 | error type, and HAL_USART_ErrorCallback() user callback is executed. |
| - | 723 | Transfer is kept ongoing on USART side. |
|
| 721 | If user wants to abort it, Abort services should be called by user. |
724 | If user wants to abort it, Abort services should be called by user. |
| 722 | (++) Error is considered as Blocking : Transfer could not be completed properly and is aborted. |
725 | (++) Error is considered as Blocking : Transfer could not be completed properly and is aborted. |
| 723 | This concerns Overrun Error In Interrupt mode reception and all errors in DMA mode. |
726 | This concerns Overrun Error In Interrupt mode reception and all errors in DMA mode. |
| - | 727 | Error code is set to allow user to identify error type, |
|
| 724 | Error code is set to allow user to identify error type, and HAL_USART_ErrorCallback() user callback is executed. |
728 | and HAL_USART_ErrorCallback() user callback is executed. |
| 725 | 729 | ||
| 726 | @endverbatim |
730 | @endverbatim |
| 727 | * @{ |
731 | * @{ |
| 728 | */ |
732 | */ |
| 729 | 733 | ||
| 730 | /** |
734 | /** |
| 731 | * @brief Simplex send an amount of data in blocking mode. |
735 | * @brief Simplex send an amount of data in blocking mode. |
| 732 | * @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
736 | * @note When USART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
| 733 | * the sent data is handled as a set of u16. In this case, Size must indicate the number |
737 | * the sent data is handled as a set of u16. In this case, Size must indicate the number |
| 734 | * of u16 provided through pTxData. |
738 | * of u16 provided through pTxData. |
| 735 | * @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
739 | * @note When USART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
| 736 | * address of user data buffer containing data to be sent, should be aligned on a half word frontier (16 bits) |
740 | * address of user data buffer containing data to be sent, should be aligned on a half word frontier (16 bits) |
| 737 | * (as sent data will be handled using u16 pointer cast). Depending on compilation chain, |
741 | * (as sent data will be handled using u16 pointer cast). Depending on compilation chain, |
| 738 | * use of specific alignment compilation directives or pragmas might be required to ensure proper alignment for pTxData. |
742 | * use of specific alignment compilation directives or pragmas might be required |
| - | 743 | * to ensure proper alignment for pTxData. |
|
| 739 | * @param husart USART handle. |
744 | * @param husart USART handle. |
| 740 | * @param pTxData Pointer to data buffer (u8 or u16 data elements). |
745 | * @param pTxData Pointer to data buffer (u8 or u16 data elements). |
| 741 | * @param Size Amount of data elements (u8 or u16) to be sent. |
746 | * @param Size Amount of data elements (u8 or u16) to be sent. |
| 742 | * @param Timeout Timeout duration. |
747 | * @param Timeout Timeout duration. |
| 743 | * @retval HAL status |
748 | * @retval HAL status |
| Line 770... | Line 775... | ||
| 770 | __HAL_LOCK(husart); |
775 | __HAL_LOCK(husart); |
| 771 | 776 | ||
| 772 | husart->ErrorCode = HAL_USART_ERROR_NONE; |
777 | husart->ErrorCode = HAL_USART_ERROR_NONE; |
| 773 | husart->State = HAL_USART_STATE_BUSY_TX; |
778 | husart->State = HAL_USART_STATE_BUSY_TX; |
| 774 | 779 | ||
| 775 | /* Init tickstart for timeout managment*/ |
780 | /* Init tickstart for timeout management */ |
| 776 | tickstart = HAL_GetTick(); |
781 | tickstart = HAL_GetTick(); |
| 777 | 782 | ||
| 778 | husart->TxXferSize = Size; |
783 | husart->TxXferSize = Size; |
| 779 | husart->TxXferCount = Size; |
784 | husart->TxXferCount = Size; |
| 780 | 785 | ||
| Line 841... | Line 846... | ||
| 841 | } |
846 | } |
| 842 | 847 | ||
| 843 | /** |
848 | /** |
| 844 | * @brief Receive an amount of data in blocking mode. |
849 | * @brief Receive an amount of data in blocking mode. |
| 845 | * @note To receive synchronous data, dummy data are simultaneously transmitted. |
850 | * @note To receive synchronous data, dummy data are simultaneously transmitted. |
| 846 | * @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
851 | * @note When USART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
| 847 | * the received data is handled as a set of u16. In this case, Size must indicate the number |
852 | * the received data is handled as a set of u16. In this case, Size must indicate the number |
| 848 | * of u16 available through pRxData. |
853 | * of u16 available through pRxData. |
| 849 | * @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
854 | * @note When USART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
| 850 | * address of user data buffer for storing data to be received, should be aligned on a half word frontier (16 bits) |
855 | * address of user data buffer for storing data to be received, should be aligned on a half word frontier (16 bits) |
| 851 | * (as received data will be handled using u16 pointer cast). Depending on compilation chain, |
856 | * (as received data will be handled using u16 pointer cast). Depending on compilation chain, |
| 852 | * use of specific alignment compilation directives or pragmas might be required to ensure proper alignment for pRxData. |
857 | * use of specific alignment compilation directives or pragmas might be required to ensure proper alignment for pRxData. |
| 853 | * @param husart USART handle. |
858 | * @param husart USART handle. |
| 854 | * @param pRxData Pointer to data buffer (u8 or u16 data elements). |
859 | * @param pRxData Pointer to data buffer (u8 or u16 data elements). |
| Line 885... | Line 890... | ||
| 885 | __HAL_LOCK(husart); |
890 | __HAL_LOCK(husart); |
| 886 | 891 | ||
| 887 | husart->ErrorCode = HAL_USART_ERROR_NONE; |
892 | husart->ErrorCode = HAL_USART_ERROR_NONE; |
| 888 | husart->State = HAL_USART_STATE_BUSY_RX; |
893 | husart->State = HAL_USART_STATE_BUSY_RX; |
| 889 | 894 | ||
| 890 | /* Init tickstart for timeout managment*/ |
895 | /* Init tickstart for timeout management */ |
| 891 | tickstart = HAL_GetTick(); |
896 | tickstart = HAL_GetTick(); |
| 892 | 897 | ||
| 893 | husart->RxXferSize = Size; |
898 | husart->RxXferSize = Size; |
| 894 | husart->RxXferCount = Size; |
899 | husart->RxXferCount = Size; |
| 895 | 900 | ||
| Line 960... | Line 965... | ||
| 960 | } |
965 | } |
| 961 | } |
966 | } |
| 962 | 967 | ||
| 963 | /** |
968 | /** |
| 964 | * @brief Full-Duplex Send and Receive an amount of data in blocking mode. |
969 | * @brief Full-Duplex Send and Receive an amount of data in blocking mode. |
| 965 | * @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
970 | * @note When USART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
| 966 | * the sent data and the received data are handled as sets of u16. In this case, Size must indicate the number |
971 | * the sent data and the received data are handled as sets of u16. In this case, Size must indicate the number |
| 967 | * of u16 available through pTxData and through pRxData. |
972 | * of u16 available through pTxData and through pRxData. |
| 968 | * @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
973 | * @note When USART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
| 969 | * address of user data buffers containing data to be sent/received, should be aligned on a half word frontier (16 bits) |
974 | * address of user data buffers containing data to be sent/received, should be aligned on a half word frontier (16 bits) |
| 970 | * (as sent/received data will be handled using u16 pointer cast). Depending on compilation chain, |
975 | * (as sent/received data will be handled using u16 pointer cast). Depending on compilation chain, |
| 971 | * use of specific alignment compilation directives or pragmas might be required to ensure proper alignment for pTxData and pRxData. |
976 | * use of specific alignment compilation directives or pragmas might be required to ensure proper alignment for pTxData and pRxData. |
| 972 | * @param husart USART handle. |
977 | * @param husart USART handle. |
| 973 | * @param pTxData pointer to TX data buffer (u8 or u16 data elements). |
978 | * @param pTxData pointer to TX data buffer (u8 or u16 data elements). |
| Line 1009... | Line 1014... | ||
| 1009 | __HAL_LOCK(husart); |
1014 | __HAL_LOCK(husart); |
| 1010 | 1015 | ||
| 1011 | husart->ErrorCode = HAL_USART_ERROR_NONE; |
1016 | husart->ErrorCode = HAL_USART_ERROR_NONE; |
| 1012 | husart->State = HAL_USART_STATE_BUSY_RX; |
1017 | husart->State = HAL_USART_STATE_BUSY_RX; |
| 1013 | 1018 | ||
| 1014 | /* Init tickstart for timeout managment*/ |
1019 | /* Init tickstart for timeout management */ |
| 1015 | tickstart = HAL_GetTick(); |
1020 | tickstart = HAL_GetTick(); |
| 1016 | 1021 | ||
| 1017 | husart->RxXferSize = Size; |
1022 | husart->RxXferSize = Size; |
| 1018 | husart->TxXferSize = Size; |
1023 | husart->TxXferSize = Size; |
| 1019 | husart->TxXferCount = Size; |
1024 | husart->TxXferCount = Size; |
| Line 1124... | Line 1129... | ||
| 1124 | } |
1129 | } |
| 1125 | } |
1130 | } |
| 1126 | 1131 | ||
| 1127 | /** |
1132 | /** |
| 1128 | * @brief Send an amount of data in interrupt mode. |
1133 | * @brief Send an amount of data in interrupt mode. |
| 1129 | * @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
1134 | * @note When USART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
| 1130 | * the sent data is handled as a set of u16. In this case, Size must indicate the number |
1135 | * the sent data is handled as a set of u16. In this case, Size must indicate the number |
| 1131 | * of u16 provided through pTxData. |
1136 | * of u16 provided through pTxData. |
| 1132 | * @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
1137 | * @note When USART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
| 1133 | * address of user data buffer containing data to be sent, should be aligned on a half word frontier (16 bits) |
1138 | * address of user data buffer containing data to be sent, should be aligned on a half word frontier (16 bits) |
| 1134 | * (as sent data will be handled using u16 pointer cast). Depending on compilation chain, |
1139 | * (as sent data will be handled using u16 pointer cast). Depending on compilation chain, |
| 1135 | * use of specific alignment compilation directives or pragmas might be required to ensure proper alignment for pTxData. |
1140 | * use of specific alignment compilation directives or pragmas might be required to ensure proper alignment for pTxData. |
| 1136 | * @param husart USART handle. |
1141 | * @param husart USART handle. |
| 1137 | * @param pTxData pointer to data buffer (u8 or u16 data elements). |
1142 | * @param pTxData pointer to data buffer (u8 or u16 data elements). |
| Line 1202... | Line 1207... | ||
| 1202 | } |
1207 | } |
| 1203 | 1208 | ||
| 1204 | /** |
1209 | /** |
| 1205 | * @brief Receive an amount of data in interrupt mode. |
1210 | * @brief Receive an amount of data in interrupt mode. |
| 1206 | * @note To receive synchronous data, dummy data are simultaneously transmitted. |
1211 | * @note To receive synchronous data, dummy data are simultaneously transmitted. |
| 1207 | * @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
1212 | * @note When USART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
| 1208 | * the received data is handled as a set of u16. In this case, Size must indicate the number |
1213 | * the received data is handled as a set of u16. In this case, Size must indicate the number |
| 1209 | * of u16 available through pRxData. |
1214 | * of u16 available through pRxData. |
| 1210 | * @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
1215 | * @note When USART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
| 1211 | * address of user data buffer for storing data to be received, should be aligned on a half word frontier (16 bits) |
1216 | * address of user data buffer for storing data to be received, should be aligned on a half word frontier (16 bits) |
| 1212 | * (as received data will be handled using u16 pointer cast). Depending on compilation chain, |
1217 | * (as received data will be handled using u16 pointer cast). Depending on compilation chain, |
| 1213 | * use of specific alignment compilation directives or pragmas might be required to ensure proper alignment for pRxData. |
1218 | * use of specific alignment compilation directives or pragmas might be required to ensure proper alignment for pRxData. |
| 1214 | * @param husart USART handle. |
1219 | * @param husart USART handle. |
| 1215 | * @param pRxData pointer to data buffer (u8 or u16 data elements). |
1220 | * @param pRxData pointer to data buffer (u8 or u16 data elements). |
| Line 1287... | Line 1292... | ||
| 1287 | } |
1292 | } |
| 1288 | } |
1293 | } |
| 1289 | 1294 | ||
| 1290 | /** |
1295 | /** |
| 1291 | * @brief Full-Duplex Send and Receive an amount of data in interrupt mode. |
1296 | * @brief Full-Duplex Send and Receive an amount of data in interrupt mode. |
| 1292 | * @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
1297 | * @note When USART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
| 1293 | * the sent data and the received data are handled as sets of u16. In this case, Size must indicate the number |
1298 | * the sent data and the received data are handled as sets of u16. In this case, Size must indicate the number |
| 1294 | * of u16 available through pTxData and through pRxData. |
1299 | * of u16 available through pTxData and through pRxData. |
| 1295 | * @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
1300 | * @note When USART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
| 1296 | * address of user data buffers containing data to be sent/received, should be aligned on a half word frontier (16 bits) |
1301 | * address of user data buffers containing data to be sent/received, should be aligned on a half word frontier (16 bits) |
| 1297 | * (as sent/received data will be handled using u16 pointer cast). Depending on compilation chain, |
1302 | * (as sent/received data will be handled using u16 pointer cast). Depending on compilation chain, |
| 1298 | * use of specific alignment compilation directives or pragmas might be required to ensure proper alignment for pTxData and pRxData. |
1303 | * use of specific alignment compilation directives or pragmas might be required to ensure proper alignment for pTxData and pRxData. |
| 1299 | * @param husart USART handle. |
1304 | * @param husart USART handle. |
| 1300 | * @param pTxData pointer to TX data buffer (u8 or u16 data elements). |
1305 | * @param pTxData pointer to TX data buffer (u8 or u16 data elements). |
| Line 1373... | Line 1378... | ||
| 1373 | } |
1378 | } |
| 1374 | } |
1379 | } |
| 1375 | 1380 | ||
| 1376 | /** |
1381 | /** |
| 1377 | * @brief Send an amount of data in DMA mode. |
1382 | * @brief Send an amount of data in DMA mode. |
| 1378 | * @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
1383 | * @note When USART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
| 1379 | * the sent data is handled as a set of u16. In this case, Size must indicate the number |
1384 | * the sent data is handled as a set of u16. In this case, Size must indicate the number |
| 1380 | * of u16 provided through pTxData. |
1385 | * of u16 provided through pTxData. |
| 1381 | * @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
1386 | * @note When USART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
| 1382 | * address of user data buffer containing data to be sent, should be aligned on a half word frontier (16 bits) |
1387 | * address of user data buffer containing data to be sent, should be aligned on a half word frontier (16 bits) |
| 1383 | * (as sent data will be handled by DMA from halfword frontier). Depending on compilation chain, |
1388 | * (as sent data will be handled by DMA from halfword frontier). Depending on compilation chain, |
| 1384 | * use of specific alignment compilation directives or pragmas might be required to ensure proper alignment for pTxData. |
1389 | * use of specific alignment compilation directives or pragmas might be required |
| - | 1390 | * to ensure proper alignment for pTxData. |
|
| 1385 | * @param husart USART handle. |
1391 | * @param husart USART handle. |
| 1386 | * @param pTxData pointer to data buffer (u8 or u16 data elements). |
1392 | * @param pTxData pointer to data buffer (u8 or u16 data elements). |
| 1387 | * @param Size amount of data elements (u8 or u16) to be sent. |
1393 | * @param Size amount of data elements (u8 or u16) to be sent. |
| 1388 | * @retval HAL status |
1394 | * @retval HAL status |
| 1389 | */ |
1395 | */ |
| Line 1473... | Line 1479... | ||
| 1473 | /** |
1479 | /** |
| 1474 | * @brief Receive an amount of data in DMA mode. |
1480 | * @brief Receive an amount of data in DMA mode. |
| 1475 | * @note When the USART parity is enabled (PCE = 1), the received data contain |
1481 | * @note When the USART parity is enabled (PCE = 1), the received data contain |
| 1476 | * the parity bit (MSB position). |
1482 | * the parity bit (MSB position). |
| 1477 | * @note The USART DMA transmit channel must be configured in order to generate the clock for the slave. |
1483 | * @note The USART DMA transmit channel must be configured in order to generate the clock for the slave. |
| 1478 | * @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
1484 | * @note When USART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
| 1479 | * the received data is handled as a set of u16. In this case, Size must indicate the number |
1485 | * the received data is handled as a set of u16. In this case, Size must indicate the number |
| 1480 | * of u16 available through pRxData. |
1486 | * of u16 available through pRxData. |
| 1481 | * @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
1487 | * @note When USART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
| 1482 | * address of user data buffer for storing data to be received, should be aligned on a half word frontier (16 bits) |
1488 | * address of user data buffer for storing data to be received, should be aligned on |
| 1483 | * (as received data will be handled by DMA from halfword frontier). Depending on compilation chain, |
1489 | * a half word frontier (16 bits) (as received data will be handled by DMA from halfword frontier). |
| - | 1490 | * Depending on compilation chain, use of specific alignment compilation directives or pragmas |
|
| 1484 | * use of specific alignment compilation directives or pragmas might be required to ensure proper alignment for pRxData. |
1491 | * might be required to ensure proper alignment for pRxData. |
| 1485 | * @param husart USART handle. |
1492 | * @param husart USART handle. |
| 1486 | * @param pRxData pointer to data buffer (u8 or u16 data elements). |
1493 | * @param pRxData pointer to data buffer (u8 or u16 data elements). |
| 1487 | * @param Size amount of data elements (u8 or u16) to be received. |
1494 | * @param Size amount of data elements (u8 or u16) to be received. |
| 1488 | * @retval HAL status |
1495 | * @retval HAL status |
| 1489 | */ |
1496 | */ |
| Line 1602... | Line 1609... | ||
| 1602 | } |
1609 | } |
| 1603 | 1610 | ||
| 1604 | /** |
1611 | /** |
| 1605 | * @brief Full-Duplex Transmit Receive an amount of data in non-blocking mode. |
1612 | * @brief Full-Duplex Transmit Receive an amount of data in non-blocking mode. |
| 1606 | * @note When the USART parity is enabled (PCE = 1) the data received contain the parity bit. |
1613 | * @note When the USART parity is enabled (PCE = 1) the data received contain the parity bit. |
| 1607 | * @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
1614 | * @note When USART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
| 1608 | * the sent data and the received data are handled as sets of u16. In this case, Size must indicate the number |
1615 | * the sent data and the received data are handled as sets of u16. In this case, Size must indicate the number |
| 1609 | * of u16 available through pTxData and through pRxData. |
1616 | * of u16 available through pTxData and through pRxData. |
| 1610 | * @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
1617 | * @note When USART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
| 1611 | * address of user data buffers containing data to be sent/received, should be aligned on a half word frontier (16 bits) |
1618 | * address of user data buffers containing data to be sent/received, should be aligned on a half word frontier |
| 1612 | * (as sent/received data will be handled by DMA from halfword frontier). Depending on compilation chain, |
1619 | * (16 bits) (as sent/received data will be handled by DMA from halfword frontier). Depending on compilation |
| 1613 | * use of specific alignment compilation directives or pragmas might be required to ensure proper alignment for pTxData and pRxData. |
1620 | * chain, use of specific alignment compilation directives or pragmas might be required |
| - | 1621 | * to ensure proper alignment for pTxData and pRxData. |
|
| 1614 | * @param husart USART handle. |
1622 | * @param husart USART handle. |
| 1615 | * @param pTxData pointer to TX data buffer (u8 or u16 data elements). |
1623 | * @param pTxData pointer to TX data buffer (u8 or u16 data elements). |
| 1616 | * @param pRxData pointer to RX data buffer (u8 or u16 data elements). |
1624 | * @param pRxData pointer to RX data buffer (u8 or u16 data elements). |
| 1617 | * @param Size amount of data elements (u8 or u16) to be received/sent. |
1625 | * @param Size amount of data elements (u8 or u16) to be received/sent. |
| 1618 | * @retval HAL status |
1626 | * @retval HAL status |
| Line 1808... | Line 1816... | ||
| 1808 | (state == HAL_USART_STATE_BUSY_TX_RX)) |
1816 | (state == HAL_USART_STATE_BUSY_TX_RX)) |
| 1809 | { |
1817 | { |
| 1810 | /* Clear the Overrun flag before resuming the Rx transfer*/ |
1818 | /* Clear the Overrun flag before resuming the Rx transfer*/ |
| 1811 | __HAL_USART_CLEAR_FLAG(husart, USART_CLEAR_OREF); |
1819 | __HAL_USART_CLEAR_FLAG(husart, USART_CLEAR_OREF); |
| 1812 | 1820 | ||
| 1813 | /* Reenable PE and ERR (Frame error, noise error, overrun error) interrupts */ |
1821 | /* Re-enable PE and ERR (Frame error, noise error, overrun error) interrupts */ |
| 1814 | SET_BIT(husart->Instance->CR1, USART_CR1_PEIE); |
1822 | SET_BIT(husart->Instance->CR1, USART_CR1_PEIE); |
| 1815 | SET_BIT(husart->Instance->CR3, USART_CR3_EIE); |
1823 | SET_BIT(husart->Instance->CR3, USART_CR3_EIE); |
| 1816 | 1824 | ||
| 1817 | /* Enable the USART DMA Rx request before the DMA Tx request */ |
1825 | /* Enable the USART DMA Rx request before the DMA Tx request */ |
| 1818 | SET_BIT(husart->Instance->CR3, USART_CR3_DMAR); |
1826 | SET_BIT(husart->Instance->CR3, USART_CR3_DMAR); |
| Line 2117... | Line 2125... | ||
| 2117 | 2125 | ||
| 2118 | uint32_t errorflags; |
2126 | uint32_t errorflags; |
| 2119 | uint32_t errorcode; |
2127 | uint32_t errorcode; |
| 2120 | 2128 | ||
| 2121 | /* If no error occurs */ |
2129 | /* If no error occurs */ |
| 2122 | errorflags = (isrflags & (uint32_t)(USART_ISR_PE | USART_ISR_FE | USART_ISR_ORE | USART_ISR_NE)); |
2130 | errorflags = (isrflags & (uint32_t)(USART_ISR_PE | USART_ISR_FE | USART_ISR_ORE | USART_ISR_NE | USART_ISR_RTOF)); |
| 2123 | if (errorflags == 0U) |
2131 | if (errorflags == 0U) |
| 2124 | { |
2132 | { |
| 2125 | /* USART in mode Receiver ---------------------------------------------------*/ |
2133 | /* USART in mode Receiver ---------------------------------------------------*/ |
| 2126 | if (((isrflags & USART_ISR_RXNE) != 0U) |
2134 | if (((isrflags & USART_ISR_RXNE) != 0U) |
| 2127 | && ((cr1its & USART_CR1_RXNEIE) != 0U)) |
2135 | && ((cr1its & USART_CR1_RXNEIE) != 0U)) |
| Line 2171... | Line 2179... | ||
| 2171 | __HAL_USART_CLEAR_IT(husart, USART_CLEAR_OREF); |
2179 | __HAL_USART_CLEAR_IT(husart, USART_CLEAR_OREF); |
| 2172 | 2180 | ||
| 2173 | husart->ErrorCode |= HAL_USART_ERROR_ORE; |
2181 | husart->ErrorCode |= HAL_USART_ERROR_ORE; |
| 2174 | } |
2182 | } |
| 2175 | 2183 | ||
| - | 2184 | /* USART Receiver Timeout interrupt occurred ---------------------------------*/ |
|
| - | 2185 | if (((isrflags & USART_ISR_RTOF) != 0U) && ((cr1its & USART_CR1_RTOIE) != 0U)) |
|
| - | 2186 | { |
|
| - | 2187 | __HAL_USART_CLEAR_IT(husart, USART_CLEAR_RTOF); |
|
| - | 2188 | ||
| - | 2189 | husart->ErrorCode |= HAL_USART_ERROR_RTO; |
|
| - | 2190 | } |
|
| - | 2191 | ||
| 2176 | 2192 | ||
| 2177 | /* Call USART Error Call back function if need be --------------------------*/ |
2193 | /* Call USART Error Call back function if need be --------------------------*/ |
| 2178 | if (husart->ErrorCode != HAL_USART_ERROR_NONE) |
2194 | if (husart->ErrorCode != HAL_USART_ERROR_NONE) |
| 2179 | { |
2195 | { |
| 2180 | /* USART in mode Receiver ---------------------------------------------------*/ |
2196 | /* USART in mode Receiver ---------------------------------------------------*/ |
| Line 2911... | Line 2927... | ||
| 2911 | uint32_t tickstart; |
2927 | uint32_t tickstart; |
| 2912 | 2928 | ||
| 2913 | /* Initialize the USART ErrorCode */ |
2929 | /* Initialize the USART ErrorCode */ |
| 2914 | husart->ErrorCode = HAL_USART_ERROR_NONE; |
2930 | husart->ErrorCode = HAL_USART_ERROR_NONE; |
| 2915 | 2931 | ||
| 2916 | /* Init tickstart for timeout managment*/ |
2932 | /* Init tickstart for timeout management */ |
| 2917 | tickstart = HAL_GetTick(); |
2933 | tickstart = HAL_GetTick(); |
| 2918 | 2934 | ||
| 2919 | /* Check if the Transmitter is enabled */ |
2935 | /* Check if the Transmitter is enabled */ |
| 2920 | if ((husart->Instance->CR1 & USART_CR1_TE) == USART_CR1_TE) |
2936 | if ((husart->Instance->CR1 & USART_CR1_TE) == USART_CR1_TE) |
| 2921 | { |
2937 | { |