Subversion Repositories LedShow

Rev

Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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