Subversion Repositories EngineBay2

Rev

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

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