Rev 61 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 61 | Rev 77 | ||
|---|---|---|---|
| Line 1... | Line 1... | ||
| 1 | /** |
1 | /** |
| 2 | ****************************************************************************** |
2 | ****************************************************************************** |
| 3 | * @file stm32l1xx_hal_uart.c |
3 | * @file stm32l1xx_hal_uart.c |
| 4 | * @author MCD Application Team |
4 | * @author MCD Application Team |
| 5 | * @brief UART HAL module driver. |
5 | * @brief UART HAL module driver. |
| 6 | * This file provides firmware functions to manage the following |
6 | * This file provides firmware functions to manage the following |
| 7 | * functionalities of the Universal Asynchronous Receiver Transmitter Peripheral (UART). |
7 | * functionalities of the Universal Asynchronous Receiver Transmitter Peripheral (UART). |
| 8 | * + Initialization and de-initialization functions |
8 | * + Initialization and de-initialization functions |
| 9 | * + IO operation functions |
9 | * + IO operation functions |
| 10 | * + Peripheral Control functions |
10 | * + Peripheral Control functions |
| 11 | * + Peripheral State and Errors functions |
11 | * + Peripheral State and Errors functions |
| 12 | @verbatim |
12 | * |
| 13 | ============================================================================== |
13 | ****************************************************************************** |
| 14 | ##### How to use this driver ##### |
14 | * @attention |
| 15 | ============================================================================== |
15 | * |
| 16 | [..] |
16 | * Copyright (c) 2016 STMicroelectronics. |
| 17 | The UART HAL driver can be used as follows: |
17 | * All rights reserved. |
| 18 | 18 | * |
|
| 19 | (#) Declare a UART_HandleTypeDef handle structure (eg. UART_HandleTypeDef huart). |
19 | * This software is licensed under terms that can be found in the LICENSE file |
| 20 | (#) Initialize the UART low level resources by implementing the HAL_UART_MspInit() API: |
20 | * in the root directory of this software component. |
| 21 | (##) Enable the USARTx interface clock. |
21 | * If no LICENSE file comes with this software, it is provided AS-IS. |
| 22 | (##) UART pins configuration: |
22 | * |
| 23 | (+++) Enable the clock for the UART GPIOs. |
23 | ****************************************************************************** |
| 24 | (+++) Configure the UART TX/RX pins as alternate function pull-up. |
24 | @verbatim |
| 25 | (##) NVIC configuration if you need to use interrupt process (HAL_UART_Transmit_IT() |
25 | ============================================================================== |
| 26 | and HAL_UART_Receive_IT() APIs): |
26 | ##### How to use this driver ##### |
| 27 | (+++) Configure the USARTx interrupt priority. |
27 | ============================================================================== |
| 28 | (+++) Enable the NVIC USART IRQ handle. |
28 | [..] |
| 29 | (##) DMA Configuration if you need to use DMA process (HAL_UART_Transmit_DMA() |
29 | The UART HAL driver can be used as follows: |
| 30 | and HAL_UART_Receive_DMA() APIs): |
30 | |
| 31 | (+++) Declare a DMA handle structure for the Tx/Rx channel. |
31 | (#) Declare a UART_HandleTypeDef handle structure (eg. UART_HandleTypeDef huart). |
| 32 | (+++) Enable the DMAx interface clock. |
32 | (#) Initialize the UART low level resources by implementing the HAL_UART_MspInit() API: |
| 33 | (+++) Configure the declared DMA handle structure with the required |
33 | (##) Enable the USARTx interface clock. |
| 34 | Tx/Rx parameters. |
34 | (##) UART pins configuration: |
| 35 | (+++) Configure the DMA Tx/Rx channel. |
35 | (+++) Enable the clock for the UART GPIOs. |
| 36 | (+++) Associate the initialized DMA handle to the UART DMA Tx/Rx handle. |
36 | (+++) Configure the UART TX/RX pins as alternate function pull-up. |
| 37 | (+++) Configure the priority and enable the NVIC for the transfer complete |
37 | (##) NVIC configuration if you need to use interrupt process (HAL_UART_Transmit_IT() |
| 38 | interrupt on the DMA Tx/Rx channel. |
38 | and HAL_UART_Receive_IT() APIs): |
| 39 | (+++) Configure the USARTx interrupt priority and enable the NVIC USART IRQ handle |
39 | (+++) Configure the USARTx interrupt priority. |
| 40 | (used for last byte sending completion detection in DMA non circular mode) |
40 | (+++) Enable the NVIC USART IRQ handle. |
| 41 | 41 | (##) DMA Configuration if you need to use DMA process (HAL_UART_Transmit_DMA() |
|
| 42 | (#) Program the Baud Rate, Word Length, Stop Bit, Parity, Hardware |
42 | and HAL_UART_Receive_DMA() APIs): |
| 43 | flow control and Mode(Receiver/Transmitter) in the huart Init structure. |
43 | (+++) Declare a DMA handle structure for the Tx/Rx channel. |
| 44 | 44 | (+++) Enable the DMAx interface clock. |
|
| 45 | (#) For the UART asynchronous mode, initialize the UART registers by calling |
45 | (+++) Configure the declared DMA handle structure with the required |
| 46 | the HAL_UART_Init() API. |
46 | Tx/Rx parameters. |
| 47 | 47 | (+++) Configure the DMA Tx/Rx channel. |
|
| 48 | (#) For the UART Half duplex mode, initialize the UART registers by calling |
48 | (+++) Associate the initialized DMA handle to the UART DMA Tx/Rx handle. |
| 49 | the HAL_HalfDuplex_Init() API. |
49 | (+++) Configure the priority and enable the NVIC for the transfer complete |
| 50 | 50 | interrupt on the DMA Tx/Rx channel. |
|
| 51 | (#) For the LIN mode, initialize the UART registers by calling the HAL_LIN_Init() API. |
51 | (+++) Configure the USARTx interrupt priority and enable the NVIC USART IRQ handle |
| 52 | 52 | (used for last byte sending completion detection in DMA non circular mode) |
|
| 53 | (#) For the Multi-Processor mode, initialize the UART registers by calling |
53 | |
| 54 | the HAL_MultiProcessor_Init() API. |
54 | (#) Program the Baud Rate, Word Length, Stop Bit, Parity, Hardware |
| 55 | 55 | flow control and Mode(Receiver/Transmitter) in the huart Init structure. |
|
| 56 | [..] |
56 | |
| 57 | (@) The specific UART interrupts (Transmission complete interrupt, |
57 | (#) For the UART asynchronous mode, initialize the UART registers by calling |
| 58 | RXNE interrupt and Error Interrupts) will be managed using the macros |
58 | the HAL_UART_Init() API. |
| 59 | __HAL_UART_ENABLE_IT() and __HAL_UART_DISABLE_IT() inside the transmit |
59 | |
| 60 | and receive process. |
60 | (#) For the UART Half duplex mode, initialize the UART registers by calling |
| 61 | 61 | the HAL_HalfDuplex_Init() API. |
|
| 62 | [..] |
62 | |
| 63 | (@) These APIs (HAL_UART_Init() and HAL_HalfDuplex_Init()) configure also the |
63 | (#) For the LIN mode, initialize the UART registers by calling the HAL_LIN_Init() API. |
| 64 | low level Hardware GPIO, CLOCK, CORTEX...etc) by calling the customized |
64 | |
| 65 | HAL_UART_MspInit() API. |
65 | (#) For the Multi-Processor mode, initialize the UART registers by calling |
| 66 | 66 | the HAL_MultiProcessor_Init() API. |
|
| 67 | ##### Callback registration ##### |
67 | |
| 68 | ================================== |
68 | [..] |
| 69 | 69 | (@) The specific UART interrupts (Transmission complete interrupt, |
|
| 70 | [..] |
70 | RXNE interrupt and Error Interrupts) will be managed using the macros |
| 71 | The compilation define USE_HAL_UART_REGISTER_CALLBACKS when set to 1 |
71 | __HAL_UART_ENABLE_IT() and __HAL_UART_DISABLE_IT() inside the transmit |
| 72 | allows the user to configure dynamically the driver callbacks. |
72 | and receive process. |
| 73 | 73 | ||
| 74 | [..] |
74 | [..] |
| 75 | Use Function @ref HAL_UART_RegisterCallback() to register a user callback. |
75 | (@) These APIs (HAL_UART_Init() and HAL_HalfDuplex_Init()) configure also the |
| 76 | Function @ref HAL_UART_RegisterCallback() allows to register following callbacks: |
76 | low level Hardware GPIO, CLOCK, CORTEX...etc) by calling the customized |
| 77 | (+) TxHalfCpltCallback : Tx Half Complete Callback. |
77 | HAL_UART_MspInit() API. |
| 78 | (+) TxCpltCallback : Tx Complete Callback. |
78 | |
| 79 | (+) RxHalfCpltCallback : Rx Half Complete Callback. |
79 | ##### Callback registration ##### |
| 80 | (+) RxCpltCallback : Rx Complete Callback. |
80 | ================================== |
| 81 | (+) ErrorCallback : Error Callback. |
81 | |
| 82 | (+) AbortCpltCallback : Abort Complete Callback. |
82 | [..] |
| 83 | (+) AbortTransmitCpltCallback : Abort Transmit Complete Callback. |
83 | The compilation define USE_HAL_UART_REGISTER_CALLBACKS when set to 1 |
| 84 | (+) AbortReceiveCpltCallback : Abort Receive Complete Callback. |
84 | allows the user to configure dynamically the driver callbacks. |
| 85 | (+) MspInitCallback : UART MspInit. |
85 | |
| 86 | (+) MspDeInitCallback : UART MspDeInit. |
86 | [..] |
| 87 | This function takes as parameters the HAL peripheral handle, the Callback ID |
87 | Use Function HAL_UART_RegisterCallback() to register a user callback. |
| 88 | and a pointer to the user callback function. |
88 | Function HAL_UART_RegisterCallback() allows to register following callbacks: |
| 89 | 89 | (+) TxHalfCpltCallback : Tx Half Complete Callback. |
|
| 90 | [..] |
90 | (+) TxCpltCallback : Tx Complete Callback. |
| 91 | Use function @ref HAL_UART_UnRegisterCallback() to reset a callback to the default |
91 | (+) RxHalfCpltCallback : Rx Half Complete Callback. |
| 92 | weak (surcharged) function. |
92 | (+) RxCpltCallback : Rx Complete Callback. |
| 93 | @ref HAL_UART_UnRegisterCallback() takes as parameters the HAL peripheral handle, |
93 | (+) ErrorCallback : Error Callback. |
| 94 | and the Callback ID. |
94 | (+) AbortCpltCallback : Abort Complete Callback. |
| 95 | This function allows to reset following callbacks: |
95 | (+) AbortTransmitCpltCallback : Abort Transmit Complete Callback. |
| 96 | (+) TxHalfCpltCallback : Tx Half Complete Callback. |
96 | (+) AbortReceiveCpltCallback : Abort Receive Complete Callback. |
| 97 | (+) TxCpltCallback : Tx Complete Callback. |
97 | (+) MspInitCallback : UART MspInit. |
| 98 | (+) RxHalfCpltCallback : Rx Half Complete Callback. |
98 | (+) MspDeInitCallback : UART MspDeInit. |
| 99 | (+) RxCpltCallback : Rx Complete Callback. |
99 | This function takes as parameters the HAL peripheral handle, the Callback ID |
| 100 | (+) ErrorCallback : Error Callback. |
100 | and a pointer to the user callback function. |
| 101 | (+) AbortCpltCallback : Abort Complete Callback. |
101 | |
| 102 | (+) AbortTransmitCpltCallback : Abort Transmit Complete Callback. |
102 | [..] |
| 103 | (+) AbortReceiveCpltCallback : Abort Receive Complete Callback. |
103 | Use function HAL_UART_UnRegisterCallback() to reset a callback to the default |
| 104 | (+) MspInitCallback : UART MspInit. |
104 | weak (surcharged) function. |
| 105 | (+) MspDeInitCallback : UART MspDeInit. |
105 | HAL_UART_UnRegisterCallback() takes as parameters the HAL peripheral handle, |
| 106 | 106 | and the Callback ID. |
|
| 107 | [..] |
107 | This function allows to reset following callbacks: |
| 108 | For specific callback RxEventCallback, use dedicated registration/reset functions: |
108 | (+) TxHalfCpltCallback : Tx Half Complete Callback. |
| 109 | respectively @ref HAL_UART_RegisterRxEventCallback() , @ref HAL_UART_UnRegisterRxEventCallback(). |
109 | (+) TxCpltCallback : Tx Complete Callback. |
| 110 | 110 | (+) RxHalfCpltCallback : Rx Half Complete Callback. |
|
| 111 | [..] |
111 | (+) RxCpltCallback : Rx Complete Callback. |
| 112 | By default, after the @ref HAL_UART_Init() and when the state is HAL_UART_STATE_RESET |
112 | (+) ErrorCallback : Error Callback. |
| 113 | all callbacks are set to the corresponding weak (surcharged) functions: |
113 | (+) AbortCpltCallback : Abort Complete Callback. |
| 114 | examples @ref HAL_UART_TxCpltCallback(), @ref HAL_UART_RxHalfCpltCallback(). |
114 | (+) AbortTransmitCpltCallback : Abort Transmit Complete Callback. |
| 115 | Exception done for MspInit and MspDeInit functions that are respectively |
115 | (+) AbortReceiveCpltCallback : Abort Receive Complete Callback. |
| 116 | reset to the legacy weak (surcharged) functions in the @ref HAL_UART_Init() |
116 | (+) MspInitCallback : UART MspInit. |
| 117 | and @ref HAL_UART_DeInit() only when these callbacks are null (not registered beforehand). |
117 | (+) MspDeInitCallback : UART MspDeInit. |
| 118 | If not, MspInit or MspDeInit are not null, the @ref HAL_UART_Init() and @ref HAL_UART_DeInit() |
118 | |
| 119 | keep and use the user MspInit/MspDeInit callbacks (registered beforehand). |
119 | [..] |
| 120 | 120 | For specific callback RxEventCallback, use dedicated registration/reset functions: |
|
| 121 | [..] |
121 | respectively HAL_UART_RegisterRxEventCallback() , HAL_UART_UnRegisterRxEventCallback(). |
| 122 | Callbacks can be registered/unregistered in HAL_UART_STATE_READY state only. |
122 | |
| 123 | Exception done MspInit/MspDeInit that can be registered/unregistered |
123 | [..] |
| 124 | in HAL_UART_STATE_READY or HAL_UART_STATE_RESET state, thus registered (user) |
124 | By default, after the HAL_UART_Init() and when the state is HAL_UART_STATE_RESET |
| 125 | MspInit/DeInit callbacks can be used during the Init/DeInit. |
125 | all callbacks are set to the corresponding weak (surcharged) functions: |
| 126 | In that case first register the MspInit/MspDeInit user callbacks |
126 | examples HAL_UART_TxCpltCallback(), HAL_UART_RxHalfCpltCallback(). |
| 127 | using @ref HAL_UART_RegisterCallback() before calling @ref HAL_UART_DeInit() |
127 | Exception done for MspInit and MspDeInit functions that are respectively |
| 128 | or @ref HAL_UART_Init() function. |
128 | reset to the legacy weak (surcharged) functions in the HAL_UART_Init() |
| 129 | 129 | and HAL_UART_DeInit() only when these callbacks are null (not registered beforehand). |
|
| 130 | [..] |
130 | If not, MspInit or MspDeInit are not null, the HAL_UART_Init() and HAL_UART_DeInit() |
| 131 | When The compilation define USE_HAL_UART_REGISTER_CALLBACKS is set to 0 or |
131 | keep and use the user MspInit/MspDeInit callbacks (registered beforehand). |
| 132 | not defined, the callback registration feature is not available |
132 | |
| 133 | and weak (surcharged) callbacks are used. |
133 | [..] |
| 134 | 134 | Callbacks can be registered/unregistered in HAL_UART_STATE_READY state only. |
|
| 135 | [..] |
135 | Exception done MspInit/MspDeInit that can be registered/unregistered |
| 136 | Three operation modes are available within this driver : |
136 | in HAL_UART_STATE_READY or HAL_UART_STATE_RESET state, thus registered (user) |
| 137 | 137 | MspInit/DeInit callbacks can be used during the Init/DeInit. |
|
| 138 | *** Polling mode IO operation *** |
138 | In that case first register the MspInit/MspDeInit user callbacks |
| 139 | ================================= |
139 | using HAL_UART_RegisterCallback() before calling HAL_UART_DeInit() |
| 140 | [..] |
140 | or HAL_UART_Init() function. |
| 141 | (+) Send an amount of data in blocking mode using HAL_UART_Transmit() |
141 | |
| 142 | (+) Receive an amount of data in blocking mode using HAL_UART_Receive() |
142 | [..] |
| 143 | 143 | When The compilation define USE_HAL_UART_REGISTER_CALLBACKS is set to 0 or |
|
| 144 | *** Interrupt mode IO operation *** |
144 | not defined, the callback registration feature is not available |
| 145 | =================================== |
145 | and weak (surcharged) callbacks are used. |
| 146 | [..] |
146 | |
| 147 | (+) Send an amount of data in non blocking mode using HAL_UART_Transmit_IT() |
147 | [..] |
| 148 | (+) At transmission end of transfer HAL_UART_TxCpltCallback is executed and user can |
148 | Three operation modes are available within this driver : |
| 149 | add his own code by customization of function pointer HAL_UART_TxCpltCallback |
149 | |
| 150 | (+) Receive an amount of data in non blocking mode using HAL_UART_Receive_IT() |
150 | *** Polling mode IO operation *** |
| 151 | (+) At reception end of transfer HAL_UART_RxCpltCallback is executed and user can |
151 | ================================= |
| 152 | add his own code by customization of function pointer HAL_UART_RxCpltCallback |
152 | [..] |
| 153 | (+) In case of transfer Error, HAL_UART_ErrorCallback() function is executed and user can |
153 | (+) Send an amount of data in blocking mode using HAL_UART_Transmit() |
| 154 | add his own code by customization of function pointer HAL_UART_ErrorCallback |
154 | (+) Receive an amount of data in blocking mode using HAL_UART_Receive() |
| 155 | 155 | ||
| 156 | *** DMA mode IO operation *** |
156 | *** Interrupt mode IO operation *** |
| 157 | ============================== |
157 | =================================== |
| 158 | [..] |
158 | [..] |
| 159 | (+) Send an amount of data in non blocking mode (DMA) using HAL_UART_Transmit_DMA() |
159 | (+) Send an amount of data in non blocking mode using HAL_UART_Transmit_IT() |
| 160 | (+) At transmission end of half transfer HAL_UART_TxHalfCpltCallback is executed and user can |
160 | (+) At transmission end of transfer HAL_UART_TxCpltCallback is executed and user can |
| 161 | add his own code by customization of function pointer HAL_UART_TxHalfCpltCallback |
161 | add his own code by customization of function pointer HAL_UART_TxCpltCallback |
| 162 | (+) At transmission end of transfer HAL_UART_TxCpltCallback is executed and user can |
162 | (+) Receive an amount of data in non blocking mode using HAL_UART_Receive_IT() |
| 163 | add his own code by customization of function pointer HAL_UART_TxCpltCallback |
163 | (+) At reception end of transfer HAL_UART_RxCpltCallback is executed and user can |
| 164 | (+) Receive an amount of data in non blocking mode (DMA) using HAL_UART_Receive_DMA() |
164 | add his own code by customization of function pointer HAL_UART_RxCpltCallback |
| 165 | (+) At reception end of half transfer HAL_UART_RxHalfCpltCallback is executed and user can |
165 | (+) In case of transfer Error, HAL_UART_ErrorCallback() function is executed and user can |
| 166 | add his own code by customization of function pointer HAL_UART_RxHalfCpltCallback |
166 | add his own code by customization of function pointer HAL_UART_ErrorCallback |
| 167 | (+) At reception end of transfer HAL_UART_RxCpltCallback is executed and user can |
167 | |
| 168 | add his own code by customization of function pointer HAL_UART_RxCpltCallback |
168 | *** DMA mode IO operation *** |
| 169 | (+) In case of transfer Error, HAL_UART_ErrorCallback() function is executed and user can |
169 | ============================== |
| 170 | add his own code by customization of function pointer HAL_UART_ErrorCallback |
170 | [..] |
| 171 | (+) Pause the DMA Transfer using HAL_UART_DMAPause() |
171 | (+) Send an amount of data in non blocking mode (DMA) using HAL_UART_Transmit_DMA() |
| 172 | (+) Resume the DMA Transfer using HAL_UART_DMAResume() |
172 | (+) At transmission end of half transfer HAL_UART_TxHalfCpltCallback is executed and user can |
| 173 | (+) Stop the DMA Transfer using HAL_UART_DMAStop() |
173 | add his own code by customization of function pointer HAL_UART_TxHalfCpltCallback |
| 174 | 174 | (+) At transmission end of transfer HAL_UART_TxCpltCallback is executed and user can |
|
| 175 | 175 | add his own code by customization of function pointer HAL_UART_TxCpltCallback |
|
| 176 | [..] This subsection also provides a set of additional functions providing enhanced reception |
176 | (+) Receive an amount of data in non blocking mode (DMA) using HAL_UART_Receive_DMA() |
| 177 | services to user. (For example, these functions allow application to handle use cases |
177 | (+) At reception end of half transfer HAL_UART_RxHalfCpltCallback is executed and user can |
| 178 | where number of data to be received is unknown). |
178 | add his own code by customization of function pointer HAL_UART_RxHalfCpltCallback |
| 179 | 179 | (+) At reception end of transfer HAL_UART_RxCpltCallback is executed and user can |
|
| 180 | (#) Compared to standard reception services which only consider number of received |
180 | add his own code by customization of function pointer HAL_UART_RxCpltCallback |
| 181 | data elements as reception completion criteria, these functions also consider additional events |
181 | (+) In case of transfer Error, HAL_UART_ErrorCallback() function is executed and user can |
| 182 | as triggers for updating reception status to caller : |
182 | add his own code by customization of function pointer HAL_UART_ErrorCallback |
| 183 | (+) Detection of inactivity period (RX line has not been active for a given period). |
183 | (+) Pause the DMA Transfer using HAL_UART_DMAPause() |
| 184 | (++) RX inactivity detected by IDLE event, i.e. RX line has been in idle state (normally high state) |
184 | (+) Resume the DMA Transfer using HAL_UART_DMAResume() |
| 185 | for 1 frame time, after last received byte. |
185 | (+) Stop the DMA Transfer using HAL_UART_DMAStop() |
| 186 | 186 | ||
| 187 | (#) There are two mode of transfer: |
187 | |
| 188 | (+) Blocking mode: The reception is performed in polling mode, until either expected number of data is received, |
188 | [..] This subsection also provides a set of additional functions providing enhanced reception |
| 189 | or till IDLE event occurs. Reception is handled only during function execution. |
189 | services to user. (For example, these functions allow application to handle use cases |
| 190 | When function exits, no data reception could occur. HAL status and number of actually received data elements, |
190 | where number of data to be received is unknown). |
| 191 | are returned by function after finishing transfer. |
191 | |
| 192 | (+) Non-Blocking mode: The reception is performed using Interrupts or DMA. |
192 | (#) Compared to standard reception services which only consider number of received |
| 193 | These API's return the HAL status. |
193 | data elements as reception completion criteria, these functions also consider additional events |
| 194 | The end of the data processing will be indicated through the |
194 | as triggers for updating reception status to caller : |
| 195 | dedicated UART IRQ when using Interrupt mode or the DMA IRQ when using DMA mode. |
195 | (+) Detection of inactivity period (RX line has not been active for a given period). |
| 196 | The HAL_UARTEx_RxEventCallback() user callback will be executed during Receive process |
196 | (++) RX inactivity detected by IDLE event, i.e. RX line has been in idle state (normally high state) |
| 197 | The HAL_UART_ErrorCallback()user callback will be executed when a reception error is detected. |
197 | for 1 frame time, after last received byte. |
| 198 | 198 | ||
| 199 | (#) Blocking mode API: |
199 | (#) There are two mode of transfer: |
| 200 | (+) HAL_UARTEx_ReceiveToIdle() |
200 | (+) Blocking mode: The reception is performed in polling mode, until either expected number of data is received, |
| 201 | 201 | or till IDLE event occurs. Reception is handled only during function execution. |
|
| 202 | (#) Non-Blocking mode API with Interrupt: |
202 | When function exits, no data reception could occur. HAL status and number of actually received data elements, |
| 203 | (+) HAL_UARTEx_ReceiveToIdle_IT() |
203 | are returned by function after finishing transfer. |
| 204 | 204 | (+) Non-Blocking mode: The reception is performed using Interrupts or DMA. |
|
| 205 | (#) Non-Blocking mode API with DMA: |
205 | These API's return the HAL status. |
| 206 | (+) HAL_UARTEx_ReceiveToIdle_DMA() |
206 | The end of the data processing will be indicated through the |
| 207 | 207 | dedicated UART IRQ when using Interrupt mode or the DMA IRQ when using DMA mode. |
|
| 208 | 208 | The HAL_UARTEx_RxEventCallback() user callback will be executed during Receive process |
|
| 209 | *** UART HAL driver macros list *** |
209 | The HAL_UART_ErrorCallback()user callback will be executed when a reception error is detected. |
| 210 | ============================================= |
210 | |
| 211 | [..] |
211 | (#) Blocking mode API: |
| 212 | Below the list of most used macros in UART HAL driver. |
212 | (+) HAL_UARTEx_ReceiveToIdle() |
| 213 | 213 | ||
| 214 | (+) __HAL_UART_ENABLE: Enable the UART peripheral |
214 | (#) Non-Blocking mode API with Interrupt: |
| 215 | (+) __HAL_UART_DISABLE: Disable the UART peripheral |
215 | (+) HAL_UARTEx_ReceiveToIdle_IT() |
| 216 | (+) __HAL_UART_GET_FLAG : Check whether the specified UART flag is set or not |
216 | |
| 217 | (+) __HAL_UART_CLEAR_FLAG : Clear the specified UART pending flag |
217 | (#) Non-Blocking mode API with DMA: |
| 218 | (+) __HAL_UART_ENABLE_IT: Enable the specified UART interrupt |
218 | (+) HAL_UARTEx_ReceiveToIdle_DMA() |
| 219 | (+) __HAL_UART_DISABLE_IT: Disable the specified UART interrupt |
219 | |
| 220 | (+) __HAL_UART_GET_IT_SOURCE: Check whether the specified UART interrupt has occurred or not |
220 | |
| 221 | 221 | *** UART HAL driver macros list *** |
|
| 222 | [..] |
222 | ============================================= |
| 223 | (@) You can refer to the UART HAL driver header file for more useful macros |
223 | [..] |
| 224 | 224 | Below the list of most used macros in UART HAL driver. |
|
| 225 | @endverbatim |
225 | |
| 226 | [..] |
226 | (+) __HAL_UART_ENABLE: Enable the UART peripheral |
| 227 | (@) Additional remark: If the parity is enabled, then the MSB bit of the data written |
227 | (+) __HAL_UART_DISABLE: Disable the UART peripheral |
| 228 | in the data register is transmitted but is changed by the parity bit. |
228 | (+) __HAL_UART_GET_FLAG : Check whether the specified UART flag is set or not |
| 229 | Depending on the frame length defined by the M bit (8-bits or 9-bits), |
229 | (+) __HAL_UART_CLEAR_FLAG : Clear the specified UART pending flag |
| 230 | the possible UART frame formats are as listed in the following table: |
230 | (+) __HAL_UART_ENABLE_IT: Enable the specified UART interrupt |
| 231 | +-------------------------------------------------------------+ |
231 | (+) __HAL_UART_DISABLE_IT: Disable the specified UART interrupt |
| 232 | | M bit | PCE bit | UART frame | |
232 | (+) __HAL_UART_GET_IT_SOURCE: Check whether the specified UART interrupt has occurred or not |
| 233 | |---------------------|---------------------------------------| |
233 | |
| 234 | | 0 | 0 | | SB | 8 bit data | STB | | |
234 | [..] |
| 235 | |---------|-----------|---------------------------------------| |
235 | (@) You can refer to the UART HAL driver header file for more useful macros |
| 236 | | 0 | 1 | | SB | 7 bit data | PB | STB | | |
236 | |
| 237 | |---------|-----------|---------------------------------------| |
237 | @endverbatim |
| 238 | | 1 | 0 | | SB | 9 bit data | STB | | |
238 | [..] |
| 239 | |---------|-----------|---------------------------------------| |
239 | (@) Additional remark: If the parity is enabled, then the MSB bit of the data written |
| 240 | | 1 | 1 | | SB | 8 bit data | PB | STB | | |
240 | in the data register is transmitted but is changed by the parity bit. |
| 241 | +-------------------------------------------------------------+ |
241 | Depending on the frame length defined by the M bit (8-bits or 9-bits), |
| 242 | ****************************************************************************** |
242 | the possible UART frame formats are as listed in the following table: |
| 243 | * @attention |
243 | +-------------------------------------------------------------+ |
| 244 | * |
244 | | M bit | PCE bit | UART frame | |
| 245 | * <h2><center>© Copyright (c) 2016 STMicroelectronics. |
245 | |---------------------|---------------------------------------| |
| 246 | * All rights reserved.</center></h2> |
246 | | 0 | 0 | | SB | 8 bit data | STB | | |
| 247 | * |
247 | |---------|-----------|---------------------------------------| |
| 248 | * This software component is licensed by ST under BSD 3-Clause license, |
248 | | 0 | 1 | | SB | 7 bit data | PB | STB | | |
| 249 | * the "License"; You may not use this file except in compliance with the |
249 | |---------|-----------|---------------------------------------| |
| 250 | * License. You may obtain a copy of the License at: |
250 | | 1 | 0 | | SB | 9 bit data | STB | | |
| 251 | * opensource.org/licenses/BSD-3-Clause |
251 | |---------|-----------|---------------------------------------| |
| 252 | * |
252 | | 1 | 1 | | SB | 8 bit data | PB | STB | | |
| 253 | ****************************************************************************** |
253 | +-------------------------------------------------------------+ |
| 254 | */ |
254 | ****************************************************************************** |
| 255 | 255 | */ |
|
| 256 | /* Includes ------------------------------------------------------------------*/ |
256 | |
| 257 | #include "stm32l1xx_hal.h" |
257 | /* Includes ------------------------------------------------------------------*/ |
| 258 | 258 | #include "stm32l1xx_hal.h" |
|
| 259 | /** @addtogroup STM32L1xx_HAL_Driver |
259 | |
| 260 | * @{ |
260 | /** @addtogroup STM32L1xx_HAL_Driver |
| 261 | */ |
261 | * @{ |
| 262 | 262 | */ |
|
| 263 | /** @defgroup UART UART |
263 | |
| 264 | * @brief HAL UART module driver |
264 | /** @defgroup UART UART |
| 265 | * @{ |
265 | * @brief HAL UART module driver |
| 266 | */ |
266 | * @{ |
| 267 | #ifdef HAL_UART_MODULE_ENABLED |
267 | */ |
| 268 | 268 | #ifdef HAL_UART_MODULE_ENABLED |
|
| 269 | /* Private typedef -----------------------------------------------------------*/ |
269 | |
| 270 | /* Private define ------------------------------------------------------------*/ |
270 | /* Private typedef -----------------------------------------------------------*/ |
| 271 | /** @addtogroup UART_Private_Constants |
271 | /* Private define ------------------------------------------------------------*/ |
| 272 | * @{ |
272 | /** @addtogroup UART_Private_Constants |
| 273 | */ |
273 | * @{ |
| 274 | /** |
274 | */ |
| 275 | * @} |
275 | /** |
| 276 | */ |
276 | * @} |
| 277 | /* Private macro -------------------------------------------------------------*/ |
277 | */ |
| 278 | /* Private variables ---------------------------------------------------------*/ |
278 | /* Private macro -------------------------------------------------------------*/ |
| 279 | /* Private function prototypes -----------------------------------------------*/ |
279 | /* Private variables ---------------------------------------------------------*/ |
| 280 | /** @addtogroup UART_Private_Functions UART Private Functions |
280 | /* Private function prototypes -----------------------------------------------*/ |
| 281 | * @{ |
281 | /** @addtogroup UART_Private_Functions UART Private Functions |
| 282 | */ |
282 | * @{ |
| 283 | 283 | */ |
|
| 284 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
284 | |
| 285 | void UART_InitCallbacksToDefault(UART_HandleTypeDef *huart); |
285 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
| 286 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
286 | void UART_InitCallbacksToDefault(UART_HandleTypeDef *huart); |
| 287 | static void UART_EndTxTransfer(UART_HandleTypeDef *huart); |
287 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
| 288 | static void UART_EndRxTransfer(UART_HandleTypeDef *huart); |
288 | static void UART_EndTxTransfer(UART_HandleTypeDef *huart); |
| 289 | static void UART_DMATransmitCplt(DMA_HandleTypeDef *hdma); |
289 | static void UART_EndRxTransfer(UART_HandleTypeDef *huart); |
| 290 | static void UART_DMAReceiveCplt(DMA_HandleTypeDef *hdma); |
290 | static void UART_DMATransmitCplt(DMA_HandleTypeDef *hdma); |
| 291 | static void UART_DMATxHalfCplt(DMA_HandleTypeDef *hdma); |
291 | static void UART_DMAReceiveCplt(DMA_HandleTypeDef *hdma); |
| 292 | static void UART_DMARxHalfCplt(DMA_HandleTypeDef *hdma); |
292 | static void UART_DMATxHalfCplt(DMA_HandleTypeDef *hdma); |
| 293 | static void UART_DMAError(DMA_HandleTypeDef *hdma); |
293 | static void UART_DMARxHalfCplt(DMA_HandleTypeDef *hdma); |
| 294 | static void UART_DMAAbortOnError(DMA_HandleTypeDef *hdma); |
294 | static void UART_DMAError(DMA_HandleTypeDef *hdma); |
| 295 | static void UART_DMATxAbortCallback(DMA_HandleTypeDef *hdma); |
295 | static void UART_DMAAbortOnError(DMA_HandleTypeDef *hdma); |
| 296 | static void UART_DMARxAbortCallback(DMA_HandleTypeDef *hdma); |
296 | static void UART_DMATxAbortCallback(DMA_HandleTypeDef *hdma); |
| 297 | static void UART_DMATxOnlyAbortCallback(DMA_HandleTypeDef *hdma); |
297 | static void UART_DMARxAbortCallback(DMA_HandleTypeDef *hdma); |
| 298 | static void UART_DMARxOnlyAbortCallback(DMA_HandleTypeDef *hdma); |
298 | static void UART_DMATxOnlyAbortCallback(DMA_HandleTypeDef *hdma); |
| 299 | static HAL_StatusTypeDef UART_Transmit_IT(UART_HandleTypeDef *huart); |
299 | static void UART_DMARxOnlyAbortCallback(DMA_HandleTypeDef *hdma); |
| 300 | static HAL_StatusTypeDef UART_EndTransmit_IT(UART_HandleTypeDef *huart); |
300 | static HAL_StatusTypeDef UART_Transmit_IT(UART_HandleTypeDef *huart); |
| 301 | static HAL_StatusTypeDef UART_Receive_IT(UART_HandleTypeDef *huart); |
301 | static HAL_StatusTypeDef UART_EndTransmit_IT(UART_HandleTypeDef *huart); |
| 302 | static HAL_StatusTypeDef UART_WaitOnFlagUntilTimeout(UART_HandleTypeDef *huart, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout); |
302 | static HAL_StatusTypeDef UART_Receive_IT(UART_HandleTypeDef *huart); |
| 303 | static void UART_SetConfig(UART_HandleTypeDef *huart); |
303 | static HAL_StatusTypeDef UART_WaitOnFlagUntilTimeout(UART_HandleTypeDef *huart, uint32_t Flag, FlagStatus Status, |
| 304 | 304 | uint32_t Tickstart, uint32_t Timeout); |
|
| 305 | /** |
305 | static void UART_SetConfig(UART_HandleTypeDef *huart); |
| 306 | * @} |
306 | |
| 307 | */ |
307 | /** |
| 308 | 308 | * @} |
|
| 309 | /* Exported functions ---------------------------------------------------------*/ |
309 | */ |
| 310 | /** @defgroup UART_Exported_Functions UART Exported Functions |
310 | |
| 311 | * @{ |
311 | /* Exported functions ---------------------------------------------------------*/ |
| 312 | */ |
312 | /** @defgroup UART_Exported_Functions UART Exported Functions |
| 313 | 313 | * @{ |
|
| 314 | /** @defgroup UART_Exported_Functions_Group1 Initialization and de-initialization functions |
314 | */ |
| 315 | * @brief Initialization and Configuration functions |
315 | |
| 316 | * |
316 | /** @defgroup UART_Exported_Functions_Group1 Initialization and de-initialization functions |
| 317 | @verbatim |
317 | * @brief Initialization and Configuration functions |
| 318 | =============================================================================== |
318 | * |
| 319 | ##### Initialization and Configuration functions ##### |
319 | @verbatim |
| 320 | =============================================================================== |
320 | =============================================================================== |
| 321 | [..] |
321 | ##### Initialization and Configuration functions ##### |
| 322 | This subsection provides a set of functions allowing to initialize the USARTx or the UARTy |
322 | =============================================================================== |
| 323 | in asynchronous mode. |
323 | [..] |
| 324 | (+) For the asynchronous mode only these parameters can be configured: |
324 | This subsection provides a set of functions allowing to initialize the USARTx or the UARTy |
| 325 | (++) Baud Rate |
325 | in asynchronous mode. |
| 326 | (++) Word Length |
326 | (+) For the asynchronous mode only these parameters can be configured: |
| 327 | (++) Stop Bit |
327 | (++) Baud Rate |
| 328 | (++) Parity: If the parity is enabled, then the MSB bit of the data written |
328 | (++) Word Length |
| 329 | in the data register is transmitted but is changed by the parity bit. |
329 | (++) Stop Bit |
| 330 | Depending on the frame length defined by the M bit (8-bits or 9-bits), |
330 | (++) Parity: If the parity is enabled, then the MSB bit of the data written |
| 331 | please refer to Reference manual for possible UART frame formats. |
331 | in the data register is transmitted but is changed by the parity bit. |
| 332 | (++) Hardware flow control |
332 | Depending on the frame length defined by the M bit (8-bits or 9-bits), |
| 333 | (++) Receiver/transmitter modes |
333 | please refer to Reference manual for possible UART frame formats. |
| 334 | (++) Over Sampling Method |
334 | (++) Hardware flow control |
| 335 | [..] |
335 | (++) Receiver/transmitter modes |
| 336 | The HAL_UART_Init(), HAL_HalfDuplex_Init(), HAL_LIN_Init() and HAL_MultiProcessor_Init() APIs |
336 | (++) Over Sampling Method |
| 337 | follow respectively the UART asynchronous, UART Half duplex, LIN and Multi-Processor configuration |
337 | [..] |
| 338 | procedures (details for the procedures are available in reference manual (RM0038)). |
338 | The HAL_UART_Init(), HAL_HalfDuplex_Init(), HAL_LIN_Init() and HAL_MultiProcessor_Init() APIs |
| 339 | 339 | follow respectively the UART asynchronous, UART Half duplex, LIN and Multi-Processor configuration |
|
| 340 | @endverbatim |
340 | procedures (details for the procedures are available in reference manual (RM0038)). |
| 341 | * @{ |
341 | |
| 342 | */ |
342 | @endverbatim |
| 343 | 343 | * @{ |
|
| 344 | /** |
344 | */ |
| 345 | * @brief Initializes the UART mode according to the specified parameters in |
345 | |
| 346 | * the UART_InitTypeDef and create the associated handle. |
346 | /** |
| 347 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
347 | * @brief Initializes the UART mode according to the specified parameters in |
| 348 | * the configuration information for the specified UART module. |
348 | * the UART_InitTypeDef and create the associated handle. |
| 349 | * @retval HAL status |
349 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
| 350 | */ |
350 | * the configuration information for the specified UART module. |
| 351 | HAL_StatusTypeDef HAL_UART_Init(UART_HandleTypeDef *huart) |
351 | * @retval HAL status |
| 352 | { |
352 | */ |
| 353 | /* Check the UART handle allocation */ |
353 | HAL_StatusTypeDef HAL_UART_Init(UART_HandleTypeDef *huart) |
| 354 | if (huart == NULL) |
354 | { |
| 355 | { |
355 | /* Check the UART handle allocation */ |
| 356 | return HAL_ERROR; |
356 | if (huart == NULL) |
| 357 | } |
357 | { |
| 358 | 358 | return HAL_ERROR; |
|
| 359 | /* Check the parameters */ |
359 | } |
| 360 | if (huart->Init.HwFlowCtl != UART_HWCONTROL_NONE) |
360 | |
| 361 | { |
361 | /* Check the parameters */ |
| 362 | /* The hardware flow control is available only for USART1, USART2 and USART3 */ |
362 | if (huart->Init.HwFlowCtl != UART_HWCONTROL_NONE) |
| 363 | assert_param(IS_UART_HWFLOW_INSTANCE(huart->Instance)); |
363 | { |
| 364 | assert_param(IS_UART_HARDWARE_FLOW_CONTROL(huart->Init.HwFlowCtl)); |
364 | /* The hardware flow control is available only for USART1, USART2 and USART3 */ |
| 365 | } |
365 | assert_param(IS_UART_HWFLOW_INSTANCE(huart->Instance)); |
| 366 | else |
366 | assert_param(IS_UART_HARDWARE_FLOW_CONTROL(huart->Init.HwFlowCtl)); |
| 367 | { |
367 | } |
| 368 | assert_param(IS_UART_INSTANCE(huart->Instance)); |
368 | else |
| 369 | } |
369 | { |
| 370 | assert_param(IS_UART_WORD_LENGTH(huart->Init.WordLength)); |
370 | assert_param(IS_UART_INSTANCE(huart->Instance)); |
| 371 | assert_param(IS_UART_OVERSAMPLING(huart->Init.OverSampling)); |
371 | } |
| 372 | 372 | assert_param(IS_UART_WORD_LENGTH(huart->Init.WordLength)); |
|
| 373 | if (huart->gState == HAL_UART_STATE_RESET) |
373 | assert_param(IS_UART_OVERSAMPLING(huart->Init.OverSampling)); |
| 374 | { |
374 | |
| 375 | /* Allocate lock resource and initialize it */ |
375 | if (huart->gState == HAL_UART_STATE_RESET) |
| 376 | huart->Lock = HAL_UNLOCKED; |
376 | { |
| 377 | 377 | /* Allocate lock resource and initialize it */ |
|
| 378 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
378 | huart->Lock = HAL_UNLOCKED; |
| 379 | UART_InitCallbacksToDefault(huart); |
379 | |
| 380 | 380 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
|
| 381 | if (huart->MspInitCallback == NULL) |
381 | UART_InitCallbacksToDefault(huart); |
| 382 | { |
382 | |
| 383 | huart->MspInitCallback = HAL_UART_MspInit; |
383 | if (huart->MspInitCallback == NULL) |
| 384 | } |
384 | { |
| 385 | 385 | huart->MspInitCallback = HAL_UART_MspInit; |
|
| 386 | /* Init the low level hardware */ |
386 | } |
| 387 | huart->MspInitCallback(huart); |
387 | |
| 388 | #else |
388 | /* Init the low level hardware */ |
| 389 | /* Init the low level hardware : GPIO, CLOCK */ |
389 | huart->MspInitCallback(huart); |
| 390 | HAL_UART_MspInit(huart); |
390 | #else |
| 391 | #endif /* (USE_HAL_UART_REGISTER_CALLBACKS) */ |
391 | /* Init the low level hardware : GPIO, CLOCK */ |
| 392 | } |
392 | HAL_UART_MspInit(huart); |
| 393 | 393 | #endif /* (USE_HAL_UART_REGISTER_CALLBACKS) */ |
|
| 394 | huart->gState = HAL_UART_STATE_BUSY; |
394 | } |
| 395 | 395 | ||
| 396 | /* Disable the peripheral */ |
396 | huart->gState = HAL_UART_STATE_BUSY; |
| 397 | __HAL_UART_DISABLE(huart); |
397 | |
| 398 | 398 | /* Disable the peripheral */ |
|
| 399 | /* Set the UART Communication parameters */ |
399 | __HAL_UART_DISABLE(huart); |
| 400 | UART_SetConfig(huart); |
400 | |
| 401 | 401 | /* Set the UART Communication parameters */ |
|
| 402 | /* In asynchronous mode, the following bits must be kept cleared: |
402 | UART_SetConfig(huart); |
| 403 | - LINEN and CLKEN bits in the USART_CR2 register, |
403 | |
| 404 | - SCEN, HDSEL and IREN bits in the USART_CR3 register.*/ |
404 | /* In asynchronous mode, the following bits must be kept cleared: |
| 405 | CLEAR_BIT(huart->Instance->CR2, (USART_CR2_LINEN | USART_CR2_CLKEN)); |
405 | - LINEN and CLKEN bits in the USART_CR2 register, |
| 406 | CLEAR_BIT(huart->Instance->CR3, (USART_CR3_SCEN | USART_CR3_HDSEL | USART_CR3_IREN)); |
406 | - SCEN, HDSEL and IREN bits in the USART_CR3 register.*/ |
| 407 | 407 | CLEAR_BIT(huart->Instance->CR2, (USART_CR2_LINEN | USART_CR2_CLKEN)); |
|
| 408 | /* Enable the peripheral */ |
408 | CLEAR_BIT(huart->Instance->CR3, (USART_CR3_SCEN | USART_CR3_HDSEL | USART_CR3_IREN)); |
| 409 | __HAL_UART_ENABLE(huart); |
409 | |
| 410 | 410 | /* Enable the peripheral */ |
|
| 411 | /* Initialize the UART state */ |
411 | __HAL_UART_ENABLE(huart); |
| 412 | huart->ErrorCode = HAL_UART_ERROR_NONE; |
412 | |
| 413 | huart->gState = HAL_UART_STATE_READY; |
413 | /* Initialize the UART state */ |
| 414 | huart->RxState = HAL_UART_STATE_READY; |
414 | huart->ErrorCode = HAL_UART_ERROR_NONE; |
| 415 | 415 | huart->gState = HAL_UART_STATE_READY; |
|
| 416 | return HAL_OK; |
416 | huart->RxState = HAL_UART_STATE_READY; |
| 417 | } |
417 | huart->RxEventType = HAL_UART_RXEVENT_TC; |
| 418 | 418 | ||
| 419 | /** |
419 | return HAL_OK; |
| 420 | * @brief Initializes the half-duplex mode according to the specified |
420 | } |
| 421 | * parameters in the UART_InitTypeDef and create the associated handle. |
421 | |
| 422 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
422 | /** |
| 423 | * the configuration information for the specified UART module. |
423 | * @brief Initializes the half-duplex mode according to the specified |
| 424 | * @retval HAL status |
424 | * parameters in the UART_InitTypeDef and create the associated handle. |
| 425 | */ |
425 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
| 426 | HAL_StatusTypeDef HAL_HalfDuplex_Init(UART_HandleTypeDef *huart) |
426 | * the configuration information for the specified UART module. |
| 427 | { |
427 | * @retval HAL status |
| 428 | /* Check the UART handle allocation */ |
428 | */ |
| 429 | if (huart == NULL) |
429 | HAL_StatusTypeDef HAL_HalfDuplex_Init(UART_HandleTypeDef *huart) |
| 430 | { |
430 | { |
| 431 | return HAL_ERROR; |
431 | /* Check the UART handle allocation */ |
| 432 | } |
432 | if (huart == NULL) |
| 433 | 433 | { |
|
| 434 | /* Check the parameters */ |
434 | return HAL_ERROR; |
| 435 | assert_param(IS_UART_HALFDUPLEX_INSTANCE(huart->Instance)); |
435 | } |
| 436 | assert_param(IS_UART_WORD_LENGTH(huart->Init.WordLength)); |
436 | |
| 437 | assert_param(IS_UART_OVERSAMPLING(huart->Init.OverSampling)); |
437 | /* Check the parameters */ |
| 438 | 438 | assert_param(IS_UART_HALFDUPLEX_INSTANCE(huart->Instance)); |
|
| 439 | if (huart->gState == HAL_UART_STATE_RESET) |
439 | assert_param(IS_UART_WORD_LENGTH(huart->Init.WordLength)); |
| 440 | { |
440 | assert_param(IS_UART_OVERSAMPLING(huart->Init.OverSampling)); |
| 441 | /* Allocate lock resource and initialize it */ |
441 | |
| 442 | huart->Lock = HAL_UNLOCKED; |
442 | if (huart->gState == HAL_UART_STATE_RESET) |
| 443 | 443 | { |
|
| 444 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
444 | /* Allocate lock resource and initialize it */ |
| 445 | UART_InitCallbacksToDefault(huart); |
445 | huart->Lock = HAL_UNLOCKED; |
| 446 | 446 | ||
| 447 | if (huart->MspInitCallback == NULL) |
447 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
| 448 | { |
448 | UART_InitCallbacksToDefault(huart); |
| 449 | huart->MspInitCallback = HAL_UART_MspInit; |
449 | |
| 450 | } |
450 | if (huart->MspInitCallback == NULL) |
| 451 | 451 | { |
|
| 452 | /* Init the low level hardware */ |
452 | huart->MspInitCallback = HAL_UART_MspInit; |
| 453 | huart->MspInitCallback(huart); |
453 | } |
| 454 | #else |
454 | |
| 455 | /* Init the low level hardware : GPIO, CLOCK */ |
455 | /* Init the low level hardware */ |
| 456 | HAL_UART_MspInit(huart); |
456 | huart->MspInitCallback(huart); |
| 457 | #endif /* (USE_HAL_UART_REGISTER_CALLBACKS) */ |
457 | #else |
| 458 | } |
458 | /* Init the low level hardware : GPIO, CLOCK */ |
| 459 | 459 | HAL_UART_MspInit(huart); |
|
| 460 | huart->gState = HAL_UART_STATE_BUSY; |
460 | #endif /* (USE_HAL_UART_REGISTER_CALLBACKS) */ |
| 461 | 461 | } |
|
| 462 | /* Disable the peripheral */ |
462 | |
| 463 | __HAL_UART_DISABLE(huart); |
463 | huart->gState = HAL_UART_STATE_BUSY; |
| 464 | 464 | ||
| 465 | /* Set the UART Communication parameters */ |
465 | /* Disable the peripheral */ |
| 466 | UART_SetConfig(huart); |
466 | __HAL_UART_DISABLE(huart); |
| 467 | 467 | ||
| 468 | /* In half-duplex mode, the following bits must be kept cleared: |
468 | /* Set the UART Communication parameters */ |
| 469 | - LINEN and CLKEN bits in the USART_CR2 register, |
469 | UART_SetConfig(huart); |
| 470 | - SCEN and IREN bits in the USART_CR3 register.*/ |
470 | |
| 471 | CLEAR_BIT(huart->Instance->CR2, (USART_CR2_LINEN | USART_CR2_CLKEN)); |
471 | /* In half-duplex mode, the following bits must be kept cleared: |
| 472 | CLEAR_BIT(huart->Instance->CR3, (USART_CR3_IREN | USART_CR3_SCEN)); |
472 | - LINEN and CLKEN bits in the USART_CR2 register, |
| 473 | 473 | - SCEN and IREN bits in the USART_CR3 register.*/ |
|
| 474 | /* Enable the Half-Duplex mode by setting the HDSEL bit in the CR3 register */ |
474 | CLEAR_BIT(huart->Instance->CR2, (USART_CR2_LINEN | USART_CR2_CLKEN)); |
| 475 | SET_BIT(huart->Instance->CR3, USART_CR3_HDSEL); |
475 | CLEAR_BIT(huart->Instance->CR3, (USART_CR3_IREN | USART_CR3_SCEN)); |
| 476 | 476 | ||
| 477 | /* Enable the peripheral */ |
477 | /* Enable the Half-Duplex mode by setting the HDSEL bit in the CR3 register */ |
| 478 | __HAL_UART_ENABLE(huart); |
478 | SET_BIT(huart->Instance->CR3, USART_CR3_HDSEL); |
| 479 | 479 | ||
| 480 | /* Initialize the UART state*/ |
480 | /* Enable the peripheral */ |
| 481 | huart->ErrorCode = HAL_UART_ERROR_NONE; |
481 | __HAL_UART_ENABLE(huart); |
| 482 | huart->gState = HAL_UART_STATE_READY; |
482 | |
| 483 | huart->RxState = HAL_UART_STATE_READY; |
483 | /* Initialize the UART state*/ |
| 484 | 484 | huart->ErrorCode = HAL_UART_ERROR_NONE; |
|
| 485 | return HAL_OK; |
485 | huart->gState = HAL_UART_STATE_READY; |
| 486 | } |
486 | huart->RxState = HAL_UART_STATE_READY; |
| 487 | 487 | huart->RxEventType = HAL_UART_RXEVENT_TC; |
|
| 488 | /** |
488 | |
| 489 | * @brief Initializes the LIN mode according to the specified |
489 | return HAL_OK; |
| 490 | * parameters in the UART_InitTypeDef and create the associated handle. |
490 | } |
| 491 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
491 | |
| 492 | * the configuration information for the specified UART module. |
492 | /** |
| 493 | * @param BreakDetectLength Specifies the LIN break detection length. |
493 | * @brief Initializes the LIN mode according to the specified |
| 494 | * This parameter can be one of the following values: |
494 | * parameters in the UART_InitTypeDef and create the associated handle. |
| 495 | * @arg UART_LINBREAKDETECTLENGTH_10B: 10-bit break detection |
495 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
| 496 | * @arg UART_LINBREAKDETECTLENGTH_11B: 11-bit break detection |
496 | * the configuration information for the specified UART module. |
| 497 | * @retval HAL status |
497 | * @param BreakDetectLength Specifies the LIN break detection length. |
| 498 | */ |
498 | * This parameter can be one of the following values: |
| 499 | HAL_StatusTypeDef HAL_LIN_Init(UART_HandleTypeDef *huart, uint32_t BreakDetectLength) |
499 | * @arg UART_LINBREAKDETECTLENGTH_10B: 10-bit break detection |
| 500 | { |
500 | * @arg UART_LINBREAKDETECTLENGTH_11B: 11-bit break detection |
| 501 | /* Check the UART handle allocation */ |
501 | * @retval HAL status |
| 502 | if (huart == NULL) |
502 | */ |
| 503 | { |
503 | HAL_StatusTypeDef HAL_LIN_Init(UART_HandleTypeDef *huart, uint32_t BreakDetectLength) |
| 504 | return HAL_ERROR; |
504 | { |
| 505 | } |
505 | /* Check the UART handle allocation */ |
| 506 | 506 | if (huart == NULL) |
|
| 507 | /* Check the LIN UART instance */ |
507 | { |
| 508 | assert_param(IS_UART_LIN_INSTANCE(huart->Instance)); |
508 | return HAL_ERROR; |
| 509 | 509 | } |
|
| 510 | /* Check the Break detection length parameter */ |
510 | |
| 511 | assert_param(IS_UART_LIN_BREAK_DETECT_LENGTH(BreakDetectLength)); |
511 | /* Check the LIN UART instance */ |
| 512 | assert_param(IS_UART_LIN_WORD_LENGTH(huart->Init.WordLength)); |
512 | assert_param(IS_UART_LIN_INSTANCE(huart->Instance)); |
| 513 | assert_param(IS_UART_LIN_OVERSAMPLING(huart->Init.OverSampling)); |
513 | |
| 514 | 514 | /* Check the Break detection length parameter */ |
|
| 515 | if (huart->gState == HAL_UART_STATE_RESET) |
515 | assert_param(IS_UART_LIN_BREAK_DETECT_LENGTH(BreakDetectLength)); |
| 516 | { |
516 | assert_param(IS_UART_LIN_WORD_LENGTH(huart->Init.WordLength)); |
| 517 | /* Allocate lock resource and initialize it */ |
517 | assert_param(IS_UART_LIN_OVERSAMPLING(huart->Init.OverSampling)); |
| 518 | huart->Lock = HAL_UNLOCKED; |
518 | |
| 519 | 519 | if (huart->gState == HAL_UART_STATE_RESET) |
|
| 520 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
520 | { |
| 521 | UART_InitCallbacksToDefault(huart); |
521 | /* Allocate lock resource and initialize it */ |
| 522 | 522 | huart->Lock = HAL_UNLOCKED; |
|
| 523 | if (huart->MspInitCallback == NULL) |
523 | |
| 524 | { |
524 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
| 525 | huart->MspInitCallback = HAL_UART_MspInit; |
525 | UART_InitCallbacksToDefault(huart); |
| 526 | } |
526 | |
| 527 | 527 | if (huart->MspInitCallback == NULL) |
|
| 528 | /* Init the low level hardware */ |
528 | { |
| 529 | huart->MspInitCallback(huart); |
529 | huart->MspInitCallback = HAL_UART_MspInit; |
| 530 | #else |
530 | } |
| 531 | /* Init the low level hardware : GPIO, CLOCK */ |
531 | |
| 532 | HAL_UART_MspInit(huart); |
532 | /* Init the low level hardware */ |
| 533 | #endif /* (USE_HAL_UART_REGISTER_CALLBACKS) */ |
533 | huart->MspInitCallback(huart); |
| 534 | } |
534 | #else |
| 535 | 535 | /* Init the low level hardware : GPIO, CLOCK */ |
|
| 536 | huart->gState = HAL_UART_STATE_BUSY; |
536 | HAL_UART_MspInit(huart); |
| 537 | 537 | #endif /* (USE_HAL_UART_REGISTER_CALLBACKS) */ |
|
| 538 | /* Disable the peripheral */ |
538 | } |
| 539 | __HAL_UART_DISABLE(huart); |
539 | |
| 540 | 540 | huart->gState = HAL_UART_STATE_BUSY; |
|
| 541 | /* Set the UART Communication parameters */ |
541 | |
| 542 | UART_SetConfig(huart); |
542 | /* Disable the peripheral */ |
| 543 | 543 | __HAL_UART_DISABLE(huart); |
|
| 544 | /* In LIN mode, the following bits must be kept cleared: |
544 | |
| 545 | - CLKEN bits in the USART_CR2 register, |
545 | /* Set the UART Communication parameters */ |
| 546 | - SCEN, HDSEL and IREN bits in the USART_CR3 register.*/ |
546 | UART_SetConfig(huart); |
| 547 | CLEAR_BIT(huart->Instance->CR2, (USART_CR2_CLKEN)); |
547 | |
| 548 | CLEAR_BIT(huart->Instance->CR3, (USART_CR3_HDSEL | USART_CR3_IREN | USART_CR3_SCEN)); |
548 | /* In LIN mode, the following bits must be kept cleared: |
| 549 | 549 | - CLKEN bits in the USART_CR2 register, |
|
| 550 | /* Enable the LIN mode by setting the LINEN bit in the CR2 register */ |
550 | - SCEN, HDSEL and IREN bits in the USART_CR3 register.*/ |
| 551 | SET_BIT(huart->Instance->CR2, USART_CR2_LINEN); |
551 | CLEAR_BIT(huart->Instance->CR2, (USART_CR2_CLKEN)); |
| 552 | 552 | CLEAR_BIT(huart->Instance->CR3, (USART_CR3_HDSEL | USART_CR3_IREN | USART_CR3_SCEN)); |
|
| 553 | /* Set the USART LIN Break detection length. */ |
553 | |
| 554 | CLEAR_BIT(huart->Instance->CR2, USART_CR2_LBDL); |
554 | /* Enable the LIN mode by setting the LINEN bit in the CR2 register */ |
| 555 | SET_BIT(huart->Instance->CR2, BreakDetectLength); |
555 | SET_BIT(huart->Instance->CR2, USART_CR2_LINEN); |
| 556 | 556 | ||
| 557 | /* Enable the peripheral */ |
557 | /* Set the USART LIN Break detection length. */ |
| 558 | __HAL_UART_ENABLE(huart); |
558 | CLEAR_BIT(huart->Instance->CR2, USART_CR2_LBDL); |
| 559 | 559 | SET_BIT(huart->Instance->CR2, BreakDetectLength); |
|
| 560 | /* Initialize the UART state*/ |
560 | |
| 561 | huart->ErrorCode = HAL_UART_ERROR_NONE; |
561 | /* Enable the peripheral */ |
| 562 | huart->gState = HAL_UART_STATE_READY; |
562 | __HAL_UART_ENABLE(huart); |
| 563 | huart->RxState = HAL_UART_STATE_READY; |
563 | |
| 564 | 564 | /* Initialize the UART state*/ |
|
| 565 | return HAL_OK; |
565 | huart->ErrorCode = HAL_UART_ERROR_NONE; |
| 566 | } |
566 | huart->gState = HAL_UART_STATE_READY; |
| 567 | 567 | huart->RxState = HAL_UART_STATE_READY; |
|
| 568 | /** |
568 | huart->RxEventType = HAL_UART_RXEVENT_TC; |
| 569 | * @brief Initializes the Multi-Processor mode according to the specified |
569 | |
| 570 | * parameters in the UART_InitTypeDef and create the associated handle. |
570 | return HAL_OK; |
| 571 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
571 | } |
| 572 | * the configuration information for the specified UART module. |
572 | |
| 573 | * @param Address USART address |
573 | /** |
| 574 | * @param WakeUpMethod specifies the USART wake-up method. |
574 | * @brief Initializes the Multi-Processor mode according to the specified |
| 575 | * This parameter can be one of the following values: |
575 | * parameters in the UART_InitTypeDef and create the associated handle. |
| 576 | * @arg UART_WAKEUPMETHOD_IDLELINE: Wake-up by an idle line detection |
576 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
| 577 | * @arg UART_WAKEUPMETHOD_ADDRESSMARK: Wake-up by an address mark |
577 | * the configuration information for the specified UART module. |
| 578 | * @retval HAL status |
578 | * @param Address USART address |
| 579 | */ |
579 | * @param WakeUpMethod specifies the USART wake-up method. |
| 580 | HAL_StatusTypeDef HAL_MultiProcessor_Init(UART_HandleTypeDef *huart, uint8_t Address, uint32_t WakeUpMethod) |
580 | * This parameter can be one of the following values: |
| 581 | { |
581 | * @arg UART_WAKEUPMETHOD_IDLELINE: Wake-up by an idle line detection |
| 582 | /* Check the UART handle allocation */ |
582 | * @arg UART_WAKEUPMETHOD_ADDRESSMARK: Wake-up by an address mark |
| 583 | if (huart == NULL) |
583 | * @retval HAL status |
| 584 | { |
584 | */ |
| 585 | return HAL_ERROR; |
585 | HAL_StatusTypeDef HAL_MultiProcessor_Init(UART_HandleTypeDef *huart, uint8_t Address, uint32_t WakeUpMethod) |
| 586 | } |
586 | { |
| 587 | 587 | /* Check the UART handle allocation */ |
|
| 588 | /* Check the parameters */ |
588 | if (huart == NULL) |
| 589 | assert_param(IS_UART_MULTIPROCESSOR_INSTANCE(huart->Instance)); |
589 | { |
| 590 | 590 | return HAL_ERROR; |
|
| 591 | /* Check the Address & wake up method parameters */ |
591 | } |
| 592 | assert_param(IS_UART_WAKEUPMETHOD(WakeUpMethod)); |
592 | |
| 593 | assert_param(IS_UART_ADDRESS(Address)); |
593 | /* Check the parameters */ |
| 594 | assert_param(IS_UART_WORD_LENGTH(huart->Init.WordLength)); |
594 | assert_param(IS_UART_MULTIPROCESSOR_INSTANCE(huart->Instance)); |
| 595 | assert_param(IS_UART_OVERSAMPLING(huart->Init.OverSampling)); |
595 | |
| 596 | 596 | /* Check the Address & wake up method parameters */ |
|
| 597 | if (huart->gState == HAL_UART_STATE_RESET) |
597 | assert_param(IS_UART_WAKEUPMETHOD(WakeUpMethod)); |
| 598 | { |
598 | assert_param(IS_UART_ADDRESS(Address)); |
| 599 | /* Allocate lock resource and initialize it */ |
599 | assert_param(IS_UART_WORD_LENGTH(huart->Init.WordLength)); |
| 600 | huart->Lock = HAL_UNLOCKED; |
600 | assert_param(IS_UART_OVERSAMPLING(huart->Init.OverSampling)); |
| 601 | 601 | ||
| 602 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
602 | if (huart->gState == HAL_UART_STATE_RESET) |
| 603 | UART_InitCallbacksToDefault(huart); |
603 | { |
| 604 | 604 | /* Allocate lock resource and initialize it */ |
|
| 605 | if (huart->MspInitCallback == NULL) |
605 | huart->Lock = HAL_UNLOCKED; |
| 606 | { |
606 | |
| 607 | huart->MspInitCallback = HAL_UART_MspInit; |
607 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
| 608 | } |
608 | UART_InitCallbacksToDefault(huart); |
| 609 | 609 | ||
| 610 | /* Init the low level hardware */ |
610 | if (huart->MspInitCallback == NULL) |
| 611 | huart->MspInitCallback(huart); |
611 | { |
| 612 | #else |
612 | huart->MspInitCallback = HAL_UART_MspInit; |
| 613 | /* Init the low level hardware : GPIO, CLOCK */ |
613 | } |
| 614 | HAL_UART_MspInit(huart); |
614 | |
| 615 | #endif /* (USE_HAL_UART_REGISTER_CALLBACKS) */ |
615 | /* Init the low level hardware */ |
| 616 | } |
616 | huart->MspInitCallback(huart); |
| 617 | 617 | #else |
|
| 618 | huart->gState = HAL_UART_STATE_BUSY; |
618 | /* Init the low level hardware : GPIO, CLOCK */ |
| 619 | 619 | HAL_UART_MspInit(huart); |
|
| 620 | /* Disable the peripheral */ |
620 | #endif /* (USE_HAL_UART_REGISTER_CALLBACKS) */ |
| 621 | __HAL_UART_DISABLE(huart); |
621 | } |
| 622 | 622 | ||
| 623 | /* Set the UART Communication parameters */ |
623 | huart->gState = HAL_UART_STATE_BUSY; |
| 624 | UART_SetConfig(huart); |
624 | |
| 625 | 625 | /* Disable the peripheral */ |
|
| 626 | /* In Multi-Processor mode, the following bits must be kept cleared: |
626 | __HAL_UART_DISABLE(huart); |
| 627 | - LINEN and CLKEN bits in the USART_CR2 register, |
627 | |
| 628 | - SCEN, HDSEL and IREN bits in the USART_CR3 register */ |
628 | /* Set the UART Communication parameters */ |
| 629 | CLEAR_BIT(huart->Instance->CR2, (USART_CR2_LINEN | USART_CR2_CLKEN)); |
629 | UART_SetConfig(huart); |
| 630 | CLEAR_BIT(huart->Instance->CR3, (USART_CR3_SCEN | USART_CR3_HDSEL | USART_CR3_IREN)); |
630 | |
| 631 | 631 | /* In Multi-Processor mode, the following bits must be kept cleared: |
|
| 632 | /* Set the USART address node */ |
632 | - LINEN and CLKEN bits in the USART_CR2 register, |
| 633 | CLEAR_BIT(huart->Instance->CR2, USART_CR2_ADD); |
633 | - SCEN, HDSEL and IREN bits in the USART_CR3 register */ |
| 634 | SET_BIT(huart->Instance->CR2, Address); |
634 | CLEAR_BIT(huart->Instance->CR2, (USART_CR2_LINEN | USART_CR2_CLKEN)); |
| 635 | 635 | CLEAR_BIT(huart->Instance->CR3, (USART_CR3_SCEN | USART_CR3_HDSEL | USART_CR3_IREN)); |
|
| 636 | /* Set the wake up method by setting the WAKE bit in the CR1 register */ |
636 | |
| 637 | CLEAR_BIT(huart->Instance->CR1, USART_CR1_WAKE); |
637 | /* Set the USART address node */ |
| 638 | SET_BIT(huart->Instance->CR1, WakeUpMethod); |
638 | CLEAR_BIT(huart->Instance->CR2, USART_CR2_ADD); |
| 639 | 639 | SET_BIT(huart->Instance->CR2, Address); |
|
| 640 | /* Enable the peripheral */ |
640 | |
| 641 | __HAL_UART_ENABLE(huart); |
641 | /* Set the wake up method by setting the WAKE bit in the CR1 register */ |
| 642 | 642 | CLEAR_BIT(huart->Instance->CR1, USART_CR1_WAKE); |
|
| 643 | /* Initialize the UART state */ |
643 | SET_BIT(huart->Instance->CR1, WakeUpMethod); |
| 644 | huart->ErrorCode = HAL_UART_ERROR_NONE; |
644 | |
| 645 | huart->gState = HAL_UART_STATE_READY; |
645 | /* Enable the peripheral */ |
| 646 | huart->RxState = HAL_UART_STATE_READY; |
646 | __HAL_UART_ENABLE(huart); |
| 647 | 647 | ||
| 648 | return HAL_OK; |
648 | /* Initialize the UART state */ |
| 649 | } |
649 | huart->ErrorCode = HAL_UART_ERROR_NONE; |
| 650 | 650 | huart->gState = HAL_UART_STATE_READY; |
|
| 651 | /** |
651 | huart->RxState = HAL_UART_STATE_READY; |
| 652 | * @brief DeInitializes the UART peripheral. |
652 | huart->RxEventType = HAL_UART_RXEVENT_TC; |
| 653 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
653 | |
| 654 | * the configuration information for the specified UART module. |
654 | return HAL_OK; |
| 655 | * @retval HAL status |
655 | } |
| 656 | */ |
656 | |
| 657 | HAL_StatusTypeDef HAL_UART_DeInit(UART_HandleTypeDef *huart) |
657 | /** |
| 658 | { |
658 | * @brief DeInitializes the UART peripheral. |
| 659 | /* Check the UART handle allocation */ |
659 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
| 660 | if (huart == NULL) |
660 | * the configuration information for the specified UART module. |
| 661 | { |
661 | * @retval HAL status |
| 662 | return HAL_ERROR; |
662 | */ |
| 663 | } |
663 | HAL_StatusTypeDef HAL_UART_DeInit(UART_HandleTypeDef *huart) |
| 664 | 664 | { |
|
| 665 | /* Check the parameters */ |
665 | /* Check the UART handle allocation */ |
| 666 | assert_param(IS_UART_INSTANCE(huart->Instance)); |
666 | if (huart == NULL) |
| 667 | 667 | { |
|
| 668 | huart->gState = HAL_UART_STATE_BUSY; |
668 | return HAL_ERROR; |
| 669 | 669 | } |
|
| 670 | /* Disable the Peripheral */ |
670 | |
| 671 | __HAL_UART_DISABLE(huart); |
671 | /* Check the parameters */ |
| 672 | 672 | assert_param(IS_UART_INSTANCE(huart->Instance)); |
|
| 673 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
673 | |
| 674 | if (huart->MspDeInitCallback == NULL) |
674 | huart->gState = HAL_UART_STATE_BUSY; |
| 675 | { |
675 | |
| 676 | huart->MspDeInitCallback = HAL_UART_MspDeInit; |
676 | /* Disable the Peripheral */ |
| 677 | } |
677 | __HAL_UART_DISABLE(huart); |
| 678 | /* DeInit the low level hardware */ |
678 | |
| 679 | huart->MspDeInitCallback(huart); |
679 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
| 680 | #else |
680 | if (huart->MspDeInitCallback == NULL) |
| 681 | /* DeInit the low level hardware */ |
681 | { |
| 682 | HAL_UART_MspDeInit(huart); |
682 | huart->MspDeInitCallback = HAL_UART_MspDeInit; |
| 683 | #endif /* (USE_HAL_UART_REGISTER_CALLBACKS) */ |
683 | } |
| 684 | 684 | /* DeInit the low level hardware */ |
|
| 685 | huart->ErrorCode = HAL_UART_ERROR_NONE; |
685 | huart->MspDeInitCallback(huart); |
| 686 | huart->gState = HAL_UART_STATE_RESET; |
686 | #else |
| 687 | huart->RxState = HAL_UART_STATE_RESET; |
687 | /* DeInit the low level hardware */ |
| 688 | huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
688 | HAL_UART_MspDeInit(huart); |
| 689 | 689 | #endif /* (USE_HAL_UART_REGISTER_CALLBACKS) */ |
|
| 690 | /* Process Unlock */ |
690 | |
| 691 | __HAL_UNLOCK(huart); |
691 | huart->ErrorCode = HAL_UART_ERROR_NONE; |
| 692 | 692 | huart->gState = HAL_UART_STATE_RESET; |
|
| 693 | return HAL_OK; |
693 | huart->RxState = HAL_UART_STATE_RESET; |
| 694 | } |
694 | huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
| 695 | 695 | huart->RxEventType = HAL_UART_RXEVENT_TC; |
|
| 696 | /** |
696 | |
| 697 | * @brief UART MSP Init. |
697 | /* Process Unlock */ |
| 698 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
698 | __HAL_UNLOCK(huart); |
| 699 | * the configuration information for the specified UART module. |
699 | |
| 700 | * @retval None |
700 | return HAL_OK; |
| 701 | */ |
701 | } |
| 702 | __weak void HAL_UART_MspInit(UART_HandleTypeDef *huart) |
702 | |
| 703 | { |
703 | /** |
| 704 | /* Prevent unused argument(s) compilation warning */ |
704 | * @brief UART MSP Init. |
| 705 | UNUSED(huart); |
705 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
| 706 | /* NOTE: This function should not be modified, when the callback is needed, |
706 | * the configuration information for the specified UART module. |
| 707 | the HAL_UART_MspInit could be implemented in the user file |
707 | * @retval None |
| 708 | */ |
708 | */ |
| 709 | } |
709 | __weak void HAL_UART_MspInit(UART_HandleTypeDef *huart) |
| 710 | 710 | { |
|
| 711 | /** |
711 | /* Prevent unused argument(s) compilation warning */ |
| 712 | * @brief UART MSP DeInit. |
712 | UNUSED(huart); |
| 713 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
713 | /* NOTE: This function should not be modified, when the callback is needed, |
| 714 | * the configuration information for the specified UART module. |
714 | the HAL_UART_MspInit could be implemented in the user file |
| 715 | * @retval None |
715 | */ |
| 716 | */ |
716 | } |
| 717 | __weak void HAL_UART_MspDeInit(UART_HandleTypeDef *huart) |
717 | |
| 718 | { |
718 | /** |
| 719 | /* Prevent unused argument(s) compilation warning */ |
719 | * @brief UART MSP DeInit. |
| 720 | UNUSED(huart); |
720 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
| 721 | /* NOTE: This function should not be modified, when the callback is needed, |
721 | * the configuration information for the specified UART module. |
| 722 | the HAL_UART_MspDeInit could be implemented in the user file |
722 | * @retval None |
| 723 | */ |
723 | */ |
| 724 | } |
724 | __weak void HAL_UART_MspDeInit(UART_HandleTypeDef *huart) |
| 725 | 725 | { |
|
| 726 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
726 | /* Prevent unused argument(s) compilation warning */ |
| 727 | /** |
727 | UNUSED(huart); |
| 728 | * @brief Register a User UART Callback |
728 | /* NOTE: This function should not be modified, when the callback is needed, |
| 729 | * To be used instead of the weak predefined callback |
729 | the HAL_UART_MspDeInit could be implemented in the user file |
| 730 | * @param huart uart handle |
730 | */ |
| 731 | * @param CallbackID ID of the callback to be registered |
731 | } |
| 732 | * This parameter can be one of the following values: |
732 | |
| 733 | * @arg @ref HAL_UART_TX_HALFCOMPLETE_CB_ID Tx Half Complete Callback ID |
733 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
| 734 | * @arg @ref HAL_UART_TX_COMPLETE_CB_ID Tx Complete Callback ID |
734 | /** |
| 735 | * @arg @ref HAL_UART_RX_HALFCOMPLETE_CB_ID Rx Half Complete Callback ID |
735 | * @brief Register a User UART Callback |
| 736 | * @arg @ref HAL_UART_RX_COMPLETE_CB_ID Rx Complete Callback ID |
736 | * To be used instead of the weak predefined callback |
| 737 | * @arg @ref HAL_UART_ERROR_CB_ID Error Callback ID |
737 | * @note The HAL_UART_RegisterCallback() may be called before HAL_UART_Init(), HAL_HalfDuplex_Init(), HAL_LIN_Init(), |
| 738 | * @arg @ref HAL_UART_ABORT_COMPLETE_CB_ID Abort Complete Callback ID |
738 | * HAL_MultiProcessor_Init() to register callbacks for HAL_UART_MSPINIT_CB_ID and HAL_UART_MSPDEINIT_CB_ID |
| 739 | * @arg @ref HAL_UART_ABORT_TRANSMIT_COMPLETE_CB_ID Abort Transmit Complete Callback ID |
739 | * @param huart uart handle |
| 740 | * @arg @ref HAL_UART_ABORT_RECEIVE_COMPLETE_CB_ID Abort Receive Complete Callback ID |
740 | * @param CallbackID ID of the callback to be registered |
| 741 | * @arg @ref HAL_UART_MSPINIT_CB_ID MspInit Callback ID |
741 | * This parameter can be one of the following values: |
| 742 | * @arg @ref HAL_UART_MSPDEINIT_CB_ID MspDeInit Callback ID |
742 | * @arg @ref HAL_UART_TX_HALFCOMPLETE_CB_ID Tx Half Complete Callback ID |
| 743 | * @param pCallback pointer to the Callback function |
743 | * @arg @ref HAL_UART_TX_COMPLETE_CB_ID Tx Complete Callback ID |
| 744 | * @retval HAL status |
744 | * @arg @ref HAL_UART_RX_HALFCOMPLETE_CB_ID Rx Half Complete Callback ID |
| 745 | */ |
745 | * @arg @ref HAL_UART_RX_COMPLETE_CB_ID Rx Complete Callback ID |
| 746 | HAL_StatusTypeDef HAL_UART_RegisterCallback(UART_HandleTypeDef *huart, HAL_UART_CallbackIDTypeDef CallbackID, pUART_CallbackTypeDef pCallback) |
746 | * @arg @ref HAL_UART_ERROR_CB_ID Error Callback ID |
| 747 | { |
747 | * @arg @ref HAL_UART_ABORT_COMPLETE_CB_ID Abort Complete Callback ID |
| 748 | HAL_StatusTypeDef status = HAL_OK; |
748 | * @arg @ref HAL_UART_ABORT_TRANSMIT_COMPLETE_CB_ID Abort Transmit Complete Callback ID |
| 749 | 749 | * @arg @ref HAL_UART_ABORT_RECEIVE_COMPLETE_CB_ID Abort Receive Complete Callback ID |
|
| 750 | if (pCallback == NULL) |
750 | * @arg @ref HAL_UART_MSPINIT_CB_ID MspInit Callback ID |
| 751 | { |
751 | * @arg @ref HAL_UART_MSPDEINIT_CB_ID MspDeInit Callback ID |
| 752 | /* Update the error code */ |
752 | * @param pCallback pointer to the Callback function |
| 753 | huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK; |
753 | * @retval HAL status |
| 754 | 754 | */ |
|
| 755 | return HAL_ERROR; |
755 | HAL_StatusTypeDef HAL_UART_RegisterCallback(UART_HandleTypeDef *huart, HAL_UART_CallbackIDTypeDef CallbackID, |
| 756 | } |
756 | pUART_CallbackTypeDef pCallback) |
| 757 | /* Process locked */ |
757 | { |
| 758 | __HAL_LOCK(huart); |
758 | HAL_StatusTypeDef status = HAL_OK; |
| 759 | 759 | ||
| 760 | if (huart->gState == HAL_UART_STATE_READY) |
760 | if (pCallback == NULL) |
| 761 | { |
761 | { |
| 762 | switch (CallbackID) |
762 | /* Update the error code */ |
| 763 | { |
763 | huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK; |
| 764 | case HAL_UART_TX_HALFCOMPLETE_CB_ID : |
764 | |
| 765 | huart->TxHalfCpltCallback = pCallback; |
765 | return HAL_ERROR; |
| 766 | break; |
766 | } |
| 767 | 767 | ||
| 768 | case HAL_UART_TX_COMPLETE_CB_ID : |
768 | if (huart->gState == HAL_UART_STATE_READY) |
| 769 | huart->TxCpltCallback = pCallback; |
769 | { |
| 770 | break; |
770 | switch (CallbackID) |
| 771 | 771 | { |
|
| 772 | case HAL_UART_RX_HALFCOMPLETE_CB_ID : |
772 | case HAL_UART_TX_HALFCOMPLETE_CB_ID : |
| 773 | huart->RxHalfCpltCallback = pCallback; |
773 | huart->TxHalfCpltCallback = pCallback; |
| 774 | break; |
774 | break; |
| 775 | 775 | ||
| 776 | case HAL_UART_RX_COMPLETE_CB_ID : |
776 | case HAL_UART_TX_COMPLETE_CB_ID : |
| 777 | huart->RxCpltCallback = pCallback; |
777 | huart->TxCpltCallback = pCallback; |
| 778 | break; |
778 | break; |
| 779 | 779 | ||
| 780 | case HAL_UART_ERROR_CB_ID : |
780 | case HAL_UART_RX_HALFCOMPLETE_CB_ID : |
| 781 | huart->ErrorCallback = pCallback; |
781 | huart->RxHalfCpltCallback = pCallback; |
| 782 | break; |
782 | break; |
| 783 | 783 | ||
| 784 | case HAL_UART_ABORT_COMPLETE_CB_ID : |
784 | case HAL_UART_RX_COMPLETE_CB_ID : |
| 785 | huart->AbortCpltCallback = pCallback; |
785 | huart->RxCpltCallback = pCallback; |
| 786 | break; |
786 | break; |
| 787 | 787 | ||
| 788 | case HAL_UART_ABORT_TRANSMIT_COMPLETE_CB_ID : |
788 | case HAL_UART_ERROR_CB_ID : |
| 789 | huart->AbortTransmitCpltCallback = pCallback; |
789 | huart->ErrorCallback = pCallback; |
| 790 | break; |
790 | break; |
| 791 | 791 | ||
| 792 | case HAL_UART_ABORT_RECEIVE_COMPLETE_CB_ID : |
792 | case HAL_UART_ABORT_COMPLETE_CB_ID : |
| 793 | huart->AbortReceiveCpltCallback = pCallback; |
793 | huart->AbortCpltCallback = pCallback; |
| 794 | break; |
794 | break; |
| 795 | 795 | ||
| 796 | case HAL_UART_MSPINIT_CB_ID : |
796 | case HAL_UART_ABORT_TRANSMIT_COMPLETE_CB_ID : |
| 797 | huart->MspInitCallback = pCallback; |
797 | huart->AbortTransmitCpltCallback = pCallback; |
| 798 | break; |
798 | break; |
| 799 | 799 | ||
| 800 | case HAL_UART_MSPDEINIT_CB_ID : |
800 | case HAL_UART_ABORT_RECEIVE_COMPLETE_CB_ID : |
| 801 | huart->MspDeInitCallback = pCallback; |
801 | huart->AbortReceiveCpltCallback = pCallback; |
| 802 | break; |
802 | break; |
| 803 | 803 | ||
| 804 | default : |
804 | case HAL_UART_MSPINIT_CB_ID : |
| 805 | /* Update the error code */ |
805 | huart->MspInitCallback = pCallback; |
| 806 | huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK; |
806 | break; |
| 807 | 807 | ||
| 808 | /* Return error status */ |
808 | case HAL_UART_MSPDEINIT_CB_ID : |
| 809 | status = HAL_ERROR; |
809 | huart->MspDeInitCallback = pCallback; |
| 810 | break; |
810 | break; |
| 811 | } |
811 | |
| 812 | } |
812 | default : |
| 813 | else if (huart->gState == HAL_UART_STATE_RESET) |
813 | /* Update the error code */ |
| 814 | { |
814 | huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK; |
| 815 | switch (CallbackID) |
815 | |
| 816 | { |
816 | /* Return error status */ |
| 817 | case HAL_UART_MSPINIT_CB_ID : |
817 | status = HAL_ERROR; |
| 818 | huart->MspInitCallback = pCallback; |
818 | break; |
| 819 | break; |
819 | } |
| 820 | 820 | } |
|
| 821 | case HAL_UART_MSPDEINIT_CB_ID : |
821 | else if (huart->gState == HAL_UART_STATE_RESET) |
| 822 | huart->MspDeInitCallback = pCallback; |
822 | { |
| 823 | break; |
823 | switch (CallbackID) |
| 824 | 824 | { |
|
| 825 | default : |
825 | case HAL_UART_MSPINIT_CB_ID : |
| 826 | /* Update the error code */ |
826 | huart->MspInitCallback = pCallback; |
| 827 | huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK; |
827 | break; |
| 828 | 828 | ||
| 829 | /* Return error status */ |
829 | case HAL_UART_MSPDEINIT_CB_ID : |
| 830 | status = HAL_ERROR; |
830 | huart->MspDeInitCallback = pCallback; |
| 831 | break; |
831 | break; |
| 832 | } |
832 | |
| 833 | } |
833 | default : |
| 834 | else |
834 | /* Update the error code */ |
| 835 | { |
835 | huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK; |
| 836 | /* Update the error code */ |
836 | |
| 837 | huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK; |
837 | /* Return error status */ |
| 838 | 838 | status = HAL_ERROR; |
|
| 839 | /* Return error status */ |
839 | break; |
| 840 | status = HAL_ERROR; |
840 | } |
| 841 | } |
841 | } |
| 842 | 842 | else |
|
| 843 | /* Release Lock */ |
843 | { |
| 844 | __HAL_UNLOCK(huart); |
844 | /* Update the error code */ |
| 845 | 845 | huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK; |
|
| 846 | return status; |
846 | |
| 847 | } |
847 | /* Return error status */ |
| 848 | 848 | status = HAL_ERROR; |
|
| 849 | /** |
849 | } |
| 850 | * @brief Unregister an UART Callback |
850 | |
| 851 | * UART callaback is redirected to the weak predefined callback |
851 | return status; |
| 852 | * @param huart uart handle |
852 | } |
| 853 | * @param CallbackID ID of the callback to be unregistered |
853 | |
| 854 | * This parameter can be one of the following values: |
854 | /** |
| 855 | * @arg @ref HAL_UART_TX_HALFCOMPLETE_CB_ID Tx Half Complete Callback ID |
855 | * @brief Unregister an UART Callback |
| 856 | * @arg @ref HAL_UART_TX_COMPLETE_CB_ID Tx Complete Callback ID |
856 | * UART callaback is redirected to the weak predefined callback |
| 857 | * @arg @ref HAL_UART_RX_HALFCOMPLETE_CB_ID Rx Half Complete Callback ID |
857 | * @note The HAL_UART_UnRegisterCallback() may be called before HAL_UART_Init(), HAL_HalfDuplex_Init(), |
| 858 | * @arg @ref HAL_UART_RX_COMPLETE_CB_ID Rx Complete Callback ID |
858 | * HAL_LIN_Init(), HAL_MultiProcessor_Init() to un-register callbacks for HAL_UART_MSPINIT_CB_ID |
| 859 | * @arg @ref HAL_UART_ERROR_CB_ID Error Callback ID |
859 | * and HAL_UART_MSPDEINIT_CB_ID |
| 860 | * @arg @ref HAL_UART_ABORT_COMPLETE_CB_ID Abort Complete Callback ID |
860 | * @param huart uart handle |
| 861 | * @arg @ref HAL_UART_ABORT_TRANSMIT_COMPLETE_CB_ID Abort Transmit Complete Callback ID |
861 | * @param CallbackID ID of the callback to be unregistered |
| 862 | * @arg @ref HAL_UART_ABORT_RECEIVE_COMPLETE_CB_ID Abort Receive Complete Callback ID |
862 | * This parameter can be one of the following values: |
| 863 | * @arg @ref HAL_UART_MSPINIT_CB_ID MspInit Callback ID |
863 | * @arg @ref HAL_UART_TX_HALFCOMPLETE_CB_ID Tx Half Complete Callback ID |
| 864 | * @arg @ref HAL_UART_MSPDEINIT_CB_ID MspDeInit Callback ID |
864 | * @arg @ref HAL_UART_TX_COMPLETE_CB_ID Tx Complete Callback ID |
| 865 | * @retval HAL status |
865 | * @arg @ref HAL_UART_RX_HALFCOMPLETE_CB_ID Rx Half Complete Callback ID |
| 866 | */ |
866 | * @arg @ref HAL_UART_RX_COMPLETE_CB_ID Rx Complete Callback ID |
| 867 | HAL_StatusTypeDef HAL_UART_UnRegisterCallback(UART_HandleTypeDef *huart, HAL_UART_CallbackIDTypeDef CallbackID) |
867 | * @arg @ref HAL_UART_ERROR_CB_ID Error Callback ID |
| 868 | { |
868 | * @arg @ref HAL_UART_ABORT_COMPLETE_CB_ID Abort Complete Callback ID |
| 869 | HAL_StatusTypeDef status = HAL_OK; |
869 | * @arg @ref HAL_UART_ABORT_TRANSMIT_COMPLETE_CB_ID Abort Transmit Complete Callback ID |
| 870 | 870 | * @arg @ref HAL_UART_ABORT_RECEIVE_COMPLETE_CB_ID Abort Receive Complete Callback ID |
|
| 871 | /* Process locked */ |
871 | * @arg @ref HAL_UART_MSPINIT_CB_ID MspInit Callback ID |
| 872 | __HAL_LOCK(huart); |
872 | * @arg @ref HAL_UART_MSPDEINIT_CB_ID MspDeInit Callback ID |
| 873 | 873 | * @retval HAL status |
|
| 874 | if (HAL_UART_STATE_READY == huart->gState) |
874 | */ |
| 875 | { |
875 | HAL_StatusTypeDef HAL_UART_UnRegisterCallback(UART_HandleTypeDef *huart, HAL_UART_CallbackIDTypeDef CallbackID) |
| 876 | switch (CallbackID) |
876 | { |
| 877 | { |
877 | HAL_StatusTypeDef status = HAL_OK; |
| 878 | case HAL_UART_TX_HALFCOMPLETE_CB_ID : |
878 | |
| 879 | huart->TxHalfCpltCallback = HAL_UART_TxHalfCpltCallback; /* Legacy weak TxHalfCpltCallback */ |
879 | if (HAL_UART_STATE_READY == huart->gState) |
| 880 | break; |
880 | { |
| 881 | 881 | switch (CallbackID) |
|
| 882 | case HAL_UART_TX_COMPLETE_CB_ID : |
882 | { |
| 883 | huart->TxCpltCallback = HAL_UART_TxCpltCallback; /* Legacy weak TxCpltCallback */ |
883 | case HAL_UART_TX_HALFCOMPLETE_CB_ID : |
| 884 | break; |
884 | huart->TxHalfCpltCallback = HAL_UART_TxHalfCpltCallback; /* Legacy weak TxHalfCpltCallback */ |
| 885 | 885 | break; |
|
| 886 | case HAL_UART_RX_HALFCOMPLETE_CB_ID : |
886 | |
| 887 | huart->RxHalfCpltCallback = HAL_UART_RxHalfCpltCallback; /* Legacy weak RxHalfCpltCallback */ |
887 | case HAL_UART_TX_COMPLETE_CB_ID : |
| 888 | break; |
888 | huart->TxCpltCallback = HAL_UART_TxCpltCallback; /* Legacy weak TxCpltCallback */ |
| 889 | 889 | break; |
|
| 890 | case HAL_UART_RX_COMPLETE_CB_ID : |
890 | |
| 891 | huart->RxCpltCallback = HAL_UART_RxCpltCallback; /* Legacy weak RxCpltCallback */ |
891 | case HAL_UART_RX_HALFCOMPLETE_CB_ID : |
| 892 | break; |
892 | huart->RxHalfCpltCallback = HAL_UART_RxHalfCpltCallback; /* Legacy weak RxHalfCpltCallback */ |
| 893 | 893 | break; |
|
| 894 | case HAL_UART_ERROR_CB_ID : |
894 | |
| 895 | huart->ErrorCallback = HAL_UART_ErrorCallback; /* Legacy weak ErrorCallback */ |
895 | case HAL_UART_RX_COMPLETE_CB_ID : |
| 896 | break; |
896 | huart->RxCpltCallback = HAL_UART_RxCpltCallback; /* Legacy weak RxCpltCallback */ |
| 897 | 897 | break; |
|
| 898 | case HAL_UART_ABORT_COMPLETE_CB_ID : |
898 | |
| 899 | huart->AbortCpltCallback = HAL_UART_AbortCpltCallback; /* Legacy weak AbortCpltCallback */ |
899 | case HAL_UART_ERROR_CB_ID : |
| 900 | break; |
900 | huart->ErrorCallback = HAL_UART_ErrorCallback; /* Legacy weak ErrorCallback */ |
| 901 | 901 | break; |
|
| 902 | case HAL_UART_ABORT_TRANSMIT_COMPLETE_CB_ID : |
902 | |
| 903 | huart->AbortTransmitCpltCallback = HAL_UART_AbortTransmitCpltCallback; /* Legacy weak AbortTransmitCpltCallback */ |
903 | case HAL_UART_ABORT_COMPLETE_CB_ID : |
| 904 | break; |
904 | huart->AbortCpltCallback = HAL_UART_AbortCpltCallback; /* Legacy weak AbortCpltCallback */ |
| 905 | 905 | break; |
|
| 906 | case HAL_UART_ABORT_RECEIVE_COMPLETE_CB_ID : |
906 | |
| 907 | huart->AbortReceiveCpltCallback = HAL_UART_AbortReceiveCpltCallback; /* Legacy weak AbortReceiveCpltCallback */ |
907 | case HAL_UART_ABORT_TRANSMIT_COMPLETE_CB_ID : |
| 908 | break; |
908 | huart->AbortTransmitCpltCallback = HAL_UART_AbortTransmitCpltCallback; /* Legacy weak AbortTransmitCpltCallback */ |
| 909 | 909 | break; |
|
| 910 | case HAL_UART_MSPINIT_CB_ID : |
910 | |
| 911 | huart->MspInitCallback = HAL_UART_MspInit; /* Legacy weak MspInitCallback */ |
911 | case HAL_UART_ABORT_RECEIVE_COMPLETE_CB_ID : |
| 912 | break; |
912 | huart->AbortReceiveCpltCallback = HAL_UART_AbortReceiveCpltCallback; /* Legacy weak AbortReceiveCpltCallback */ |
| 913 | 913 | break; |
|
| 914 | case HAL_UART_MSPDEINIT_CB_ID : |
914 | |
| 915 | huart->MspDeInitCallback = HAL_UART_MspDeInit; /* Legacy weak MspDeInitCallback */ |
915 | case HAL_UART_MSPINIT_CB_ID : |
| 916 | break; |
916 | huart->MspInitCallback = HAL_UART_MspInit; /* Legacy weak MspInitCallback */ |
| 917 | 917 | break; |
|
| 918 | default : |
918 | |
| 919 | /* Update the error code */ |
919 | case HAL_UART_MSPDEINIT_CB_ID : |
| 920 | huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK; |
920 | huart->MspDeInitCallback = HAL_UART_MspDeInit; /* Legacy weak MspDeInitCallback */ |
| 921 | 921 | break; |
|
| 922 | /* Return error status */ |
922 | |
| 923 | status = HAL_ERROR; |
923 | default : |
| 924 | break; |
924 | /* Update the error code */ |
| 925 | } |
925 | huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK; |
| 926 | } |
926 | |
| 927 | else if (HAL_UART_STATE_RESET == huart->gState) |
927 | /* Return error status */ |
| 928 | { |
928 | status = HAL_ERROR; |
| 929 | switch (CallbackID) |
929 | break; |
| 930 | { |
930 | } |
| 931 | case HAL_UART_MSPINIT_CB_ID : |
931 | } |
| 932 | huart->MspInitCallback = HAL_UART_MspInit; |
932 | else if (HAL_UART_STATE_RESET == huart->gState) |
| 933 | break; |
933 | { |
| 934 | 934 | switch (CallbackID) |
|
| 935 | case HAL_UART_MSPDEINIT_CB_ID : |
935 | { |
| 936 | huart->MspDeInitCallback = HAL_UART_MspDeInit; |
936 | case HAL_UART_MSPINIT_CB_ID : |
| 937 | break; |
937 | huart->MspInitCallback = HAL_UART_MspInit; |
| 938 | 938 | break; |
|
| 939 | default : |
939 | |
| 940 | /* Update the error code */ |
940 | case HAL_UART_MSPDEINIT_CB_ID : |
| 941 | huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK; |
941 | huart->MspDeInitCallback = HAL_UART_MspDeInit; |
| 942 | 942 | break; |
|
| 943 | /* Return error status */ |
943 | |
| 944 | status = HAL_ERROR; |
944 | default : |
| 945 | break; |
945 | /* Update the error code */ |
| 946 | } |
946 | huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK; |
| 947 | } |
947 | |
| 948 | else |
948 | /* Return error status */ |
| 949 | { |
949 | status = HAL_ERROR; |
| 950 | /* Update the error code */ |
950 | break; |
| 951 | huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK; |
951 | } |
| 952 | 952 | } |
|
| 953 | /* Return error status */ |
953 | else |
| 954 | status = HAL_ERROR; |
954 | { |
| 955 | } |
955 | /* Update the error code */ |
| 956 | 956 | huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK; |
|
| 957 | /* Release Lock */ |
957 | |
| 958 | __HAL_UNLOCK(huart); |
958 | /* Return error status */ |
| 959 | 959 | status = HAL_ERROR; |
|
| 960 | return status; |
960 | } |
| 961 | } |
961 | |
| 962 | 962 | return status; |
|
| 963 | /** |
963 | } |
| 964 | * @brief Register a User UART Rx Event Callback |
964 | |
| 965 | * To be used instead of the weak predefined callback |
965 | /** |
| 966 | * @param huart Uart handle |
966 | * @brief Register a User UART Rx Event Callback |
| 967 | * @param pCallback Pointer to the Rx Event Callback function |
967 | * To be used instead of the weak predefined callback |
| 968 | * @retval HAL status |
968 | * @param huart Uart handle |
| 969 | */ |
969 | * @param pCallback Pointer to the Rx Event Callback function |
| 970 | HAL_StatusTypeDef HAL_UART_RegisterRxEventCallback(UART_HandleTypeDef *huart, pUART_RxEventCallbackTypeDef pCallback) |
970 | * @retval HAL status |
| 971 | { |
971 | */ |
| 972 | HAL_StatusTypeDef status = HAL_OK; |
972 | HAL_StatusTypeDef HAL_UART_RegisterRxEventCallback(UART_HandleTypeDef *huart, pUART_RxEventCallbackTypeDef pCallback) |
| 973 | 973 | { |
|
| 974 | if (pCallback == NULL) |
974 | HAL_StatusTypeDef status = HAL_OK; |
| 975 | { |
975 | |
| 976 | huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK; |
976 | if (pCallback == NULL) |
| 977 | 977 | { |
|
| 978 | return HAL_ERROR; |
978 | huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK; |
| 979 | } |
979 | |
| 980 | 980 | return HAL_ERROR; |
|
| 981 | /* Process locked */ |
981 | } |
| 982 | __HAL_LOCK(huart); |
982 | |
| 983 | 983 | /* Process locked */ |
|
| 984 | if (huart->gState == HAL_UART_STATE_READY) |
984 | __HAL_LOCK(huart); |
| 985 | { |
985 | |
| 986 | huart->RxEventCallback = pCallback; |
986 | if (huart->gState == HAL_UART_STATE_READY) |
| 987 | } |
987 | { |
| 988 | else |
988 | huart->RxEventCallback = pCallback; |
| 989 | { |
989 | } |
| 990 | huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK; |
990 | else |
| 991 | 991 | { |
|
| 992 | status = HAL_ERROR; |
992 | huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK; |
| 993 | } |
993 | |
| 994 | 994 | status = HAL_ERROR; |
|
| 995 | /* Release Lock */ |
995 | } |
| 996 | __HAL_UNLOCK(huart); |
996 | |
| 997 | 997 | /* Release Lock */ |
|
| 998 | return status; |
998 | __HAL_UNLOCK(huart); |
| 999 | } |
999 | |
| 1000 | 1000 | return status; |
|
| 1001 | /** |
1001 | } |
| 1002 | * @brief UnRegister the UART Rx Event Callback |
1002 | |
| 1003 | * UART Rx Event Callback is redirected to the weak HAL_UARTEx_RxEventCallback() predefined callback |
1003 | /** |
| 1004 | * @param huart Uart handle |
1004 | * @brief UnRegister the UART Rx Event Callback |
| 1005 | * @retval HAL status |
1005 | * UART Rx Event Callback is redirected to the weak HAL_UARTEx_RxEventCallback() predefined callback |
| 1006 | */ |
1006 | * @param huart Uart handle |
| 1007 | HAL_StatusTypeDef HAL_UART_UnRegisterRxEventCallback(UART_HandleTypeDef *huart) |
1007 | * @retval HAL status |
| 1008 | { |
1008 | */ |
| 1009 | HAL_StatusTypeDef status = HAL_OK; |
1009 | HAL_StatusTypeDef HAL_UART_UnRegisterRxEventCallback(UART_HandleTypeDef *huart) |
| 1010 | 1010 | { |
|
| 1011 | /* Process locked */ |
1011 | HAL_StatusTypeDef status = HAL_OK; |
| 1012 | __HAL_LOCK(huart); |
1012 | |
| 1013 | 1013 | /* Process locked */ |
|
| 1014 | if (huart->gState == HAL_UART_STATE_READY) |
1014 | __HAL_LOCK(huart); |
| 1015 | { |
1015 | |
| 1016 | huart->RxEventCallback = HAL_UARTEx_RxEventCallback; /* Legacy weak UART Rx Event Callback */ |
1016 | if (huart->gState == HAL_UART_STATE_READY) |
| 1017 | } |
1017 | { |
| 1018 | else |
1018 | huart->RxEventCallback = HAL_UARTEx_RxEventCallback; /* Legacy weak UART Rx Event Callback */ |
| 1019 | { |
1019 | } |
| 1020 | huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK; |
1020 | else |
| 1021 | 1021 | { |
|
| 1022 | status = HAL_ERROR; |
1022 | huart->ErrorCode |= HAL_UART_ERROR_INVALID_CALLBACK; |
| 1023 | } |
1023 | |
| 1024 | 1024 | status = HAL_ERROR; |
|
| 1025 | /* Release Lock */ |
1025 | } |
| 1026 | __HAL_UNLOCK(huart); |
1026 | |
| 1027 | return status; |
1027 | /* Release Lock */ |
| 1028 | } |
1028 | __HAL_UNLOCK(huart); |
| 1029 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
1029 | return status; |
| 1030 | 1030 | } |
|
| 1031 | /** |
1031 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
| 1032 | * @} |
1032 | |
| 1033 | */ |
1033 | /** |
| 1034 | 1034 | * @} |
|
| 1035 | /** @defgroup UART_Exported_Functions_Group2 IO operation functions |
1035 | */ |
| 1036 | * @brief UART Transmit and Receive functions |
1036 | |
| 1037 | * |
1037 | /** @defgroup UART_Exported_Functions_Group2 IO operation functions |
| 1038 | @verbatim |
1038 | * @brief UART Transmit and Receive functions |
| 1039 | =============================================================================== |
1039 | * |
| 1040 | ##### IO operation functions ##### |
1040 | @verbatim |
| 1041 | =============================================================================== |
1041 | =============================================================================== |
| 1042 | This subsection provides a set of functions allowing to manage the UART asynchronous |
1042 | ##### IO operation functions ##### |
| 1043 | and Half duplex data transfers. |
1043 | =============================================================================== |
| 1044 | 1044 | This subsection provides a set of functions allowing to manage the UART asynchronous |
|
| 1045 | (#) There are two modes of transfer: |
1045 | and Half duplex data transfers. |
| 1046 | (+) Blocking mode: The communication is performed in polling mode. |
1046 | |
| 1047 | The HAL status of all data processing is returned by the same function |
1047 | (#) There are two modes of transfer: |
| 1048 | after finishing transfer. |
1048 | (+) Blocking mode: The communication is performed in polling mode. |
| 1049 | (+) Non-Blocking mode: The communication is performed using Interrupts |
1049 | The HAL status of all data processing is returned by the same function |
| 1050 | or DMA, these API's return the HAL status. |
1050 | after finishing transfer. |
| 1051 | The end of the data processing will be indicated through the |
1051 | (+) Non-Blocking mode: The communication is performed using Interrupts |
| 1052 | dedicated UART IRQ when using Interrupt mode or the DMA IRQ when |
1052 | or DMA, these API's return the HAL status. |
| 1053 | using DMA mode. |
1053 | The end of the data processing will be indicated through the |
| 1054 | The HAL_UART_TxCpltCallback(), HAL_UART_RxCpltCallback() user callbacks |
1054 | dedicated UART IRQ when using Interrupt mode or the DMA IRQ when |
| 1055 | will be executed respectively at the end of the transmit or receive process |
1055 | using DMA mode. |
| 1056 | The HAL_UART_ErrorCallback()user callback will be executed when a communication error is detected. |
1056 | The HAL_UART_TxCpltCallback(), HAL_UART_RxCpltCallback() user callbacks |
| 1057 | 1057 | will be executed respectively at the end of the transmit or receive process |
|
| 1058 | (#) Blocking mode API's are : |
1058 | The HAL_UART_ErrorCallback()user callback will be executed when a communication error is detected. |
| 1059 | (+) HAL_UART_Transmit() |
1059 | |
| 1060 | (+) HAL_UART_Receive() |
1060 | (#) Blocking mode API's are : |
| 1061 | 1061 | (+) HAL_UART_Transmit() |
|
| 1062 | (#) Non-Blocking mode API's with Interrupt are : |
1062 | (+) HAL_UART_Receive() |
| 1063 | (+) HAL_UART_Transmit_IT() |
1063 | |
| 1064 | (+) HAL_UART_Receive_IT() |
1064 | (#) Non-Blocking mode API's with Interrupt are : |
| 1065 | (+) HAL_UART_IRQHandler() |
1065 | (+) HAL_UART_Transmit_IT() |
| 1066 | 1066 | (+) HAL_UART_Receive_IT() |
|
| 1067 | (#) Non-Blocking mode API's with DMA are : |
1067 | (+) HAL_UART_IRQHandler() |
| 1068 | (+) HAL_UART_Transmit_DMA() |
1068 | |
| 1069 | (+) HAL_UART_Receive_DMA() |
1069 | (#) Non-Blocking mode API's with DMA are : |
| 1070 | (+) HAL_UART_DMAPause() |
1070 | (+) HAL_UART_Transmit_DMA() |
| 1071 | (+) HAL_UART_DMAResume() |
1071 | (+) HAL_UART_Receive_DMA() |
| 1072 | (+) HAL_UART_DMAStop() |
1072 | (+) HAL_UART_DMAPause() |
| 1073 | 1073 | (+) HAL_UART_DMAResume() |
|
| 1074 | (#) A set of Transfer Complete Callbacks are provided in Non_Blocking mode: |
1074 | (+) HAL_UART_DMAStop() |
| 1075 | (+) HAL_UART_TxHalfCpltCallback() |
1075 | |
| 1076 | (+) HAL_UART_TxCpltCallback() |
1076 | (#) A set of Transfer Complete Callbacks are provided in Non_Blocking mode: |
| 1077 | (+) HAL_UART_RxHalfCpltCallback() |
1077 | (+) HAL_UART_TxHalfCpltCallback() |
| 1078 | (+) HAL_UART_RxCpltCallback() |
1078 | (+) HAL_UART_TxCpltCallback() |
| 1079 | (+) HAL_UART_ErrorCallback() |
1079 | (+) HAL_UART_RxHalfCpltCallback() |
| 1080 | 1080 | (+) HAL_UART_RxCpltCallback() |
|
| 1081 | (#) Non-Blocking mode transfers could be aborted using Abort API's : |
1081 | (+) HAL_UART_ErrorCallback() |
| 1082 | (+) HAL_UART_Abort() |
1082 | |
| 1083 | (+) HAL_UART_AbortTransmit() |
1083 | (#) Non-Blocking mode transfers could be aborted using Abort API's : |
| 1084 | (+) HAL_UART_AbortReceive() |
1084 | (+) HAL_UART_Abort() |
| 1085 | (+) HAL_UART_Abort_IT() |
1085 | (+) HAL_UART_AbortTransmit() |
| 1086 | (+) HAL_UART_AbortTransmit_IT() |
1086 | (+) HAL_UART_AbortReceive() |
| 1087 | (+) HAL_UART_AbortReceive_IT() |
1087 | (+) HAL_UART_Abort_IT() |
| 1088 | 1088 | (+) HAL_UART_AbortTransmit_IT() |
|
| 1089 | (#) For Abort services based on interrupts (HAL_UART_Abortxxx_IT), a set of Abort Complete Callbacks are provided: |
1089 | (+) HAL_UART_AbortReceive_IT() |
| 1090 | (+) HAL_UART_AbortCpltCallback() |
1090 | |
| 1091 | (+) HAL_UART_AbortTransmitCpltCallback() |
1091 | (#) For Abort services based on interrupts (HAL_UART_Abortxxx_IT), a set of Abort Complete Callbacks are provided: |
| 1092 | (+) HAL_UART_AbortReceiveCpltCallback() |
1092 | (+) HAL_UART_AbortCpltCallback() |
| 1093 | 1093 | (+) HAL_UART_AbortTransmitCpltCallback() |
|
| 1094 | (#) A Rx Event Reception Callback (Rx event notification) is available for Non_Blocking modes of enhanced reception services: |
1094 | (+) HAL_UART_AbortReceiveCpltCallback() |
| 1095 | (+) HAL_UARTEx_RxEventCallback() |
1095 | |
| 1096 | 1096 | (#) A Rx Event Reception Callback (Rx event notification) is available for Non_Blocking modes of enhanced reception services: |
|
| 1097 | (#) In Non-Blocking mode transfers, possible errors are split into 2 categories. |
1097 | (+) HAL_UARTEx_RxEventCallback() |
| 1098 | Errors are handled as follows : |
1098 | |
| 1099 | (+) Error is considered as Recoverable and non blocking : Transfer could go till end, but error severity is |
1099 | (#) In Non-Blocking mode transfers, possible errors are split into 2 categories. |
| 1100 | to be evaluated by user : this concerns Frame Error, Parity Error or Noise Error in Interrupt mode reception . |
1100 | Errors are handled as follows : |
| 1101 | Received character is then retrieved and stored in Rx buffer, Error code is set to allow user to identify error type, |
1101 | (+) Error is considered as Recoverable and non blocking : Transfer could go till end, but error severity is |
| 1102 | and HAL_UART_ErrorCallback() user callback is executed. Transfer is kept ongoing on UART side. |
1102 | to be evaluated by user : this concerns Frame Error, Parity Error or Noise Error in Interrupt mode reception . |
| 1103 | If user wants to abort it, Abort services should be called by user. |
1103 | Received character is then retrieved and stored in Rx buffer, Error code is set to allow user to identify error type, |
| 1104 | (+) Error is considered as Blocking : Transfer could not be completed properly and is aborted. |
1104 | and HAL_UART_ErrorCallback() user callback is executed. Transfer is kept ongoing on UART side. |
| 1105 | This concerns Overrun Error In Interrupt mode reception and all errors in DMA mode. |
1105 | If user wants to abort it, Abort services should be called by user. |
| 1106 | Error code is set to allow user to identify error type, and HAL_UART_ErrorCallback() user callback is executed. |
1106 | (+) Error is considered as Blocking : Transfer could not be completed properly and is aborted. |
| 1107 | 1107 | This concerns Overrun Error In Interrupt mode reception and all errors in DMA mode. |
|
| 1108 | -@- In the Half duplex communication, it is forbidden to run the transmit |
1108 | Error code is set to allow user to identify error type, and HAL_UART_ErrorCallback() user callback is executed. |
| 1109 | and receive process in parallel, the UART state HAL_UART_STATE_BUSY_TX_RX can't be useful. |
1109 | |
| 1110 | 1110 | -@- In the Half duplex communication, it is forbidden to run the transmit |
|
| 1111 | @endverbatim |
1111 | and receive process in parallel, the UART state HAL_UART_STATE_BUSY_TX_RX can't be useful. |
| 1112 | * @{ |
1112 | |
| 1113 | */ |
1113 | @endverbatim |
| 1114 | 1114 | * @{ |
|
| 1115 | /** |
1115 | */ |
| 1116 | * @brief Sends an amount of data in blocking mode. |
1116 | |
| 1117 | * @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
1117 | /** |
| 1118 | * the sent data is handled as a set of u16. In this case, Size must indicate the number |
1118 | * @brief Sends an amount of data in blocking mode. |
| 1119 | * of u16 provided through pData. |
1119 | * @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
| 1120 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
1120 | * the sent data is handled as a set of u16. In this case, Size must indicate the number |
| 1121 | * the configuration information for the specified UART module. |
1121 | * of u16 provided through pData. |
| 1122 | * @param pData Pointer to data buffer (u8 or u16 data elements). |
1122 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
| 1123 | * @param Size Amount of data elements (u8 or u16) to be sent |
1123 | * the configuration information for the specified UART module. |
| 1124 | * @param Timeout Timeout duration |
1124 | * @param pData Pointer to data buffer (u8 or u16 data elements). |
| 1125 | * @retval HAL status |
1125 | * @param Size Amount of data elements (u8 or u16) to be sent |
| 1126 | */ |
1126 | * @param Timeout Timeout duration |
| 1127 | HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout) |
1127 | * @retval HAL status |
| 1128 | { |
1128 | */ |
| 1129 | uint8_t *pdata8bits; |
1129 | HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, const uint8_t *pData, uint16_t Size, uint32_t Timeout) |
| 1130 | uint16_t *pdata16bits; |
1130 | { |
| 1131 | uint32_t tickstart = 0U; |
1131 | const uint8_t *pdata8bits; |
| 1132 | 1132 | const uint16_t *pdata16bits; |
|
| 1133 | /* Check that a Tx process is not already ongoing */ |
1133 | uint32_t tickstart = 0U; |
| 1134 | if (huart->gState == HAL_UART_STATE_READY) |
1134 | |
| 1135 | { |
1135 | /* Check that a Tx process is not already ongoing */ |
| 1136 | if ((pData == NULL) || (Size == 0U)) |
1136 | if (huart->gState == HAL_UART_STATE_READY) |
| 1137 | { |
1137 | { |
| 1138 | return HAL_ERROR; |
1138 | if ((pData == NULL) || (Size == 0U)) |
| 1139 | } |
1139 | { |
| 1140 | 1140 | return HAL_ERROR; |
|
| 1141 | /* Process Locked */ |
1141 | } |
| 1142 | __HAL_LOCK(huart); |
1142 | |
| 1143 | 1143 | huart->ErrorCode = HAL_UART_ERROR_NONE; |
|
| 1144 | huart->ErrorCode = HAL_UART_ERROR_NONE; |
1144 | huart->gState = HAL_UART_STATE_BUSY_TX; |
| 1145 | huart->gState = HAL_UART_STATE_BUSY_TX; |
1145 | |
| 1146 | 1146 | /* Init tickstart for timeout management */ |
|
| 1147 | /* Init tickstart for timeout management */ |
1147 | tickstart = HAL_GetTick(); |
| 1148 | tickstart = HAL_GetTick(); |
1148 | |
| 1149 | 1149 | huart->TxXferSize = Size; |
|
| 1150 | huart->TxXferSize = Size; |
1150 | huart->TxXferCount = Size; |
| 1151 | huart->TxXferCount = Size; |
1151 | |
| 1152 | 1152 | /* In case of 9bits/No Parity transfer, pData needs to be handled as a uint16_t pointer */ |
|
| 1153 | /* In case of 9bits/No Parity transfer, pData needs to be handled as a uint16_t pointer */ |
1153 | if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE)) |
| 1154 | if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE)) |
1154 | { |
| 1155 | { |
1155 | pdata8bits = NULL; |
| 1156 | pdata8bits = NULL; |
1156 | pdata16bits = (const uint16_t *) pData; |
| 1157 | pdata16bits = (uint16_t *) pData; |
1157 | } |
| 1158 | } |
1158 | else |
| 1159 | else |
1159 | { |
| 1160 | { |
1160 | pdata8bits = pData; |
| 1161 | pdata8bits = pData; |
1161 | pdata16bits = NULL; |
| 1162 | pdata16bits = NULL; |
1162 | } |
| 1163 | } |
1163 | |
| 1164 | 1164 | while (huart->TxXferCount > 0U) |
|
| 1165 | /* Process Unlocked */ |
1165 | { |
| 1166 | __HAL_UNLOCK(huart); |
1166 | if (UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK) |
| 1167 | 1167 | { |
|
| 1168 | while (huart->TxXferCount > 0U) |
1168 | return HAL_TIMEOUT; |
| 1169 | { |
1169 | } |
| 1170 | if (UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK) |
1170 | if (pdata8bits == NULL) |
| 1171 | { |
1171 | { |
| 1172 | return HAL_TIMEOUT; |
1172 | huart->Instance->DR = (uint16_t)(*pdata16bits & 0x01FFU); |
| 1173 | } |
1173 | pdata16bits++; |
| 1174 | if (pdata8bits == NULL) |
1174 | } |
| 1175 | { |
1175 | else |
| 1176 | huart->Instance->DR = (uint16_t)(*pdata16bits & 0x01FFU); |
1176 | { |
| 1177 | pdata16bits++; |
1177 | huart->Instance->DR = (uint8_t)(*pdata8bits & 0xFFU); |
| 1178 | } |
1178 | pdata8bits++; |
| 1179 | else |
1179 | } |
| 1180 | { |
1180 | huart->TxXferCount--; |
| 1181 | huart->Instance->DR = (uint8_t)(*pdata8bits & 0xFFU); |
1181 | } |
| 1182 | pdata8bits++; |
1182 | |
| 1183 | } |
1183 | if (UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_TC, RESET, tickstart, Timeout) != HAL_OK) |
| 1184 | huart->TxXferCount--; |
1184 | { |
| 1185 | } |
1185 | return HAL_TIMEOUT; |
| 1186 | 1186 | } |
|
| 1187 | if (UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_TC, RESET, tickstart, Timeout) != HAL_OK) |
1187 | |
| 1188 | { |
1188 | /* At end of Tx process, restore huart->gState to Ready */ |
| 1189 | return HAL_TIMEOUT; |
1189 | huart->gState = HAL_UART_STATE_READY; |
| 1190 | } |
1190 | |
| 1191 | 1191 | return HAL_OK; |
|
| 1192 | /* At end of Tx process, restore huart->gState to Ready */ |
1192 | } |
| 1193 | huart->gState = HAL_UART_STATE_READY; |
1193 | else |
| 1194 | 1194 | { |
|
| 1195 | return HAL_OK; |
1195 | return HAL_BUSY; |
| 1196 | } |
1196 | } |
| 1197 | else |
1197 | } |
| 1198 | { |
1198 | |
| 1199 | return HAL_BUSY; |
1199 | /** |
| 1200 | } |
1200 | * @brief Receives an amount of data in blocking mode. |
| 1201 | } |
1201 | * @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
| 1202 | 1202 | * the received data is handled as a set of u16. In this case, Size must indicate the number |
|
| 1203 | /** |
1203 | * of u16 available through pData. |
| 1204 | * @brief Receives an amount of data in blocking mode. |
1204 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
| 1205 | * @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
1205 | * the configuration information for the specified UART module. |
| 1206 | * the received data is handled as a set of u16. In this case, Size must indicate the number |
1206 | * @param pData Pointer to data buffer (u8 or u16 data elements). |
| 1207 | * of u16 available through pData. |
1207 | * @param Size Amount of data elements (u8 or u16) to be received. |
| 1208 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
1208 | * @param Timeout Timeout duration |
| 1209 | * the configuration information for the specified UART module. |
1209 | * @retval HAL status |
| 1210 | * @param pData Pointer to data buffer (u8 or u16 data elements). |
1210 | */ |
| 1211 | * @param Size Amount of data elements (u8 or u16) to be received. |
1211 | HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout) |
| 1212 | * @param Timeout Timeout duration |
1212 | { |
| 1213 | * @retval HAL status |
1213 | uint8_t *pdata8bits; |
| 1214 | */ |
1214 | uint16_t *pdata16bits; |
| 1215 | HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout) |
1215 | uint32_t tickstart = 0U; |
| 1216 | { |
1216 | |
| 1217 | uint8_t *pdata8bits; |
1217 | /* Check that a Rx process is not already ongoing */ |
| 1218 | uint16_t *pdata16bits; |
1218 | if (huart->RxState == HAL_UART_STATE_READY) |
| 1219 | uint32_t tickstart = 0U; |
1219 | { |
| 1220 | 1220 | if ((pData == NULL) || (Size == 0U)) |
|
| 1221 | /* Check that a Rx process is not already ongoing */ |
1221 | { |
| 1222 | if (huart->RxState == HAL_UART_STATE_READY) |
1222 | return HAL_ERROR; |
| 1223 | { |
1223 | } |
| 1224 | if ((pData == NULL) || (Size == 0U)) |
1224 | |
| 1225 | { |
1225 | huart->ErrorCode = HAL_UART_ERROR_NONE; |
| 1226 | return HAL_ERROR; |
1226 | huart->RxState = HAL_UART_STATE_BUSY_RX; |
| 1227 | } |
1227 | huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
| 1228 | 1228 | ||
| 1229 | /* Process Locked */ |
1229 | /* Init tickstart for timeout management */ |
| 1230 | __HAL_LOCK(huart); |
1230 | tickstart = HAL_GetTick(); |
| 1231 | 1231 | ||
| 1232 | huart->ErrorCode = HAL_UART_ERROR_NONE; |
1232 | huart->RxXferSize = Size; |
| 1233 | huart->RxState = HAL_UART_STATE_BUSY_RX; |
1233 | huart->RxXferCount = Size; |
| 1234 | huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
1234 | |
| 1235 | 1235 | /* In case of 9bits/No Parity transfer, pRxData needs to be handled as a uint16_t pointer */ |
|
| 1236 | /* Init tickstart for timeout management */ |
1236 | if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE)) |
| 1237 | tickstart = HAL_GetTick(); |
1237 | { |
| 1238 | 1238 | pdata8bits = NULL; |
|
| 1239 | huart->RxXferSize = Size; |
1239 | pdata16bits = (uint16_t *) pData; |
| 1240 | huart->RxXferCount = Size; |
1240 | } |
| 1241 | 1241 | else |
|
| 1242 | /* In case of 9bits/No Parity transfer, pRxData needs to be handled as a uint16_t pointer */ |
1242 | { |
| 1243 | if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE)) |
1243 | pdata8bits = pData; |
| 1244 | { |
1244 | pdata16bits = NULL; |
| 1245 | pdata8bits = NULL; |
1245 | } |
| 1246 | pdata16bits = (uint16_t *) pData; |
1246 | |
| 1247 | } |
1247 | /* Check the remain data to be received */ |
| 1248 | else |
1248 | while (huart->RxXferCount > 0U) |
| 1249 | { |
1249 | { |
| 1250 | pdata8bits = pData; |
1250 | if (UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK) |
| 1251 | pdata16bits = NULL; |
1251 | { |
| 1252 | } |
1252 | return HAL_TIMEOUT; |
| 1253 | 1253 | } |
|
| 1254 | /* Process Unlocked */ |
1254 | if (pdata8bits == NULL) |
| 1255 | __HAL_UNLOCK(huart); |
1255 | { |
| 1256 | 1256 | *pdata16bits = (uint16_t)(huart->Instance->DR & 0x01FF); |
|
| 1257 | /* Check the remain data to be received */ |
1257 | pdata16bits++; |
| 1258 | while (huart->RxXferCount > 0U) |
1258 | } |
| 1259 | { |
1259 | else |
| 1260 | if (UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK) |
1260 | { |
| 1261 | { |
1261 | if ((huart->Init.WordLength == UART_WORDLENGTH_9B) || ((huart->Init.WordLength == UART_WORDLENGTH_8B) && (huart->Init.Parity == UART_PARITY_NONE))) |
| 1262 | return HAL_TIMEOUT; |
1262 | { |
| 1263 | } |
1263 | *pdata8bits = (uint8_t)(huart->Instance->DR & (uint8_t)0x00FF); |
| 1264 | if (pdata8bits == NULL) |
1264 | } |
| 1265 | { |
1265 | else |
| 1266 | *pdata16bits = (uint16_t)(huart->Instance->DR & 0x01FF); |
1266 | { |
| 1267 | pdata16bits++; |
1267 | *pdata8bits = (uint8_t)(huart->Instance->DR & (uint8_t)0x007F); |
| 1268 | } |
1268 | } |
| 1269 | else |
1269 | pdata8bits++; |
| 1270 | { |
1270 | } |
| 1271 | if ((huart->Init.WordLength == UART_WORDLENGTH_9B) || ((huart->Init.WordLength == UART_WORDLENGTH_8B) && (huart->Init.Parity == UART_PARITY_NONE))) |
1271 | huart->RxXferCount--; |
| 1272 | { |
1272 | } |
| 1273 | *pdata8bits = (uint8_t)(huart->Instance->DR & (uint8_t)0x00FF); |
1273 | |
| 1274 | } |
1274 | /* At end of Rx process, restore huart->RxState to Ready */ |
| 1275 | else |
1275 | huart->RxState = HAL_UART_STATE_READY; |
| 1276 | { |
1276 | |
| 1277 | *pdata8bits = (uint8_t)(huart->Instance->DR & (uint8_t)0x007F); |
1277 | return HAL_OK; |
| 1278 | } |
1278 | } |
| 1279 | pdata8bits++; |
1279 | else |
| 1280 | } |
1280 | { |
| 1281 | huart->RxXferCount--; |
1281 | return HAL_BUSY; |
| 1282 | } |
1282 | } |
| 1283 | 1283 | } |
|
| 1284 | /* At end of Rx process, restore huart->RxState to Ready */ |
1284 | |
| 1285 | huart->RxState = HAL_UART_STATE_READY; |
1285 | /** |
| 1286 | 1286 | * @brief Sends an amount of data in non blocking mode. |
|
| 1287 | return HAL_OK; |
1287 | * @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
| 1288 | } |
1288 | * the sent data is handled as a set of u16. In this case, Size must indicate the number |
| 1289 | else |
1289 | * of u16 provided through pData. |
| 1290 | { |
1290 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
| 1291 | return HAL_BUSY; |
1291 | * the configuration information for the specified UART module. |
| 1292 | } |
1292 | * @param pData Pointer to data buffer (u8 or u16 data elements). |
| 1293 | } |
1293 | * @param Size Amount of data elements (u8 or u16) to be sent |
| 1294 | 1294 | * @retval HAL status |
|
| 1295 | /** |
1295 | */ |
| 1296 | * @brief Sends an amount of data in non blocking mode. |
1296 | HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, const uint8_t *pData, uint16_t Size) |
| 1297 | * @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
1297 | { |
| 1298 | * the sent data is handled as a set of u16. In this case, Size must indicate the number |
1298 | /* Check that a Tx process is not already ongoing */ |
| 1299 | * of u16 provided through pData. |
1299 | if (huart->gState == HAL_UART_STATE_READY) |
| 1300 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
1300 | { |
| 1301 | * the configuration information for the specified UART module. |
1301 | if ((pData == NULL) || (Size == 0U)) |
| 1302 | * @param pData Pointer to data buffer (u8 or u16 data elements). |
1302 | { |
| 1303 | * @param Size Amount of data elements (u8 or u16) to be sent |
1303 | return HAL_ERROR; |
| 1304 | * @retval HAL status |
1304 | } |
| 1305 | */ |
1305 | |
| 1306 | HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size) |
1306 | huart->pTxBuffPtr = pData; |
| 1307 | { |
1307 | huart->TxXferSize = Size; |
| 1308 | /* Check that a Tx process is not already ongoing */ |
1308 | huart->TxXferCount = Size; |
| 1309 | if (huart->gState == HAL_UART_STATE_READY) |
1309 | |
| 1310 | { |
1310 | huart->ErrorCode = HAL_UART_ERROR_NONE; |
| 1311 | if ((pData == NULL) || (Size == 0U)) |
1311 | huart->gState = HAL_UART_STATE_BUSY_TX; |
| 1312 | { |
1312 | |
| 1313 | return HAL_ERROR; |
1313 | /* Enable the UART Transmit data register empty Interrupt */ |
| 1314 | } |
1314 | __HAL_UART_ENABLE_IT(huart, UART_IT_TXE); |
| 1315 | 1315 | ||
| 1316 | /* Process Locked */ |
1316 | return HAL_OK; |
| 1317 | __HAL_LOCK(huart); |
1317 | } |
| 1318 | 1318 | else |
|
| 1319 | huart->pTxBuffPtr = pData; |
1319 | { |
| 1320 | huart->TxXferSize = Size; |
1320 | return HAL_BUSY; |
| 1321 | huart->TxXferCount = Size; |
1321 | } |
| 1322 | 1322 | } |
|
| 1323 | huart->ErrorCode = HAL_UART_ERROR_NONE; |
1323 | |
| 1324 | huart->gState = HAL_UART_STATE_BUSY_TX; |
1324 | /** |
| 1325 | 1325 | * @brief Receives an amount of data in non blocking mode. |
|
| 1326 | /* Process Unlocked */ |
1326 | * @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
| 1327 | __HAL_UNLOCK(huart); |
1327 | * the received data is handled as a set of u16. In this case, Size must indicate the number |
| 1328 | 1328 | * of u16 available through pData. |
|
| 1329 | /* Enable the UART Transmit data register empty Interrupt */ |
1329 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
| 1330 | __HAL_UART_ENABLE_IT(huart, UART_IT_TXE); |
1330 | * the configuration information for the specified UART module. |
| 1331 | 1331 | * @param pData Pointer to data buffer (u8 or u16 data elements). |
|
| 1332 | return HAL_OK; |
1332 | * @param Size Amount of data elements (u8 or u16) to be received. |
| 1333 | } |
1333 | * @retval HAL status |
| 1334 | else |
1334 | */ |
| 1335 | { |
1335 | HAL_StatusTypeDef HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size) |
| 1336 | return HAL_BUSY; |
1336 | { |
| 1337 | } |
1337 | /* Check that a Rx process is not already ongoing */ |
| 1338 | } |
1338 | if (huart->RxState == HAL_UART_STATE_READY) |
| 1339 | 1339 | { |
|
| 1340 | /** |
1340 | if ((pData == NULL) || (Size == 0U)) |
| 1341 | * @brief Receives an amount of data in non blocking mode. |
1341 | { |
| 1342 | * @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
1342 | return HAL_ERROR; |
| 1343 | * the received data is handled as a set of u16. In this case, Size must indicate the number |
1343 | } |
| 1344 | * of u16 available through pData. |
1344 | |
| 1345 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
1345 | /* Set Reception type to Standard reception */ |
| 1346 | * the configuration information for the specified UART module. |
1346 | huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
| 1347 | * @param pData Pointer to data buffer (u8 or u16 data elements). |
1347 | |
| 1348 | * @param Size Amount of data elements (u8 or u16) to be received. |
1348 | return (UART_Start_Receive_IT(huart, pData, Size)); |
| 1349 | * @retval HAL status |
1349 | } |
| 1350 | */ |
1350 | else |
| 1351 | HAL_StatusTypeDef HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size) |
1351 | { |
| 1352 | { |
1352 | return HAL_BUSY; |
| 1353 | /* Check that a Rx process is not already ongoing */ |
1353 | } |
| 1354 | if (huart->RxState == HAL_UART_STATE_READY) |
1354 | } |
| 1355 | { |
1355 | |
| 1356 | if ((pData == NULL) || (Size == 0U)) |
1356 | /** |
| 1357 | { |
1357 | * @brief Sends an amount of data in DMA mode. |
| 1358 | return HAL_ERROR; |
1358 | * @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
| 1359 | } |
1359 | * the sent data is handled as a set of u16. In this case, Size must indicate the number |
| 1360 | 1360 | * of u16 provided through pData. |
|
| 1361 | /* Process Locked */ |
1361 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
| 1362 | __HAL_LOCK(huart); |
1362 | * the configuration information for the specified UART module. |
| 1363 | 1363 | * @param pData Pointer to data buffer (u8 or u16 data elements). |
|
| 1364 | /* Set Reception type to Standard reception */ |
1364 | * @param Size Amount of data elements (u8 or u16) to be sent |
| 1365 | huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
1365 | * @retval HAL status |
| 1366 | 1366 | */ |
|
| 1367 | return(UART_Start_Receive_IT(huart, pData, Size)); |
1367 | HAL_StatusTypeDef HAL_UART_Transmit_DMA(UART_HandleTypeDef *huart, const uint8_t *pData, uint16_t Size) |
| 1368 | } |
1368 | { |
| 1369 | else |
1369 | const uint32_t *tmp; |
| 1370 | { |
1370 | |
| 1371 | return HAL_BUSY; |
1371 | /* Check that a Tx process is not already ongoing */ |
| 1372 | } |
1372 | if (huart->gState == HAL_UART_STATE_READY) |
| 1373 | } |
1373 | { |
| 1374 | 1374 | if ((pData == NULL) || (Size == 0U)) |
|
| 1375 | /** |
1375 | { |
| 1376 | * @brief Sends an amount of data in DMA mode. |
1376 | return HAL_ERROR; |
| 1377 | * @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
1377 | } |
| 1378 | * the sent data is handled as a set of u16. In this case, Size must indicate the number |
1378 | |
| 1379 | * of u16 provided through pData. |
1379 | huart->pTxBuffPtr = pData; |
| 1380 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
1380 | huart->TxXferSize = Size; |
| 1381 | * the configuration information for the specified UART module. |
1381 | huart->TxXferCount = Size; |
| 1382 | * @param pData Pointer to data buffer (u8 or u16 data elements). |
1382 | |
| 1383 | * @param Size Amount of data elements (u8 or u16) to be sent |
1383 | huart->ErrorCode = HAL_UART_ERROR_NONE; |
| 1384 | * @retval HAL status |
1384 | huart->gState = HAL_UART_STATE_BUSY_TX; |
| 1385 | */ |
1385 | |
| 1386 | HAL_StatusTypeDef HAL_UART_Transmit_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size) |
1386 | /* Set the UART DMA transfer complete callback */ |
| 1387 | { |
1387 | huart->hdmatx->XferCpltCallback = UART_DMATransmitCplt; |
| 1388 | uint32_t *tmp; |
1388 | |
| 1389 | 1389 | /* Set the UART DMA Half transfer complete callback */ |
|
| 1390 | /* Check that a Tx process is not already ongoing */ |
1390 | huart->hdmatx->XferHalfCpltCallback = UART_DMATxHalfCplt; |
| 1391 | if (huart->gState == HAL_UART_STATE_READY) |
1391 | |
| 1392 | { |
1392 | /* Set the DMA error callback */ |
| 1393 | if ((pData == NULL) || (Size == 0U)) |
1393 | huart->hdmatx->XferErrorCallback = UART_DMAError; |
| 1394 | { |
1394 | |
| 1395 | return HAL_ERROR; |
1395 | /* Set the DMA abort callback */ |
| 1396 | } |
1396 | huart->hdmatx->XferAbortCallback = NULL; |
| 1397 | 1397 | ||
| 1398 | /* Process Locked */ |
1398 | /* Enable the UART transmit DMA channel */ |
| 1399 | __HAL_LOCK(huart); |
1399 | tmp = (const uint32_t *)&pData; |
| 1400 | 1400 | HAL_DMA_Start_IT(huart->hdmatx, *(const uint32_t *)tmp, (uint32_t)&huart->Instance->DR, Size); |
|
| 1401 | huart->pTxBuffPtr = pData; |
1401 | |
| 1402 | huart->TxXferSize = Size; |
1402 | /* Clear the TC flag in the SR register by writing 0 to it */ |
| 1403 | huart->TxXferCount = Size; |
1403 | __HAL_UART_CLEAR_FLAG(huart, UART_FLAG_TC); |
| 1404 | 1404 | ||
| 1405 | huart->ErrorCode = HAL_UART_ERROR_NONE; |
1405 | /* Enable the DMA transfer for transmit request by setting the DMAT bit |
| 1406 | huart->gState = HAL_UART_STATE_BUSY_TX; |
1406 | in the UART CR3 register */ |
| 1407 | 1407 | ATOMIC_SET_BIT(huart->Instance->CR3, USART_CR3_DMAT); |
|
| 1408 | /* Set the UART DMA transfer complete callback */ |
1408 | |
| 1409 | huart->hdmatx->XferCpltCallback = UART_DMATransmitCplt; |
1409 | return HAL_OK; |
| 1410 | 1410 | } |
|
| 1411 | /* Set the UART DMA Half transfer complete callback */ |
1411 | else |
| 1412 | huart->hdmatx->XferHalfCpltCallback = UART_DMATxHalfCplt; |
1412 | { |
| 1413 | 1413 | return HAL_BUSY; |
|
| 1414 | /* Set the DMA error callback */ |
1414 | } |
| 1415 | huart->hdmatx->XferErrorCallback = UART_DMAError; |
1415 | } |
| 1416 | 1416 | ||
| 1417 | /* Set the DMA abort callback */ |
1417 | /** |
| 1418 | huart->hdmatx->XferAbortCallback = NULL; |
1418 | * @brief Receives an amount of data in DMA mode. |
| 1419 | 1419 | * @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
|
| 1420 | /* Enable the UART transmit DMA channel */ |
1420 | * the received data is handled as a set of u16. In this case, Size must indicate the number |
| 1421 | tmp = (uint32_t *)&pData; |
1421 | * of u16 available through pData. |
| 1422 | HAL_DMA_Start_IT(huart->hdmatx, *(uint32_t *)tmp, (uint32_t)&huart->Instance->DR, Size); |
1422 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
| 1423 | 1423 | * the configuration information for the specified UART module. |
|
| 1424 | /* Clear the TC flag in the SR register by writing 0 to it */ |
1424 | * @param pData Pointer to data buffer (u8 or u16 data elements). |
| 1425 | __HAL_UART_CLEAR_FLAG(huart, UART_FLAG_TC); |
1425 | * @param Size Amount of data elements (u8 or u16) to be received. |
| 1426 | 1426 | * @note When the UART parity is enabled (PCE = 1) the received data contains the parity bit. |
|
| 1427 | /* Process Unlocked */ |
1427 | * @retval HAL status |
| 1428 | __HAL_UNLOCK(huart); |
1428 | */ |
| 1429 | 1429 | HAL_StatusTypeDef HAL_UART_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size) |
|
| 1430 | /* Enable the DMA transfer for transmit request by setting the DMAT bit |
1430 | { |
| 1431 | in the UART CR3 register */ |
1431 | /* Check that a Rx process is not already ongoing */ |
| 1432 | SET_BIT(huart->Instance->CR3, USART_CR3_DMAT); |
1432 | if (huart->RxState == HAL_UART_STATE_READY) |
| 1433 | 1433 | { |
|
| 1434 | return HAL_OK; |
1434 | if ((pData == NULL) || (Size == 0U)) |
| 1435 | } |
1435 | { |
| 1436 | else |
1436 | return HAL_ERROR; |
| 1437 | { |
1437 | } |
| 1438 | return HAL_BUSY; |
1438 | |
| 1439 | } |
1439 | /* Set Reception type to Standard reception */ |
| 1440 | } |
1440 | huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
| 1441 | 1441 | ||
| 1442 | /** |
1442 | return (UART_Start_Receive_DMA(huart, pData, Size)); |
| 1443 | * @brief Receives an amount of data in DMA mode. |
1443 | } |
| 1444 | * @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01), |
1444 | else |
| 1445 | * the received data is handled as a set of u16. In this case, Size must indicate the number |
1445 | { |
| 1446 | * of u16 available through pData. |
1446 | return HAL_BUSY; |
| 1447 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
1447 | } |
| 1448 | * the configuration information for the specified UART module. |
1448 | } |
| 1449 | * @param pData Pointer to data buffer (u8 or u16 data elements). |
1449 | |
| 1450 | * @param Size Amount of data elements (u8 or u16) to be received. |
1450 | /** |
| 1451 | * @note When the UART parity is enabled (PCE = 1) the received data contains the parity bit. |
1451 | * @brief Pauses the DMA Transfer. |
| 1452 | * @retval HAL status |
1452 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
| 1453 | */ |
1453 | * the configuration information for the specified UART module. |
| 1454 | HAL_StatusTypeDef HAL_UART_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size) |
1454 | * @retval HAL status |
| 1455 | { |
1455 | */ |
| 1456 | /* Check that a Rx process is not already ongoing */ |
1456 | HAL_StatusTypeDef HAL_UART_DMAPause(UART_HandleTypeDef *huart) |
| 1457 | if (huart->RxState == HAL_UART_STATE_READY) |
1457 | { |
| 1458 | { |
1458 | uint32_t dmarequest = 0x00U; |
| 1459 | if ((pData == NULL) || (Size == 0U)) |
1459 | |
| 1460 | { |
1460 | dmarequest = HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAT); |
| 1461 | return HAL_ERROR; |
1461 | if ((huart->gState == HAL_UART_STATE_BUSY_TX) && dmarequest) |
| 1462 | } |
1462 | { |
| 1463 | 1463 | /* Disable the UART DMA Tx request */ |
|
| 1464 | /* Process Locked */ |
1464 | ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAT); |
| 1465 | __HAL_LOCK(huart); |
1465 | } |
| 1466 | 1466 | ||
| 1467 | /* Set Reception type to Standard reception */ |
1467 | dmarequest = HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR); |
| 1468 | huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
1468 | if ((huart->RxState == HAL_UART_STATE_BUSY_RX) && dmarequest) |
| 1469 | 1469 | { |
|
| 1470 | return(UART_Start_Receive_DMA(huart, pData, Size)); |
1470 | /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */ |
| 1471 | } |
1471 | ATOMIC_CLEAR_BIT(huart->Instance->CR1, USART_CR1_PEIE); |
| 1472 | else |
1472 | ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE); |
| 1473 | { |
1473 | |
| 1474 | return HAL_BUSY; |
1474 | /* Disable the UART DMA Rx request */ |
| 1475 | } |
1475 | ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR); |
| 1476 | } |
1476 | } |
| 1477 | 1477 | ||
| 1478 | /** |
1478 | return HAL_OK; |
| 1479 | * @brief Pauses the DMA Transfer. |
1479 | } |
| 1480 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
1480 | |
| 1481 | * the configuration information for the specified UART module. |
1481 | /** |
| 1482 | * @retval HAL status |
1482 | * @brief Resumes the DMA Transfer. |
| 1483 | */ |
1483 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
| 1484 | HAL_StatusTypeDef HAL_UART_DMAPause(UART_HandleTypeDef *huart) |
1484 | * the configuration information for the specified UART module. |
| 1485 | { |
1485 | * @retval HAL status |
| 1486 | uint32_t dmarequest = 0x00U; |
1486 | */ |
| 1487 | 1487 | HAL_StatusTypeDef HAL_UART_DMAResume(UART_HandleTypeDef *huart) |
|
| 1488 | /* Process Locked */ |
1488 | { |
| 1489 | __HAL_LOCK(huart); |
1489 | |
| 1490 | 1490 | if (huart->gState == HAL_UART_STATE_BUSY_TX) |
|
| 1491 | dmarequest = HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAT); |
1491 | { |
| 1492 | if ((huart->gState == HAL_UART_STATE_BUSY_TX) && dmarequest) |
1492 | /* Enable the UART DMA Tx request */ |
| 1493 | { |
1493 | ATOMIC_SET_BIT(huart->Instance->CR3, USART_CR3_DMAT); |
| 1494 | /* Disable the UART DMA Tx request */ |
1494 | } |
| 1495 | CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAT); |
1495 | |
| 1496 | } |
1496 | if (huart->RxState == HAL_UART_STATE_BUSY_RX) |
| 1497 | 1497 | { |
|
| 1498 | dmarequest = HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR); |
1498 | /* Clear the Overrun flag before resuming the Rx transfer*/ |
| 1499 | if ((huart->RxState == HAL_UART_STATE_BUSY_RX) && dmarequest) |
1499 | __HAL_UART_CLEAR_OREFLAG(huart); |
| 1500 | { |
1500 | |
| 1501 | /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */ |
1501 | /* Re-enable PE and ERR (Frame error, noise error, overrun error) interrupts */ |
| 1502 | CLEAR_BIT(huart->Instance->CR1, USART_CR1_PEIE); |
1502 | if (huart->Init.Parity != UART_PARITY_NONE) |
| 1503 | CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE); |
1503 | { |
| 1504 | 1504 | ATOMIC_SET_BIT(huart->Instance->CR1, USART_CR1_PEIE); |
|
| 1505 | /* Disable the UART DMA Rx request */ |
1505 | } |
| 1506 | CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR); |
1506 | ATOMIC_SET_BIT(huart->Instance->CR3, USART_CR3_EIE); |
| 1507 | } |
1507 | |
| 1508 | 1508 | /* Enable the UART DMA Rx request */ |
|
| 1509 | /* Process Unlocked */ |
1509 | ATOMIC_SET_BIT(huart->Instance->CR3, USART_CR3_DMAR); |
| 1510 | __HAL_UNLOCK(huart); |
1510 | } |
| 1511 | 1511 | ||
| 1512 | return HAL_OK; |
1512 | return HAL_OK; |
| 1513 | } |
1513 | } |
| 1514 | 1514 | ||
| 1515 | /** |
1515 | /** |
| 1516 | * @brief Resumes the DMA Transfer. |
1516 | * @brief Stops the DMA Transfer. |
| 1517 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
1517 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
| 1518 | * the configuration information for the specified UART module. |
1518 | * the configuration information for the specified UART module. |
| 1519 | * @retval HAL status |
1519 | * @retval HAL status |
| 1520 | */ |
1520 | */ |
| 1521 | HAL_StatusTypeDef HAL_UART_DMAResume(UART_HandleTypeDef *huart) |
1521 | HAL_StatusTypeDef HAL_UART_DMAStop(UART_HandleTypeDef *huart) |
| 1522 | { |
1522 | { |
| 1523 | /* Process Locked */ |
1523 | uint32_t dmarequest = 0x00U; |
| 1524 | __HAL_LOCK(huart); |
1524 | /* The Lock is not implemented on this API to allow the user application |
| 1525 | 1525 | to call the HAL UART API under callbacks HAL_UART_TxCpltCallback() / HAL_UART_RxCpltCallback(): |
|
| 1526 | if (huart->gState == HAL_UART_STATE_BUSY_TX) |
1526 | when calling HAL_DMA_Abort() API the DMA TX/RX Transfer complete interrupt is generated |
| 1527 | { |
1527 | and the correspond call back is executed HAL_UART_TxCpltCallback() / HAL_UART_RxCpltCallback() |
| 1528 | /* Enable the UART DMA Tx request */ |
1528 | */ |
| 1529 | SET_BIT(huart->Instance->CR3, USART_CR3_DMAT); |
1529 | |
| 1530 | } |
1530 | /* Stop UART DMA Tx request if ongoing */ |
| 1531 | 1531 | dmarequest = HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAT); |
|
| 1532 | if (huart->RxState == HAL_UART_STATE_BUSY_RX) |
1532 | if ((huart->gState == HAL_UART_STATE_BUSY_TX) && dmarequest) |
| 1533 | { |
1533 | { |
| 1534 | /* Clear the Overrun flag before resuming the Rx transfer*/ |
1534 | ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAT); |
| 1535 | __HAL_UART_CLEAR_OREFLAG(huart); |
1535 | |
| 1536 | 1536 | /* Abort the UART DMA Tx channel */ |
|
| 1537 | /* Re-enable PE and ERR (Frame error, noise error, overrun error) interrupts */ |
1537 | if (huart->hdmatx != NULL) |
| 1538 | SET_BIT(huart->Instance->CR1, USART_CR1_PEIE); |
1538 | { |
| 1539 | SET_BIT(huart->Instance->CR3, USART_CR3_EIE); |
1539 | HAL_DMA_Abort(huart->hdmatx); |
| 1540 | 1540 | } |
|
| 1541 | /* Enable the UART DMA Rx request */ |
1541 | UART_EndTxTransfer(huart); |
| 1542 | SET_BIT(huart->Instance->CR3, USART_CR3_DMAR); |
1542 | } |
| 1543 | } |
1543 | |
| 1544 | 1544 | /* Stop UART DMA Rx request if ongoing */ |
|
| 1545 | /* Process Unlocked */ |
1545 | dmarequest = HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR); |
| 1546 | __HAL_UNLOCK(huart); |
1546 | if ((huart->RxState == HAL_UART_STATE_BUSY_RX) && dmarequest) |
| 1547 | 1547 | { |
|
| 1548 | return HAL_OK; |
1548 | ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR); |
| 1549 | } |
1549 | |
| 1550 | 1550 | /* Abort the UART DMA Rx channel */ |
|
| 1551 | /** |
1551 | if (huart->hdmarx != NULL) |
| 1552 | * @brief Stops the DMA Transfer. |
1552 | { |
| 1553 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
1553 | HAL_DMA_Abort(huart->hdmarx); |
| 1554 | * the configuration information for the specified UART module. |
1554 | } |
| 1555 | * @retval HAL status |
1555 | UART_EndRxTransfer(huart); |
| 1556 | */ |
1556 | } |
| 1557 | HAL_StatusTypeDef HAL_UART_DMAStop(UART_HandleTypeDef *huart) |
1557 | |
| 1558 | { |
1558 | return HAL_OK; |
| 1559 | uint32_t dmarequest = 0x00U; |
1559 | } |
| 1560 | /* The Lock is not implemented on this API to allow the user application |
1560 | |
| 1561 | to call the HAL UART API under callbacks HAL_UART_TxCpltCallback() / HAL_UART_RxCpltCallback(): |
1561 | /** |
| 1562 | when calling HAL_DMA_Abort() API the DMA TX/RX Transfer complete interrupt is generated |
1562 | * @brief Receive an amount of data in blocking mode till either the expected number of data is received or an IDLE event occurs. |
| 1563 | and the correspond call back is executed HAL_UART_TxCpltCallback() / HAL_UART_RxCpltCallback() |
1563 | * @note HAL_OK is returned if reception is completed (expected number of data has been received) |
| 1564 | */ |
1564 | * or if reception is stopped after IDLE event (less than the expected number of data has been received) |
| 1565 | 1565 | * In this case, RxLen output parameter indicates number of data available in reception buffer. |
|
| 1566 | /* Stop UART DMA Tx request if ongoing */ |
1566 | * @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M = 01), |
| 1567 | dmarequest = HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAT); |
1567 | * the received data is handled as a set of uint16_t. In this case, Size must indicate the number |
| 1568 | if ((huart->gState == HAL_UART_STATE_BUSY_TX) && dmarequest) |
1568 | * of uint16_t available through pData. |
| 1569 | { |
1569 | * @param huart UART handle. |
| 1570 | CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAT); |
1570 | * @param pData Pointer to data buffer (uint8_t or uint16_t data elements). |
| 1571 | 1571 | * @param Size Amount of data elements (uint8_t or uint16_t) to be received. |
|
| 1572 | /* Abort the UART DMA Tx channel */ |
1572 | * @param RxLen Number of data elements finally received (could be lower than Size, in case reception ends on IDLE event) |
| 1573 | if (huart->hdmatx != NULL) |
1573 | * @param Timeout Timeout duration expressed in ms (covers the whole reception sequence). |
| 1574 | { |
1574 | * @retval HAL status |
| 1575 | HAL_DMA_Abort(huart->hdmatx); |
1575 | */ |
| 1576 | } |
1576 | HAL_StatusTypeDef HAL_UARTEx_ReceiveToIdle(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint16_t *RxLen, |
| 1577 | UART_EndTxTransfer(huart); |
1577 | uint32_t Timeout) |
| 1578 | } |
1578 | { |
| 1579 | 1579 | uint8_t *pdata8bits; |
|
| 1580 | /* Stop UART DMA Rx request if ongoing */ |
1580 | uint16_t *pdata16bits; |
| 1581 | dmarequest = HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR); |
1581 | uint32_t tickstart; |
| 1582 | if ((huart->RxState == HAL_UART_STATE_BUSY_RX) && dmarequest) |
1582 | |
| 1583 | { |
1583 | /* Check that a Rx process is not already ongoing */ |
| 1584 | CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR); |
1584 | if (huart->RxState == HAL_UART_STATE_READY) |
| 1585 | 1585 | { |
|
| 1586 | /* Abort the UART DMA Rx channel */ |
1586 | if ((pData == NULL) || (Size == 0U)) |
| 1587 | if (huart->hdmarx != NULL) |
1587 | { |
| 1588 | { |
1588 | return HAL_ERROR; |
| 1589 | HAL_DMA_Abort(huart->hdmarx); |
1589 | } |
| 1590 | } |
1590 | |
| 1591 | UART_EndRxTransfer(huart); |
1591 | huart->ErrorCode = HAL_UART_ERROR_NONE; |
| 1592 | } |
1592 | huart->RxState = HAL_UART_STATE_BUSY_RX; |
| 1593 | 1593 | huart->ReceptionType = HAL_UART_RECEPTION_TOIDLE; |
|
| 1594 | return HAL_OK; |
1594 | huart->RxEventType = HAL_UART_RXEVENT_TC; |
| 1595 | } |
1595 | |
| 1596 | 1596 | /* Init tickstart for timeout management */ |
|
| 1597 | /** |
1597 | tickstart = HAL_GetTick(); |
| 1598 | * @brief Receive an amount of data in blocking mode till either the expected number of data is received or an IDLE event occurs. |
1598 | |
| 1599 | * @note HAL_OK is returned if reception is completed (expected number of data has been received) |
1599 | huart->RxXferSize = Size; |
| 1600 | * or if reception is stopped after IDLE event (less than the expected number of data has been received) |
1600 | huart->RxXferCount = Size; |
| 1601 | * In this case, RxLen output parameter indicates number of data available in reception buffer. |
1601 | |
| 1602 | * @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M = 01), |
1602 | /* In case of 9bits/No Parity transfer, pRxData needs to be handled as a uint16_t pointer */ |
| 1603 | * the received data is handled as a set of uint16_t. In this case, Size must indicate the number |
1603 | if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE)) |
| 1604 | * of uint16_t available through pData. |
1604 | { |
| 1605 | * @param huart UART handle. |
1605 | pdata8bits = NULL; |
| 1606 | * @param pData Pointer to data buffer (uint8_t or uint16_t data elements). |
1606 | pdata16bits = (uint16_t *) pData; |
| 1607 | * @param Size Amount of data elements (uint8_t or uint16_t) to be received. |
1607 | } |
| 1608 | * @param RxLen Number of data elements finally received (could be lower than Size, in case reception ends on IDLE event) |
1608 | else |
| 1609 | * @param Timeout Timeout duration expressed in ms (covers the whole reception sequence). |
1609 | { |
| 1610 | * @retval HAL status |
1610 | pdata8bits = pData; |
| 1611 | */ |
1611 | pdata16bits = NULL; |
| 1612 | HAL_StatusTypeDef HAL_UARTEx_ReceiveToIdle(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint16_t *RxLen, uint32_t Timeout) |
1612 | } |
| 1613 | { |
1613 | |
| 1614 | uint8_t *pdata8bits; |
1614 | /* Initialize output number of received elements */ |
| 1615 | uint16_t *pdata16bits; |
1615 | *RxLen = 0U; |
| 1616 | uint32_t tickstart; |
1616 | |
| 1617 | 1617 | /* as long as data have to be received */ |
|
| 1618 | /* Check that a Rx process is not already ongoing */ |
1618 | while (huart->RxXferCount > 0U) |
| 1619 | if (huart->RxState == HAL_UART_STATE_READY) |
1619 | { |
| 1620 | { |
1620 | /* Check if IDLE flag is set */ |
| 1621 | if ((pData == NULL) || (Size == 0U)) |
1621 | if (__HAL_UART_GET_FLAG(huart, UART_FLAG_IDLE)) |
| 1622 | { |
1622 | { |
| 1623 | return HAL_ERROR; |
1623 | /* Clear IDLE flag in ISR */ |
| 1624 | } |
1624 | __HAL_UART_CLEAR_IDLEFLAG(huart); |
| 1625 | 1625 | ||
| 1626 | __HAL_LOCK(huart); |
1626 | /* If Set, but no data ever received, clear flag without exiting loop */ |
| 1627 | 1627 | /* If Set, and data has already been received, this means Idle Event is valid : End reception */ |
|
| 1628 | huart->ErrorCode = HAL_UART_ERROR_NONE; |
1628 | if (*RxLen > 0U) |
| 1629 | huart->RxState = HAL_UART_STATE_BUSY_RX; |
1629 | { |
| 1630 | huart->ReceptionType = HAL_UART_RECEPTION_TOIDLE; |
1630 | huart->RxEventType = HAL_UART_RXEVENT_IDLE; |
| 1631 | 1631 | huart->RxState = HAL_UART_STATE_READY; |
|
| 1632 | /* Init tickstart for timeout management */ |
1632 | |
| 1633 | tickstart = HAL_GetTick(); |
1633 | return HAL_OK; |
| 1634 | 1634 | } |
|
| 1635 | huart->RxXferSize = Size; |
1635 | } |
| 1636 | huart->RxXferCount = Size; |
1636 | |
| 1637 | 1637 | /* Check if RXNE flag is set */ |
|
| 1638 | /* In case of 9bits/No Parity transfer, pRxData needs to be handled as a uint16_t pointer */ |
1638 | if (__HAL_UART_GET_FLAG(huart, UART_FLAG_RXNE)) |
| 1639 | if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE)) |
1639 | { |
| 1640 | { |
1640 | if (pdata8bits == NULL) |
| 1641 | pdata8bits = NULL; |
1641 | { |
| 1642 | pdata16bits = (uint16_t *) pData; |
1642 | *pdata16bits = (uint16_t)(huart->Instance->DR & (uint16_t)0x01FF); |
| 1643 | } |
1643 | pdata16bits++; |
| 1644 | else |
1644 | } |
| 1645 | { |
1645 | else |
| 1646 | pdata8bits = pData; |
1646 | { |
| 1647 | pdata16bits = NULL; |
1647 | if ((huart->Init.WordLength == UART_WORDLENGTH_9B) || ((huart->Init.WordLength == UART_WORDLENGTH_8B) && (huart->Init.Parity == UART_PARITY_NONE))) |
| 1648 | } |
1648 | { |
| 1649 | 1649 | *pdata8bits = (uint8_t)(huart->Instance->DR & (uint8_t)0x00FF); |
|
| 1650 | __HAL_UNLOCK(huart); |
1650 | } |
| 1651 | 1651 | else |
|
| 1652 | /* Initialize output number of received elements */ |
1652 | { |
| 1653 | *RxLen = 0U; |
1653 | *pdata8bits = (uint8_t)(huart->Instance->DR & (uint8_t)0x007F); |
| 1654 | 1654 | } |
|
| 1655 | /* as long as data have to be received */ |
1655 | |
| 1656 | while (huart->RxXferCount > 0U) |
1656 | pdata8bits++; |
| 1657 | { |
1657 | } |
| 1658 | /* Check if IDLE flag is set */ |
1658 | /* Increment number of received elements */ |
| 1659 | if (__HAL_UART_GET_FLAG(huart, UART_FLAG_IDLE)) |
1659 | *RxLen += 1U; |
| 1660 | { |
1660 | huart->RxXferCount--; |
| 1661 | /* Clear IDLE flag in ISR */ |
1661 | } |
| 1662 | __HAL_UART_CLEAR_IDLEFLAG(huart); |
1662 | |
| 1663 | 1663 | /* Check for the Timeout */ |
|
| 1664 | /* If Set, but no data ever received, clear flag without exiting loop */ |
1664 | if (Timeout != HAL_MAX_DELAY) |
| 1665 | /* If Set, and data has already been received, this means Idle Event is valid : End reception */ |
1665 | { |
| 1666 | if (*RxLen > 0U) |
1666 | if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U)) |
| 1667 | { |
1667 | { |
| 1668 | huart->RxState = HAL_UART_STATE_READY; |
1668 | huart->RxState = HAL_UART_STATE_READY; |
| 1669 | 1669 | ||
| 1670 | return HAL_OK; |
1670 | return HAL_TIMEOUT; |
| 1671 | } |
1671 | } |
| 1672 | } |
1672 | } |
| 1673 | 1673 | } |
|
| 1674 | /* Check if RXNE flag is set */ |
1674 | |
| 1675 | if (__HAL_UART_GET_FLAG(huart, UART_FLAG_RXNE)) |
1675 | /* Set number of received elements in output parameter : RxLen */ |
| 1676 | { |
1676 | *RxLen = huart->RxXferSize - huart->RxXferCount; |
| 1677 | if (pdata8bits == NULL) |
1677 | /* At end of Rx process, restore huart->RxState to Ready */ |
| 1678 | { |
1678 | huart->RxState = HAL_UART_STATE_READY; |
| 1679 | *pdata16bits = (uint16_t)(huart->Instance->DR & (uint16_t)0x01FF); |
1679 | |
| 1680 | pdata16bits++; |
1680 | return HAL_OK; |
| 1681 | } |
1681 | } |
| 1682 | else |
1682 | else |
| 1683 | { |
1683 | { |
| 1684 | if ((huart->Init.WordLength == UART_WORDLENGTH_9B) || ((huart->Init.WordLength == UART_WORDLENGTH_8B) && (huart->Init.Parity == UART_PARITY_NONE))) |
1684 | return HAL_BUSY; |
| 1685 | { |
1685 | } |
| 1686 | *pdata8bits = (uint8_t)(huart->Instance->DR & (uint8_t)0x00FF); |
1686 | } |
| 1687 | } |
1687 | |
| 1688 | else |
1688 | /** |
| 1689 | { |
1689 | * @brief Receive an amount of data in interrupt mode till either the expected number of data is received or an IDLE event occurs. |
| 1690 | *pdata8bits = (uint8_t)(huart->Instance->DR & (uint8_t)0x007F); |
1690 | * @note Reception is initiated by this function call. Further progress of reception is achieved thanks |
| 1691 | } |
1691 | * to UART interrupts raised by RXNE and IDLE events. Callback is called at end of reception indicating |
| 1692 | 1692 | * number of received data elements. |
|
| 1693 | pdata8bits++; |
1693 | * @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M = 01), |
| 1694 | } |
1694 | * the received data is handled as a set of uint16_t. In this case, Size must indicate the number |
| 1695 | /* Increment number of received elements */ |
1695 | * of uint16_t available through pData. |
| 1696 | *RxLen += 1U; |
1696 | * @param huart UART handle. |
| 1697 | huart->RxXferCount--; |
1697 | * @param pData Pointer to data buffer (uint8_t or uint16_t data elements). |
| 1698 | } |
1698 | * @param Size Amount of data elements (uint8_t or uint16_t) to be received. |
| 1699 | 1699 | * @retval HAL status |
|
| 1700 | /* Check for the Timeout */ |
1700 | */ |
| 1701 | if (Timeout != HAL_MAX_DELAY) |
1701 | HAL_StatusTypeDef HAL_UARTEx_ReceiveToIdle_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size) |
| 1702 | { |
1702 | { |
| 1703 | if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U)) |
1703 | HAL_StatusTypeDef status; |
| 1704 | { |
1704 | |
| 1705 | huart->RxState = HAL_UART_STATE_READY; |
1705 | /* Check that a Rx process is not already ongoing */ |
| 1706 | 1706 | if (huart->RxState == HAL_UART_STATE_READY) |
|
| 1707 | return HAL_TIMEOUT; |
1707 | { |
| 1708 | } |
1708 | if ((pData == NULL) || (Size == 0U)) |
| 1709 | } |
1709 | { |
| 1710 | } |
1710 | return HAL_ERROR; |
| 1711 | 1711 | } |
|
| 1712 | /* Set number of received elements in output parameter : RxLen */ |
1712 | |
| 1713 | *RxLen = huart->RxXferSize - huart->RxXferCount; |
1713 | /* Set Reception type to reception till IDLE Event*/ |
| 1714 | /* At end of Rx process, restore huart->RxState to Ready */ |
1714 | huart->ReceptionType = HAL_UART_RECEPTION_TOIDLE; |
| 1715 | huart->RxState = HAL_UART_STATE_READY; |
1715 | huart->RxEventType = HAL_UART_RXEVENT_TC; |
| 1716 | 1716 | ||
| 1717 | return HAL_OK; |
1717 | status = UART_Start_Receive_IT(huart, pData, Size); |
| 1718 | } |
1718 | |
| 1719 | else |
1719 | /* Check Rx process has been successfully started */ |
| 1720 | { |
1720 | if (status == HAL_OK) |
| 1721 | return HAL_BUSY; |
1721 | { |
| 1722 | } |
1722 | if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE) |
| 1723 | } |
1723 | { |
| 1724 | 1724 | __HAL_UART_CLEAR_IDLEFLAG(huart); |
|
| 1725 | /** |
1725 | ATOMIC_SET_BIT(huart->Instance->CR1, USART_CR1_IDLEIE); |
| 1726 | * @brief Receive an amount of data in interrupt mode till either the expected number of data is received or an IDLE event occurs. |
1726 | } |
| 1727 | * @note Reception is initiated by this function call. Further progress of reception is achieved thanks |
1727 | else |
| 1728 | * to UART interrupts raised by RXNE and IDLE events. Callback is called at end of reception indicating |
1728 | { |
| 1729 | * number of received data elements. |
1729 | /* In case of errors already pending when reception is started, |
| 1730 | * @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M = 01), |
1730 | Interrupts may have already been raised and lead to reception abortion. |
| 1731 | * the received data is handled as a set of uint16_t. In this case, Size must indicate the number |
1731 | (Overrun error for instance). |
| 1732 | * of uint16_t available through pData. |
1732 | In such case Reception Type has been reset to HAL_UART_RECEPTION_STANDARD. */ |
| 1733 | * @param huart UART handle. |
1733 | status = HAL_ERROR; |
| 1734 | * @param pData Pointer to data buffer (uint8_t or uint16_t data elements). |
1734 | } |
| 1735 | * @param Size Amount of data elements (uint8_t or uint16_t) to be received. |
1735 | } |
| 1736 | * @retval HAL status |
1736 | |
| 1737 | */ |
1737 | return status; |
| 1738 | HAL_StatusTypeDef HAL_UARTEx_ReceiveToIdle_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size) |
1738 | } |
| 1739 | { |
1739 | else |
| 1740 | HAL_StatusTypeDef status; |
1740 | { |
| 1741 | 1741 | return HAL_BUSY; |
|
| 1742 | /* Check that a Rx process is not already ongoing */ |
1742 | } |
| 1743 | if (huart->RxState == HAL_UART_STATE_READY) |
1743 | } |
| 1744 | { |
1744 | |
| 1745 | if ((pData == NULL) || (Size == 0U)) |
1745 | /** |
| 1746 | { |
1746 | * @brief Receive an amount of data in DMA mode till either the expected number of data is received or an IDLE event occurs. |
| 1747 | return HAL_ERROR; |
1747 | * @note Reception is initiated by this function call. Further progress of reception is achieved thanks |
| 1748 | } |
1748 | * to DMA services, transferring automatically received data elements in user reception buffer and |
| 1749 | 1749 | * calling registered callbacks at half/end of reception. UART IDLE events are also used to consider |
|
| 1750 | __HAL_LOCK(huart); |
1750 | * reception phase as ended. In all cases, callback execution will indicate number of received data elements. |
| 1751 | 1751 | * @note When the UART parity is enabled (PCE = 1), the received data contain |
|
| 1752 | /* Set Reception type to reception till IDLE Event*/ |
1752 | * the parity bit (MSB position). |
| 1753 | huart->ReceptionType = HAL_UART_RECEPTION_TOIDLE; |
1753 | * @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M = 01), |
| 1754 | 1754 | * the received data is handled as a set of uint16_t. In this case, Size must indicate the number |
|
| 1755 | status = UART_Start_Receive_IT(huart, pData, Size); |
1755 | * of uint16_t available through pData. |
| 1756 | 1756 | * @param huart UART handle. |
|
| 1757 | /* Check Rx process has been successfully started */ |
1757 | * @param pData Pointer to data buffer (uint8_t or uint16_t data elements). |
| 1758 | if (status == HAL_OK) |
1758 | * @param Size Amount of data elements (uint8_t or uint16_t) to be received. |
| 1759 | { |
1759 | * @retval HAL status |
| 1760 | if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE) |
1760 | */ |
| 1761 | { |
1761 | HAL_StatusTypeDef HAL_UARTEx_ReceiveToIdle_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size) |
| 1762 | __HAL_UART_CLEAR_IDLEFLAG(huart); |
1762 | { |
| 1763 | SET_BIT(huart->Instance->CR1, USART_CR1_IDLEIE); |
1763 | HAL_StatusTypeDef status; |
| 1764 | } |
1764 | |
| 1765 | else |
1765 | /* Check that a Rx process is not already ongoing */ |
| 1766 | { |
1766 | if (huart->RxState == HAL_UART_STATE_READY) |
| 1767 | /* In case of errors already pending when reception is started, |
1767 | { |
| 1768 | Interrupts may have already been raised and lead to reception abortion. |
1768 | if ((pData == NULL) || (Size == 0U)) |
| 1769 | (Overrun error for instance). |
1769 | { |
| 1770 | In such case Reception Type has been reset to HAL_UART_RECEPTION_STANDARD. */ |
1770 | return HAL_ERROR; |
| 1771 | status = HAL_ERROR; |
1771 | } |
| 1772 | } |
1772 | |
| 1773 | } |
1773 | /* Set Reception type to reception till IDLE Event*/ |
| 1774 | 1774 | huart->ReceptionType = HAL_UART_RECEPTION_TOIDLE; |
|
| 1775 | return status; |
1775 | huart->RxEventType = HAL_UART_RXEVENT_TC; |
| 1776 | } |
1776 | |
| 1777 | else |
1777 | status = UART_Start_Receive_DMA(huart, pData, Size); |
| 1778 | { |
1778 | |
| 1779 | return HAL_BUSY; |
1779 | /* Check Rx process has been successfully started */ |
| 1780 | } |
1780 | if (status == HAL_OK) |
| 1781 | } |
1781 | { |
| 1782 | 1782 | if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE) |
|
| 1783 | /** |
1783 | { |
| 1784 | * @brief Receive an amount of data in DMA mode till either the expected number of data is received or an IDLE event occurs. |
1784 | __HAL_UART_CLEAR_IDLEFLAG(huart); |
| 1785 | * @note Reception is initiated by this function call. Further progress of reception is achieved thanks |
1785 | ATOMIC_SET_BIT(huart->Instance->CR1, USART_CR1_IDLEIE); |
| 1786 | * to DMA services, transferring automatically received data elements in user reception buffer and |
1786 | } |
| 1787 | * calling registered callbacks at half/end of reception. UART IDLE events are also used to consider |
1787 | else |
| 1788 | * reception phase as ended. In all cases, callback execution will indicate number of received data elements. |
1788 | { |
| 1789 | * @note When the UART parity is enabled (PCE = 1), the received data contain |
1789 | /* In case of errors already pending when reception is started, |
| 1790 | * the parity bit (MSB position). |
1790 | Interrupts may have already been raised and lead to reception abortion. |
| 1791 | * @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M = 01), |
1791 | (Overrun error for instance). |
| 1792 | * the received data is handled as a set of uint16_t. In this case, Size must indicate the number |
1792 | In such case Reception Type has been reset to HAL_UART_RECEPTION_STANDARD. */ |
| 1793 | * of uint16_t available through pData. |
1793 | status = HAL_ERROR; |
| 1794 | * @param huart UART handle. |
1794 | } |
| 1795 | * @param pData Pointer to data buffer (uint8_t or uint16_t data elements). |
1795 | } |
| 1796 | * @param Size Amount of data elements (uint8_t or uint16_t) to be received. |
1796 | |
| 1797 | * @retval HAL status |
1797 | return status; |
| 1798 | */ |
1798 | } |
| 1799 | HAL_StatusTypeDef HAL_UARTEx_ReceiveToIdle_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size) |
1799 | else |
| 1800 | { |
1800 | { |
| 1801 | HAL_StatusTypeDef status; |
1801 | return HAL_BUSY; |
| 1802 | 1802 | } |
|
| 1803 | /* Check that a Rx process is not already ongoing */ |
1803 | } |
| 1804 | if (huart->RxState == HAL_UART_STATE_READY) |
1804 | |
| 1805 | { |
1805 | /** |
| 1806 | if ((pData == NULL) || (Size == 0U)) |
1806 | * @brief Provide Rx Event type that has lead to RxEvent callback execution. |
| 1807 | { |
1807 | * @note When HAL_UARTEx_ReceiveToIdle_IT() or HAL_UARTEx_ReceiveToIdle_DMA() API are called, progress |
| 1808 | return HAL_ERROR; |
1808 | * of reception process is provided to application through calls of Rx Event callback (either default one |
| 1809 | } |
1809 | * HAL_UARTEx_RxEventCallback() or user registered one). As several types of events could occur (IDLE event, |
| 1810 | 1810 | * Half Transfer, or Transfer Complete), this function allows to retrieve the Rx Event type that has lead |
|
| 1811 | __HAL_LOCK(huart); |
1811 | * to Rx Event callback execution. |
| 1812 | 1812 | * @note This function is expected to be called within the user implementation of Rx Event Callback, |
|
| 1813 | /* Set Reception type to reception till IDLE Event*/ |
1813 | * in order to provide the accurate value : |
| 1814 | huart->ReceptionType = HAL_UART_RECEPTION_TOIDLE; |
1814 | * In Interrupt Mode : |
| 1815 | 1815 | * - HAL_UART_RXEVENT_TC : when Reception has been completed (expected nb of data has been received) |
|
| 1816 | status = UART_Start_Receive_DMA(huart, pData, Size); |
1816 | * - HAL_UART_RXEVENT_IDLE : when Idle event occurred prior reception has been completed (nb of |
| 1817 | 1817 | * received data is lower than expected one) |
|
| 1818 | /* Check Rx process has been successfully started */ |
1818 | * In DMA Mode : |
| 1819 | if (status == HAL_OK) |
1819 | * - HAL_UART_RXEVENT_TC : when Reception has been completed (expected nb of data has been received) |
| 1820 | { |
1820 | * - HAL_UART_RXEVENT_HT : when half of expected nb of data has been received |
| 1821 | if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE) |
1821 | * - HAL_UART_RXEVENT_IDLE : when Idle event occurred prior reception has been completed (nb of |
| 1822 | { |
1822 | * received data is lower than expected one). |
| 1823 | __HAL_UART_CLEAR_IDLEFLAG(huart); |
1823 | * In DMA mode, RxEvent callback could be called several times; |
| 1824 | SET_BIT(huart->Instance->CR1, USART_CR1_IDLEIE); |
1824 | * When DMA is configured in Normal Mode, HT event does not stop Reception process; |
| 1825 | } |
1825 | * When DMA is configured in Circular Mode, HT, TC or IDLE events don't stop Reception process; |
| 1826 | else |
1826 | * @param huart UART handle. |
| 1827 | { |
1827 | * @retval Rx Event Type (returned value will be a value of @ref UART_RxEvent_Type_Values) |
| 1828 | /* In case of errors already pending when reception is started, |
1828 | */ |
| 1829 | Interrupts may have already been raised and lead to reception abortion. |
1829 | HAL_UART_RxEventTypeTypeDef HAL_UARTEx_GetRxEventType(UART_HandleTypeDef *huart) |
| 1830 | (Overrun error for instance). |
1830 | { |
| 1831 | In such case Reception Type has been reset to HAL_UART_RECEPTION_STANDARD. */ |
1831 | /* Return Rx Event type value, as stored in UART handle */ |
| 1832 | status = HAL_ERROR; |
1832 | return(huart->RxEventType); |
| 1833 | } |
1833 | } |
| 1834 | } |
1834 | |
| 1835 | 1835 | /** |
|
| 1836 | return status; |
1836 | * @brief Abort ongoing transfers (blocking mode). |
| 1837 | } |
1837 | * @param huart UART handle. |
| 1838 | else |
1838 | * @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode. |
| 1839 | { |
1839 | * This procedure performs following operations : |
| 1840 | return HAL_BUSY; |
1840 | * - Disable UART Interrupts (Tx and Rx) |
| 1841 | } |
1841 | * - Disable the DMA transfer in the peripheral register (if enabled) |
| 1842 | } |
1842 | * - Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode) |
| 1843 | 1843 | * - Set handle State to READY |
|
| 1844 | /** |
1844 | * @note This procedure is executed in blocking mode : when exiting function, Abort is considered as completed. |
| 1845 | * @brief Abort ongoing transfers (blocking mode). |
1845 | * @retval HAL status |
| 1846 | * @param huart UART handle. |
1846 | */ |
| 1847 | * @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode. |
1847 | HAL_StatusTypeDef HAL_UART_Abort(UART_HandleTypeDef *huart) |
| 1848 | * This procedure performs following operations : |
1848 | { |
| 1849 | * - Disable UART Interrupts (Tx and Rx) |
1849 | /* Disable TXEIE, TCIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */ |
| 1850 | * - Disable the DMA transfer in the peripheral register (if enabled) |
1850 | ATOMIC_CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE)); |
| 1851 | * - Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode) |
1851 | ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE); |
| 1852 | * - Set handle State to READY |
1852 | |
| 1853 | * @note This procedure is executed in blocking mode : when exiting function, Abort is considered as completed. |
1853 | /* If Reception till IDLE event was ongoing, disable IDLEIE interrupt */ |
| 1854 | * @retval HAL status |
1854 | if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE) |
| 1855 | */ |
1855 | { |
| 1856 | HAL_StatusTypeDef HAL_UART_Abort(UART_HandleTypeDef *huart) |
1856 | ATOMIC_CLEAR_BIT(huart->Instance->CR1, (USART_CR1_IDLEIE)); |
| 1857 | { |
1857 | } |
| 1858 | /* Disable TXEIE, TCIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */ |
1858 | |
| 1859 | CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE)); |
1859 | /* Disable the UART DMA Tx request if enabled */ |
| 1860 | CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE); |
1860 | if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAT)) |
| 1861 | 1861 | { |
|
| 1862 | /* If Reception till IDLE event was ongoing, disable IDLEIE interrupt */ |
1862 | ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAT); |
| 1863 | if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE) |
1863 | |
| 1864 | { |
1864 | /* Abort the UART DMA Tx channel: use blocking DMA Abort API (no callback) */ |
| 1865 | CLEAR_BIT(huart->Instance->CR1, (USART_CR1_IDLEIE)); |
1865 | if (huart->hdmatx != NULL) |
| 1866 | } |
1866 | { |
| 1867 | 1867 | /* Set the UART DMA Abort callback to Null. |
|
| 1868 | /* Disable the UART DMA Tx request if enabled */ |
1868 | No call back execution at end of DMA abort procedure */ |
| 1869 | if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAT)) |
1869 | huart->hdmatx->XferAbortCallback = NULL; |
| 1870 | { |
1870 | |
| 1871 | CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAT); |
1871 | if (HAL_DMA_Abort(huart->hdmatx) != HAL_OK) |
| 1872 | 1872 | { |
|
| 1873 | /* Abort the UART DMA Tx channel: use blocking DMA Abort API (no callback) */ |
1873 | if (HAL_DMA_GetError(huart->hdmatx) == HAL_DMA_ERROR_TIMEOUT) |
| 1874 | if (huart->hdmatx != NULL) |
1874 | { |
| 1875 | { |
1875 | /* Set error code to DMA */ |
| 1876 | /* Set the UART DMA Abort callback to Null. |
1876 | huart->ErrorCode = HAL_UART_ERROR_DMA; |
| 1877 | No call back execution at end of DMA abort procedure */ |
1877 | |
| 1878 | huart->hdmatx->XferAbortCallback = NULL; |
1878 | return HAL_TIMEOUT; |
| 1879 | 1879 | } |
|
| 1880 | if (HAL_DMA_Abort(huart->hdmatx) != HAL_OK) |
1880 | } |
| 1881 | { |
1881 | } |
| 1882 | if (HAL_DMA_GetError(huart->hdmatx) == HAL_DMA_ERROR_TIMEOUT) |
1882 | } |
| 1883 | { |
1883 | |
| 1884 | /* Set error code to DMA */ |
1884 | /* Disable the UART DMA Rx request if enabled */ |
| 1885 | huart->ErrorCode = HAL_UART_ERROR_DMA; |
1885 | if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR)) |
| 1886 | 1886 | { |
|
| 1887 | return HAL_TIMEOUT; |
1887 | ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR); |
| 1888 | } |
1888 | |
| 1889 | } |
1889 | /* Abort the UART DMA Rx channel: use blocking DMA Abort API (no callback) */ |
| 1890 | } |
1890 | if (huart->hdmarx != NULL) |
| 1891 | } |
1891 | { |
| 1892 | 1892 | /* Set the UART DMA Abort callback to Null. |
|
| 1893 | /* Disable the UART DMA Rx request if enabled */ |
1893 | No call back execution at end of DMA abort procedure */ |
| 1894 | if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR)) |
1894 | huart->hdmarx->XferAbortCallback = NULL; |
| 1895 | { |
1895 | |
| 1896 | CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR); |
1896 | if (HAL_DMA_Abort(huart->hdmarx) != HAL_OK) |
| 1897 | 1897 | { |
|
| 1898 | /* Abort the UART DMA Rx channel: use blocking DMA Abort API (no callback) */ |
1898 | if (HAL_DMA_GetError(huart->hdmarx) == HAL_DMA_ERROR_TIMEOUT) |
| 1899 | if (huart->hdmarx != NULL) |
1899 | { |
| 1900 | { |
1900 | /* Set error code to DMA */ |
| 1901 | /* Set the UART DMA Abort callback to Null. |
1901 | huart->ErrorCode = HAL_UART_ERROR_DMA; |
| 1902 | No call back execution at end of DMA abort procedure */ |
1902 | |
| 1903 | huart->hdmarx->XferAbortCallback = NULL; |
1903 | return HAL_TIMEOUT; |
| 1904 | 1904 | } |
|
| 1905 | if (HAL_DMA_Abort(huart->hdmarx) != HAL_OK) |
1905 | } |
| 1906 | { |
1906 | } |
| 1907 | if (HAL_DMA_GetError(huart->hdmarx) == HAL_DMA_ERROR_TIMEOUT) |
1907 | } |
| 1908 | { |
1908 | |
| 1909 | /* Set error code to DMA */ |
1909 | /* Reset Tx and Rx transfer counters */ |
| 1910 | huart->ErrorCode = HAL_UART_ERROR_DMA; |
1910 | huart->TxXferCount = 0x00U; |
| 1911 | 1911 | huart->RxXferCount = 0x00U; |
|
| 1912 | return HAL_TIMEOUT; |
1912 | |
| 1913 | } |
1913 | /* Reset ErrorCode */ |
| 1914 | } |
1914 | huart->ErrorCode = HAL_UART_ERROR_NONE; |
| 1915 | } |
1915 | |
| 1916 | } |
1916 | /* Restore huart->RxState and huart->gState to Ready */ |
| 1917 | 1917 | huart->RxState = HAL_UART_STATE_READY; |
|
| 1918 | /* Reset Tx and Rx transfer counters */ |
1918 | huart->gState = HAL_UART_STATE_READY; |
| 1919 | huart->TxXferCount = 0x00U; |
1919 | huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
| 1920 | huart->RxXferCount = 0x00U; |
1920 | |
| 1921 | 1921 | return HAL_OK; |
|
| 1922 | /* Reset ErrorCode */ |
1922 | } |
| 1923 | huart->ErrorCode = HAL_UART_ERROR_NONE; |
1923 | |
| 1924 | 1924 | /** |
|
| 1925 | /* Restore huart->RxState and huart->gState to Ready */ |
1925 | * @brief Abort ongoing Transmit transfer (blocking mode). |
| 1926 | huart->RxState = HAL_UART_STATE_READY; |
1926 | * @param huart UART handle. |
| 1927 | huart->gState = HAL_UART_STATE_READY; |
1927 | * @note This procedure could be used for aborting any ongoing Tx transfer started in Interrupt or DMA mode. |
| 1928 | huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
1928 | * This procedure performs following operations : |
| 1929 | 1929 | * - Disable UART Interrupts (Tx) |
|
| 1930 | return HAL_OK; |
1930 | * - Disable the DMA transfer in the peripheral register (if enabled) |
| 1931 | } |
1931 | * - Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode) |
| 1932 | 1932 | * - Set handle State to READY |
|
| 1933 | /** |
1933 | * @note This procedure is executed in blocking mode : when exiting function, Abort is considered as completed. |
| 1934 | * @brief Abort ongoing Transmit transfer (blocking mode). |
1934 | * @retval HAL status |
| 1935 | * @param huart UART handle. |
1935 | */ |
| 1936 | * @note This procedure could be used for aborting any ongoing Tx transfer started in Interrupt or DMA mode. |
1936 | HAL_StatusTypeDef HAL_UART_AbortTransmit(UART_HandleTypeDef *huart) |
| 1937 | * This procedure performs following operations : |
1937 | { |
| 1938 | * - Disable UART Interrupts (Tx) |
1938 | /* Disable TXEIE and TCIE interrupts */ |
| 1939 | * - Disable the DMA transfer in the peripheral register (if enabled) |
1939 | ATOMIC_CLEAR_BIT(huart->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE)); |
| 1940 | * - Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode) |
1940 | |
| 1941 | * - Set handle State to READY |
1941 | /* Disable the UART DMA Tx request if enabled */ |
| 1942 | * @note This procedure is executed in blocking mode : when exiting function, Abort is considered as completed. |
1942 | if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAT)) |
| 1943 | * @retval HAL status |
1943 | { |
| 1944 | */ |
1944 | ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAT); |
| 1945 | HAL_StatusTypeDef HAL_UART_AbortTransmit(UART_HandleTypeDef *huart) |
1945 | |
| 1946 | { |
1946 | /* Abort the UART DMA Tx channel : use blocking DMA Abort API (no callback) */ |
| 1947 | /* Disable TXEIE and TCIE interrupts */ |
1947 | if (huart->hdmatx != NULL) |
| 1948 | CLEAR_BIT(huart->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE)); |
1948 | { |
| 1949 | 1949 | /* Set the UART DMA Abort callback to Null. |
|
| 1950 | /* Disable the UART DMA Tx request if enabled */ |
1950 | No call back execution at end of DMA abort procedure */ |
| 1951 | if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAT)) |
1951 | huart->hdmatx->XferAbortCallback = NULL; |
| 1952 | { |
1952 | |
| 1953 | CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAT); |
1953 | if (HAL_DMA_Abort(huart->hdmatx) != HAL_OK) |
| 1954 | 1954 | { |
|
| 1955 | /* Abort the UART DMA Tx channel : use blocking DMA Abort API (no callback) */ |
1955 | if (HAL_DMA_GetError(huart->hdmatx) == HAL_DMA_ERROR_TIMEOUT) |
| 1956 | if (huart->hdmatx != NULL) |
1956 | { |
| 1957 | { |
1957 | /* Set error code to DMA */ |
| 1958 | /* Set the UART DMA Abort callback to Null. |
1958 | huart->ErrorCode = HAL_UART_ERROR_DMA; |
| 1959 | No call back execution at end of DMA abort procedure */ |
1959 | |
| 1960 | huart->hdmatx->XferAbortCallback = NULL; |
1960 | return HAL_TIMEOUT; |
| 1961 | 1961 | } |
|
| 1962 | if (HAL_DMA_Abort(huart->hdmatx) != HAL_OK) |
1962 | } |
| 1963 | { |
1963 | } |
| 1964 | if (HAL_DMA_GetError(huart->hdmatx) == HAL_DMA_ERROR_TIMEOUT) |
1964 | } |
| 1965 | { |
1965 | |
| 1966 | /* Set error code to DMA */ |
1966 | /* Reset Tx transfer counter */ |
| 1967 | huart->ErrorCode = HAL_UART_ERROR_DMA; |
1967 | huart->TxXferCount = 0x00U; |
| 1968 | 1968 | ||
| 1969 | return HAL_TIMEOUT; |
1969 | /* Restore huart->gState to Ready */ |
| 1970 | } |
1970 | huart->gState = HAL_UART_STATE_READY; |
| 1971 | } |
1971 | |
| 1972 | } |
1972 | return HAL_OK; |
| 1973 | } |
1973 | } |
| 1974 | 1974 | ||
| 1975 | /* Reset Tx transfer counter */ |
1975 | /** |
| 1976 | huart->TxXferCount = 0x00U; |
1976 | * @brief Abort ongoing Receive transfer (blocking mode). |
| 1977 | 1977 | * @param huart UART handle. |
|
| 1978 | /* Restore huart->gState to Ready */ |
1978 | * @note This procedure could be used for aborting any ongoing Rx transfer started in Interrupt or DMA mode. |
| 1979 | huart->gState = HAL_UART_STATE_READY; |
1979 | * This procedure performs following operations : |
| 1980 | 1980 | * - Disable UART Interrupts (Rx) |
|
| 1981 | return HAL_OK; |
1981 | * - Disable the DMA transfer in the peripheral register (if enabled) |
| 1982 | } |
1982 | * - Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode) |
| 1983 | 1983 | * - Set handle State to READY |
|
| 1984 | /** |
1984 | * @note This procedure is executed in blocking mode : when exiting function, Abort is considered as completed. |
| 1985 | * @brief Abort ongoing Receive transfer (blocking mode). |
1985 | * @retval HAL status |
| 1986 | * @param huart UART handle. |
1986 | */ |
| 1987 | * @note This procedure could be used for aborting any ongoing Rx transfer started in Interrupt or DMA mode. |
1987 | HAL_StatusTypeDef HAL_UART_AbortReceive(UART_HandleTypeDef *huart) |
| 1988 | * This procedure performs following operations : |
1988 | { |
| 1989 | * - Disable UART Interrupts (Rx) |
1989 | /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */ |
| 1990 | * - Disable the DMA transfer in the peripheral register (if enabled) |
1990 | ATOMIC_CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE)); |
| 1991 | * - Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode) |
1991 | ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE); |
| 1992 | * - Set handle State to READY |
1992 | |
| 1993 | * @note This procedure is executed in blocking mode : when exiting function, Abort is considered as completed. |
1993 | /* If Reception till IDLE event was ongoing, disable IDLEIE interrupt */ |
| 1994 | * @retval HAL status |
1994 | if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE) |
| 1995 | */ |
1995 | { |
| 1996 | HAL_StatusTypeDef HAL_UART_AbortReceive(UART_HandleTypeDef *huart) |
1996 | ATOMIC_CLEAR_BIT(huart->Instance->CR1, (USART_CR1_IDLEIE)); |
| 1997 | { |
1997 | } |
| 1998 | /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */ |
1998 | |
| 1999 | CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE)); |
1999 | /* Disable the UART DMA Rx request if enabled */ |
| 2000 | CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE); |
2000 | if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR)) |
| 2001 | 2001 | { |
|
| 2002 | /* If Reception till IDLE event was ongoing, disable IDLEIE interrupt */ |
2002 | ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR); |
| 2003 | if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE) |
2003 | |
| 2004 | { |
2004 | /* Abort the UART DMA Rx channel : use blocking DMA Abort API (no callback) */ |
| 2005 | CLEAR_BIT(huart->Instance->CR1, (USART_CR1_IDLEIE)); |
2005 | if (huart->hdmarx != NULL) |
| 2006 | } |
2006 | { |
| 2007 | 2007 | /* Set the UART DMA Abort callback to Null. |
|
| 2008 | /* Disable the UART DMA Rx request if enabled */ |
2008 | No call back execution at end of DMA abort procedure */ |
| 2009 | if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR)) |
2009 | huart->hdmarx->XferAbortCallback = NULL; |
| 2010 | { |
2010 | |
| 2011 | CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR); |
2011 | if (HAL_DMA_Abort(huart->hdmarx) != HAL_OK) |
| 2012 | 2012 | { |
|
| 2013 | /* Abort the UART DMA Rx channel : use blocking DMA Abort API (no callback) */ |
2013 | if (HAL_DMA_GetError(huart->hdmarx) == HAL_DMA_ERROR_TIMEOUT) |
| 2014 | if (huart->hdmarx != NULL) |
2014 | { |
| 2015 | { |
2015 | /* Set error code to DMA */ |
| 2016 | /* Set the UART DMA Abort callback to Null. |
2016 | huart->ErrorCode = HAL_UART_ERROR_DMA; |
| 2017 | No call back execution at end of DMA abort procedure */ |
2017 | |
| 2018 | huart->hdmarx->XferAbortCallback = NULL; |
2018 | return HAL_TIMEOUT; |
| 2019 | 2019 | } |
|
| 2020 | if (HAL_DMA_Abort(huart->hdmarx) != HAL_OK) |
2020 | } |
| 2021 | { |
2021 | } |
| 2022 | if (HAL_DMA_GetError(huart->hdmarx) == HAL_DMA_ERROR_TIMEOUT) |
2022 | } |
| 2023 | { |
2023 | |
| 2024 | /* Set error code to DMA */ |
2024 | /* Reset Rx transfer counter */ |
| 2025 | huart->ErrorCode = HAL_UART_ERROR_DMA; |
2025 | huart->RxXferCount = 0x00U; |
| 2026 | 2026 | ||
| 2027 | return HAL_TIMEOUT; |
2027 | /* Restore huart->RxState to Ready */ |
| 2028 | } |
2028 | huart->RxState = HAL_UART_STATE_READY; |
| 2029 | } |
2029 | huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
| 2030 | } |
2030 | |
| 2031 | } |
2031 | return HAL_OK; |
| 2032 | 2032 | } |
|
| 2033 | /* Reset Rx transfer counter */ |
2033 | |
| 2034 | huart->RxXferCount = 0x00U; |
2034 | /** |
| 2035 | 2035 | * @brief Abort ongoing transfers (Interrupt mode). |
|
| 2036 | /* Restore huart->RxState to Ready */ |
2036 | * @param huart UART handle. |
| 2037 | huart->RxState = HAL_UART_STATE_READY; |
2037 | * @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode. |
| 2038 | huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
2038 | * This procedure performs following operations : |
| 2039 | 2039 | * - Disable UART Interrupts (Tx and Rx) |
|
| 2040 | return HAL_OK; |
2040 | * - Disable the DMA transfer in the peripheral register (if enabled) |
| 2041 | } |
2041 | * - Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode) |
| 2042 | 2042 | * - Set handle State to READY |
|
| 2043 | /** |
2043 | * - At abort completion, call user abort complete callback |
| 2044 | * @brief Abort ongoing transfers (Interrupt mode). |
2044 | * @note This procedure is executed in Interrupt mode, meaning that abort procedure could be |
| 2045 | * @param huart UART handle. |
2045 | * considered as completed only when user abort complete callback is executed (not when exiting function). |
| 2046 | * @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode. |
2046 | * @retval HAL status |
| 2047 | * This procedure performs following operations : |
2047 | */ |
| 2048 | * - Disable UART Interrupts (Tx and Rx) |
2048 | HAL_StatusTypeDef HAL_UART_Abort_IT(UART_HandleTypeDef *huart) |
| 2049 | * - Disable the DMA transfer in the peripheral register (if enabled) |
2049 | { |
| 2050 | * - Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode) |
2050 | uint32_t AbortCplt = 0x01U; |
| 2051 | * - Set handle State to READY |
2051 | |
| 2052 | * - At abort completion, call user abort complete callback |
2052 | /* Disable TXEIE, TCIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */ |
| 2053 | * @note This procedure is executed in Interrupt mode, meaning that abort procedure could be |
2053 | ATOMIC_CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE)); |
| 2054 | * considered as completed only when user abort complete callback is executed (not when exiting function). |
2054 | ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE); |
| 2055 | * @retval HAL status |
2055 | |
| 2056 | */ |
2056 | /* If Reception till IDLE event was ongoing, disable IDLEIE interrupt */ |
| 2057 | HAL_StatusTypeDef HAL_UART_Abort_IT(UART_HandleTypeDef *huart) |
2057 | if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE) |
| 2058 | { |
2058 | { |
| 2059 | uint32_t AbortCplt = 0x01U; |
2059 | ATOMIC_CLEAR_BIT(huart->Instance->CR1, (USART_CR1_IDLEIE)); |
| 2060 | 2060 | } |
|
| 2061 | /* Disable TXEIE, TCIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */ |
2061 | |
| 2062 | CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE)); |
2062 | /* If DMA Tx and/or DMA Rx Handles are associated to UART Handle, DMA Abort complete callbacks should be initialised |
| 2063 | CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE); |
2063 | before any call to DMA Abort functions */ |
| 2064 | 2064 | /* DMA Tx Handle is valid */ |
|
| 2065 | /* If Reception till IDLE event was ongoing, disable IDLEIE interrupt */ |
2065 | if (huart->hdmatx != NULL) |
| 2066 | if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE) |
2066 | { |
| 2067 | { |
2067 | /* Set DMA Abort Complete callback if UART DMA Tx request if enabled. |
| 2068 | CLEAR_BIT(huart->Instance->CR1, (USART_CR1_IDLEIE)); |
2068 | Otherwise, set it to NULL */ |
| 2069 | } |
2069 | if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAT)) |
| 2070 | 2070 | { |
|
| 2071 | /* If DMA Tx and/or DMA Rx Handles are associated to UART Handle, DMA Abort complete callbacks should be initialised |
2071 | huart->hdmatx->XferAbortCallback = UART_DMATxAbortCallback; |
| 2072 | before any call to DMA Abort functions */ |
2072 | } |
| 2073 | /* DMA Tx Handle is valid */ |
2073 | else |
| 2074 | if (huart->hdmatx != NULL) |
2074 | { |
| 2075 | { |
2075 | huart->hdmatx->XferAbortCallback = NULL; |
| 2076 | /* Set DMA Abort Complete callback if UART DMA Tx request if enabled. |
2076 | } |
| 2077 | Otherwise, set it to NULL */ |
2077 | } |
| 2078 | if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAT)) |
2078 | /* DMA Rx Handle is valid */ |
| 2079 | { |
2079 | if (huart->hdmarx != NULL) |
| 2080 | huart->hdmatx->XferAbortCallback = UART_DMATxAbortCallback; |
2080 | { |
| 2081 | } |
2081 | /* Set DMA Abort Complete callback if UART DMA Rx request if enabled. |
| 2082 | else |
2082 | Otherwise, set it to NULL */ |
| 2083 | { |
2083 | if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR)) |
| 2084 | huart->hdmatx->XferAbortCallback = NULL; |
2084 | { |
| 2085 | } |
2085 | huart->hdmarx->XferAbortCallback = UART_DMARxAbortCallback; |
| 2086 | } |
2086 | } |
| 2087 | /* DMA Rx Handle is valid */ |
2087 | else |
| 2088 | if (huart->hdmarx != NULL) |
2088 | { |
| 2089 | { |
2089 | huart->hdmarx->XferAbortCallback = NULL; |
| 2090 | /* Set DMA Abort Complete callback if UART DMA Rx request if enabled. |
2090 | } |
| 2091 | Otherwise, set it to NULL */ |
2091 | } |
| 2092 | if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR)) |
2092 | |
| 2093 | { |
2093 | /* Disable the UART DMA Tx request if enabled */ |
| 2094 | huart->hdmarx->XferAbortCallback = UART_DMARxAbortCallback; |
2094 | if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAT)) |
| 2095 | } |
2095 | { |
| 2096 | else |
2096 | /* Disable DMA Tx at UART level */ |
| 2097 | { |
2097 | ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAT); |
| 2098 | huart->hdmarx->XferAbortCallback = NULL; |
2098 | |
| 2099 | } |
2099 | /* Abort the UART DMA Tx channel : use non blocking DMA Abort API (callback) */ |
| 2100 | } |
2100 | if (huart->hdmatx != NULL) |
| 2101 | 2101 | { |
|
| 2102 | /* Disable the UART DMA Tx request if enabled */ |
2102 | /* UART Tx DMA Abort callback has already been initialised : |
| 2103 | if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAT)) |
2103 | will lead to call HAL_UART_AbortCpltCallback() at end of DMA abort procedure */ |
| 2104 | { |
2104 | |
| 2105 | /* Disable DMA Tx at UART level */ |
2105 | /* Abort DMA TX */ |
| 2106 | CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAT); |
2106 | if (HAL_DMA_Abort_IT(huart->hdmatx) != HAL_OK) |
| 2107 | 2107 | { |
|
| 2108 | /* Abort the UART DMA Tx channel : use non blocking DMA Abort API (callback) */ |
2108 | huart->hdmatx->XferAbortCallback = NULL; |
| 2109 | if (huart->hdmatx != NULL) |
2109 | } |
| 2110 | { |
2110 | else |
| 2111 | /* UART Tx DMA Abort callback has already been initialised : |
2111 | { |
| 2112 | will lead to call HAL_UART_AbortCpltCallback() at end of DMA abort procedure */ |
2112 | AbortCplt = 0x00U; |
| 2113 | 2113 | } |
|
| 2114 | /* Abort DMA TX */ |
2114 | } |
| 2115 | if (HAL_DMA_Abort_IT(huart->hdmatx) != HAL_OK) |
2115 | } |
| 2116 | { |
2116 | |
| 2117 | huart->hdmatx->XferAbortCallback = NULL; |
2117 | /* Disable the UART DMA Rx request if enabled */ |
| 2118 | } |
2118 | if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR)) |
| 2119 | else |
2119 | { |
| 2120 | { |
2120 | ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR); |
| 2121 | AbortCplt = 0x00U; |
2121 | |
| 2122 | } |
2122 | /* Abort the UART DMA Rx channel : use non blocking DMA Abort API (callback) */ |
| 2123 | } |
2123 | if (huart->hdmarx != NULL) |
| 2124 | } |
2124 | { |
| 2125 | 2125 | /* UART Rx DMA Abort callback has already been initialised : |
|
| 2126 | /* Disable the UART DMA Rx request if enabled */ |
2126 | will lead to call HAL_UART_AbortCpltCallback() at end of DMA abort procedure */ |
| 2127 | if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR)) |
2127 | |
| 2128 | { |
2128 | /* Abort DMA RX */ |
| 2129 | CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR); |
2129 | if (HAL_DMA_Abort_IT(huart->hdmarx) != HAL_OK) |
| 2130 | 2130 | { |
|
| 2131 | /* Abort the UART DMA Rx channel : use non blocking DMA Abort API (callback) */ |
2131 | huart->hdmarx->XferAbortCallback = NULL; |
| 2132 | if (huart->hdmarx != NULL) |
2132 | AbortCplt = 0x01U; |
| 2133 | { |
2133 | } |
| 2134 | /* UART Rx DMA Abort callback has already been initialised : |
2134 | else |
| 2135 | will lead to call HAL_UART_AbortCpltCallback() at end of DMA abort procedure */ |
2135 | { |
| 2136 | 2136 | AbortCplt = 0x00U; |
|
| 2137 | /* Abort DMA RX */ |
2137 | } |
| 2138 | if (HAL_DMA_Abort_IT(huart->hdmarx) != HAL_OK) |
2138 | } |
| 2139 | { |
2139 | } |
| 2140 | huart->hdmarx->XferAbortCallback = NULL; |
2140 | |
| 2141 | AbortCplt = 0x01U; |
2141 | /* if no DMA abort complete callback execution is required => call user Abort Complete callback */ |
| 2142 | } |
2142 | if (AbortCplt == 0x01U) |
| 2143 | else |
2143 | { |
| 2144 | { |
2144 | /* Reset Tx and Rx transfer counters */ |
| 2145 | AbortCplt = 0x00U; |
2145 | huart->TxXferCount = 0x00U; |
| 2146 | } |
2146 | huart->RxXferCount = 0x00U; |
| 2147 | } |
2147 | |
| 2148 | } |
2148 | /* Reset ErrorCode */ |
| 2149 | 2149 | huart->ErrorCode = HAL_UART_ERROR_NONE; |
|
| 2150 | /* if no DMA abort complete callback execution is required => call user Abort Complete callback */ |
2150 | |
| 2151 | if (AbortCplt == 0x01U) |
2151 | /* Restore huart->gState and huart->RxState to Ready */ |
| 2152 | { |
2152 | huart->gState = HAL_UART_STATE_READY; |
| 2153 | /* Reset Tx and Rx transfer counters */ |
2153 | huart->RxState = HAL_UART_STATE_READY; |
| 2154 | huart->TxXferCount = 0x00U; |
2154 | huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
| 2155 | huart->RxXferCount = 0x00U; |
2155 | |
| 2156 | 2156 | /* As no DMA to be aborted, call directly user Abort complete callback */ |
|
| 2157 | /* Reset ErrorCode */ |
2157 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
| 2158 | huart->ErrorCode = HAL_UART_ERROR_NONE; |
2158 | /* Call registered Abort complete callback */ |
| 2159 | 2159 | huart->AbortCpltCallback(huart); |
|
| 2160 | /* Restore huart->gState and huart->RxState to Ready */ |
2160 | #else |
| 2161 | huart->gState = HAL_UART_STATE_READY; |
2161 | /* Call legacy weak Abort complete callback */ |
| 2162 | huart->RxState = HAL_UART_STATE_READY; |
2162 | HAL_UART_AbortCpltCallback(huart); |
| 2163 | huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
2163 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
| 2164 | 2164 | } |
|
| 2165 | /* As no DMA to be aborted, call directly user Abort complete callback */ |
2165 | |
| 2166 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
2166 | return HAL_OK; |
| 2167 | /* Call registered Abort complete callback */ |
2167 | } |
| 2168 | huart->AbortCpltCallback(huart); |
2168 | |
| 2169 | #else |
2169 | /** |
| 2170 | /* Call legacy weak Abort complete callback */ |
2170 | * @brief Abort ongoing Transmit transfer (Interrupt mode). |
| 2171 | HAL_UART_AbortCpltCallback(huart); |
2171 | * @param huart UART handle. |
| 2172 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
2172 | * @note This procedure could be used for aborting any ongoing Tx transfer started in Interrupt or DMA mode. |
| 2173 | } |
2173 | * This procedure performs following operations : |
| 2174 | 2174 | * - Disable UART Interrupts (Tx) |
|
| 2175 | return HAL_OK; |
2175 | * - Disable the DMA transfer in the peripheral register (if enabled) |
| 2176 | } |
2176 | * - Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode) |
| 2177 | 2177 | * - Set handle State to READY |
|
| 2178 | /** |
2178 | * - At abort completion, call user abort complete callback |
| 2179 | * @brief Abort ongoing Transmit transfer (Interrupt mode). |
2179 | * @note This procedure is executed in Interrupt mode, meaning that abort procedure could be |
| 2180 | * @param huart UART handle. |
2180 | * considered as completed only when user abort complete callback is executed (not when exiting function). |
| 2181 | * @note This procedure could be used for aborting any ongoing Tx transfer started in Interrupt or DMA mode. |
2181 | * @retval HAL status |
| 2182 | * This procedure performs following operations : |
2182 | */ |
| 2183 | * - Disable UART Interrupts (Tx) |
2183 | HAL_StatusTypeDef HAL_UART_AbortTransmit_IT(UART_HandleTypeDef *huart) |
| 2184 | * - Disable the DMA transfer in the peripheral register (if enabled) |
2184 | { |
| 2185 | * - Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode) |
2185 | /* Disable TXEIE and TCIE interrupts */ |
| 2186 | * - Set handle State to READY |
2186 | ATOMIC_CLEAR_BIT(huart->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE)); |
| 2187 | * - At abort completion, call user abort complete callback |
2187 | |
| 2188 | * @note This procedure is executed in Interrupt mode, meaning that abort procedure could be |
2188 | /* Disable the UART DMA Tx request if enabled */ |
| 2189 | * considered as completed only when user abort complete callback is executed (not when exiting function). |
2189 | if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAT)) |
| 2190 | * @retval HAL status |
2190 | { |
| 2191 | */ |
2191 | ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAT); |
| 2192 | HAL_StatusTypeDef HAL_UART_AbortTransmit_IT(UART_HandleTypeDef *huart) |
2192 | |
| 2193 | { |
2193 | /* Abort the UART DMA Tx channel : use blocking DMA Abort API (no callback) */ |
| 2194 | /* Disable TXEIE and TCIE interrupts */ |
2194 | if (huart->hdmatx != NULL) |
| 2195 | CLEAR_BIT(huart->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE)); |
2195 | { |
| 2196 | 2196 | /* Set the UART DMA Abort callback : |
|
| 2197 | /* Disable the UART DMA Tx request if enabled */ |
2197 | will lead to call HAL_UART_AbortCpltCallback() at end of DMA abort procedure */ |
| 2198 | if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAT)) |
2198 | huart->hdmatx->XferAbortCallback = UART_DMATxOnlyAbortCallback; |
| 2199 | { |
2199 | |
| 2200 | CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAT); |
2200 | /* Abort DMA TX */ |
| 2201 | 2201 | if (HAL_DMA_Abort_IT(huart->hdmatx) != HAL_OK) |
|
| 2202 | /* Abort the UART DMA Tx channel : use blocking DMA Abort API (no callback) */ |
2202 | { |
| 2203 | if (huart->hdmatx != NULL) |
2203 | /* Call Directly huart->hdmatx->XferAbortCallback function in case of error */ |
| 2204 | { |
2204 | huart->hdmatx->XferAbortCallback(huart->hdmatx); |
| 2205 | /* Set the UART DMA Abort callback : |
2205 | } |
| 2206 | will lead to call HAL_UART_AbortCpltCallback() at end of DMA abort procedure */ |
2206 | } |
| 2207 | huart->hdmatx->XferAbortCallback = UART_DMATxOnlyAbortCallback; |
2207 | else |
| 2208 | 2208 | { |
|
| 2209 | /* Abort DMA TX */ |
2209 | /* Reset Tx transfer counter */ |
| 2210 | if (HAL_DMA_Abort_IT(huart->hdmatx) != HAL_OK) |
2210 | huart->TxXferCount = 0x00U; |
| 2211 | { |
2211 | |
| 2212 | /* Call Directly huart->hdmatx->XferAbortCallback function in case of error */ |
2212 | /* Restore huart->gState to Ready */ |
| 2213 | huart->hdmatx->XferAbortCallback(huart->hdmatx); |
2213 | huart->gState = HAL_UART_STATE_READY; |
| 2214 | } |
2214 | |
| 2215 | } |
2215 | /* As no DMA to be aborted, call directly user Abort complete callback */ |
| 2216 | else |
2216 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
| 2217 | { |
2217 | /* Call registered Abort Transmit Complete Callback */ |
| 2218 | /* Reset Tx transfer counter */ |
2218 | huart->AbortTransmitCpltCallback(huart); |
| 2219 | huart->TxXferCount = 0x00U; |
2219 | #else |
| 2220 | 2220 | /* Call legacy weak Abort Transmit Complete Callback */ |
|
| 2221 | /* Restore huart->gState to Ready */ |
2221 | HAL_UART_AbortTransmitCpltCallback(huart); |
| 2222 | huart->gState = HAL_UART_STATE_READY; |
2222 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
| 2223 | 2223 | } |
|
| 2224 | /* As no DMA to be aborted, call directly user Abort complete callback */ |
2224 | } |
| 2225 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
2225 | else |
| 2226 | /* Call registered Abort Transmit Complete Callback */ |
2226 | { |
| 2227 | huart->AbortTransmitCpltCallback(huart); |
2227 | /* Reset Tx transfer counter */ |
| 2228 | #else |
2228 | huart->TxXferCount = 0x00U; |
| 2229 | /* Call legacy weak Abort Transmit Complete Callback */ |
2229 | |
| 2230 | HAL_UART_AbortTransmitCpltCallback(huart); |
2230 | /* Restore huart->gState to Ready */ |
| 2231 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
2231 | huart->gState = HAL_UART_STATE_READY; |
| 2232 | } |
2232 | |
| 2233 | } |
2233 | /* As no DMA to be aborted, call directly user Abort complete callback */ |
| 2234 | else |
2234 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
| 2235 | { |
2235 | /* Call registered Abort Transmit Complete Callback */ |
| 2236 | /* Reset Tx transfer counter */ |
2236 | huart->AbortTransmitCpltCallback(huart); |
| 2237 | huart->TxXferCount = 0x00U; |
2237 | #else |
| 2238 | 2238 | /* Call legacy weak Abort Transmit Complete Callback */ |
|
| 2239 | /* Restore huart->gState to Ready */ |
2239 | HAL_UART_AbortTransmitCpltCallback(huart); |
| 2240 | huart->gState = HAL_UART_STATE_READY; |
2240 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
| 2241 | 2241 | } |
|
| 2242 | /* As no DMA to be aborted, call directly user Abort complete callback */ |
2242 | |
| 2243 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
2243 | return HAL_OK; |
| 2244 | /* Call registered Abort Transmit Complete Callback */ |
2244 | } |
| 2245 | huart->AbortTransmitCpltCallback(huart); |
2245 | |
| 2246 | #else |
2246 | /** |
| 2247 | /* Call legacy weak Abort Transmit Complete Callback */ |
2247 | * @brief Abort ongoing Receive transfer (Interrupt mode). |
| 2248 | HAL_UART_AbortTransmitCpltCallback(huart); |
2248 | * @param huart UART handle. |
| 2249 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
2249 | * @note This procedure could be used for aborting any ongoing Rx transfer started in Interrupt or DMA mode. |
| 2250 | } |
2250 | * This procedure performs following operations : |
| 2251 | 2251 | * - Disable UART Interrupts (Rx) |
|
| 2252 | return HAL_OK; |
2252 | * - Disable the DMA transfer in the peripheral register (if enabled) |
| 2253 | } |
2253 | * - Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode) |
| 2254 | 2254 | * - Set handle State to READY |
|
| 2255 | /** |
2255 | * - At abort completion, call user abort complete callback |
| 2256 | * @brief Abort ongoing Receive transfer (Interrupt mode). |
2256 | * @note This procedure is executed in Interrupt mode, meaning that abort procedure could be |
| 2257 | * @param huart UART handle. |
2257 | * considered as completed only when user abort complete callback is executed (not when exiting function). |
| 2258 | * @note This procedure could be used for aborting any ongoing Rx transfer started in Interrupt or DMA mode. |
2258 | * @retval HAL status |
| 2259 | * This procedure performs following operations : |
2259 | */ |
| 2260 | * - Disable UART Interrupts (Rx) |
2260 | HAL_StatusTypeDef HAL_UART_AbortReceive_IT(UART_HandleTypeDef *huart) |
| 2261 | * - Disable the DMA transfer in the peripheral register (if enabled) |
2261 | { |
| 2262 | * - Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode) |
2262 | /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */ |
| 2263 | * - Set handle State to READY |
2263 | ATOMIC_CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE)); |
| 2264 | * - At abort completion, call user abort complete callback |
2264 | ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE); |
| 2265 | * @note This procedure is executed in Interrupt mode, meaning that abort procedure could be |
2265 | |
| 2266 | * considered as completed only when user abort complete callback is executed (not when exiting function). |
2266 | /* If Reception till IDLE event was ongoing, disable IDLEIE interrupt */ |
| 2267 | * @retval HAL status |
2267 | if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE) |
| 2268 | */ |
2268 | { |
| 2269 | HAL_StatusTypeDef HAL_UART_AbortReceive_IT(UART_HandleTypeDef *huart) |
2269 | ATOMIC_CLEAR_BIT(huart->Instance->CR1, (USART_CR1_IDLEIE)); |
| 2270 | { |
2270 | } |
| 2271 | /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */ |
2271 | |
| 2272 | CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE)); |
2272 | /* Disable the UART DMA Rx request if enabled */ |
| 2273 | CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE); |
2273 | if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR)) |
| 2274 | 2274 | { |
|
| 2275 | /* If Reception till IDLE event was ongoing, disable IDLEIE interrupt */ |
2275 | ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR); |
| 2276 | if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE) |
2276 | |
| 2277 | { |
2277 | /* Abort the UART DMA Rx channel : use blocking DMA Abort API (no callback) */ |
| 2278 | CLEAR_BIT(huart->Instance->CR1, (USART_CR1_IDLEIE)); |
2278 | if (huart->hdmarx != NULL) |
| 2279 | } |
2279 | { |
| 2280 | 2280 | /* Set the UART DMA Abort callback : |
|
| 2281 | /* Disable the UART DMA Rx request if enabled */ |
2281 | will lead to call HAL_UART_AbortCpltCallback() at end of DMA abort procedure */ |
| 2282 | if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR)) |
2282 | huart->hdmarx->XferAbortCallback = UART_DMARxOnlyAbortCallback; |
| 2283 | { |
2283 | |
| 2284 | CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR); |
2284 | /* Abort DMA RX */ |
| 2285 | 2285 | if (HAL_DMA_Abort_IT(huart->hdmarx) != HAL_OK) |
|
| 2286 | /* Abort the UART DMA Rx channel : use blocking DMA Abort API (no callback) */ |
2286 | { |
| 2287 | if (huart->hdmarx != NULL) |
2287 | /* Call Directly huart->hdmarx->XferAbortCallback function in case of error */ |
| 2288 | { |
2288 | huart->hdmarx->XferAbortCallback(huart->hdmarx); |
| 2289 | /* Set the UART DMA Abort callback : |
2289 | } |
| 2290 | will lead to call HAL_UART_AbortCpltCallback() at end of DMA abort procedure */ |
2290 | } |
| 2291 | huart->hdmarx->XferAbortCallback = UART_DMARxOnlyAbortCallback; |
2291 | else |
| 2292 | 2292 | { |
|
| 2293 | /* Abort DMA RX */ |
2293 | /* Reset Rx transfer counter */ |
| 2294 | if (HAL_DMA_Abort_IT(huart->hdmarx) != HAL_OK) |
2294 | huart->RxXferCount = 0x00U; |
| 2295 | { |
2295 | |
| 2296 | /* Call Directly huart->hdmarx->XferAbortCallback function in case of error */ |
2296 | /* Restore huart->RxState to Ready */ |
| 2297 | huart->hdmarx->XferAbortCallback(huart->hdmarx); |
2297 | huart->RxState = HAL_UART_STATE_READY; |
| 2298 | } |
2298 | huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
| 2299 | } |
2299 | |
| 2300 | else |
2300 | /* As no DMA to be aborted, call directly user Abort complete callback */ |
| 2301 | { |
2301 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
| 2302 | /* Reset Rx transfer counter */ |
2302 | /* Call registered Abort Receive Complete Callback */ |
| 2303 | huart->RxXferCount = 0x00U; |
2303 | huart->AbortReceiveCpltCallback(huart); |
| 2304 | 2304 | #else |
|
| 2305 | /* Restore huart->RxState to Ready */ |
2305 | /* Call legacy weak Abort Receive Complete Callback */ |
| 2306 | huart->RxState = HAL_UART_STATE_READY; |
2306 | HAL_UART_AbortReceiveCpltCallback(huart); |
| 2307 | huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
2307 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
| 2308 | 2308 | } |
|
| 2309 | /* As no DMA to be aborted, call directly user Abort complete callback */ |
2309 | } |
| 2310 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
2310 | else |
| 2311 | /* Call registered Abort Receive Complete Callback */ |
2311 | { |
| 2312 | huart->AbortReceiveCpltCallback(huart); |
2312 | /* Reset Rx transfer counter */ |
| 2313 | #else |
2313 | huart->RxXferCount = 0x00U; |
| 2314 | /* Call legacy weak Abort Receive Complete Callback */ |
2314 | |
| 2315 | HAL_UART_AbortReceiveCpltCallback(huart); |
2315 | /* Restore huart->RxState to Ready */ |
| 2316 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
2316 | huart->RxState = HAL_UART_STATE_READY; |
| 2317 | } |
2317 | huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
| 2318 | } |
2318 | |
| 2319 | else |
2319 | /* As no DMA to be aborted, call directly user Abort complete callback */ |
| 2320 | { |
2320 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
| 2321 | /* Reset Rx transfer counter */ |
2321 | /* Call registered Abort Receive Complete Callback */ |
| 2322 | huart->RxXferCount = 0x00U; |
2322 | huart->AbortReceiveCpltCallback(huart); |
| 2323 | 2323 | #else |
|
| 2324 | /* Restore huart->RxState to Ready */ |
2324 | /* Call legacy weak Abort Receive Complete Callback */ |
| 2325 | huart->RxState = HAL_UART_STATE_READY; |
2325 | HAL_UART_AbortReceiveCpltCallback(huart); |
| 2326 | huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
2326 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
| 2327 | 2327 | } |
|
| 2328 | /* As no DMA to be aborted, call directly user Abort complete callback */ |
2328 | |
| 2329 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
2329 | return HAL_OK; |
| 2330 | /* Call registered Abort Receive Complete Callback */ |
2330 | } |
| 2331 | huart->AbortReceiveCpltCallback(huart); |
2331 | |
| 2332 | #else |
2332 | /** |
| 2333 | /* Call legacy weak Abort Receive Complete Callback */ |
2333 | * @brief This function handles UART interrupt request. |
| 2334 | HAL_UART_AbortReceiveCpltCallback(huart); |
2334 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
| 2335 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
2335 | * the configuration information for the specified UART module. |
| 2336 | } |
2336 | * @retval None |
| 2337 | 2337 | */ |
|
| 2338 | return HAL_OK; |
2338 | void HAL_UART_IRQHandler(UART_HandleTypeDef *huart) |
| 2339 | } |
2339 | { |
| 2340 | 2340 | uint32_t isrflags = READ_REG(huart->Instance->SR); |
|
| 2341 | /** |
2341 | uint32_t cr1its = READ_REG(huart->Instance->CR1); |
| 2342 | * @brief This function handles UART interrupt request. |
2342 | uint32_t cr3its = READ_REG(huart->Instance->CR3); |
| 2343 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
2343 | uint32_t errorflags = 0x00U; |
| 2344 | * the configuration information for the specified UART module. |
2344 | uint32_t dmarequest = 0x00U; |
| 2345 | * @retval None |
2345 | |
| 2346 | */ |
2346 | /* If no error occurs */ |
| 2347 | void HAL_UART_IRQHandler(UART_HandleTypeDef *huart) |
2347 | errorflags = (isrflags & (uint32_t)(USART_SR_PE | USART_SR_FE | USART_SR_ORE | USART_SR_NE)); |
| 2348 | { |
2348 | if (errorflags == RESET) |
| 2349 | uint32_t isrflags = READ_REG(huart->Instance->SR); |
2349 | { |
| 2350 | uint32_t cr1its = READ_REG(huart->Instance->CR1); |
2350 | /* UART in mode Receiver -------------------------------------------------*/ |
| 2351 | uint32_t cr3its = READ_REG(huart->Instance->CR3); |
2351 | if (((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET)) |
| 2352 | uint32_t errorflags = 0x00U; |
2352 | { |
| 2353 | uint32_t dmarequest = 0x00U; |
2353 | UART_Receive_IT(huart); |
| 2354 | 2354 | return; |
|
| 2355 | /* If no error occurs */ |
2355 | } |
| 2356 | errorflags = (isrflags & (uint32_t)(USART_SR_PE | USART_SR_FE | USART_SR_ORE | USART_SR_NE)); |
2356 | } |
| 2357 | if (errorflags == RESET) |
2357 | |
| 2358 | { |
2358 | /* If some errors occur */ |
| 2359 | /* UART in mode Receiver -------------------------------------------------*/ |
2359 | if ((errorflags != RESET) && (((cr3its & USART_CR3_EIE) != RESET) |
| 2360 | if (((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET)) |
2360 | || ((cr1its & (USART_CR1_RXNEIE | USART_CR1_PEIE)) != RESET))) |
| 2361 | { |
2361 | { |
| 2362 | UART_Receive_IT(huart); |
2362 | /* UART parity error interrupt occurred ----------------------------------*/ |
| 2363 | return; |
2363 | if (((isrflags & USART_SR_PE) != RESET) && ((cr1its & USART_CR1_PEIE) != RESET)) |
| 2364 | } |
2364 | { |
| 2365 | } |
2365 | huart->ErrorCode |= HAL_UART_ERROR_PE; |
| 2366 | 2366 | } |
|
| 2367 | /* If some errors occur */ |
2367 | |
| 2368 | if ((errorflags != RESET) && (((cr3its & USART_CR3_EIE) != RESET) || ((cr1its & (USART_CR1_RXNEIE | USART_CR1_PEIE)) != RESET))) |
2368 | /* UART noise error interrupt occurred -----------------------------------*/ |
| 2369 | { |
2369 | if (((isrflags & USART_SR_NE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET)) |
| 2370 | /* UART parity error interrupt occurred ----------------------------------*/ |
2370 | { |
| 2371 | if (((isrflags & USART_SR_PE) != RESET) && ((cr1its & USART_CR1_PEIE) != RESET)) |
2371 | huart->ErrorCode |= HAL_UART_ERROR_NE; |
| 2372 | { |
2372 | } |
| 2373 | huart->ErrorCode |= HAL_UART_ERROR_PE; |
2373 | |
| 2374 | } |
2374 | /* UART frame error interrupt occurred -----------------------------------*/ |
| 2375 | 2375 | if (((isrflags & USART_SR_FE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET)) |
|
| 2376 | /* UART noise error interrupt occurred -----------------------------------*/ |
2376 | { |
| 2377 | if (((isrflags & USART_SR_NE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET)) |
2377 | huart->ErrorCode |= HAL_UART_ERROR_FE; |
| 2378 | { |
2378 | } |
| 2379 | huart->ErrorCode |= HAL_UART_ERROR_NE; |
2379 | |
| 2380 | } |
2380 | /* UART Over-Run interrupt occurred --------------------------------------*/ |
| 2381 | 2381 | if (((isrflags & USART_SR_ORE) != RESET) && (((cr1its & USART_CR1_RXNEIE) != RESET) |
|
| 2382 | /* UART frame error interrupt occurred -----------------------------------*/ |
2382 | || ((cr3its & USART_CR3_EIE) != RESET))) |
| 2383 | if (((isrflags & USART_SR_FE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET)) |
2383 | { |
| 2384 | { |
2384 | huart->ErrorCode |= HAL_UART_ERROR_ORE; |
| 2385 | huart->ErrorCode |= HAL_UART_ERROR_FE; |
2385 | } |
| 2386 | } |
2386 | |
| 2387 | 2387 | /* Call UART Error Call back function if need be --------------------------*/ |
|
| 2388 | /* UART Over-Run interrupt occurred --------------------------------------*/ |
2388 | if (huart->ErrorCode != HAL_UART_ERROR_NONE) |
| 2389 | if (((isrflags & USART_SR_ORE) != RESET) && (((cr1its & USART_CR1_RXNEIE) != RESET) || ((cr3its & USART_CR3_EIE) != RESET))) |
2389 | { |
| 2390 | { |
2390 | /* UART in mode Receiver -----------------------------------------------*/ |
| 2391 | huart->ErrorCode |= HAL_UART_ERROR_ORE; |
2391 | if (((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET)) |
| 2392 | } |
2392 | { |
| 2393 | 2393 | UART_Receive_IT(huart); |
|
| 2394 | /* Call UART Error Call back function if need be --------------------------*/ |
2394 | } |
| 2395 | if (huart->ErrorCode != HAL_UART_ERROR_NONE) |
2395 | |
| 2396 | { |
2396 | /* If Overrun error occurs, or if any error occurs in DMA mode reception, |
| 2397 | /* UART in mode Receiver -----------------------------------------------*/ |
2397 | consider error as blocking */ |
| 2398 | if (((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET)) |
2398 | dmarequest = HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR); |
| 2399 | { |
2399 | if (((huart->ErrorCode & HAL_UART_ERROR_ORE) != RESET) || dmarequest) |
| 2400 | UART_Receive_IT(huart); |
2400 | { |
| 2401 | } |
2401 | /* Blocking error : transfer is aborted |
| 2402 | 2402 | Set the UART state ready to be able to start again the process, |
|
| 2403 | /* If Overrun error occurs, or if any error occurs in DMA mode reception, |
2403 | Disable Rx Interrupts, and disable Rx DMA request, if ongoing */ |
| 2404 | consider error as blocking */ |
2404 | UART_EndRxTransfer(huart); |
| 2405 | dmarequest = HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR); |
2405 | |
| 2406 | if (((huart->ErrorCode & HAL_UART_ERROR_ORE) != RESET) || dmarequest) |
2406 | /* Disable the UART DMA Rx request if enabled */ |
| 2407 | { |
2407 | if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR)) |
| 2408 | /* Blocking error : transfer is aborted |
2408 | { |
| 2409 | Set the UART state ready to be able to start again the process, |
2409 | ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR); |
| 2410 | Disable Rx Interrupts, and disable Rx DMA request, if ongoing */ |
2410 | |
| 2411 | UART_EndRxTransfer(huart); |
2411 | /* Abort the UART DMA Rx channel */ |
| 2412 | 2412 | if (huart->hdmarx != NULL) |
|
| 2413 | /* Disable the UART DMA Rx request if enabled */ |
2413 | { |
| 2414 | if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR)) |
2414 | /* Set the UART DMA Abort callback : |
| 2415 | { |
2415 | will lead to call HAL_UART_ErrorCallback() at end of DMA abort procedure */ |
| 2416 | CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR); |
2416 | huart->hdmarx->XferAbortCallback = UART_DMAAbortOnError; |
| 2417 | 2417 | if (HAL_DMA_Abort_IT(huart->hdmarx) != HAL_OK) |
|
| 2418 | /* Abort the UART DMA Rx channel */ |
2418 | { |
| 2419 | if (huart->hdmarx != NULL) |
2419 | /* Call Directly XferAbortCallback function in case of error */ |
| 2420 | { |
2420 | huart->hdmarx->XferAbortCallback(huart->hdmarx); |
| 2421 | /* Set the UART DMA Abort callback : |
2421 | } |
| 2422 | will lead to call HAL_UART_ErrorCallback() at end of DMA abort procedure */ |
2422 | } |
| 2423 | huart->hdmarx->XferAbortCallback = UART_DMAAbortOnError; |
2423 | else |
| 2424 | if (HAL_DMA_Abort_IT(huart->hdmarx) != HAL_OK) |
2424 | { |
| 2425 | { |
2425 | /* Call user error callback */ |
| 2426 | /* Call Directly XferAbortCallback function in case of error */ |
2426 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
| 2427 | huart->hdmarx->XferAbortCallback(huart->hdmarx); |
2427 | /*Call registered error callback*/ |
| 2428 | } |
2428 | huart->ErrorCallback(huart); |
| 2429 | } |
2429 | #else |
| 2430 | else |
2430 | /*Call legacy weak error callback*/ |
| 2431 | { |
2431 | HAL_UART_ErrorCallback(huart); |
| 2432 | /* Call user error callback */ |
2432 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
| 2433 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
2433 | } |
| 2434 | /*Call registered error callback*/ |
2434 | } |
| 2435 | huart->ErrorCallback(huart); |
2435 | else |
| 2436 | #else |
2436 | { |
| 2437 | /*Call legacy weak error callback*/ |
2437 | /* Call user error callback */ |
| 2438 | HAL_UART_ErrorCallback(huart); |
2438 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
| 2439 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
2439 | /*Call registered error callback*/ |
| 2440 | } |
2440 | huart->ErrorCallback(huart); |
| 2441 | } |
2441 | #else |
| 2442 | else |
2442 | /*Call legacy weak error callback*/ |
| 2443 | { |
2443 | HAL_UART_ErrorCallback(huart); |
| 2444 | /* Call user error callback */ |
2444 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
| 2445 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
2445 | } |
| 2446 | /*Call registered error callback*/ |
2446 | } |
| 2447 | huart->ErrorCallback(huart); |
2447 | else |
| 2448 | #else |
2448 | { |
| 2449 | /*Call legacy weak error callback*/ |
2449 | /* Non Blocking error : transfer could go on. |
| 2450 | HAL_UART_ErrorCallback(huart); |
2450 | Error is notified to user through user error callback */ |
| 2451 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
2451 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
| 2452 | } |
2452 | /*Call registered error callback*/ |
| 2453 | } |
2453 | huart->ErrorCallback(huart); |
| 2454 | else |
2454 | #else |
| 2455 | { |
2455 | /*Call legacy weak error callback*/ |
| 2456 | /* Non Blocking error : transfer could go on. |
2456 | HAL_UART_ErrorCallback(huart); |
| 2457 | Error is notified to user through user error callback */ |
2457 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
| 2458 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
2458 | |
| 2459 | /*Call registered error callback*/ |
2459 | huart->ErrorCode = HAL_UART_ERROR_NONE; |
| 2460 | huart->ErrorCallback(huart); |
2460 | } |
| 2461 | #else |
2461 | } |
| 2462 | /*Call legacy weak error callback*/ |
2462 | return; |
| 2463 | HAL_UART_ErrorCallback(huart); |
2463 | } /* End if some error occurs */ |
| 2464 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
2464 | |
| 2465 | 2465 | /* Check current reception Mode : |
|
| 2466 | huart->ErrorCode = HAL_UART_ERROR_NONE; |
2466 | If Reception till IDLE event has been selected : */ |
| 2467 | } |
2467 | if ((huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE) |
| 2468 | } |
2468 | && ((isrflags & USART_SR_IDLE) != 0U) |
| 2469 | return; |
2469 | && ((cr1its & USART_SR_IDLE) != 0U)) |
| 2470 | } /* End if some error occurs */ |
2470 | { |
| 2471 | 2471 | __HAL_UART_CLEAR_IDLEFLAG(huart); |
|
| 2472 | /* Check current reception Mode : |
2472 | |
| 2473 | If Reception till IDLE event has been selected : */ |
2473 | /* Check if DMA mode is enabled in UART */ |
| 2474 | if ( (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE) |
2474 | if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR)) |
| 2475 | &&((isrflags & USART_SR_IDLE) != 0U) |
2475 | { |
| 2476 | &&((cr1its & USART_SR_IDLE) != 0U)) |
2476 | /* DMA mode enabled */ |
| 2477 | { |
2477 | /* Check received length : If all expected data are received, do nothing, |
| 2478 | __HAL_UART_CLEAR_IDLEFLAG(huart); |
2478 | (DMA cplt callback will be called). |
| 2479 | 2479 | Otherwise, if at least one data has already been received, IDLE event is to be notified to user */ |
|
| 2480 | /* Check if DMA mode is enabled in UART */ |
2480 | uint16_t nb_remaining_rx_data = (uint16_t) __HAL_DMA_GET_COUNTER(huart->hdmarx); |
| 2481 | if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR)) |
2481 | if ((nb_remaining_rx_data > 0U) |
| 2482 | { |
2482 | && (nb_remaining_rx_data < huart->RxXferSize)) |
| 2483 | /* DMA mode enabled */ |
2483 | { |
| 2484 | /* Check received length : If all expected data are received, do nothing, |
2484 | /* Reception is not complete */ |
| 2485 | (DMA cplt callback will be called). |
2485 | huart->RxXferCount = nb_remaining_rx_data; |
| 2486 | Otherwise, if at least one data has already been received, IDLE event is to be notified to user */ |
2486 | |
| 2487 | uint16_t nb_remaining_rx_data = (uint16_t) __HAL_DMA_GET_COUNTER(huart->hdmarx); |
2487 | /* In Normal mode, end DMA xfer and HAL UART Rx process*/ |
| 2488 | if ( (nb_remaining_rx_data > 0U) |
2488 | if (huart->hdmarx->Init.Mode != DMA_CIRCULAR) |
| 2489 | &&(nb_remaining_rx_data < huart->RxXferSize)) |
2489 | { |
| 2490 | { |
2490 | /* Disable PE and ERR (Frame error, noise error, overrun error) interrupts */ |
| 2491 | /* Reception is not complete */ |
2491 | ATOMIC_CLEAR_BIT(huart->Instance->CR1, USART_CR1_PEIE); |
| 2492 | huart->RxXferCount = nb_remaining_rx_data; |
2492 | ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE); |
| 2493 | 2493 | ||
| 2494 | /* In Normal mode, end DMA xfer and HAL UART Rx process*/ |
2494 | /* Disable the DMA transfer for the receiver request by resetting the DMAR bit |
| 2495 | if (huart->hdmarx->Init.Mode != DMA_CIRCULAR) |
2495 | in the UART CR3 register */ |
| 2496 | { |
2496 | ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR); |
| 2497 | /* Disable PE and ERR (Frame error, noise error, overrun error) interrupts */ |
2497 | |
| 2498 | CLEAR_BIT(huart->Instance->CR1, USART_CR1_PEIE); |
2498 | /* At end of Rx process, restore huart->RxState to Ready */ |
| 2499 | CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE); |
2499 | huart->RxState = HAL_UART_STATE_READY; |
| 2500 | 2500 | huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
|
| 2501 | /* Disable the DMA transfer for the receiver request by resetting the DMAR bit |
2501 | |
| 2502 | in the UART CR3 register */ |
2502 | ATOMIC_CLEAR_BIT(huart->Instance->CR1, USART_CR1_IDLEIE); |
| 2503 | CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR); |
2503 | |
| 2504 | 2504 | /* Last bytes received, so no need as the abort is immediate */ |
|
| 2505 | /* At end of Rx process, restore huart->RxState to Ready */ |
2505 | (void)HAL_DMA_Abort(huart->hdmarx); |
| 2506 | huart->RxState = HAL_UART_STATE_READY; |
2506 | } |
| 2507 | huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
2507 | |
| 2508 | 2508 | /* Initialize type of RxEvent that correspond to RxEvent callback execution; |
|
| 2509 | CLEAR_BIT(huart->Instance->CR1, USART_CR1_IDLEIE); |
2509 | In this case, Rx Event type is Idle Event */ |
| 2510 | 2510 | huart->RxEventType = HAL_UART_RXEVENT_IDLE; |
|
| 2511 | /* Last bytes received, so no need as the abort is immediate */ |
2511 | |
| 2512 | (void)HAL_DMA_Abort(huart->hdmarx); |
2512 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
| 2513 | } |
2513 | /*Call registered Rx Event callback*/ |
| 2514 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
2514 | huart->RxEventCallback(huart, (huart->RxXferSize - huart->RxXferCount)); |
| 2515 | /*Call registered Rx Event callback*/ |
2515 | #else |
| 2516 | huart->RxEventCallback(huart, (huart->RxXferSize - huart->RxXferCount)); |
2516 | /*Call legacy weak Rx Event callback*/ |
| 2517 | #else |
2517 | HAL_UARTEx_RxEventCallback(huart, (huart->RxXferSize - huart->RxXferCount)); |
| 2518 | /*Call legacy weak Rx Event callback*/ |
2518 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
| 2519 | HAL_UARTEx_RxEventCallback(huart, (huart->RxXferSize - huart->RxXferCount)); |
2519 | } |
| 2520 | #endif |
2520 | return; |
| 2521 | } |
2521 | } |
| 2522 | return; |
2522 | else |
| 2523 | } |
2523 | { |
| 2524 | else |
2524 | /* DMA mode not enabled */ |
| 2525 | { |
2525 | /* Check received length : If all expected data are received, do nothing. |
| 2526 | /* DMA mode not enabled */ |
2526 | Otherwise, if at least one data has already been received, IDLE event is to be notified to user */ |
| 2527 | /* Check received length : If all expected data are received, do nothing. |
2527 | uint16_t nb_rx_data = huart->RxXferSize - huart->RxXferCount; |
| 2528 | Otherwise, if at least one data has already been received, IDLE event is to be notified to user */ |
2528 | if ((huart->RxXferCount > 0U) |
| 2529 | uint16_t nb_rx_data = huart->RxXferSize - huart->RxXferCount; |
2529 | && (nb_rx_data > 0U)) |
| 2530 | if ( (huart->RxXferCount > 0U) |
2530 | { |
| 2531 | &&(nb_rx_data > 0U) ) |
2531 | /* Disable the UART Parity Error Interrupt and RXNE interrupts */ |
| 2532 | { |
2532 | ATOMIC_CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE)); |
| 2533 | /* Disable the UART Parity Error Interrupt and RXNE interrupts */ |
2533 | |
| 2534 | CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE)); |
2534 | /* Disable the UART Error Interrupt: (Frame error, noise error, overrun error) */ |
| 2535 | 2535 | ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE); |
|
| 2536 | /* Disable the UART Error Interrupt: (Frame error, noise error, overrun error) */ |
2536 | |
| 2537 | CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE); |
2537 | /* Rx process is completed, restore huart->RxState to Ready */ |
| 2538 | 2538 | huart->RxState = HAL_UART_STATE_READY; |
|
| 2539 | /* Rx process is completed, restore huart->RxState to Ready */ |
2539 | huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
| 2540 | huart->RxState = HAL_UART_STATE_READY; |
2540 | |
| 2541 | huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
2541 | ATOMIC_CLEAR_BIT(huart->Instance->CR1, USART_CR1_IDLEIE); |
| 2542 | 2542 | ||
| 2543 | CLEAR_BIT(huart->Instance->CR1, USART_CR1_IDLEIE); |
2543 | /* Initialize type of RxEvent that correspond to RxEvent callback execution; |
| 2544 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
2544 | In this case, Rx Event type is Idle Event */ |
| 2545 | /*Call registered Rx complete callback*/ |
2545 | huart->RxEventType = HAL_UART_RXEVENT_IDLE; |
| 2546 | huart->RxEventCallback(huart, nb_rx_data); |
2546 | |
| 2547 | #else |
2547 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
| 2548 | /*Call legacy weak Rx Event callback*/ |
2548 | /*Call registered Rx complete callback*/ |
| 2549 | HAL_UARTEx_RxEventCallback(huart, nb_rx_data); |
2549 | huart->RxEventCallback(huart, nb_rx_data); |
| 2550 | #endif |
2550 | #else |
| 2551 | } |
2551 | /*Call legacy weak Rx Event callback*/ |
| 2552 | return; |
2552 | HAL_UARTEx_RxEventCallback(huart, nb_rx_data); |
| 2553 | } |
2553 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
| 2554 | } |
2554 | } |
| 2555 | 2555 | return; |
|
| 2556 | /* UART in mode Transmitter ------------------------------------------------*/ |
2556 | } |
| 2557 | if (((isrflags & USART_SR_TXE) != RESET) && ((cr1its & USART_CR1_TXEIE) != RESET)) |
2557 | } |
| 2558 | { |
2558 | |
| 2559 | UART_Transmit_IT(huart); |
2559 | /* UART in mode Transmitter ------------------------------------------------*/ |
| 2560 | return; |
2560 | if (((isrflags & USART_SR_TXE) != RESET) && ((cr1its & USART_CR1_TXEIE) != RESET)) |
| 2561 | } |
2561 | { |
| 2562 | 2562 | UART_Transmit_IT(huart); |
|
| 2563 | /* UART in mode Transmitter end --------------------------------------------*/ |
2563 | return; |
| 2564 | if (((isrflags & USART_SR_TC) != RESET) && ((cr1its & USART_CR1_TCIE) != RESET)) |
2564 | } |
| 2565 | { |
2565 | |
| 2566 | UART_EndTransmit_IT(huart); |
2566 | /* UART in mode Transmitter end --------------------------------------------*/ |
| 2567 | return; |
2567 | if (((isrflags & USART_SR_TC) != RESET) && ((cr1its & USART_CR1_TCIE) != RESET)) |
| 2568 | } |
2568 | { |
| 2569 | } |
2569 | UART_EndTransmit_IT(huart); |
| 2570 | 2570 | return; |
|
| 2571 | /** |
2571 | } |
| 2572 | * @brief Tx Transfer completed callbacks. |
2572 | } |
| 2573 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
2573 | |
| 2574 | * the configuration information for the specified UART module. |
2574 | /** |
| 2575 | * @retval None |
2575 | * @brief Tx Transfer completed callbacks. |
| 2576 | */ |
2576 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
| 2577 | __weak void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) |
2577 | * the configuration information for the specified UART module. |
| 2578 | { |
2578 | * @retval None |
| 2579 | /* Prevent unused argument(s) compilation warning */ |
2579 | */ |
| 2580 | UNUSED(huart); |
2580 | __weak void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) |
| 2581 | /* NOTE: This function should not be modified, when the callback is needed, |
2581 | { |
| 2582 | the HAL_UART_TxCpltCallback could be implemented in the user file |
2582 | /* Prevent unused argument(s) compilation warning */ |
| 2583 | */ |
2583 | UNUSED(huart); |
| 2584 | } |
2584 | /* NOTE: This function should not be modified, when the callback is needed, |
| 2585 | 2585 | the HAL_UART_TxCpltCallback could be implemented in the user file |
|
| 2586 | /** |
2586 | */ |
| 2587 | * @brief Tx Half Transfer completed callbacks. |
2587 | } |
| 2588 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
2588 | |
| 2589 | * the configuration information for the specified UART module. |
2589 | /** |
| 2590 | * @retval None |
2590 | * @brief Tx Half Transfer completed callbacks. |
| 2591 | */ |
2591 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
| 2592 | __weak void HAL_UART_TxHalfCpltCallback(UART_HandleTypeDef *huart) |
2592 | * the configuration information for the specified UART module. |
| 2593 | { |
2593 | * @retval None |
| 2594 | /* Prevent unused argument(s) compilation warning */ |
2594 | */ |
| 2595 | UNUSED(huart); |
2595 | __weak void HAL_UART_TxHalfCpltCallback(UART_HandleTypeDef *huart) |
| 2596 | /* NOTE: This function should not be modified, when the callback is needed, |
2596 | { |
| 2597 | the HAL_UART_TxHalfCpltCallback could be implemented in the user file |
2597 | /* Prevent unused argument(s) compilation warning */ |
| 2598 | */ |
2598 | UNUSED(huart); |
| 2599 | } |
2599 | /* NOTE: This function should not be modified, when the callback is needed, |
| 2600 | 2600 | the HAL_UART_TxHalfCpltCallback could be implemented in the user file |
|
| 2601 | /** |
2601 | */ |
| 2602 | * @brief Rx Transfer completed callbacks. |
2602 | } |
| 2603 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
2603 | |
| 2604 | * the configuration information for the specified UART module. |
2604 | /** |
| 2605 | * @retval None |
2605 | * @brief Rx Transfer completed callbacks. |
| 2606 | */ |
2606 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
| 2607 | __weak void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) |
2607 | * the configuration information for the specified UART module. |
| 2608 | { |
2608 | * @retval None |
| 2609 | /* Prevent unused argument(s) compilation warning */ |
2609 | */ |
| 2610 | UNUSED(huart); |
2610 | __weak void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) |
| 2611 | /* NOTE: This function should not be modified, when the callback is needed, |
2611 | { |
| 2612 | the HAL_UART_RxCpltCallback could be implemented in the user file |
2612 | /* Prevent unused argument(s) compilation warning */ |
| 2613 | */ |
2613 | UNUSED(huart); |
| 2614 | } |
2614 | /* NOTE: This function should not be modified, when the callback is needed, |
| 2615 | 2615 | the HAL_UART_RxCpltCallback could be implemented in the user file |
|
| 2616 | /** |
2616 | */ |
| 2617 | * @brief Rx Half Transfer completed callbacks. |
2617 | } |
| 2618 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
2618 | |
| 2619 | * the configuration information for the specified UART module. |
2619 | /** |
| 2620 | * @retval None |
2620 | * @brief Rx Half Transfer completed callbacks. |
| 2621 | */ |
2621 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
| 2622 | __weak void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart) |
2622 | * the configuration information for the specified UART module. |
| 2623 | { |
2623 | * @retval None |
| 2624 | /* Prevent unused argument(s) compilation warning */ |
2624 | */ |
| 2625 | UNUSED(huart); |
2625 | __weak void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart) |
| 2626 | /* NOTE: This function should not be modified, when the callback is needed, |
2626 | { |
| 2627 | the HAL_UART_RxHalfCpltCallback could be implemented in the user file |
2627 | /* Prevent unused argument(s) compilation warning */ |
| 2628 | */ |
2628 | UNUSED(huart); |
| 2629 | } |
2629 | /* NOTE: This function should not be modified, when the callback is needed, |
| 2630 | 2630 | the HAL_UART_RxHalfCpltCallback could be implemented in the user file |
|
| 2631 | /** |
2631 | */ |
| 2632 | * @brief UART error callbacks. |
2632 | } |
| 2633 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
2633 | |
| 2634 | * the configuration information for the specified UART module. |
2634 | /** |
| 2635 | * @retval None |
2635 | * @brief UART error callbacks. |
| 2636 | */ |
2636 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
| 2637 | __weak void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart) |
2637 | * the configuration information for the specified UART module. |
| 2638 | { |
2638 | * @retval None |
| 2639 | /* Prevent unused argument(s) compilation warning */ |
2639 | */ |
| 2640 | UNUSED(huart); |
2640 | __weak void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart) |
| 2641 | /* NOTE: This function should not be modified, when the callback is needed, |
2641 | { |
| 2642 | the HAL_UART_ErrorCallback could be implemented in the user file |
2642 | /* Prevent unused argument(s) compilation warning */ |
| 2643 | */ |
2643 | UNUSED(huart); |
| 2644 | } |
2644 | /* NOTE: This function should not be modified, when the callback is needed, |
| 2645 | 2645 | the HAL_UART_ErrorCallback could be implemented in the user file |
|
| 2646 | /** |
2646 | */ |
| 2647 | * @brief UART Abort Complete callback. |
2647 | } |
| 2648 | * @param huart UART handle. |
2648 | |
| 2649 | * @retval None |
2649 | /** |
| 2650 | */ |
2650 | * @brief UART Abort Complete callback. |
| 2651 | __weak void HAL_UART_AbortCpltCallback(UART_HandleTypeDef *huart) |
2651 | * @param huart UART handle. |
| 2652 | { |
2652 | * @retval None |
| 2653 | /* Prevent unused argument(s) compilation warning */ |
2653 | */ |
| 2654 | UNUSED(huart); |
2654 | __weak void HAL_UART_AbortCpltCallback(UART_HandleTypeDef *huart) |
| 2655 | 2655 | { |
|
| 2656 | /* NOTE : This function should not be modified, when the callback is needed, |
2656 | /* Prevent unused argument(s) compilation warning */ |
| 2657 | the HAL_UART_AbortCpltCallback can be implemented in the user file. |
2657 | UNUSED(huart); |
| 2658 | */ |
2658 | |
| 2659 | } |
2659 | /* NOTE : This function should not be modified, when the callback is needed, |
| 2660 | 2660 | the HAL_UART_AbortCpltCallback can be implemented in the user file. |
|
| 2661 | /** |
2661 | */ |
| 2662 | * @brief UART Abort Complete callback. |
2662 | } |
| 2663 | * @param huart UART handle. |
2663 | |
| 2664 | * @retval None |
2664 | /** |
| 2665 | */ |
2665 | * @brief UART Abort Complete callback. |
| 2666 | __weak void HAL_UART_AbortTransmitCpltCallback(UART_HandleTypeDef *huart) |
2666 | * @param huart UART handle. |
| 2667 | { |
2667 | * @retval None |
| 2668 | /* Prevent unused argument(s) compilation warning */ |
2668 | */ |
| 2669 | UNUSED(huart); |
2669 | __weak void HAL_UART_AbortTransmitCpltCallback(UART_HandleTypeDef *huart) |
| 2670 | 2670 | { |
|
| 2671 | /* NOTE : This function should not be modified, when the callback is needed, |
2671 | /* Prevent unused argument(s) compilation warning */ |
| 2672 | the HAL_UART_AbortTransmitCpltCallback can be implemented in the user file. |
2672 | UNUSED(huart); |
| 2673 | */ |
2673 | |
| 2674 | } |
2674 | /* NOTE : This function should not be modified, when the callback is needed, |
| 2675 | 2675 | the HAL_UART_AbortTransmitCpltCallback can be implemented in the user file. |
|
| 2676 | /** |
2676 | */ |
| 2677 | * @brief UART Abort Receive Complete callback. |
2677 | } |
| 2678 | * @param huart UART handle. |
2678 | |
| 2679 | * @retval None |
2679 | /** |
| 2680 | */ |
2680 | * @brief UART Abort Receive Complete callback. |
| 2681 | __weak void HAL_UART_AbortReceiveCpltCallback(UART_HandleTypeDef *huart) |
2681 | * @param huart UART handle. |
| 2682 | { |
2682 | * @retval None |
| 2683 | /* Prevent unused argument(s) compilation warning */ |
2683 | */ |
| 2684 | UNUSED(huart); |
2684 | __weak void HAL_UART_AbortReceiveCpltCallback(UART_HandleTypeDef *huart) |
| 2685 | 2685 | { |
|
| 2686 | /* NOTE : This function should not be modified, when the callback is needed, |
2686 | /* Prevent unused argument(s) compilation warning */ |
| 2687 | the HAL_UART_AbortReceiveCpltCallback can be implemented in the user file. |
2687 | UNUSED(huart); |
| 2688 | */ |
2688 | |
| 2689 | } |
2689 | /* NOTE : This function should not be modified, when the callback is needed, |
| 2690 | 2690 | the HAL_UART_AbortReceiveCpltCallback can be implemented in the user file. |
|
| 2691 | /** |
2691 | */ |
| 2692 | * @brief Reception Event Callback (Rx event notification called after use of advanced reception service). |
2692 | } |
| 2693 | * @param huart UART handle |
2693 | |
| 2694 | * @param Size Number of data available in application reception buffer (indicates a position in |
2694 | /** |
| 2695 | * reception buffer until which, data are available) |
2695 | * @brief Reception Event Callback (Rx event notification called after use of advanced reception service). |
| 2696 | * @retval None |
2696 | * @param huart UART handle |
| 2697 | */ |
2697 | * @param Size Number of data available in application reception buffer (indicates a position in |
| 2698 | __weak void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size) |
2698 | * reception buffer until which, data are available) |
| 2699 | { |
2699 | * @retval None |
| 2700 | /* Prevent unused argument(s) compilation warning */ |
2700 | */ |
| 2701 | UNUSED(huart); |
2701 | __weak void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size) |
| 2702 | UNUSED(Size); |
2702 | { |
| 2703 | 2703 | /* Prevent unused argument(s) compilation warning */ |
|
| 2704 | /* NOTE : This function should not be modified, when the callback is needed, |
2704 | UNUSED(huart); |
| 2705 | the HAL_UARTEx_RxEventCallback can be implemented in the user file. |
2705 | UNUSED(Size); |
| 2706 | */ |
2706 | |
| 2707 | } |
2707 | /* NOTE : This function should not be modified, when the callback is needed, |
| 2708 | 2708 | the HAL_UARTEx_RxEventCallback can be implemented in the user file. |
|
| 2709 | /** |
2709 | */ |
| 2710 | * @} |
2710 | } |
| 2711 | */ |
2711 | |
| 2712 | 2712 | /** |
|
| 2713 | /** @defgroup UART_Exported_Functions_Group3 Peripheral Control functions |
2713 | * @} |
| 2714 | * @brief UART control functions |
2714 | */ |
| 2715 | * |
2715 | |
| 2716 | @verbatim |
2716 | /** @defgroup UART_Exported_Functions_Group3 Peripheral Control functions |
| 2717 | ============================================================================== |
2717 | * @brief UART control functions |
| 2718 | ##### Peripheral Control functions ##### |
2718 | * |
| 2719 | ============================================================================== |
2719 | @verbatim |
| 2720 | [..] |
2720 | ============================================================================== |
| 2721 | This subsection provides a set of functions allowing to control the UART: |
2721 | ##### Peripheral Control functions ##### |
| 2722 | (+) HAL_LIN_SendBreak() API can be helpful to transmit the break character. |
2722 | ============================================================================== |
| 2723 | (+) HAL_MultiProcessor_EnterMuteMode() API can be helpful to enter the UART in mute mode. |
2723 | [..] |
| 2724 | (+) HAL_MultiProcessor_ExitMuteMode() API can be helpful to exit the UART mute mode by software. |
2724 | This subsection provides a set of functions allowing to control the UART: |
| 2725 | (+) HAL_HalfDuplex_EnableTransmitter() API to enable the UART transmitter and disables the UART receiver in Half Duplex mode |
2725 | (+) HAL_LIN_SendBreak() API can be helpful to transmit the break character. |
| 2726 | (+) HAL_HalfDuplex_EnableReceiver() API to enable the UART receiver and disables the UART transmitter in Half Duplex mode |
2726 | (+) HAL_MultiProcessor_EnterMuteMode() API can be helpful to enter the UART in mute mode. |
| 2727 | 2727 | (+) HAL_MultiProcessor_ExitMuteMode() API can be helpful to exit the UART mute mode by software. |
|
| 2728 | @endverbatim |
2728 | (+) HAL_HalfDuplex_EnableTransmitter() API to enable the UART transmitter and disables the UART receiver in Half Duplex mode |
| 2729 | * @{ |
2729 | (+) HAL_HalfDuplex_EnableReceiver() API to enable the UART receiver and disables the UART transmitter in Half Duplex mode |
| 2730 | */ |
2730 | |
| 2731 | 2731 | @endverbatim |
|
| 2732 | /** |
2732 | * @{ |
| 2733 | * @brief Transmits break characters. |
2733 | */ |
| 2734 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
2734 | |
| 2735 | * the configuration information for the specified UART module. |
2735 | /** |
| 2736 | * @retval HAL status |
2736 | * @brief Transmits break characters. |
| 2737 | */ |
2737 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
| 2738 | HAL_StatusTypeDef HAL_LIN_SendBreak(UART_HandleTypeDef *huart) |
2738 | * the configuration information for the specified UART module. |
| 2739 | { |
2739 | * @retval HAL status |
| 2740 | /* Check the parameters */ |
2740 | */ |
| 2741 | assert_param(IS_UART_INSTANCE(huart->Instance)); |
2741 | HAL_StatusTypeDef HAL_LIN_SendBreak(UART_HandleTypeDef *huart) |
| 2742 | 2742 | { |
|
| 2743 | /* Process Locked */ |
2743 | /* Check the parameters */ |
| 2744 | __HAL_LOCK(huart); |
2744 | assert_param(IS_UART_INSTANCE(huart->Instance)); |
| 2745 | 2745 | ||
| 2746 | huart->gState = HAL_UART_STATE_BUSY; |
2746 | /* Process Locked */ |
| 2747 | 2747 | __HAL_LOCK(huart); |
|
| 2748 | /* Send break characters */ |
2748 | |
| 2749 | SET_BIT(huart->Instance->CR1, USART_CR1_SBK); |
2749 | huart->gState = HAL_UART_STATE_BUSY; |
| 2750 | 2750 | ||
| 2751 | huart->gState = HAL_UART_STATE_READY; |
2751 | /* Send break characters */ |
| 2752 | 2752 | ATOMIC_SET_BIT(huart->Instance->CR1, USART_CR1_SBK); |
|
| 2753 | /* Process Unlocked */ |
2753 | |
| 2754 | __HAL_UNLOCK(huart); |
2754 | huart->gState = HAL_UART_STATE_READY; |
| 2755 | 2755 | ||
| 2756 | return HAL_OK; |
2756 | /* Process Unlocked */ |
| 2757 | } |
2757 | __HAL_UNLOCK(huart); |
| 2758 | 2758 | ||
| 2759 | /** |
2759 | return HAL_OK; |
| 2760 | * @brief Enters the UART in mute mode. |
2760 | } |
| 2761 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
2761 | |
| 2762 | * the configuration information for the specified UART module. |
2762 | /** |
| 2763 | * @retval HAL status |
2763 | * @brief Enters the UART in mute mode. |
| 2764 | */ |
2764 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
| 2765 | HAL_StatusTypeDef HAL_MultiProcessor_EnterMuteMode(UART_HandleTypeDef *huart) |
2765 | * the configuration information for the specified UART module. |
| 2766 | { |
2766 | * @retval HAL status |
| 2767 | /* Check the parameters */ |
2767 | */ |
| 2768 | assert_param(IS_UART_INSTANCE(huart->Instance)); |
2768 | HAL_StatusTypeDef HAL_MultiProcessor_EnterMuteMode(UART_HandleTypeDef *huart) |
| 2769 | 2769 | { |
|
| 2770 | /* Process Locked */ |
2770 | /* Check the parameters */ |
| 2771 | __HAL_LOCK(huart); |
2771 | assert_param(IS_UART_INSTANCE(huart->Instance)); |
| 2772 | 2772 | ||
| 2773 | huart->gState = HAL_UART_STATE_BUSY; |
2773 | /* Process Locked */ |
| 2774 | 2774 | __HAL_LOCK(huart); |
|
| 2775 | /* Enable the USART mute mode by setting the RWU bit in the CR1 register */ |
2775 | |
| 2776 | SET_BIT(huart->Instance->CR1, USART_CR1_RWU); |
2776 | huart->gState = HAL_UART_STATE_BUSY; |
| 2777 | 2777 | ||
| 2778 | huart->gState = HAL_UART_STATE_READY; |
2778 | /* Enable the USART mute mode by setting the RWU bit in the CR1 register */ |
| 2779 | 2779 | ATOMIC_SET_BIT(huart->Instance->CR1, USART_CR1_RWU); |
|
| 2780 | /* Process Unlocked */ |
2780 | |
| 2781 | __HAL_UNLOCK(huart); |
2781 | huart->gState = HAL_UART_STATE_READY; |
| 2782 | 2782 | huart->RxEventType = HAL_UART_RXEVENT_TC; |
|
| 2783 | return HAL_OK; |
2783 | |
| 2784 | } |
2784 | /* Process Unlocked */ |
| 2785 | 2785 | __HAL_UNLOCK(huart); |
|
| 2786 | /** |
2786 | |
| 2787 | * @brief Exits the UART mute mode: wake up software. |
2787 | return HAL_OK; |
| 2788 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
2788 | } |
| 2789 | * the configuration information for the specified UART module. |
2789 | |
| 2790 | * @retval HAL status |
2790 | /** |
| 2791 | */ |
2791 | * @brief Exits the UART mute mode: wake up software. |
| 2792 | HAL_StatusTypeDef HAL_MultiProcessor_ExitMuteMode(UART_HandleTypeDef *huart) |
2792 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
| 2793 | { |
2793 | * the configuration information for the specified UART module. |
| 2794 | /* Check the parameters */ |
2794 | * @retval HAL status |
| 2795 | assert_param(IS_UART_INSTANCE(huart->Instance)); |
2795 | */ |
| 2796 | 2796 | HAL_StatusTypeDef HAL_MultiProcessor_ExitMuteMode(UART_HandleTypeDef *huart) |
|
| 2797 | /* Process Locked */ |
2797 | { |
| 2798 | __HAL_LOCK(huart); |
2798 | /* Check the parameters */ |
| 2799 | 2799 | assert_param(IS_UART_INSTANCE(huart->Instance)); |
|
| 2800 | huart->gState = HAL_UART_STATE_BUSY; |
2800 | |
| 2801 | 2801 | /* Process Locked */ |
|
| 2802 | /* Disable the USART mute mode by clearing the RWU bit in the CR1 register */ |
2802 | __HAL_LOCK(huart); |
| 2803 | CLEAR_BIT(huart->Instance->CR1, USART_CR1_RWU); |
2803 | |
| 2804 | 2804 | huart->gState = HAL_UART_STATE_BUSY; |
|
| 2805 | huart->gState = HAL_UART_STATE_READY; |
2805 | |
| 2806 | 2806 | /* Disable the USART mute mode by clearing the RWU bit in the CR1 register */ |
|
| 2807 | /* Process Unlocked */ |
2807 | ATOMIC_CLEAR_BIT(huart->Instance->CR1, USART_CR1_RWU); |
| 2808 | __HAL_UNLOCK(huart); |
2808 | |
| 2809 | 2809 | huart->gState = HAL_UART_STATE_READY; |
|
| 2810 | return HAL_OK; |
2810 | huart->RxEventType = HAL_UART_RXEVENT_TC; |
| 2811 | } |
2811 | |
| 2812 | 2812 | /* Process Unlocked */ |
|
| 2813 | /** |
2813 | __HAL_UNLOCK(huart); |
| 2814 | * @brief Enables the UART transmitter and disables the UART receiver. |
2814 | |
| 2815 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
2815 | return HAL_OK; |
| 2816 | * the configuration information for the specified UART module. |
2816 | } |
| 2817 | * @retval HAL status |
2817 | |
| 2818 | */ |
2818 | /** |
| 2819 | HAL_StatusTypeDef HAL_HalfDuplex_EnableTransmitter(UART_HandleTypeDef *huart) |
2819 | * @brief Enables the UART transmitter and disables the UART receiver. |
| 2820 | { |
2820 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
| 2821 | uint32_t tmpreg = 0x00U; |
2821 | * the configuration information for the specified UART module. |
| 2822 | 2822 | * @retval HAL status |
|
| 2823 | /* Process Locked */ |
2823 | */ |
| 2824 | __HAL_LOCK(huart); |
2824 | HAL_StatusTypeDef HAL_HalfDuplex_EnableTransmitter(UART_HandleTypeDef *huart) |
| 2825 | 2825 | { |
|
| 2826 | huart->gState = HAL_UART_STATE_BUSY; |
2826 | uint32_t tmpreg = 0x00U; |
| 2827 | 2827 | ||
| 2828 | /*-------------------------- USART CR1 Configuration -----------------------*/ |
2828 | /* Process Locked */ |
| 2829 | tmpreg = huart->Instance->CR1; |
2829 | __HAL_LOCK(huart); |
| 2830 | 2830 | ||
| 2831 | /* Clear TE and RE bits */ |
2831 | huart->gState = HAL_UART_STATE_BUSY; |
| 2832 | tmpreg &= (uint32_t)~((uint32_t)(USART_CR1_TE | USART_CR1_RE)); |
2832 | |
| 2833 | 2833 | /*-------------------------- USART CR1 Configuration -----------------------*/ |
|
| 2834 | /* Enable the USART's transmit interface by setting the TE bit in the USART CR1 register */ |
2834 | tmpreg = huart->Instance->CR1; |
| 2835 | tmpreg |= (uint32_t)USART_CR1_TE; |
2835 | |
| 2836 | 2836 | /* Clear TE and RE bits */ |
|
| 2837 | /* Write to USART CR1 */ |
2837 | tmpreg &= (uint32_t)~((uint32_t)(USART_CR1_TE | USART_CR1_RE)); |
| 2838 | WRITE_REG(huart->Instance->CR1, (uint32_t)tmpreg); |
2838 | |
| 2839 | 2839 | /* Enable the USART's transmit interface by setting the TE bit in the USART CR1 register */ |
|
| 2840 | huart->gState = HAL_UART_STATE_READY; |
2840 | tmpreg |= (uint32_t)USART_CR1_TE; |
| 2841 | 2841 | ||
| 2842 | /* Process Unlocked */ |
2842 | /* Write to USART CR1 */ |
| 2843 | __HAL_UNLOCK(huart); |
2843 | WRITE_REG(huart->Instance->CR1, (uint32_t)tmpreg); |
| 2844 | 2844 | ||
| 2845 | return HAL_OK; |
2845 | huart->gState = HAL_UART_STATE_READY; |
| 2846 | } |
2846 | |
| 2847 | 2847 | /* Process Unlocked */ |
|
| 2848 | /** |
2848 | __HAL_UNLOCK(huart); |
| 2849 | * @brief Enables the UART receiver and disables the UART transmitter. |
2849 | |
| 2850 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
2850 | return HAL_OK; |
| 2851 | * the configuration information for the specified UART module. |
2851 | } |
| 2852 | * @retval HAL status |
2852 | |
| 2853 | */ |
2853 | /** |
| 2854 | HAL_StatusTypeDef HAL_HalfDuplex_EnableReceiver(UART_HandleTypeDef *huart) |
2854 | * @brief Enables the UART receiver and disables the UART transmitter. |
| 2855 | { |
2855 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
| 2856 | uint32_t tmpreg = 0x00U; |
2856 | * the configuration information for the specified UART module. |
| 2857 | 2857 | * @retval HAL status |
|
| 2858 | /* Process Locked */ |
2858 | */ |
| 2859 | __HAL_LOCK(huart); |
2859 | HAL_StatusTypeDef HAL_HalfDuplex_EnableReceiver(UART_HandleTypeDef *huart) |
| 2860 | 2860 | { |
|
| 2861 | huart->gState = HAL_UART_STATE_BUSY; |
2861 | uint32_t tmpreg = 0x00U; |
| 2862 | 2862 | ||
| 2863 | /*-------------------------- USART CR1 Configuration -----------------------*/ |
2863 | /* Process Locked */ |
| 2864 | tmpreg = huart->Instance->CR1; |
2864 | __HAL_LOCK(huart); |
| 2865 | 2865 | ||
| 2866 | /* Clear TE and RE bits */ |
2866 | huart->gState = HAL_UART_STATE_BUSY; |
| 2867 | tmpreg &= (uint32_t)~((uint32_t)(USART_CR1_TE | USART_CR1_RE)); |
2867 | |
| 2868 | 2868 | /*-------------------------- USART CR1 Configuration -----------------------*/ |
|
| 2869 | /* Enable the USART's receive interface by setting the RE bit in the USART CR1 register */ |
2869 | tmpreg = huart->Instance->CR1; |
| 2870 | tmpreg |= (uint32_t)USART_CR1_RE; |
2870 | |
| 2871 | 2871 | /* Clear TE and RE bits */ |
|
| 2872 | /* Write to USART CR1 */ |
2872 | tmpreg &= (uint32_t)~((uint32_t)(USART_CR1_TE | USART_CR1_RE)); |
| 2873 | WRITE_REG(huart->Instance->CR1, (uint32_t)tmpreg); |
2873 | |
| 2874 | 2874 | /* Enable the USART's receive interface by setting the RE bit in the USART CR1 register */ |
|
| 2875 | huart->gState = HAL_UART_STATE_READY; |
2875 | tmpreg |= (uint32_t)USART_CR1_RE; |
| 2876 | 2876 | ||
| 2877 | /* Process Unlocked */ |
2877 | /* Write to USART CR1 */ |
| 2878 | __HAL_UNLOCK(huart); |
2878 | WRITE_REG(huart->Instance->CR1, (uint32_t)tmpreg); |
| 2879 | 2879 | ||
| 2880 | return HAL_OK; |
2880 | huart->gState = HAL_UART_STATE_READY; |
| 2881 | } |
2881 | |
| 2882 | 2882 | /* Process Unlocked */ |
|
| 2883 | /** |
2883 | __HAL_UNLOCK(huart); |
| 2884 | * @} |
2884 | |
| 2885 | */ |
2885 | return HAL_OK; |
| 2886 | 2886 | } |
|
| 2887 | /** @defgroup UART_Exported_Functions_Group4 Peripheral State and Errors functions |
2887 | |
| 2888 | * @brief UART State and Errors functions |
2888 | /** |
| 2889 | * |
2889 | * @} |
| 2890 | @verbatim |
2890 | */ |
| 2891 | ============================================================================== |
2891 | |
| 2892 | ##### Peripheral State and Errors functions ##### |
2892 | /** @defgroup UART_Exported_Functions_Group4 Peripheral State and Errors functions |
| 2893 | ============================================================================== |
2893 | * @brief UART State and Errors functions |
| 2894 | [..] |
2894 | * |
| 2895 | This subsection provides a set of functions allowing to return the State of |
2895 | @verbatim |
| 2896 | UART communication process, return Peripheral Errors occurred during communication |
2896 | ============================================================================== |
| 2897 | process |
2897 | ##### Peripheral State and Errors functions ##### |
| 2898 | (+) HAL_UART_GetState() API can be helpful to check in run-time the state of the UART peripheral. |
2898 | ============================================================================== |
| 2899 | (+) HAL_UART_GetError() check in run-time errors that could be occurred during communication. |
2899 | [..] |
| 2900 | 2900 | This subsection provides a set of functions allowing to return the State of |
|
| 2901 | @endverbatim |
2901 | UART communication process, return Peripheral Errors occurred during communication |
| 2902 | * @{ |
2902 | process |
| 2903 | */ |
2903 | (+) HAL_UART_GetState() API can be helpful to check in run-time the state of the UART peripheral. |
| 2904 | 2904 | (+) HAL_UART_GetError() check in run-time errors that could be occurred during communication. |
|
| 2905 | /** |
2905 | |
| 2906 | * @brief Returns the UART state. |
2906 | @endverbatim |
| 2907 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
2907 | * @{ |
| 2908 | * the configuration information for the specified UART module. |
2908 | */ |
| 2909 | * @retval HAL state |
2909 | |
| 2910 | */ |
2910 | /** |
| 2911 | HAL_UART_StateTypeDef HAL_UART_GetState(UART_HandleTypeDef *huart) |
2911 | * @brief Returns the UART state. |
| 2912 | { |
2912 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
| 2913 | uint32_t temp1 = 0x00U, temp2 = 0x00U; |
2913 | * the configuration information for the specified UART module. |
| 2914 | temp1 = huart->gState; |
2914 | * @retval HAL state |
| 2915 | temp2 = huart->RxState; |
2915 | */ |
| 2916 | 2916 | HAL_UART_StateTypeDef HAL_UART_GetState(const UART_HandleTypeDef *huart) |
|
| 2917 | return (HAL_UART_StateTypeDef)(temp1 | temp2); |
2917 | { |
| 2918 | } |
2918 | uint32_t temp1 = 0x00U, temp2 = 0x00U; |
| 2919 | 2919 | temp1 = huart->gState; |
|
| 2920 | /** |
2920 | temp2 = huart->RxState; |
| 2921 | * @brief Return the UART error code |
2921 | |
| 2922 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
2922 | return (HAL_UART_StateTypeDef)(temp1 | temp2); |
| 2923 | * the configuration information for the specified UART. |
2923 | } |
| 2924 | * @retval UART Error Code |
2924 | |
| 2925 | */ |
2925 | /** |
| 2926 | uint32_t HAL_UART_GetError(UART_HandleTypeDef *huart) |
2926 | * @brief Return the UART error code |
| 2927 | { |
2927 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
| 2928 | return huart->ErrorCode; |
2928 | * the configuration information for the specified UART. |
| 2929 | } |
2929 | * @retval UART Error Code |
| 2930 | 2930 | */ |
|
| 2931 | /** |
2931 | uint32_t HAL_UART_GetError(const UART_HandleTypeDef *huart) |
| 2932 | * @} |
2932 | { |
| 2933 | */ |
2933 | return huart->ErrorCode; |
| 2934 | 2934 | } |
|
| 2935 | /** |
2935 | |
| 2936 | * @} |
2936 | /** |
| 2937 | */ |
2937 | * @} |
| 2938 | 2938 | */ |
|
| 2939 | /** @defgroup UART_Private_Functions UART Private Functions |
2939 | |
| 2940 | * @{ |
2940 | /** |
| 2941 | */ |
2941 | * @} |
| 2942 | 2942 | */ |
|
| 2943 | /** |
2943 | |
| 2944 | * @brief Initialize the callbacks to their default values. |
2944 | /** @defgroup UART_Private_Functions UART Private Functions |
| 2945 | * @param huart UART handle. |
2945 | * @{ |
| 2946 | * @retval none |
2946 | */ |
| 2947 | */ |
2947 | |
| 2948 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
2948 | /** |
| 2949 | void UART_InitCallbacksToDefault(UART_HandleTypeDef *huart) |
2949 | * @brief Initialize the callbacks to their default values. |
| 2950 | { |
2950 | * @param huart UART handle. |
| 2951 | /* Init the UART Callback settings */ |
2951 | * @retval none |
| 2952 | huart->TxHalfCpltCallback = HAL_UART_TxHalfCpltCallback; /* Legacy weak TxHalfCpltCallback */ |
2952 | */ |
| 2953 | huart->TxCpltCallback = HAL_UART_TxCpltCallback; /* Legacy weak TxCpltCallback */ |
2953 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
| 2954 | huart->RxHalfCpltCallback = HAL_UART_RxHalfCpltCallback; /* Legacy weak RxHalfCpltCallback */ |
2954 | void UART_InitCallbacksToDefault(UART_HandleTypeDef *huart) |
| 2955 | huart->RxCpltCallback = HAL_UART_RxCpltCallback; /* Legacy weak RxCpltCallback */ |
2955 | { |
| 2956 | huart->ErrorCallback = HAL_UART_ErrorCallback; /* Legacy weak ErrorCallback */ |
2956 | /* Init the UART Callback settings */ |
| 2957 | huart->AbortCpltCallback = HAL_UART_AbortCpltCallback; /* Legacy weak AbortCpltCallback */ |
2957 | huart->TxHalfCpltCallback = HAL_UART_TxHalfCpltCallback; /* Legacy weak TxHalfCpltCallback */ |
| 2958 | huart->AbortTransmitCpltCallback = HAL_UART_AbortTransmitCpltCallback; /* Legacy weak AbortTransmitCpltCallback */ |
2958 | huart->TxCpltCallback = HAL_UART_TxCpltCallback; /* Legacy weak TxCpltCallback */ |
| 2959 | huart->AbortReceiveCpltCallback = HAL_UART_AbortReceiveCpltCallback; /* Legacy weak AbortReceiveCpltCallback */ |
2959 | huart->RxHalfCpltCallback = HAL_UART_RxHalfCpltCallback; /* Legacy weak RxHalfCpltCallback */ |
| 2960 | huart->RxEventCallback = HAL_UARTEx_RxEventCallback; /* Legacy weak RxEventCallback */ |
2960 | huart->RxCpltCallback = HAL_UART_RxCpltCallback; /* Legacy weak RxCpltCallback */ |
| 2961 | 2961 | huart->ErrorCallback = HAL_UART_ErrorCallback; /* Legacy weak ErrorCallback */ |
|
| 2962 | } |
2962 | huart->AbortCpltCallback = HAL_UART_AbortCpltCallback; /* Legacy weak AbortCpltCallback */ |
| 2963 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
2963 | huart->AbortTransmitCpltCallback = HAL_UART_AbortTransmitCpltCallback; /* Legacy weak AbortTransmitCpltCallback */ |
| 2964 | 2964 | huart->AbortReceiveCpltCallback = HAL_UART_AbortReceiveCpltCallback; /* Legacy weak AbortReceiveCpltCallback */ |
|
| 2965 | /** |
2965 | huart->RxEventCallback = HAL_UARTEx_RxEventCallback; /* Legacy weak RxEventCallback */ |
| 2966 | * @brief DMA UART transmit process complete callback. |
2966 | |
| 2967 | * @param hdma Pointer to a DMA_HandleTypeDef structure that contains |
2967 | } |
| 2968 | * the configuration information for the specified DMA module. |
2968 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
| 2969 | * @retval None |
2969 | |
| 2970 | */ |
2970 | /** |
| 2971 | static void UART_DMATransmitCplt(DMA_HandleTypeDef *hdma) |
2971 | * @brief DMA UART transmit process complete callback. |
| 2972 | { |
2972 | * @param hdma Pointer to a DMA_HandleTypeDef structure that contains |
| 2973 | UART_HandleTypeDef *huart = (UART_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
2973 | * the configuration information for the specified DMA module. |
| 2974 | /* DMA Normal mode*/ |
2974 | * @retval None |
| 2975 | if ((hdma->Instance->CCR & DMA_CCR_CIRC) == 0U) |
2975 | */ |
| 2976 | { |
2976 | static void UART_DMATransmitCplt(DMA_HandleTypeDef *hdma) |
| 2977 | huart->TxXferCount = 0x00U; |
2977 | { |
| 2978 | 2978 | UART_HandleTypeDef *huart = (UART_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
|
| 2979 | /* Disable the DMA transfer for transmit request by setting the DMAT bit |
2979 | /* DMA Normal mode*/ |
| 2980 | in the UART CR3 register */ |
2980 | if ((hdma->Instance->CCR & DMA_CCR_CIRC) == 0U) |
| 2981 | CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAT); |
2981 | { |
| 2982 | 2982 | huart->TxXferCount = 0x00U; |
|
| 2983 | /* Enable the UART Transmit Complete Interrupt */ |
2983 | |
| 2984 | SET_BIT(huart->Instance->CR1, USART_CR1_TCIE); |
2984 | /* Disable the DMA transfer for transmit request by setting the DMAT bit |
| 2985 | 2985 | in the UART CR3 register */ |
|
| 2986 | } |
2986 | ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAT); |
| 2987 | /* DMA Circular mode */ |
2987 | |
| 2988 | else |
2988 | /* Enable the UART Transmit Complete Interrupt */ |
| 2989 | { |
2989 | ATOMIC_SET_BIT(huart->Instance->CR1, USART_CR1_TCIE); |
| 2990 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
2990 | |
| 2991 | /*Call registered Tx complete callback*/ |
2991 | } |
| 2992 | huart->TxCpltCallback(huart); |
2992 | /* DMA Circular mode */ |
| 2993 | #else |
2993 | else |
| 2994 | /*Call legacy weak Tx complete callback*/ |
2994 | { |
| 2995 | HAL_UART_TxCpltCallback(huart); |
2995 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
| 2996 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
2996 | /*Call registered Tx complete callback*/ |
| 2997 | } |
2997 | huart->TxCpltCallback(huart); |
| 2998 | } |
2998 | #else |
| 2999 | 2999 | /*Call legacy weak Tx complete callback*/ |
|
| 3000 | /** |
3000 | HAL_UART_TxCpltCallback(huart); |
| 3001 | * @brief DMA UART transmit process half complete callback |
3001 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
| 3002 | * @param hdma Pointer to a DMA_HandleTypeDef structure that contains |
3002 | } |
| 3003 | * the configuration information for the specified DMA module. |
3003 | } |
| 3004 | * @retval None |
3004 | |
| 3005 | */ |
3005 | /** |
| 3006 | static void UART_DMATxHalfCplt(DMA_HandleTypeDef *hdma) |
3006 | * @brief DMA UART transmit process half complete callback |
| 3007 | { |
3007 | * @param hdma Pointer to a DMA_HandleTypeDef structure that contains |
| 3008 | UART_HandleTypeDef *huart = (UART_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
3008 | * the configuration information for the specified DMA module. |
| 3009 | 3009 | * @retval None |
|
| 3010 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
3010 | */ |
| 3011 | /*Call registered Tx complete callback*/ |
3011 | static void UART_DMATxHalfCplt(DMA_HandleTypeDef *hdma) |
| 3012 | huart->TxHalfCpltCallback(huart); |
3012 | { |
| 3013 | #else |
3013 | UART_HandleTypeDef *huart = (UART_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
| 3014 | /*Call legacy weak Tx complete callback*/ |
3014 | |
| 3015 | HAL_UART_TxHalfCpltCallback(huart); |
3015 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
| 3016 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
3016 | /*Call registered Tx complete callback*/ |
| 3017 | } |
3017 | huart->TxHalfCpltCallback(huart); |
| 3018 | 3018 | #else |
|
| 3019 | /** |
3019 | /*Call legacy weak Tx complete callback*/ |
| 3020 | * @brief DMA UART receive process complete callback. |
3020 | HAL_UART_TxHalfCpltCallback(huart); |
| 3021 | * @param hdma Pointer to a DMA_HandleTypeDef structure that contains |
3021 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
| 3022 | * the configuration information for the specified DMA module. |
3022 | } |
| 3023 | * @retval None |
3023 | |
| 3024 | */ |
3024 | /** |
| 3025 | static void UART_DMAReceiveCplt(DMA_HandleTypeDef *hdma) |
3025 | * @brief DMA UART receive process complete callback. |
| 3026 | { |
3026 | * @param hdma Pointer to a DMA_HandleTypeDef structure that contains |
| 3027 | UART_HandleTypeDef *huart = (UART_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
3027 | * the configuration information for the specified DMA module. |
| 3028 | /* DMA Normal mode*/ |
3028 | * @retval None |
| 3029 | if ((hdma->Instance->CCR & DMA_CCR_CIRC) == 0U) |
3029 | */ |
| 3030 | { |
3030 | static void UART_DMAReceiveCplt(DMA_HandleTypeDef *hdma) |
| 3031 | huart->RxXferCount = 0U; |
3031 | { |
| 3032 | 3032 | UART_HandleTypeDef *huart = (UART_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
|
| 3033 | /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */ |
3033 | |
| 3034 | CLEAR_BIT(huart->Instance->CR1, USART_CR1_PEIE); |
3034 | /* DMA Normal mode*/ |
| 3035 | CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE); |
3035 | if ((hdma->Instance->CCR & DMA_CCR_CIRC) == 0U) |
| 3036 | 3036 | { |
|
| 3037 | /* Disable the DMA transfer for the receiver request by setting the DMAR bit |
3037 | huart->RxXferCount = 0U; |
| 3038 | in the UART CR3 register */ |
3038 | |
| 3039 | CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR); |
3039 | /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */ |
| 3040 | 3040 | ATOMIC_CLEAR_BIT(huart->Instance->CR1, USART_CR1_PEIE); |
|
| 3041 | /* At end of Rx process, restore huart->RxState to Ready */ |
3041 | ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE); |
| 3042 | huart->RxState = HAL_UART_STATE_READY; |
3042 | |
| 3043 | 3043 | /* Disable the DMA transfer for the receiver request by setting the DMAR bit |
|
| 3044 | /* If Reception till IDLE event has been selected, Disable IDLE Interrupt */ |
3044 | in the UART CR3 register */ |
| 3045 | if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE) |
3045 | ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR); |
| 3046 | { |
3046 | |
| 3047 | CLEAR_BIT(huart->Instance->CR1, USART_CR1_IDLEIE); |
3047 | /* At end of Rx process, restore huart->RxState to Ready */ |
| 3048 | } |
3048 | huart->RxState = HAL_UART_STATE_READY; |
| 3049 | } |
3049 | |
| 3050 | 3050 | /* If Reception till IDLE event has been selected, Disable IDLE Interrupt */ |
|
| 3051 | /* Check current reception Mode : |
3051 | if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE) |
| 3052 | If Reception till IDLE event has been selected : use Rx Event callback */ |
3052 | { |
| 3053 | if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE) |
3053 | ATOMIC_CLEAR_BIT(huart->Instance->CR1, USART_CR1_IDLEIE); |
| 3054 | { |
3054 | } |
| 3055 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
3055 | } |
| 3056 | /*Call registered Rx Event callback*/ |
3056 | |
| 3057 | huart->RxEventCallback(huart, huart->RxXferSize); |
3057 | /* Initialize type of RxEvent that correspond to RxEvent callback execution; |
| 3058 | #else |
3058 | In this case, Rx Event type is Transfer Complete */ |
| 3059 | /*Call legacy weak Rx Event callback*/ |
3059 | huart->RxEventType = HAL_UART_RXEVENT_TC; |
| 3060 | HAL_UARTEx_RxEventCallback(huart, huart->RxXferSize); |
3060 | |
| 3061 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
3061 | /* Check current reception Mode : |
| 3062 | } |
3062 | If Reception till IDLE event has been selected : use Rx Event callback */ |
| 3063 | else |
3063 | if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE) |
| 3064 | { |
3064 | { |
| 3065 | /* In other cases : use Rx Complete callback */ |
3065 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
| 3066 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
3066 | /*Call registered Rx Event callback*/ |
| 3067 | /*Call registered Rx complete callback*/ |
3067 | huart->RxEventCallback(huart, huart->RxXferSize); |
| 3068 | huart->RxCpltCallback(huart); |
3068 | #else |
| 3069 | #else |
3069 | /*Call legacy weak Rx Event callback*/ |
| 3070 | /*Call legacy weak Rx complete callback*/ |
3070 | HAL_UARTEx_RxEventCallback(huart, huart->RxXferSize); |
| 3071 | HAL_UART_RxCpltCallback(huart); |
3071 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
| 3072 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
3072 | } |
| 3073 | } |
3073 | else |
| 3074 | } |
3074 | { |
| 3075 | 3075 | /* In other cases : use Rx Complete callback */ |
|
| 3076 | /** |
3076 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
| 3077 | * @brief DMA UART receive process half complete callback |
3077 | /*Call registered Rx complete callback*/ |
| 3078 | * @param hdma Pointer to a DMA_HandleTypeDef structure that contains |
3078 | huart->RxCpltCallback(huart); |
| 3079 | * the configuration information for the specified DMA module. |
3079 | #else |
| 3080 | * @retval None |
3080 | /*Call legacy weak Rx complete callback*/ |
| 3081 | */ |
3081 | HAL_UART_RxCpltCallback(huart); |
| 3082 | static void UART_DMARxHalfCplt(DMA_HandleTypeDef *hdma) |
3082 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
| 3083 | { |
3083 | } |
| 3084 | UART_HandleTypeDef *huart = (UART_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
3084 | } |
| 3085 | 3085 | ||
| 3086 | /* Check current reception Mode : |
3086 | /** |
| 3087 | If Reception till IDLE event has been selected : use Rx Event callback */ |
3087 | * @brief DMA UART receive process half complete callback |
| 3088 | if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE) |
3088 | * @param hdma Pointer to a DMA_HandleTypeDef structure that contains |
| 3089 | { |
3089 | * the configuration information for the specified DMA module. |
| 3090 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
3090 | * @retval None |
| 3091 | /*Call registered Rx Event callback*/ |
3091 | */ |
| 3092 | huart->RxEventCallback(huart, huart->RxXferSize/2U); |
3092 | static void UART_DMARxHalfCplt(DMA_HandleTypeDef *hdma) |
| 3093 | #else |
3093 | { |
| 3094 | /*Call legacy weak Rx Event callback*/ |
3094 | UART_HandleTypeDef *huart = (UART_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
| 3095 | HAL_UARTEx_RxEventCallback(huart, huart->RxXferSize/2U); |
3095 | |
| 3096 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
3096 | /* Initialize type of RxEvent that correspond to RxEvent callback execution; |
| 3097 | } |
3097 | In this case, Rx Event type is Half Transfer */ |
| 3098 | else |
3098 | huart->RxEventType = HAL_UART_RXEVENT_HT; |
| 3099 | { |
3099 | |
| 3100 | /* In other cases : use Rx Half Complete callback */ |
3100 | /* Check current reception Mode : |
| 3101 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
3101 | If Reception till IDLE event has been selected : use Rx Event callback */ |
| 3102 | /*Call registered Rx Half complete callback*/ |
3102 | if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE) |
| 3103 | huart->RxHalfCpltCallback(huart); |
3103 | { |
| 3104 | #else |
3104 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
| 3105 | /*Call legacy weak Rx Half complete callback*/ |
3105 | /*Call registered Rx Event callback*/ |
| 3106 | HAL_UART_RxHalfCpltCallback(huart); |
3106 | huart->RxEventCallback(huart, huart->RxXferSize / 2U); |
| 3107 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
3107 | #else |
| 3108 | } |
3108 | /*Call legacy weak Rx Event callback*/ |
| 3109 | } |
3109 | HAL_UARTEx_RxEventCallback(huart, huart->RxXferSize / 2U); |
| 3110 | 3110 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
|
| 3111 | /** |
3111 | } |
| 3112 | * @brief DMA UART communication error callback. |
3112 | else |
| 3113 | * @param hdma Pointer to a DMA_HandleTypeDef structure that contains |
3113 | { |
| 3114 | * the configuration information for the specified DMA module. |
3114 | /* In other cases : use Rx Half Complete callback */ |
| 3115 | * @retval None |
3115 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
| 3116 | */ |
3116 | /*Call registered Rx Half complete callback*/ |
| 3117 | static void UART_DMAError(DMA_HandleTypeDef *hdma) |
3117 | huart->RxHalfCpltCallback(huart); |
| 3118 | { |
3118 | #else |
| 3119 | uint32_t dmarequest = 0x00U; |
3119 | /*Call legacy weak Rx Half complete callback*/ |
| 3120 | UART_HandleTypeDef *huart = (UART_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
3120 | HAL_UART_RxHalfCpltCallback(huart); |
| 3121 | 3121 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
|
| 3122 | /* Stop UART DMA Tx request if ongoing */ |
3122 | } |
| 3123 | dmarequest = HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAT); |
3123 | } |
| 3124 | if ((huart->gState == HAL_UART_STATE_BUSY_TX) && dmarequest) |
3124 | |
| 3125 | { |
3125 | /** |
| 3126 | huart->TxXferCount = 0x00U; |
3126 | * @brief DMA UART communication error callback. |
| 3127 | UART_EndTxTransfer(huart); |
3127 | * @param hdma Pointer to a DMA_HandleTypeDef structure that contains |
| 3128 | } |
3128 | * the configuration information for the specified DMA module. |
| 3129 | 3129 | * @retval None |
|
| 3130 | /* Stop UART DMA Rx request if ongoing */ |
3130 | */ |
| 3131 | dmarequest = HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR); |
3131 | static void UART_DMAError(DMA_HandleTypeDef *hdma) |
| 3132 | if ((huart->RxState == HAL_UART_STATE_BUSY_RX) && dmarequest) |
3132 | { |
| 3133 | { |
3133 | uint32_t dmarequest = 0x00U; |
| 3134 | huart->RxXferCount = 0x00U; |
3134 | UART_HandleTypeDef *huart = (UART_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
| 3135 | UART_EndRxTransfer(huart); |
3135 | |
| 3136 | } |
3136 | /* Stop UART DMA Tx request if ongoing */ |
| 3137 | 3137 | dmarequest = HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAT); |
|
| 3138 | huart->ErrorCode |= HAL_UART_ERROR_DMA; |
3138 | if ((huart->gState == HAL_UART_STATE_BUSY_TX) && dmarequest) |
| 3139 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
3139 | { |
| 3140 | /*Call registered error callback*/ |
3140 | huart->TxXferCount = 0x00U; |
| 3141 | huart->ErrorCallback(huart); |
3141 | UART_EndTxTransfer(huart); |
| 3142 | #else |
3142 | } |
| 3143 | /*Call legacy weak error callback*/ |
3143 | |
| 3144 | HAL_UART_ErrorCallback(huart); |
3144 | /* Stop UART DMA Rx request if ongoing */ |
| 3145 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
3145 | dmarequest = HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR); |
| 3146 | } |
3146 | if ((huart->RxState == HAL_UART_STATE_BUSY_RX) && dmarequest) |
| 3147 | 3147 | { |
|
| 3148 | /** |
3148 | huart->RxXferCount = 0x00U; |
| 3149 | * @brief This function handles UART Communication Timeout. |
3149 | UART_EndRxTransfer(huart); |
| 3150 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
3150 | } |
| 3151 | * the configuration information for the specified UART module. |
3151 | |
| 3152 | * @param Flag specifies the UART flag to check. |
3152 | huart->ErrorCode |= HAL_UART_ERROR_DMA; |
| 3153 | * @param Status The new Flag status (SET or RESET). |
3153 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
| 3154 | * @param Tickstart Tick start value |
3154 | /*Call registered error callback*/ |
| 3155 | * @param Timeout Timeout duration |
3155 | huart->ErrorCallback(huart); |
| 3156 | * @retval HAL status |
3156 | #else |
| 3157 | */ |
3157 | /*Call legacy weak error callback*/ |
| 3158 | static HAL_StatusTypeDef UART_WaitOnFlagUntilTimeout(UART_HandleTypeDef *huart, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout) |
3158 | HAL_UART_ErrorCallback(huart); |
| 3159 | { |
3159 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
| 3160 | /* Wait until flag is set */ |
3160 | } |
| 3161 | while ((__HAL_UART_GET_FLAG(huart, Flag) ? SET : RESET) == Status) |
3161 | |
| 3162 | { |
3162 | /** |
| 3163 | /* Check for the Timeout */ |
3163 | * @brief This function handles UART Communication Timeout. It waits |
| 3164 | if (Timeout != HAL_MAX_DELAY) |
3164 | * until a flag is no longer in the specified status. |
| 3165 | { |
3165 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
| 3166 | if ((Timeout == 0U) || ((HAL_GetTick() - Tickstart) > Timeout)) |
3166 | * the configuration information for the specified UART module. |
| 3167 | { |
3167 | * @param Flag specifies the UART flag to check. |
| 3168 | /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */ |
3168 | * @param Status The actual Flag status (SET or RESET). |
| 3169 | CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE)); |
3169 | * @param Tickstart Tick start value |
| 3170 | CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE); |
3170 | * @param Timeout Timeout duration |
| 3171 | 3171 | * @retval HAL status |
|
| 3172 | huart->gState = HAL_UART_STATE_READY; |
3172 | */ |
| 3173 | huart->RxState = HAL_UART_STATE_READY; |
3173 | static HAL_StatusTypeDef UART_WaitOnFlagUntilTimeout(UART_HandleTypeDef *huart, uint32_t Flag, FlagStatus Status, |
| 3174 | 3174 | uint32_t Tickstart, uint32_t Timeout) |
|
| 3175 | /* Process Unlocked */ |
3175 | { |
| 3176 | __HAL_UNLOCK(huart); |
3176 | /* Wait until flag is set */ |
| 3177 | 3177 | while ((__HAL_UART_GET_FLAG(huart, Flag) ? SET : RESET) == Status) |
|
| 3178 | return HAL_TIMEOUT; |
3178 | { |
| 3179 | } |
3179 | /* Check for the Timeout */ |
| 3180 | } |
3180 | if (Timeout != HAL_MAX_DELAY) |
| 3181 | } |
3181 | { |
| 3182 | return HAL_OK; |
3182 | if ((Timeout == 0U) || ((HAL_GetTick() - Tickstart) > Timeout)) |
| 3183 | } |
3183 | { |
| 3184 | 3184 | /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */ |
|
| 3185 | /** |
3185 | ATOMIC_CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE)); |
| 3186 | * @brief Start Receive operation in interrupt mode. |
3186 | ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE); |
| 3187 | * @note This function could be called by all HAL UART API providing reception in Interrupt mode. |
3187 | |
| 3188 | * @note When calling this function, parameters validity is considered as already checked, |
3188 | huart->gState = HAL_UART_STATE_READY; |
| 3189 | * i.e. Rx State, buffer address, ... |
3189 | huart->RxState = HAL_UART_STATE_READY; |
| 3190 | * UART Handle is assumed as Locked. |
3190 | |
| 3191 | * @param huart UART handle. |
3191 | /* Process Unlocked */ |
| 3192 | * @param pData Pointer to data buffer (u8 or u16 data elements). |
3192 | __HAL_UNLOCK(huart); |
| 3193 | * @param Size Amount of data elements (u8 or u16) to be received. |
3193 | |
| 3194 | * @retval HAL status |
3194 | return HAL_TIMEOUT; |
| 3195 | */ |
3195 | } |
| 3196 | HAL_StatusTypeDef UART_Start_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size) |
3196 | } |
| 3197 | { |
3197 | } |
| 3198 | huart->pRxBuffPtr = pData; |
3198 | return HAL_OK; |
| 3199 | huart->RxXferSize = Size; |
3199 | } |
| 3200 | huart->RxXferCount = Size; |
3200 | |
| 3201 | 3201 | /** |
|
| 3202 | huart->ErrorCode = HAL_UART_ERROR_NONE; |
3202 | * @brief Start Receive operation in interrupt mode. |
| 3203 | huart->RxState = HAL_UART_STATE_BUSY_RX; |
3203 | * @note This function could be called by all HAL UART API providing reception in Interrupt mode. |
| 3204 | 3204 | * @note When calling this function, parameters validity is considered as already checked, |
|
| 3205 | /* Process Unlocked */ |
3205 | * i.e. Rx State, buffer address, ... |
| 3206 | __HAL_UNLOCK(huart); |
3206 | * UART Handle is assumed as Locked. |
| 3207 | 3207 | * @param huart UART handle. |
|
| 3208 | /* Enable the UART Parity Error Interrupt */ |
3208 | * @param pData Pointer to data buffer (u8 or u16 data elements). |
| 3209 | __HAL_UART_ENABLE_IT(huart, UART_IT_PE); |
3209 | * @param Size Amount of data elements (u8 or u16) to be received. |
| 3210 | 3210 | * @retval HAL status |
|
| 3211 | /* Enable the UART Error Interrupt: (Frame error, noise error, overrun error) */ |
3211 | */ |
| 3212 | __HAL_UART_ENABLE_IT(huart, UART_IT_ERR); |
3212 | HAL_StatusTypeDef UART_Start_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size) |
| 3213 | 3213 | { |
|
| 3214 | /* Enable the UART Data Register not empty Interrupt */ |
3214 | huart->pRxBuffPtr = pData; |
| 3215 | __HAL_UART_ENABLE_IT(huart, UART_IT_RXNE); |
3215 | huart->RxXferSize = Size; |
| 3216 | 3216 | huart->RxXferCount = Size; |
|
| 3217 | return HAL_OK; |
3217 | |
| 3218 | } |
3218 | huart->ErrorCode = HAL_UART_ERROR_NONE; |
| 3219 | 3219 | huart->RxState = HAL_UART_STATE_BUSY_RX; |
|
| 3220 | /** |
3220 | |
| 3221 | * @brief Start Receive operation in DMA mode. |
3221 | if (huart->Init.Parity != UART_PARITY_NONE) |
| 3222 | * @note This function could be called by all HAL UART API providing reception in DMA mode. |
3222 | { |
| 3223 | * @note When calling this function, parameters validity is considered as already checked, |
3223 | /* Enable the UART Parity Error Interrupt */ |
| 3224 | * i.e. Rx State, buffer address, ... |
3224 | __HAL_UART_ENABLE_IT(huart, UART_IT_PE); |
| 3225 | * UART Handle is assumed as Locked. |
3225 | } |
| 3226 | * @param huart UART handle. |
3226 | |
| 3227 | * @param pData Pointer to data buffer (u8 or u16 data elements). |
3227 | /* Enable the UART Error Interrupt: (Frame error, noise error, overrun error) */ |
| 3228 | * @param Size Amount of data elements (u8 or u16) to be received. |
3228 | __HAL_UART_ENABLE_IT(huart, UART_IT_ERR); |
| 3229 | * @retval HAL status |
3229 | |
| 3230 | */ |
3230 | /* Enable the UART Data Register not empty Interrupt */ |
| 3231 | HAL_StatusTypeDef UART_Start_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size) |
3231 | __HAL_UART_ENABLE_IT(huart, UART_IT_RXNE); |
| 3232 | { |
3232 | |
| 3233 | uint32_t *tmp; |
3233 | return HAL_OK; |
| 3234 | 3234 | } |
|
| 3235 | huart->pRxBuffPtr = pData; |
3235 | |
| 3236 | huart->RxXferSize = Size; |
3236 | /** |
| 3237 | 3237 | * @brief Start Receive operation in DMA mode. |
|
| 3238 | huart->ErrorCode = HAL_UART_ERROR_NONE; |
3238 | * @note This function could be called by all HAL UART API providing reception in DMA mode. |
| 3239 | huart->RxState = HAL_UART_STATE_BUSY_RX; |
3239 | * @note When calling this function, parameters validity is considered as already checked, |
| 3240 | 3240 | * i.e. Rx State, buffer address, ... |
|
| 3241 | /* Set the UART DMA transfer complete callback */ |
3241 | * UART Handle is assumed as Locked. |
| 3242 | huart->hdmarx->XferCpltCallback = UART_DMAReceiveCplt; |
3242 | * @param huart UART handle. |
| 3243 | 3243 | * @param pData Pointer to data buffer (u8 or u16 data elements). |
|
| 3244 | /* Set the UART DMA Half transfer complete callback */ |
3244 | * @param Size Amount of data elements (u8 or u16) to be received. |
| 3245 | huart->hdmarx->XferHalfCpltCallback = UART_DMARxHalfCplt; |
3245 | * @retval HAL status |
| 3246 | 3246 | */ |
|
| 3247 | /* Set the DMA error callback */ |
3247 | HAL_StatusTypeDef UART_Start_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size) |
| 3248 | huart->hdmarx->XferErrorCallback = UART_DMAError; |
3248 | { |
| 3249 | 3249 | uint32_t *tmp; |
|
| 3250 | /* Set the DMA abort callback */ |
3250 | |
| 3251 | huart->hdmarx->XferAbortCallback = NULL; |
3251 | huart->pRxBuffPtr = pData; |
| 3252 | 3252 | huart->RxXferSize = Size; |
|
| 3253 | /* Enable the DMA stream */ |
3253 | |
| 3254 | tmp = (uint32_t *)&pData; |
3254 | huart->ErrorCode = HAL_UART_ERROR_NONE; |
| 3255 | HAL_DMA_Start_IT(huart->hdmarx, (uint32_t)&huart->Instance->DR, *(uint32_t *)tmp, Size); |
3255 | huart->RxState = HAL_UART_STATE_BUSY_RX; |
| 3256 | 3256 | ||
| 3257 | /* Clear the Overrun flag just before enabling the DMA Rx request: can be mandatory for the second transfer */ |
3257 | /* Set the UART DMA transfer complete callback */ |
| 3258 | __HAL_UART_CLEAR_OREFLAG(huart); |
3258 | huart->hdmarx->XferCpltCallback = UART_DMAReceiveCplt; |
| 3259 | 3259 | ||
| 3260 | /* Process Unlocked */ |
3260 | /* Set the UART DMA Half transfer complete callback */ |
| 3261 | __HAL_UNLOCK(huart); |
3261 | huart->hdmarx->XferHalfCpltCallback = UART_DMARxHalfCplt; |
| 3262 | 3262 | ||
| 3263 | /* Enable the UART Parity Error Interrupt */ |
3263 | /* Set the DMA error callback */ |
| 3264 | SET_BIT(huart->Instance->CR1, USART_CR1_PEIE); |
3264 | huart->hdmarx->XferErrorCallback = UART_DMAError; |
| 3265 | 3265 | ||
| 3266 | /* Enable the UART Error Interrupt: (Frame error, noise error, overrun error) */ |
3266 | /* Set the DMA abort callback */ |
| 3267 | SET_BIT(huart->Instance->CR3, USART_CR3_EIE); |
3267 | huart->hdmarx->XferAbortCallback = NULL; |
| 3268 | 3268 | ||
| 3269 | /* Enable the DMA transfer for the receiver request by setting the DMAR bit |
3269 | /* Enable the DMA stream */ |
| 3270 | in the UART CR3 register */ |
3270 | tmp = (uint32_t *)&pData; |
| 3271 | SET_BIT(huart->Instance->CR3, USART_CR3_DMAR); |
3271 | HAL_DMA_Start_IT(huart->hdmarx, (uint32_t)&huart->Instance->DR, *(uint32_t *)tmp, Size); |
| 3272 | 3272 | ||
| 3273 | return HAL_OK; |
3273 | /* Clear the Overrun flag just before enabling the DMA Rx request: can be mandatory for the second transfer */ |
| 3274 | } |
3274 | __HAL_UART_CLEAR_OREFLAG(huart); |
| 3275 | 3275 | ||
| 3276 | /** |
3276 | if (huart->Init.Parity != UART_PARITY_NONE) |
| 3277 | * @brief End ongoing Tx transfer on UART peripheral (following error detection or Transmit completion). |
3277 | { |
| 3278 | * @param huart UART handle. |
3278 | /* Enable the UART Parity Error Interrupt */ |
| 3279 | * @retval None |
3279 | ATOMIC_SET_BIT(huart->Instance->CR1, USART_CR1_PEIE); |
| 3280 | */ |
3280 | } |
| 3281 | static void UART_EndTxTransfer(UART_HandleTypeDef *huart) |
3281 | |
| 3282 | { |
3282 | /* Enable the UART Error Interrupt: (Frame error, noise error, overrun error) */ |
| 3283 | /* Disable TXEIE and TCIE interrupts */ |
3283 | ATOMIC_SET_BIT(huart->Instance->CR3, USART_CR3_EIE); |
| 3284 | CLEAR_BIT(huart->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE)); |
3284 | |
| 3285 | 3285 | /* Enable the DMA transfer for the receiver request by setting the DMAR bit |
|
| 3286 | /* At end of Tx process, restore huart->gState to Ready */ |
3286 | in the UART CR3 register */ |
| 3287 | huart->gState = HAL_UART_STATE_READY; |
3287 | ATOMIC_SET_BIT(huart->Instance->CR3, USART_CR3_DMAR); |
| 3288 | } |
3288 | |
| 3289 | 3289 | return HAL_OK; |
|
| 3290 | /** |
3290 | } |
| 3291 | * @brief End ongoing Rx transfer on UART peripheral (following error detection or Reception completion). |
3291 | |
| 3292 | * @param huart UART handle. |
3292 | /** |
| 3293 | * @retval None |
3293 | * @brief End ongoing Tx transfer on UART peripheral (following error detection or Transmit completion). |
| 3294 | */ |
3294 | * @param huart UART handle. |
| 3295 | static void UART_EndRxTransfer(UART_HandleTypeDef *huart) |
3295 | * @retval None |
| 3296 | { |
3296 | */ |
| 3297 | /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */ |
3297 | static void UART_EndTxTransfer(UART_HandleTypeDef *huart) |
| 3298 | CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE)); |
3298 | { |
| 3299 | CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE); |
3299 | /* Disable TXEIE and TCIE interrupts */ |
| 3300 | 3300 | ATOMIC_CLEAR_BIT(huart->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE)); |
|
| 3301 | /* In case of reception waiting for IDLE event, disable also the IDLE IE interrupt source */ |
3301 | |
| 3302 | if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE) |
3302 | /* At end of Tx process, restore huart->gState to Ready */ |
| 3303 | { |
3303 | huart->gState = HAL_UART_STATE_READY; |
| 3304 | CLEAR_BIT(huart->Instance->CR1, USART_CR1_IDLEIE); |
3304 | } |
| 3305 | } |
3305 | |
| 3306 | 3306 | /** |
|
| 3307 | /* At end of Rx process, restore huart->RxState to Ready */ |
3307 | * @brief End ongoing Rx transfer on UART peripheral (following error detection or Reception completion). |
| 3308 | huart->RxState = HAL_UART_STATE_READY; |
3308 | * @param huart UART handle. |
| 3309 | huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
3309 | * @retval None |
| 3310 | } |
3310 | */ |
| 3311 | 3311 | static void UART_EndRxTransfer(UART_HandleTypeDef *huart) |
|
| 3312 | /** |
3312 | { |
| 3313 | * @brief DMA UART communication abort callback, when initiated by HAL services on Error |
3313 | /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */ |
| 3314 | * (To be called at end of DMA Abort procedure following error occurrence). |
3314 | ATOMIC_CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE)); |
| 3315 | * @param hdma Pointer to a DMA_HandleTypeDef structure that contains |
3315 | ATOMIC_CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE); |
| 3316 | * the configuration information for the specified DMA module. |
3316 | |
| 3317 | * @retval None |
3317 | /* In case of reception waiting for IDLE event, disable also the IDLE IE interrupt source */ |
| 3318 | */ |
3318 | if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE) |
| 3319 | static void UART_DMAAbortOnError(DMA_HandleTypeDef *hdma) |
3319 | { |
| 3320 | { |
3320 | ATOMIC_CLEAR_BIT(huart->Instance->CR1, USART_CR1_IDLEIE); |
| 3321 | UART_HandleTypeDef *huart = (UART_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
3321 | } |
| 3322 | huart->RxXferCount = 0x00U; |
3322 | |
| 3323 | huart->TxXferCount = 0x00U; |
3323 | /* At end of Rx process, restore huart->RxState to Ready */ |
| 3324 | 3324 | huart->RxState = HAL_UART_STATE_READY; |
|
| 3325 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
3325 | huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
| 3326 | /*Call registered error callback*/ |
3326 | } |
| 3327 | huart->ErrorCallback(huart); |
3327 | |
| 3328 | #else |
3328 | /** |
| 3329 | /*Call legacy weak error callback*/ |
3329 | * @brief DMA UART communication abort callback, when initiated by HAL services on Error |
| 3330 | HAL_UART_ErrorCallback(huart); |
3330 | * (To be called at end of DMA Abort procedure following error occurrence). |
| 3331 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
3331 | * @param hdma Pointer to a DMA_HandleTypeDef structure that contains |
| 3332 | } |
3332 | * the configuration information for the specified DMA module. |
| 3333 | 3333 | * @retval None |
|
| 3334 | /** |
3334 | */ |
| 3335 | * @brief DMA UART Tx communication abort callback, when initiated by user |
3335 | static void UART_DMAAbortOnError(DMA_HandleTypeDef *hdma) |
| 3336 | * (To be called at end of DMA Tx Abort procedure following user abort request). |
3336 | { |
| 3337 | * @note When this callback is executed, User Abort complete call back is called only if no |
3337 | UART_HandleTypeDef *huart = (UART_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
| 3338 | * Abort still ongoing for Rx DMA Handle. |
3338 | huart->RxXferCount = 0x00U; |
| 3339 | * @param hdma Pointer to a DMA_HandleTypeDef structure that contains |
3339 | huart->TxXferCount = 0x00U; |
| 3340 | * the configuration information for the specified DMA module. |
3340 | |
| 3341 | * @retval None |
3341 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
| 3342 | */ |
3342 | /*Call registered error callback*/ |
| 3343 | static void UART_DMATxAbortCallback(DMA_HandleTypeDef *hdma) |
3343 | huart->ErrorCallback(huart); |
| 3344 | { |
3344 | #else |
| 3345 | UART_HandleTypeDef *huart = (UART_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
3345 | /*Call legacy weak error callback*/ |
| 3346 | 3346 | HAL_UART_ErrorCallback(huart); |
|
| 3347 | huart->hdmatx->XferAbortCallback = NULL; |
3347 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
| 3348 | 3348 | } |
|
| 3349 | /* Check if an Abort process is still ongoing */ |
3349 | |
| 3350 | if (huart->hdmarx != NULL) |
3350 | /** |
| 3351 | { |
3351 | * @brief DMA UART Tx communication abort callback, when initiated by user |
| 3352 | if (huart->hdmarx->XferAbortCallback != NULL) |
3352 | * (To be called at end of DMA Tx Abort procedure following user abort request). |
| 3353 | { |
3353 | * @note When this callback is executed, User Abort complete call back is called only if no |
| 3354 | return; |
3354 | * Abort still ongoing for Rx DMA Handle. |
| 3355 | } |
3355 | * @param hdma Pointer to a DMA_HandleTypeDef structure that contains |
| 3356 | } |
3356 | * the configuration information for the specified DMA module. |
| 3357 | 3357 | * @retval None |
|
| 3358 | /* No Abort process still ongoing : All DMA channels are aborted, call user Abort Complete callback */ |
3358 | */ |
| 3359 | huart->TxXferCount = 0x00U; |
3359 | static void UART_DMATxAbortCallback(DMA_HandleTypeDef *hdma) |
| 3360 | huart->RxXferCount = 0x00U; |
3360 | { |
| 3361 | 3361 | UART_HandleTypeDef *huart = (UART_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
|
| 3362 | /* Reset ErrorCode */ |
3362 | |
| 3363 | huart->ErrorCode = HAL_UART_ERROR_NONE; |
3363 | huart->hdmatx->XferAbortCallback = NULL; |
| 3364 | 3364 | ||
| 3365 | /* Restore huart->gState and huart->RxState to Ready */ |
3365 | /* Check if an Abort process is still ongoing */ |
| 3366 | huart->gState = HAL_UART_STATE_READY; |
3366 | if (huart->hdmarx != NULL) |
| 3367 | huart->RxState = HAL_UART_STATE_READY; |
3367 | { |
| 3368 | huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
3368 | if (huart->hdmarx->XferAbortCallback != NULL) |
| 3369 | 3369 | { |
|
| 3370 | /* Call user Abort complete callback */ |
3370 | return; |
| 3371 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
3371 | } |
| 3372 | /* Call registered Abort complete callback */ |
3372 | } |
| 3373 | huart->AbortCpltCallback(huart); |
3373 | |
| 3374 | #else |
3374 | /* No Abort process still ongoing : All DMA channels are aborted, call user Abort Complete callback */ |
| 3375 | /* Call legacy weak Abort complete callback */ |
3375 | huart->TxXferCount = 0x00U; |
| 3376 | HAL_UART_AbortCpltCallback(huart); |
3376 | huart->RxXferCount = 0x00U; |
| 3377 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
3377 | |
| 3378 | } |
3378 | /* Reset ErrorCode */ |
| 3379 | 3379 | huart->ErrorCode = HAL_UART_ERROR_NONE; |
|
| 3380 | /** |
3380 | |
| 3381 | * @brief DMA UART Rx communication abort callback, when initiated by user |
3381 | /* Restore huart->gState and huart->RxState to Ready */ |
| 3382 | * (To be called at end of DMA Rx Abort procedure following user abort request). |
3382 | huart->gState = HAL_UART_STATE_READY; |
| 3383 | * @note When this callback is executed, User Abort complete call back is called only if no |
3383 | huart->RxState = HAL_UART_STATE_READY; |
| 3384 | * Abort still ongoing for Tx DMA Handle. |
3384 | huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
| 3385 | * @param hdma Pointer to a DMA_HandleTypeDef structure that contains |
3385 | |
| 3386 | * the configuration information for the specified DMA module. |
3386 | /* Call user Abort complete callback */ |
| 3387 | * @retval None |
3387 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
| 3388 | */ |
3388 | /* Call registered Abort complete callback */ |
| 3389 | static void UART_DMARxAbortCallback(DMA_HandleTypeDef *hdma) |
3389 | huart->AbortCpltCallback(huart); |
| 3390 | { |
3390 | #else |
| 3391 | UART_HandleTypeDef *huart = (UART_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
3391 | /* Call legacy weak Abort complete callback */ |
| 3392 | 3392 | HAL_UART_AbortCpltCallback(huart); |
|
| 3393 | huart->hdmarx->XferAbortCallback = NULL; |
3393 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
| 3394 | 3394 | } |
|
| 3395 | /* Check if an Abort process is still ongoing */ |
3395 | |
| 3396 | if (huart->hdmatx != NULL) |
3396 | /** |
| 3397 | { |
3397 | * @brief DMA UART Rx communication abort callback, when initiated by user |
| 3398 | if (huart->hdmatx->XferAbortCallback != NULL) |
3398 | * (To be called at end of DMA Rx Abort procedure following user abort request). |
| 3399 | { |
3399 | * @note When this callback is executed, User Abort complete call back is called only if no |
| 3400 | return; |
3400 | * Abort still ongoing for Tx DMA Handle. |
| 3401 | } |
3401 | * @param hdma Pointer to a DMA_HandleTypeDef structure that contains |
| 3402 | } |
3402 | * the configuration information for the specified DMA module. |
| 3403 | 3403 | * @retval None |
|
| 3404 | /* No Abort process still ongoing : All DMA channels are aborted, call user Abort Complete callback */ |
3404 | */ |
| 3405 | huart->TxXferCount = 0x00U; |
3405 | static void UART_DMARxAbortCallback(DMA_HandleTypeDef *hdma) |
| 3406 | huart->RxXferCount = 0x00U; |
3406 | { |
| 3407 | 3407 | UART_HandleTypeDef *huart = (UART_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
|
| 3408 | /* Reset ErrorCode */ |
3408 | |
| 3409 | huart->ErrorCode = HAL_UART_ERROR_NONE; |
3409 | huart->hdmarx->XferAbortCallback = NULL; |
| 3410 | 3410 | ||
| 3411 | /* Restore huart->gState and huart->RxState to Ready */ |
3411 | /* Check if an Abort process is still ongoing */ |
| 3412 | huart->gState = HAL_UART_STATE_READY; |
3412 | if (huart->hdmatx != NULL) |
| 3413 | huart->RxState = HAL_UART_STATE_READY; |
3413 | { |
| 3414 | huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
3414 | if (huart->hdmatx->XferAbortCallback != NULL) |
| 3415 | 3415 | { |
|
| 3416 | /* Call user Abort complete callback */ |
3416 | return; |
| 3417 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
3417 | } |
| 3418 | /* Call registered Abort complete callback */ |
3418 | } |
| 3419 | huart->AbortCpltCallback(huart); |
3419 | |
| 3420 | #else |
3420 | /* No Abort process still ongoing : All DMA channels are aborted, call user Abort Complete callback */ |
| 3421 | /* Call legacy weak Abort complete callback */ |
3421 | huart->TxXferCount = 0x00U; |
| 3422 | HAL_UART_AbortCpltCallback(huart); |
3422 | huart->RxXferCount = 0x00U; |
| 3423 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
3423 | |
| 3424 | } |
3424 | /* Reset ErrorCode */ |
| 3425 | 3425 | huart->ErrorCode = HAL_UART_ERROR_NONE; |
|
| 3426 | /** |
3426 | |
| 3427 | * @brief DMA UART Tx communication abort callback, when initiated by user by a call to |
3427 | /* Restore huart->gState and huart->RxState to Ready */ |
| 3428 | * HAL_UART_AbortTransmit_IT API (Abort only Tx transfer) |
3428 | huart->gState = HAL_UART_STATE_READY; |
| 3429 | * (This callback is executed at end of DMA Tx Abort procedure following user abort request, |
3429 | huart->RxState = HAL_UART_STATE_READY; |
| 3430 | * and leads to user Tx Abort Complete callback execution). |
3430 | huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
| 3431 | * @param hdma Pointer to a DMA_HandleTypeDef structure that contains |
3431 | |
| 3432 | * the configuration information for the specified DMA module. |
3432 | /* Call user Abort complete callback */ |
| 3433 | * @retval None |
3433 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
| 3434 | */ |
3434 | /* Call registered Abort complete callback */ |
| 3435 | static void UART_DMATxOnlyAbortCallback(DMA_HandleTypeDef *hdma) |
3435 | huart->AbortCpltCallback(huart); |
| 3436 | { |
3436 | #else |
| 3437 | UART_HandleTypeDef *huart = (UART_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
3437 | /* Call legacy weak Abort complete callback */ |
| 3438 | 3438 | HAL_UART_AbortCpltCallback(huart); |
|
| 3439 | huart->TxXferCount = 0x00U; |
3439 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
| 3440 | 3440 | } |
|
| 3441 | /* Restore huart->gState to Ready */ |
3441 | |
| 3442 | huart->gState = HAL_UART_STATE_READY; |
3442 | /** |
| 3443 | 3443 | * @brief DMA UART Tx communication abort callback, when initiated by user by a call to |
|
| 3444 | /* Call user Abort complete callback */ |
3444 | * HAL_UART_AbortTransmit_IT API (Abort only Tx transfer) |
| 3445 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
3445 | * (This callback is executed at end of DMA Tx Abort procedure following user abort request, |
| 3446 | /* Call registered Abort Transmit Complete Callback */ |
3446 | * and leads to user Tx Abort Complete callback execution). |
| 3447 | huart->AbortTransmitCpltCallback(huart); |
3447 | * @param hdma Pointer to a DMA_HandleTypeDef structure that contains |
| 3448 | #else |
3448 | * the configuration information for the specified DMA module. |
| 3449 | /* Call legacy weak Abort Transmit Complete Callback */ |
3449 | * @retval None |
| 3450 | HAL_UART_AbortTransmitCpltCallback(huart); |
3450 | */ |
| 3451 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
3451 | static void UART_DMATxOnlyAbortCallback(DMA_HandleTypeDef *hdma) |
| 3452 | } |
3452 | { |
| 3453 | 3453 | UART_HandleTypeDef *huart = (UART_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
|
| 3454 | /** |
3454 | |
| 3455 | * @brief DMA UART Rx communication abort callback, when initiated by user by a call to |
3455 | huart->TxXferCount = 0x00U; |
| 3456 | * HAL_UART_AbortReceive_IT API (Abort only Rx transfer) |
3456 | |
| 3457 | * (This callback is executed at end of DMA Rx Abort procedure following user abort request, |
3457 | /* Restore huart->gState to Ready */ |
| 3458 | * and leads to user Rx Abort Complete callback execution). |
3458 | huart->gState = HAL_UART_STATE_READY; |
| 3459 | * @param hdma Pointer to a DMA_HandleTypeDef structure that contains |
3459 | |
| 3460 | * the configuration information for the specified DMA module. |
3460 | /* Call user Abort complete callback */ |
| 3461 | * @retval None |
3461 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
| 3462 | */ |
3462 | /* Call registered Abort Transmit Complete Callback */ |
| 3463 | static void UART_DMARxOnlyAbortCallback(DMA_HandleTypeDef *hdma) |
3463 | huart->AbortTransmitCpltCallback(huart); |
| 3464 | { |
3464 | #else |
| 3465 | UART_HandleTypeDef *huart = (UART_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
3465 | /* Call legacy weak Abort Transmit Complete Callback */ |
| 3466 | 3466 | HAL_UART_AbortTransmitCpltCallback(huart); |
|
| 3467 | huart->RxXferCount = 0x00U; |
3467 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
| 3468 | 3468 | } |
|
| 3469 | /* Restore huart->RxState to Ready */ |
3469 | |
| 3470 | huart->RxState = HAL_UART_STATE_READY; |
3470 | /** |
| 3471 | huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
3471 | * @brief DMA UART Rx communication abort callback, when initiated by user by a call to |
| 3472 | 3472 | * HAL_UART_AbortReceive_IT API (Abort only Rx transfer) |
|
| 3473 | /* Call user Abort complete callback */ |
3473 | * (This callback is executed at end of DMA Rx Abort procedure following user abort request, |
| 3474 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
3474 | * and leads to user Rx Abort Complete callback execution). |
| 3475 | /* Call registered Abort Receive Complete Callback */ |
3475 | * @param hdma Pointer to a DMA_HandleTypeDef structure that contains |
| 3476 | huart->AbortReceiveCpltCallback(huart); |
3476 | * the configuration information for the specified DMA module. |
| 3477 | #else |
3477 | * @retval None |
| 3478 | /* Call legacy weak Abort Receive Complete Callback */ |
3478 | */ |
| 3479 | HAL_UART_AbortReceiveCpltCallback(huart); |
3479 | static void UART_DMARxOnlyAbortCallback(DMA_HandleTypeDef *hdma) |
| 3480 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
3480 | { |
| 3481 | } |
3481 | UART_HandleTypeDef *huart = (UART_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
| 3482 | 3482 | ||
| 3483 | /** |
3483 | huart->RxXferCount = 0x00U; |
| 3484 | * @brief Sends an amount of data in non blocking mode. |
3484 | |
| 3485 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
3485 | /* Restore huart->RxState to Ready */ |
| 3486 | * the configuration information for the specified UART module. |
3486 | huart->RxState = HAL_UART_STATE_READY; |
| 3487 | * @retval HAL status |
3487 | huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
| 3488 | */ |
3488 | |
| 3489 | static HAL_StatusTypeDef UART_Transmit_IT(UART_HandleTypeDef *huart) |
3489 | /* Call user Abort complete callback */ |
| 3490 | { |
3490 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
| 3491 | uint16_t *tmp; |
3491 | /* Call registered Abort Receive Complete Callback */ |
| 3492 | 3492 | huart->AbortReceiveCpltCallback(huart); |
|
| 3493 | /* Check that a Tx process is ongoing */ |
3493 | #else |
| 3494 | if (huart->gState == HAL_UART_STATE_BUSY_TX) |
3494 | /* Call legacy weak Abort Receive Complete Callback */ |
| 3495 | { |
3495 | HAL_UART_AbortReceiveCpltCallback(huart); |
| 3496 | if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE)) |
3496 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
| 3497 | { |
3497 | } |
| 3498 | tmp = (uint16_t *) huart->pTxBuffPtr; |
3498 | |
| 3499 | huart->Instance->DR = (uint16_t)(*tmp & (uint16_t)0x01FF); |
3499 | /** |
| 3500 | huart->pTxBuffPtr += 2U; |
3500 | * @brief Sends an amount of data in non blocking mode. |
| 3501 | } |
3501 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
| 3502 | else |
3502 | * the configuration information for the specified UART module. |
| 3503 | { |
3503 | * @retval HAL status |
| 3504 | huart->Instance->DR = (uint8_t)(*huart->pTxBuffPtr++ & (uint8_t)0x00FF); |
3504 | */ |
| 3505 | } |
3505 | static HAL_StatusTypeDef UART_Transmit_IT(UART_HandleTypeDef *huart) |
| 3506 | 3506 | { |
|
| 3507 | if (--huart->TxXferCount == 0U) |
3507 | const uint16_t *tmp; |
| 3508 | { |
3508 | |
| 3509 | /* Disable the UART Transmit Complete Interrupt */ |
3509 | /* Check that a Tx process is ongoing */ |
| 3510 | __HAL_UART_DISABLE_IT(huart, UART_IT_TXE); |
3510 | if (huart->gState == HAL_UART_STATE_BUSY_TX) |
| 3511 | 3511 | { |
|
| 3512 | /* Enable the UART Transmit Complete Interrupt */ |
3512 | if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE)) |
| 3513 | __HAL_UART_ENABLE_IT(huart, UART_IT_TC); |
3513 | { |
| 3514 | } |
3514 | tmp = (const uint16_t *) huart->pTxBuffPtr; |
| 3515 | return HAL_OK; |
3515 | huart->Instance->DR = (uint16_t)(*tmp & (uint16_t)0x01FF); |
| 3516 | } |
3516 | huart->pTxBuffPtr += 2U; |
| 3517 | else |
3517 | } |
| 3518 | { |
3518 | else |
| 3519 | return HAL_BUSY; |
3519 | { |
| 3520 | } |
3520 | huart->Instance->DR = (uint8_t)(*huart->pTxBuffPtr++ & (uint8_t)0x00FF); |
| 3521 | } |
3521 | } |
| 3522 | 3522 | ||
| 3523 | /** |
3523 | if (--huart->TxXferCount == 0U) |
| 3524 | * @brief Wraps up transmission in non blocking mode. |
3524 | { |
| 3525 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
3525 | /* Disable the UART Transmit Data Register Empty Interrupt */ |
| 3526 | * the configuration information for the specified UART module. |
3526 | __HAL_UART_DISABLE_IT(huart, UART_IT_TXE); |
| 3527 | * @retval HAL status |
3527 | |
| 3528 | */ |
3528 | /* Enable the UART Transmit Complete Interrupt */ |
| 3529 | static HAL_StatusTypeDef UART_EndTransmit_IT(UART_HandleTypeDef *huart) |
3529 | __HAL_UART_ENABLE_IT(huart, UART_IT_TC); |
| 3530 | { |
3530 | } |
| 3531 | /* Disable the UART Transmit Complete Interrupt */ |
3531 | return HAL_OK; |
| 3532 | __HAL_UART_DISABLE_IT(huart, UART_IT_TC); |
3532 | } |
| 3533 | 3533 | else |
|
| 3534 | /* Tx process is ended, restore huart->gState to Ready */ |
3534 | { |
| 3535 | huart->gState = HAL_UART_STATE_READY; |
3535 | return HAL_BUSY; |
| 3536 | 3536 | } |
|
| 3537 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
3537 | } |
| 3538 | /*Call registered Tx complete callback*/ |
3538 | |
| 3539 | huart->TxCpltCallback(huart); |
3539 | /** |
| 3540 | #else |
3540 | * @brief Wraps up transmission in non blocking mode. |
| 3541 | /*Call legacy weak Tx complete callback*/ |
3541 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
| 3542 | HAL_UART_TxCpltCallback(huart); |
3542 | * the configuration information for the specified UART module. |
| 3543 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
3543 | * @retval HAL status |
| 3544 | 3544 | */ |
|
| 3545 | return HAL_OK; |
3545 | static HAL_StatusTypeDef UART_EndTransmit_IT(UART_HandleTypeDef *huart) |
| 3546 | } |
3546 | { |
| 3547 | 3547 | /* Disable the UART Transmit Complete Interrupt */ |
|
| 3548 | /** |
3548 | __HAL_UART_DISABLE_IT(huart, UART_IT_TC); |
| 3549 | * @brief Receives an amount of data in non blocking mode |
3549 | |
| 3550 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
3550 | /* Tx process is ended, restore huart->gState to Ready */ |
| 3551 | * the configuration information for the specified UART module. |
3551 | huart->gState = HAL_UART_STATE_READY; |
| 3552 | * @retval HAL status |
3552 | |
| 3553 | */ |
3553 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
| 3554 | static HAL_StatusTypeDef UART_Receive_IT(UART_HandleTypeDef *huart) |
3554 | /*Call registered Tx complete callback*/ |
| 3555 | { |
3555 | huart->TxCpltCallback(huart); |
| 3556 | uint8_t *pdata8bits; |
3556 | #else |
| 3557 | uint16_t *pdata16bits; |
3557 | /*Call legacy weak Tx complete callback*/ |
| 3558 | 3558 | HAL_UART_TxCpltCallback(huart); |
|
| 3559 | /* Check that a Rx process is ongoing */ |
3559 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
| 3560 | if (huart->RxState == HAL_UART_STATE_BUSY_RX) |
3560 | |
| 3561 | { |
3561 | return HAL_OK; |
| 3562 | if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE)) |
3562 | } |
| 3563 | { |
3563 | |
| 3564 | pdata8bits = NULL; |
3564 | /** |
| 3565 | pdata16bits = (uint16_t *) huart->pRxBuffPtr; |
3565 | * @brief Receives an amount of data in non blocking mode |
| 3566 | *pdata16bits = (uint16_t)(huart->Instance->DR & (uint16_t)0x01FF); |
3566 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
| 3567 | huart->pRxBuffPtr += 2U; |
3567 | * the configuration information for the specified UART module. |
| 3568 | } |
3568 | * @retval HAL status |
| 3569 | else |
3569 | */ |
| 3570 | { |
3570 | static HAL_StatusTypeDef UART_Receive_IT(UART_HandleTypeDef *huart) |
| 3571 | pdata8bits = (uint8_t *) huart->pRxBuffPtr; |
3571 | { |
| 3572 | pdata16bits = NULL; |
3572 | uint8_t *pdata8bits; |
| 3573 | 3573 | uint16_t *pdata16bits; |
|
| 3574 | if ((huart->Init.WordLength == UART_WORDLENGTH_9B) || ((huart->Init.WordLength == UART_WORDLENGTH_8B) && (huart->Init.Parity == UART_PARITY_NONE))) |
3574 | |
| 3575 | { |
3575 | /* Check that a Rx process is ongoing */ |
| 3576 | *pdata8bits = (uint8_t)(huart->Instance->DR & (uint8_t)0x00FF); |
3576 | if (huart->RxState == HAL_UART_STATE_BUSY_RX) |
| 3577 | } |
3577 | { |
| 3578 | else |
3578 | if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE)) |
| 3579 | { |
3579 | { |
| 3580 | *pdata8bits = (uint8_t)(huart->Instance->DR & (uint8_t)0x007F); |
3580 | pdata8bits = NULL; |
| 3581 | } |
3581 | pdata16bits = (uint16_t *) huart->pRxBuffPtr; |
| 3582 | huart->pRxBuffPtr += 1U; |
3582 | *pdata16bits = (uint16_t)(huart->Instance->DR & (uint16_t)0x01FF); |
| 3583 | } |
3583 | huart->pRxBuffPtr += 2U; |
| 3584 | 3584 | } |
|
| 3585 | if (--huart->RxXferCount == 0U) |
3585 | else |
| 3586 | { |
3586 | { |
| 3587 | /* Disable the UART Data Register not empty Interrupt */ |
3587 | pdata8bits = (uint8_t *) huart->pRxBuffPtr; |
| 3588 | __HAL_UART_DISABLE_IT(huart, UART_IT_RXNE); |
3588 | pdata16bits = NULL; |
| 3589 | 3589 | ||
| 3590 | /* Disable the UART Parity Error Interrupt */ |
3590 | if ((huart->Init.WordLength == UART_WORDLENGTH_9B) || ((huart->Init.WordLength == UART_WORDLENGTH_8B) && (huart->Init.Parity == UART_PARITY_NONE))) |
| 3591 | __HAL_UART_DISABLE_IT(huart, UART_IT_PE); |
3591 | { |
| 3592 | 3592 | *pdata8bits = (uint8_t)(huart->Instance->DR & (uint8_t)0x00FF); |
|
| 3593 | /* Disable the UART Error Interrupt: (Frame error, noise error, overrun error) */ |
3593 | } |
| 3594 | __HAL_UART_DISABLE_IT(huart, UART_IT_ERR); |
3594 | else |
| 3595 | 3595 | { |
|
| 3596 | /* Rx process is completed, restore huart->RxState to Ready */ |
3596 | *pdata8bits = (uint8_t)(huart->Instance->DR & (uint8_t)0x007F); |
| 3597 | huart->RxState = HAL_UART_STATE_READY; |
3597 | } |
| 3598 | 3598 | huart->pRxBuffPtr += 1U; |
|
| 3599 | /* Check current reception Mode : |
3599 | } |
| 3600 | If Reception till IDLE event has been selected : */ |
3600 | |
| 3601 | if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE) |
3601 | if (--huart->RxXferCount == 0U) |
| 3602 | { |
3602 | { |
| 3603 | /* Set reception type to Standard */ |
3603 | /* Disable the UART Data Register not empty Interrupt */ |
| 3604 | huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
3604 | __HAL_UART_DISABLE_IT(huart, UART_IT_RXNE); |
| 3605 | 3605 | ||
| 3606 | /* Disable IDLE interrupt */ |
3606 | /* Disable the UART Parity Error Interrupt */ |
| 3607 | CLEAR_BIT(huart->Instance->CR1, USART_CR1_IDLEIE); |
3607 | __HAL_UART_DISABLE_IT(huart, UART_IT_PE); |
| 3608 | 3608 | ||
| 3609 | /* Check if IDLE flag is set */ |
3609 | /* Disable the UART Error Interrupt: (Frame error, noise error, overrun error) */ |
| 3610 | if (__HAL_UART_GET_FLAG(huart, UART_FLAG_IDLE)) |
3610 | __HAL_UART_DISABLE_IT(huart, UART_IT_ERR); |
| 3611 | { |
3611 | |
| 3612 | /* Clear IDLE flag in ISR */ |
3612 | /* Rx process is completed, restore huart->RxState to Ready */ |
| 3613 | __HAL_UART_CLEAR_IDLEFLAG(huart); |
3613 | huart->RxState = HAL_UART_STATE_READY; |
| 3614 | } |
3614 | |
| 3615 | 3615 | /* Initialize type of RxEvent to Transfer Complete */ |
|
| 3616 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
3616 | huart->RxEventType = HAL_UART_RXEVENT_TC; |
| 3617 | /*Call registered Rx Event callback*/ |
3617 | |
| 3618 | huart->RxEventCallback(huart, huart->RxXferSize); |
3618 | /* Check current reception Mode : |
| 3619 | #else |
3619 | If Reception till IDLE event has been selected : */ |
| 3620 | /*Call legacy weak Rx Event callback*/ |
3620 | if (huart->ReceptionType == HAL_UART_RECEPTION_TOIDLE) |
| 3621 | HAL_UARTEx_RxEventCallback(huart, huart->RxXferSize); |
3621 | { |
| 3622 | #endif |
3622 | /* Set reception type to Standard */ |
| 3623 | } |
3623 | huart->ReceptionType = HAL_UART_RECEPTION_STANDARD; |
| 3624 | else |
3624 | |
| 3625 | { |
3625 | /* Disable IDLE interrupt */ |
| 3626 | /* Standard reception API called */ |
3626 | ATOMIC_CLEAR_BIT(huart->Instance->CR1, USART_CR1_IDLEIE); |
| 3627 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
3627 | |
| 3628 | /*Call registered Rx complete callback*/ |
3628 | /* Check if IDLE flag is set */ |
| 3629 | huart->RxCpltCallback(huart); |
3629 | if (__HAL_UART_GET_FLAG(huart, UART_FLAG_IDLE)) |
| 3630 | #else |
3630 | { |
| 3631 | /*Call legacy weak Rx complete callback*/ |
3631 | /* Clear IDLE flag in ISR */ |
| 3632 | HAL_UART_RxCpltCallback(huart); |
3632 | __HAL_UART_CLEAR_IDLEFLAG(huart); |
| 3633 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
3633 | } |
| 3634 | } |
3634 | |
| 3635 | 3635 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
|
| 3636 | return HAL_OK; |
3636 | /*Call registered Rx Event callback*/ |
| 3637 | } |
3637 | huart->RxEventCallback(huart, huart->RxXferSize); |
| 3638 | return HAL_OK; |
3638 | #else |
| 3639 | } |
3639 | /*Call legacy weak Rx Event callback*/ |
| 3640 | else |
3640 | HAL_UARTEx_RxEventCallback(huart, huart->RxXferSize); |
| 3641 | { |
3641 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
| 3642 | return HAL_BUSY; |
3642 | } |
| 3643 | } |
3643 | else |
| 3644 | } |
3644 | { |
| 3645 | 3645 | /* Standard reception API called */ |
|
| 3646 | /** |
3646 | #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) |
| 3647 | * @brief Configures the UART peripheral. |
3647 | /*Call registered Rx complete callback*/ |
| 3648 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
3648 | huart->RxCpltCallback(huart); |
| 3649 | * the configuration information for the specified UART module. |
3649 | #else |
| 3650 | * @retval None |
3650 | /*Call legacy weak Rx complete callback*/ |
| 3651 | */ |
3651 | HAL_UART_RxCpltCallback(huart); |
| 3652 | static void UART_SetConfig(UART_HandleTypeDef *huart) |
3652 | #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ |
| 3653 | { |
3653 | } |
| 3654 | uint32_t tmpreg; |
3654 | |
| 3655 | uint32_t pclk; |
3655 | return HAL_OK; |
| 3656 | 3656 | } |
|
| 3657 | /* Check the parameters */ |
3657 | return HAL_OK; |
| 3658 | assert_param(IS_UART_BAUDRATE(huart->Init.BaudRate)); |
3658 | } |
| 3659 | assert_param(IS_UART_STOPBITS(huart->Init.StopBits)); |
3659 | else |
| 3660 | assert_param(IS_UART_PARITY(huart->Init.Parity)); |
3660 | { |
| 3661 | assert_param(IS_UART_MODE(huart->Init.Mode)); |
3661 | return HAL_BUSY; |
| 3662 | 3662 | } |
|
| 3663 | /*-------------------------- USART CR2 Configuration -----------------------*/ |
3663 | } |
| 3664 | /* Configure the UART Stop Bits: Set STOP[13:12] bits |
3664 | |
| 3665 | according to huart->Init.StopBits value */ |
3665 | /** |
| 3666 | MODIFY_REG(huart->Instance->CR2, USART_CR2_STOP, huart->Init.StopBits); |
3666 | * @brief Configures the UART peripheral. |
| 3667 | 3667 | * @param huart Pointer to a UART_HandleTypeDef structure that contains |
|
| 3668 | /*-------------------------- USART CR1 Configuration -----------------------*/ |
3668 | * the configuration information for the specified UART module. |
| 3669 | /* Configure the UART Word Length, Parity and mode: |
3669 | * @retval None |
| 3670 | Set the M bits according to huart->Init.WordLength value |
3670 | */ |
| 3671 | Set PCE and PS bits according to huart->Init.Parity value |
3671 | static void UART_SetConfig(UART_HandleTypeDef *huart) |
| 3672 | Set TE and RE bits according to huart->Init.Mode value |
3672 | { |
| 3673 | Set OVER8 bit according to huart->Init.OverSampling value */ |
3673 | uint32_t tmpreg; |
| 3674 | 3674 | uint32_t pclk; |
|
| 3675 | tmpreg = (uint32_t)huart->Init.WordLength | huart->Init.Parity | huart->Init.Mode | huart->Init.OverSampling; |
3675 | |
| 3676 | MODIFY_REG(huart->Instance->CR1, |
3676 | /* Check the parameters */ |
| 3677 | (uint32_t)(USART_CR1_M | USART_CR1_PCE | USART_CR1_PS | USART_CR1_TE | USART_CR1_RE | USART_CR1_OVER8), |
3677 | assert_param(IS_UART_BAUDRATE(huart->Init.BaudRate)); |
| 3678 | tmpreg); |
3678 | assert_param(IS_UART_STOPBITS(huart->Init.StopBits)); |
| 3679 | 3679 | assert_param(IS_UART_PARITY(huart->Init.Parity)); |
|
| 3680 | /*-------------------------- USART CR3 Configuration -----------------------*/ |
3680 | assert_param(IS_UART_MODE(huart->Init.Mode)); |
| 3681 | /* Configure the UART HFC: Set CTSE and RTSE bits according to huart->Init.HwFlowCtl value */ |
3681 | |
| 3682 | MODIFY_REG(huart->Instance->CR3, (USART_CR3_RTSE | USART_CR3_CTSE), huart->Init.HwFlowCtl); |
3682 | /*-------------------------- USART CR2 Configuration -----------------------*/ |
| 3683 | 3683 | /* Configure the UART Stop Bits: Set STOP[13:12] bits |
|
| 3684 | 3684 | according to huart->Init.StopBits value */ |
|
| 3685 | if((huart->Instance == USART1)) |
3685 | MODIFY_REG(huart->Instance->CR2, USART_CR2_STOP, huart->Init.StopBits); |
| 3686 | { |
3686 | |
| 3687 | pclk = HAL_RCC_GetPCLK2Freq(); |
3687 | /*-------------------------- USART CR1 Configuration -----------------------*/ |
| 3688 | } |
3688 | /* Configure the UART Word Length, Parity and mode: |
| 3689 | else |
3689 | Set the M bits according to huart->Init.WordLength value |
| 3690 | { |
3690 | Set PCE and PS bits according to huart->Init.Parity value |
| 3691 | pclk = HAL_RCC_GetPCLK1Freq(); |
3691 | Set TE and RE bits according to huart->Init.Mode value |
| 3692 | } |
3692 | Set OVER8 bit according to huart->Init.OverSampling value */ |
| 3693 | 3693 | ||
| 3694 | /*-------------------------- USART BRR Configuration ---------------------*/ |
3694 | tmpreg = (uint32_t)huart->Init.WordLength | huart->Init.Parity | huart->Init.Mode | huart->Init.OverSampling; |
| 3695 | if (huart->Init.OverSampling == UART_OVERSAMPLING_8) |
3695 | MODIFY_REG(huart->Instance->CR1, |
| 3696 | { |
3696 | (uint32_t)(USART_CR1_M | USART_CR1_PCE | USART_CR1_PS | USART_CR1_TE | USART_CR1_RE | USART_CR1_OVER8), |
| 3697 | huart->Instance->BRR = UART_BRR_SAMPLING8(pclk, huart->Init.BaudRate); |
3697 | tmpreg); |
| 3698 | } |
3698 | |
| 3699 | else |
3699 | /*-------------------------- USART CR3 Configuration -----------------------*/ |
| 3700 | { |
3700 | /* Configure the UART HFC: Set CTSE and RTSE bits according to huart->Init.HwFlowCtl value */ |
| 3701 | huart->Instance->BRR = UART_BRR_SAMPLING16(pclk, huart->Init.BaudRate); |
3701 | MODIFY_REG(huart->Instance->CR3, (USART_CR3_RTSE | USART_CR3_CTSE), huart->Init.HwFlowCtl); |
| 3702 | } |
3702 | |
| 3703 | } |
3703 | |
| 3704 | 3704 | if((huart->Instance == USART1)) |
|
| 3705 | /** |
3705 | { |
| 3706 | * @} |
3706 | pclk = HAL_RCC_GetPCLK2Freq(); |
| 3707 | */ |
3707 | } |
| 3708 | 3708 | else |
|
| 3709 | #endif /* HAL_UART_MODULE_ENABLED */ |
3709 | { |
| 3710 | /** |
3710 | pclk = HAL_RCC_GetPCLK1Freq(); |
| 3711 | * @} |
3711 | } |
| 3712 | */ |
3712 | |
| 3713 | 3713 | /*-------------------------- USART BRR Configuration ---------------------*/ |
|
| 3714 | /** |
3714 | if (huart->Init.OverSampling == UART_OVERSAMPLING_8) |
| 3715 | * @} |
3715 | { |
| 3716 | */ |
3716 | huart->Instance->BRR = UART_BRR_SAMPLING8(pclk, huart->Init.BaudRate); |
| 3717 | 3717 | } |
|
| 3718 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
3718 | else |
| - | 3719 | { |
|
| - | 3720 | huart->Instance->BRR = UART_BRR_SAMPLING16(pclk, huart->Init.BaudRate); |
|
| - | 3721 | } |
|
| - | 3722 | } |
|
| - | 3723 | ||
| - | 3724 | /** |
|
| - | 3725 | * @} |
|
| - | 3726 | */ |
|
| - | 3727 | ||
| - | 3728 | #endif /* HAL_UART_MODULE_ENABLED */ |
|
| - | 3729 | /** |
|
| - | 3730 | * @} |
|
| - | 3731 | */ |
|
| - | 3732 | ||
| - | 3733 | /** |
|
| - | 3734 | * @} |
|
| - | 3735 | */ |
|
| - | 3736 | ||