Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2 | Rev 9 | ||
---|---|---|---|
Line 6... | Line 6... | ||
6 | * This file provides firmware functions to manage the following |
6 | * This file provides firmware functions to manage the following |
7 | * functionalities of the SMARTCARD peripheral: |
7 | * functionalities of the SMARTCARD peripheral: |
8 | * + Initialization and de-initialization functions |
8 | * + Initialization and de-initialization functions |
9 | * + IO operation functions |
9 | * + IO operation functions |
10 | * + Peripheral Control functions |
10 | * + Peripheral Control functions |
11 | * + Peripheral State and Errors functions |
11 | * + Peripheral State and Error functions |
- | 12 | * |
|
12 | @verbatim |
13 | @verbatim |
13 | ============================================================================== |
14 | ============================================================================== |
14 | ##### How to use this driver ##### |
15 | ##### How to use this driver ##### |
15 | ============================================================================== |
16 | ============================================================================== |
16 | [..] |
17 | [..] |
17 | The SMARTCARD HAL driver can be used as follows: |
18 | The SMARTCARD HAL driver can be used as follows: |
18 | 19 | ||
19 | (#) Declare a SMARTCARD_HandleTypeDef handle structure. |
20 | (#) Declare a SMARTCARD_HandleTypeDef handle structure. |
20 | (#) Initialize the SMARTCARD low level resources by implementing the HAL_SMARTCARD_MspInit() API: |
21 | (#) Initialize the SMARTCARD low level resources by implementing the HAL_SMARTCARD_MspInit() API: |
21 | (##) Enable the USARTx interface clock. |
22 | (##) Enable the interface clock of the USARTx associated to the SMARTCARD. |
22 | (##) SMARTCARD pins configuration: |
23 | (##) SMARTCARD pins configuration: |
23 | (+++) Enable the clock for the SMARTCARD GPIOs. |
24 | (+++) Enable the clock for the SMARTCARD GPIOs. |
24 | (+++) Configure the SMARTCARD pins as alternate function pull-up. |
25 | (+++) Configure SMARTCARD pins as alternate function pull-up. |
25 | (##) NVIC configuration if you need to use interrupt process (HAL_SMARTCARD_Transmit_IT() |
26 | (##) NVIC configuration if you need to use interrupt process (HAL_SMARTCARD_Transmit_IT() |
26 | and HAL_SMARTCARD_Receive_IT() APIs): |
27 | and HAL_SMARTCARD_Receive_IT() APIs): |
27 | (+++) Configure the USARTx interrupt priority. |
28 | (+++) Configure the USARTx interrupt priority. |
28 | (+++) Enable the NVIC USART IRQ handle. |
29 | (+++) Enable the NVIC USART IRQ handle. |
29 | (##) DMA Configuration if you need to use DMA process (HAL_SMARTCARD_Transmit_DMA() |
30 | (##) DMA Configuration if you need to use DMA process (HAL_SMARTCARD_Transmit_DMA() |
Line 35... | Line 36... | ||
35 | (+++) Associate the initialized DMA handle to the SMARTCARD DMA Tx/Rx handle. |
36 | (+++) Associate the initialized DMA handle to the SMARTCARD DMA Tx/Rx handle. |
36 | (+++) Configure the priority and enable the NVIC for the transfer complete interrupt on the DMA Tx/Rx channel. |
37 | (+++) Configure the priority and enable the NVIC for the transfer complete interrupt on the DMA Tx/Rx channel. |
37 | (+++) Configure the USARTx interrupt priority and enable the NVIC USART IRQ handle |
38 | (+++) Configure the USARTx interrupt priority and enable the NVIC USART IRQ handle |
38 | (used for last byte sending completion detection in DMA non circular mode) |
39 | (used for last byte sending completion detection in DMA non circular mode) |
39 | 40 | ||
40 | (#) Program the Baud Rate, Word Length, Stop Bit, Parity, Hardware |
41 | (#) Program the Baud Rate, Word Length , Stop Bit, Parity, Hardware |
41 | flow control and Mode(Receiver/Transmitter) in the SMARTCARD Init structure. |
42 | flow control and Mode(Receiver/Transmitter) in the SMARTCARD Init structure. |
42 | 43 | ||
43 | (#) Initialize the SMARTCARD registers by calling the HAL_SMARTCARD_Init() API: |
44 | (#) Initialize the SMARTCARD registers by calling the HAL_SMARTCARD_Init() API: |
44 | (++) These APIs configure also the low level Hardware GPIO, CLOCK, CORTEX...etc) |
45 | (++) These APIs configure also the low level Hardware GPIO, CLOCK, CORTEX...etc) |
45 | by calling the customized HAL_SMARTCARD_MspInit() API. |
46 | by calling the customized HAL_SMARTCARD_MspInit() API. |
46 | [..] |
47 | [..] |
47 | (@)The specific SMARTCARD interrupts (Transmission complete interrupt, |
48 | (@) The specific SMARTCARD interrupts (Transmission complete interrupt, |
48 | RXNE interrupt and Error Interrupts) will be managed using the macros |
49 | RXNE interrupt and Error Interrupts) will be managed using the macros |
49 | __HAL_SMARTCARD_ENABLE_IT() and __HAL_SMARTCARD_DISABLE_IT() inside the transmit and receive process. |
50 | __HAL_SMARTCARD_ENABLE_IT() and __HAL_SMARTCARD_DISABLE_IT() inside the transmit and receive process. |
50 | 51 | ||
51 | [..] |
52 | [..] |
52 | Three operation modes are available within this driver: |
53 | Three operation modes are available within this driver : |
53 | 54 | ||
54 | *** Polling mode IO operation *** |
55 | *** Polling mode IO operation *** |
55 | ================================= |
56 | ================================= |
56 | [..] |
57 | [..] |
57 | (+) Send an amount of data in blocking mode using HAL_SMARTCARD_Transmit() |
58 | (+) Send an amount of data in blocking mode using HAL_SMARTCARD_Transmit() |
58 | (+) Receive an amount of data in blocking mode using HAL_SMARTCARD_Receive() |
59 | (+) Receive an amount of data in blocking mode using HAL_SMARTCARD_Receive() |
- | 60 | ||
59 | *** Interrupt mode IO operation *** |
61 | *** Interrupt mode IO operation *** |
60 | =================================== |
62 | =================================== |
61 | [..] |
63 | [..] |
62 | (+) Send an amount of data in non blocking mode using HAL_SMARTCARD_Transmit_IT() |
64 | (+) Send an amount of data in non blocking mode using HAL_SMARTCARD_Transmit_IT() |
63 | (+) At transmission end of transfer HAL_SMARTCARD_TxCpltCallback is executed and user can |
65 | (+) At transmission end of transfer HAL_SMARTCARD_TxCpltCallback is executed and user can |
Line 79... | Line 81... | ||
79 | add his own code by customization of function pointer HAL_SMARTCARD_RxCpltCallback |
81 | add his own code by customization of function pointer HAL_SMARTCARD_RxCpltCallback |
80 | (+) In case of transfer Error, HAL_SMARTCARD_ErrorCallback() function is executed and user can |
82 | (+) In case of transfer Error, HAL_SMARTCARD_ErrorCallback() function is executed and user can |
81 | add his own code by customization of function pointer HAL_SMARTCARD_ErrorCallback |
83 | add his own code by customization of function pointer HAL_SMARTCARD_ErrorCallback |
82 | 84 | ||
83 | *** SMARTCARD HAL driver macros list *** |
85 | *** SMARTCARD HAL driver macros list *** |
84 | ============================================= |
86 | ======================================== |
85 | [..] |
87 | [..] |
86 | Below the list of most used macros in SMARTCARD HAL driver. |
88 | Below the list of most used macros in SMARTCARD HAL driver. |
87 | 89 | ||
88 | (+) __HAL_SMARTCARD_ENABLE: Enable the SMARTCARD peripheral |
90 | (+) __HAL_SMARTCARD_ENABLE: Enable the SMARTCARD peripheral |
89 | (+) __HAL_SMARTCARD_DISABLE: Disable the SMARTCARD peripheral |
91 | (+) __HAL_SMARTCARD_DISABLE: Disable the SMARTCARD peripheral |
Line 93... | Line 95... | ||
93 | (+) __HAL_SMARTCARD_DISABLE_IT: Disable the specified SMARTCARD interrupt |
95 | (+) __HAL_SMARTCARD_DISABLE_IT: Disable the specified SMARTCARD interrupt |
94 | 96 | ||
95 | [..] |
97 | [..] |
96 | (@) You can refer to the SMARTCARD HAL driver header file for more useful macros |
98 | (@) You can refer to the SMARTCARD HAL driver header file for more useful macros |
97 | 99 | ||
- | 100 | ##### Callback registration ##### |
|
- | 101 | ================================== |
|
- | 102 | ||
- | 103 | [..] |
|
- | 104 | The compilation define USE_HAL_SMARTCARD_REGISTER_CALLBACKS when set to 1 |
|
- | 105 | allows the user to configure dynamically the driver callbacks. |
|
- | 106 | ||
- | 107 | [..] |
|
- | 108 | Use Function @ref HAL_SMARTCARD_RegisterCallback() to register a user callback. |
|
- | 109 | Function @ref HAL_SMARTCARD_RegisterCallback() allows to register following callbacks: |
|
- | 110 | (+) TxCpltCallback : Tx Complete Callback. |
|
- | 111 | (+) RxCpltCallback : Rx Complete Callback. |
|
- | 112 | (+) ErrorCallback : Error Callback. |
|
- | 113 | (+) AbortCpltCallback : Abort Complete Callback. |
|
- | 114 | (+) AbortTransmitCpltCallback : Abort Transmit Complete Callback. |
|
- | 115 | (+) AbortReceiveCpltCallback : Abort Receive Complete Callback. |
|
- | 116 | (+) MspInitCallback : SMARTCARD MspInit. |
|
- | 117 | (+) MspDeInitCallback : SMARTCARD MspDeInit. |
|
- | 118 | This function takes as parameters the HAL peripheral handle, the Callback ID |
|
- | 119 | and a pointer to the user callback function. |
|
- | 120 | ||
- | 121 | [..] |
|
- | 122 | Use function @ref HAL_SMARTCARD_UnRegisterCallback() to reset a callback to the default |
|
- | 123 | weak (surcharged) function. |
|
- | 124 | @ref HAL_SMARTCARD_UnRegisterCallback() takes as parameters the HAL peripheral handle, |
|
- | 125 | and the Callback ID. |
|
- | 126 | This function allows to reset following callbacks: |
|
- | 127 | (+) TxCpltCallback : Tx Complete Callback. |
|
- | 128 | (+) RxCpltCallback : Rx Complete Callback. |
|
- | 129 | (+) ErrorCallback : Error Callback. |
|
- | 130 | (+) AbortCpltCallback : Abort Complete Callback. |
|
- | 131 | (+) AbortTransmitCpltCallback : Abort Transmit Complete Callback. |
|
- | 132 | (+) AbortReceiveCpltCallback : Abort Receive Complete Callback. |
|
- | 133 | (+) MspInitCallback : SMARTCARD MspInit. |
|
- | 134 | (+) MspDeInitCallback : SMARTCARD MspDeInit. |
|
- | 135 | ||
- | 136 | [..] |
|
- | 137 | By default, after the @ref HAL_SMARTCARD_Init() and when the state is HAL_SMARTCARD_STATE_RESET |
|
- | 138 | all callbacks are set to the corresponding weak (surcharged) functions: |
|
- | 139 | examples @ref HAL_SMARTCARD_TxCpltCallback(), @ref HAL_SMARTCARD_RxCpltCallback(). |
|
- | 140 | Exception done for MspInit and MspDeInit functions that are respectively |
|
- | 141 | reset to the legacy weak (surcharged) functions in the @ref HAL_SMARTCARD_Init() |
|
- | 142 | and @ref HAL_SMARTCARD_DeInit() only when these callbacks are null (not registered beforehand). |
|
- | 143 | If not, MspInit or MspDeInit are not null, the @ref HAL_SMARTCARD_Init() and @ref HAL_SMARTCARD_DeInit() |
|
- | 144 | keep and use the user MspInit/MspDeInit callbacks (registered beforehand). |
|
- | 145 | ||
- | 146 | [..] |
|
- | 147 | Callbacks can be registered/unregistered in HAL_SMARTCARD_STATE_READY state only. |
|
- | 148 | Exception done MspInit/MspDeInit that can be registered/unregistered |
|
- | 149 | in HAL_SMARTCARD_STATE_READY or HAL_SMARTCARD_STATE_RESET state, thus registered (user) |
|
- | 150 | MspInit/DeInit callbacks can be used during the Init/DeInit. |
|
- | 151 | In that case first register the MspInit/MspDeInit user callbacks |
|
- | 152 | using @ref HAL_SMARTCARD_RegisterCallback() before calling @ref HAL_SMARTCARD_DeInit() |
|
- | 153 | or @ref HAL_SMARTCARD_Init() function. |
|
- | 154 | ||
- | 155 | [..] |
|
- | 156 | When The compilation define USE_HAL_SMARTCARD_REGISTER_CALLBACKS is set to 0 or |
|
- | 157 | not defined, the callback registration feature is not available |
|
- | 158 | and weak (surcharged) callbacks are used. |
|
- | 159 | ||
98 | @endverbatim |
160 | @endverbatim |
99 | [..] |
- | |
100 | (@) Additionnal remark: If the parity is enabled, then the MSB bit of the data written |
- | |
101 | in the data register is transmitted but is changed by the parity bit. |
- | |
102 | Depending on the frame length defined by the M bit (8-bits or 9-bits), |
- | |
103 | the possible SMARTCARD frame formats are as listed in the following table: |
- | |
104 | +-------------------------------------------------------------+ |
- | |
105 | | M bit | PCE bit | SMARTCARD frame | |
- | |
106 | |---------------------|---------------------------------------| |
- | |
107 | | 1 | 1 | | SB | 8 bit data | PB | STB | | |
- | |
108 | +-------------------------------------------------------------+ |
- | |
109 | ****************************************************************************** |
161 | ****************************************************************************** |
110 | * @attention |
162 | * @attention |
111 | * |
163 | * |
112 | * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2> |
164 | * <h2><center>© Copyright (c) 2016 STMicroelectronics. |
- | 165 | * All rights reserved.</center></h2> |
|
113 | * |
166 | * |
114 | * Redistribution and use in source and binary forms, with or without modification, |
167 | * This software component is licensed by ST under BSD 3-Clause license, |
115 | * are permitted provided that the following conditions are met: |
168 | * the "License"; You may not use this file except in compliance with the |
116 | * 1. Redistributions of source code must retain the above copyright notice, |
- | |
117 | * this list of conditions and the following disclaimer. |
- | |
118 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
- | |
119 | * this list of conditions and the following disclaimer in the documentation |
- | |
120 | * and/or other materials provided with the distribution. |
169 | * License. You may obtain a copy of the License at: |
121 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
- | |
122 | * may be used to endorse or promote products derived from this software |
170 | * opensource.org/licenses/BSD-3-Clause |
123 | * without specific prior written permission. |
- | |
124 | * |
- | |
125 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
- | |
126 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
- | |
127 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
- | |
128 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
- | |
129 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
- | |
130 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
- | |
131 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
- | |
132 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
- | |
133 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
- | |
134 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
- | |
135 | * |
171 | * |
136 | ****************************************************************************** |
172 | ****************************************************************************** |
137 | */ |
173 | */ |
138 | 174 | ||
139 | /* Includes ------------------------------------------------------------------*/ |
175 | /* Includes ------------------------------------------------------------------*/ |
Line 154... | Line 190... | ||
154 | * @{ |
190 | * @{ |
155 | */ |
191 | */ |
156 | /** |
192 | /** |
157 | * @} |
193 | * @} |
158 | */ |
194 | */ |
- | 195 | ||
159 | /* Private macro -------------------------------------------------------------*/ |
196 | /* Private macro -------------------------------------------------------------*/ |
160 | /* Private variables ---------------------------------------------------------*/ |
197 | /* Private variables ---------------------------------------------------------*/ |
161 | /* Private function prototypes -----------------------------------------------*/ |
198 | /* Private function prototypes -----------------------------------------------*/ |
162 | /** @addtogroup SMARTCARD_Private_Functions |
199 | /** @addtogroup SMARTCARD_Private_Functions |
163 | * @{ |
200 | * @{ |
164 | */ |
201 | */ |
- | 202 | #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1) |
|
- | 203 | void SMARTCARD_InitCallbacksToDefault(SMARTCARD_HandleTypeDef *hsc); |
|
- | 204 | #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACKS */ |
|
165 | static void SMARTCARD_EndTxTransfer(SMARTCARD_HandleTypeDef *hsc); |
205 | static void SMARTCARD_EndTxTransfer(SMARTCARD_HandleTypeDef *hsc); |
166 | static void SMARTCARD_EndRxTransfer(SMARTCARD_HandleTypeDef *hsc); |
206 | static void SMARTCARD_EndRxTransfer(SMARTCARD_HandleTypeDef *hsc); |
167 | static void SMARTCARD_SetConfig(SMARTCARD_HandleTypeDef *hsc); |
207 | static void SMARTCARD_SetConfig (SMARTCARD_HandleTypeDef *hsc); |
168 | static HAL_StatusTypeDef SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsc); |
208 | static HAL_StatusTypeDef SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsc); |
169 | static HAL_StatusTypeDef SMARTCARD_EndTransmit_IT(SMARTCARD_HandleTypeDef *hsmartcard); |
209 | static HAL_StatusTypeDef SMARTCARD_EndTransmit_IT(SMARTCARD_HandleTypeDef *hsc); |
170 | static HAL_StatusTypeDef SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsc); |
210 | static HAL_StatusTypeDef SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsc); |
171 | static void SMARTCARD_DMATransmitCplt(DMA_HandleTypeDef *hdma); |
211 | static void SMARTCARD_DMATransmitCplt(DMA_HandleTypeDef *hdma); |
172 | static void SMARTCARD_DMAReceiveCplt(DMA_HandleTypeDef *hdma); |
212 | static void SMARTCARD_DMAReceiveCplt(DMA_HandleTypeDef *hdma); |
173 | static void SMARTCARD_DMAError(DMA_HandleTypeDef *hdma); |
213 | static void SMARTCARD_DMAError(DMA_HandleTypeDef *hdma); |
174 | static void SMARTCARD_DMAAbortOnError(DMA_HandleTypeDef *hdma); |
214 | static void SMARTCARD_DMAAbortOnError(DMA_HandleTypeDef *hdma); |
Line 178... | Line 218... | ||
178 | static void SMARTCARD_DMARxOnlyAbortCallback(DMA_HandleTypeDef *hdma); |
218 | static void SMARTCARD_DMARxOnlyAbortCallback(DMA_HandleTypeDef *hdma); |
179 | static HAL_StatusTypeDef SMARTCARD_WaitOnFlagUntilTimeout(SMARTCARD_HandleTypeDef *hsc, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout); |
219 | static HAL_StatusTypeDef SMARTCARD_WaitOnFlagUntilTimeout(SMARTCARD_HandleTypeDef *hsc, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout); |
180 | /** |
220 | /** |
181 | * @} |
221 | * @} |
182 | */ |
222 | */ |
- | 223 | ||
183 | /* Exported functions --------------------------------------------------------*/ |
224 | /* Exported functions --------------------------------------------------------*/ |
184 | /** @defgroup SMARTCARD_Exported_Functions SMARTCARD Exported Functions |
225 | /** @defgroup SMARTCARD_Exported_Functions SMARTCARD Exported Functions |
185 | * @{ |
226 | * @{ |
186 | */ |
227 | */ |
187 | 228 | ||
188 | /** @defgroup SMARTCARD_Exported_Functions_Group1 SmartCard Initialization and de-initialization functions |
229 | /** @defgroup SMARTCARD_Exported_Functions_Group1 SmartCard Initialization and de-initialization functions |
189 | * @brief Initialization and Configuration functions |
230 | * @brief Initialization and Configuration functions |
190 | * |
231 | * |
191 | @verbatim |
232 | @verbatim |
192 | ============================================================================== |
233 | ============================================================================== |
193 | ##### Initialization and Configuration functions ##### |
234 | ##### Initialization and Configuration functions ##### |
194 | ============================================================================== |
235 | ============================================================================== |
195 | [..] |
236 | [..] |
196 | This subsection provides a set of functions allowing to initialize the USART |
237 | This subsection provides a set of functions allowing to initialize the USART |
197 | in Smartcard mode. |
238 | in Smartcard mode. |
198 | [..] |
239 | [..] |
Line 229... | Line 270... | ||
229 | (@) It is also possible to choose 0.5 stop bit for receiving but it is recommended |
270 | (@) It is also possible to choose 0.5 stop bit for receiving but it is recommended |
230 | to use 1.5 stop bits for both transmitting and receiving to avoid switching |
271 | to use 1.5 stop bits for both transmitting and receiving to avoid switching |
231 | between the two configurations. |
272 | between the two configurations. |
232 | [..] |
273 | [..] |
233 | The HAL_SMARTCARD_Init() function follows the USART SmartCard configuration |
274 | The HAL_SMARTCARD_Init() function follows the USART SmartCard configuration |
234 | procedure (details for the procedure are available in reference manual (RM0329)). |
275 | procedures (details for the procedures are available in reference manuals |
- | 276 | (RM0008 for STM32F10Xxx MCUs and RM0041 for STM32F100xx MCUs)). |
|
235 | 277 | ||
236 | @endverbatim |
278 | @endverbatim |
- | 279 | ||
- | 280 | The SMARTCARD frame format is given in the following table: |
|
- | 281 | +-------------------------------------------------------------+ |
|
- | 282 | | M bit | PCE bit | SMARTCARD frame | |
|
- | 283 | |---------------------|---------------------------------------| |
|
- | 284 | | 1 | 1 | | SB | 8 bit data | PB | STB | | |
|
- | 285 | +-------------------------------------------------------------+ |
|
237 | * @{ |
286 | * @{ |
238 | */ |
287 | */ |
239 | 288 | ||
240 | /** |
289 | /** |
241 | * @brief Initializes the SmartCard mode according to the specified |
290 | * @brief Initializes the SmartCard mode according to the specified |
242 | * parameters in the SMARTCARD_InitTypeDef and create the associated handle. |
291 | * parameters in the SMARTCARD_InitTypeDef and create the associated handle. |
243 | * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains |
292 | * @param hsc Pointer to a SMARTCARD_HandleTypeDef structure that contains |
244 | * the configuration information for SMARTCARD module. |
293 | * the configuration information for SMARTCARD module. |
245 | * @retval HAL status |
294 | * @retval HAL status |
246 | */ |
295 | */ |
247 | HAL_StatusTypeDef HAL_SMARTCARD_Init(SMARTCARD_HandleTypeDef *hsc) |
296 | HAL_StatusTypeDef HAL_SMARTCARD_Init(SMARTCARD_HandleTypeDef *hsc) |
248 | { |
297 | { |
249 | /* Check the SMARTCARD handle allocation */ |
298 | /* Check the SMARTCARD handle allocation */ |
250 | if (hsc == NULL) |
299 | if(hsc == NULL) |
251 | { |
300 | { |
252 | return HAL_ERROR; |
301 | return HAL_ERROR; |
253 | } |
302 | } |
254 | 303 | ||
255 | /* Check the parameters */ |
304 | /* Check the parameters */ |
256 | assert_param(IS_SMARTCARD_INSTANCE(hsc->Instance)); |
305 | assert_param(IS_SMARTCARD_INSTANCE(hsc->Instance)); |
- | 306 | assert_param(IS_SMARTCARD_NACK_STATE(hsc->Init.NACKState)); |
|
257 | 307 | ||
258 | - | ||
259 | if (hsc->gState == HAL_SMARTCARD_STATE_RESET) |
308 | if(hsc->gState == HAL_SMARTCARD_STATE_RESET) |
260 | { |
309 | { |
261 | /* Allocate lock resource and initialize it */ |
310 | /* Allocate lock resource and initialize it */ |
262 | hsc->Lock = HAL_UNLOCKED; |
311 | hsc->Lock = HAL_UNLOCKED; |
263 | 312 | ||
- | 313 | #if USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1 |
|
- | 314 | SMARTCARD_InitCallbacksToDefault(hsc); |
|
- | 315 | ||
- | 316 | if (hsc->MspInitCallback == NULL) |
|
- | 317 | { |
|
- | 318 | hsc->MspInitCallback = HAL_SMARTCARD_MspInit; |
|
- | 319 | } |
|
- | 320 | ||
- | 321 | /* Init the low level hardware */ |
|
- | 322 | hsc->MspInitCallback(hsc); |
|
- | 323 | #else |
|
264 | /* Init the low level hardware : GPIO, CLOCK, CORTEX...etc */ |
324 | /* Init the low level hardware : GPIO, CLOCK */ |
265 | HAL_SMARTCARD_MspInit(hsc); |
325 | HAL_SMARTCARD_MspInit(hsc); |
- | 326 | #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACKS */ |
|
266 | } |
327 | } |
267 | 328 | ||
268 | hsc->gState = HAL_SMARTCARD_STATE_BUSY; |
329 | hsc->gState = HAL_SMARTCARD_STATE_BUSY; |
269 | 330 | ||
270 | /* Set the Prescaler */ |
331 | /* Set the Prescaler */ |
271 | MODIFY_REG(hsc->Instance->GTPR, USART_GTPR_PSC, hsc->Init.Prescaler); |
332 | MODIFY_REG(hsc->Instance->GTPR, USART_GTPR_PSC, hsc->Init.Prescaler); |
272 | 333 | ||
273 | /* Set the Guard Time */ |
334 | /* Set the Guard Time */ |
274 | MODIFY_REG(hsc->Instance->GTPR, USART_GTPR_GT, ((hsc->Init.GuardTime) << 8U)); |
335 | MODIFY_REG(hsc->Instance->GTPR, USART_GTPR_GT, ((hsc->Init.GuardTime)<<8U)); |
275 | 336 | ||
276 | /* Set the Smartcard Communication parameters */ |
337 | /* Set the Smartcard Communication parameters */ |
277 | SMARTCARD_SetConfig(hsc); |
338 | SMARTCARD_SetConfig(hsc); |
278 | 339 | ||
279 | /* In SmartCard mode, the following bits must be kept cleared: |
340 | /* In SmartCard mode, the following bits must be kept cleared: |
Line 297... | Line 358... | ||
297 | /* Enable the SC mode by setting the SCEN bit in the CR3 register */ |
358 | /* Enable the SC mode by setting the SCEN bit in the CR3 register */ |
298 | hsc->Instance->CR3 |= (USART_CR3_SCEN); |
359 | hsc->Instance->CR3 |= (USART_CR3_SCEN); |
299 | 360 | ||
300 | /* Initialize the SMARTCARD state*/ |
361 | /* Initialize the SMARTCARD state*/ |
301 | hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE; |
362 | hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE; |
302 | hsc->gState = HAL_SMARTCARD_STATE_READY; |
363 | hsc->gState= HAL_SMARTCARD_STATE_READY; |
303 | hsc->RxState = HAL_SMARTCARD_STATE_READY; |
364 | hsc->RxState= HAL_SMARTCARD_STATE_READY; |
304 | 365 | ||
305 | return HAL_OK; |
366 | return HAL_OK; |
306 | } |
367 | } |
307 | 368 | ||
308 | /** |
369 | /** |
309 | * @brief DeInitializes the USART SmartCard peripheral |
370 | * @brief DeInitializes the USART SmartCard peripheral |
310 | * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains |
371 | * @param hsc Pointer to a SMARTCARD_HandleTypeDef structure that contains |
311 | * the configuration information for SMARTCARD module. |
372 | * the configuration information for SMARTCARD module. |
312 | * @retval HAL status |
373 | * @retval HAL status |
313 | */ |
374 | */ |
314 | HAL_StatusTypeDef HAL_SMARTCARD_DeInit(SMARTCARD_HandleTypeDef *hsc) |
375 | HAL_StatusTypeDef HAL_SMARTCARD_DeInit(SMARTCARD_HandleTypeDef *hsc) |
315 | { |
376 | { |
316 | /* Check the SMARTCARD handle allocation */ |
377 | /* Check the SMARTCARD handle allocation */ |
317 | if (hsc == NULL) |
378 | if(hsc == NULL) |
318 | { |
379 | { |
319 | return HAL_ERROR; |
380 | return HAL_ERROR; |
320 | } |
381 | } |
321 | 382 | ||
322 | /* Check the parameters */ |
383 | /* Check the parameters */ |
323 | assert_param(IS_SMARTCARD_INSTANCE(hsc->Instance)); |
384 | assert_param(IS_SMARTCARD_INSTANCE(hsc->Instance)); |
324 | 385 | ||
325 | hsc->gState = HAL_SMARTCARD_STATE_BUSY; |
386 | hsc->gState = HAL_SMARTCARD_STATE_BUSY; |
326 | 387 | ||
- | 388 | /* Disable the Peripheral */ |
|
- | 389 | __HAL_SMARTCARD_DISABLE(hsc); |
|
- | 390 | ||
327 | /* DeInit the low level hardware */ |
391 | /* DeInit the low level hardware */ |
- | 392 | #if USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1 |
|
- | 393 | if (hsc->MspDeInitCallback == NULL) |
|
- | 394 | { |
|
- | 395 | hsc->MspDeInitCallback = HAL_SMARTCARD_MspDeInit; |
|
- | 396 | } |
|
- | 397 | /* DeInit the low level hardware */ |
|
- | 398 | hsc->MspDeInitCallback(hsc); |
|
- | 399 | #else |
|
328 | HAL_SMARTCARD_MspDeInit(hsc); |
400 | HAL_SMARTCARD_MspDeInit(hsc); |
- | 401 | #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACKS */ |
|
329 | 402 | ||
330 | hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE; |
403 | hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE; |
331 | hsc->gState = HAL_SMARTCARD_STATE_RESET; |
404 | hsc->gState = HAL_SMARTCARD_STATE_RESET; |
332 | hsc->RxState = HAL_SMARTCARD_STATE_RESET; |
405 | hsc->RxState = HAL_SMARTCARD_STATE_RESET; |
333 | 406 | ||
Line 336... | Line 409... | ||
336 | 409 | ||
337 | return HAL_OK; |
410 | return HAL_OK; |
338 | } |
411 | } |
339 | 412 | ||
340 | /** |
413 | /** |
341 | * @brief SMARTCARD MSP Init. |
414 | * @brief SMARTCARD MSP Init |
342 | * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains |
415 | * @param hsc Pointer to a SMARTCARD_HandleTypeDef structure that contains |
343 | * the configuration information for SMARTCARD module. |
416 | * the configuration information for SMARTCARD module. |
344 | * @retval None |
417 | * @retval None |
345 | */ |
418 | */ |
346 | __weak void HAL_SMARTCARD_MspInit(SMARTCARD_HandleTypeDef *hsc) |
419 | __weak void HAL_SMARTCARD_MspInit(SMARTCARD_HandleTypeDef *hsc) |
347 | { |
420 | { |
348 | /* Prevent unused argument(s) compilation warning */ |
421 | /* Prevent unused argument(s) compilation warning */ |
349 | UNUSED(hsc); |
422 | UNUSED(hsc); |
- | 423 | ||
350 | /* NOTE: This function should not be modified, when the callback is needed, |
424 | /* NOTE : This function should not be modified, when the callback is needed, |
351 | the HAL_SMARTCARD_MspInit could be implemented in the user file |
425 | the HAL_SMARTCARD_MspInit can be implemented in the user file |
352 | */ |
426 | */ |
353 | } |
427 | } |
354 | 428 | ||
355 | /** |
429 | /** |
356 | * @brief SMARTCARD MSP DeInit |
430 | * @brief SMARTCARD MSP DeInit |
357 | * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains |
431 | * @param hsc Pointer to a SMARTCARD_HandleTypeDef structure that contains |
358 | * the configuration information for SMARTCARD module. |
432 | * the configuration information for SMARTCARD module. |
359 | * @retval None |
433 | * @retval None |
360 | */ |
434 | */ |
361 | __weak void HAL_SMARTCARD_MspDeInit(SMARTCARD_HandleTypeDef *hsc) |
435 | __weak void HAL_SMARTCARD_MspDeInit(SMARTCARD_HandleTypeDef *hsc) |
362 | { |
436 | { |
363 | /* Prevent unused argument(s) compilation warning */ |
437 | /* Prevent unused argument(s) compilation warning */ |
364 | UNUSED(hsc); |
438 | UNUSED(hsc); |
- | 439 | ||
365 | /* NOTE: This function should not be modified, when the callback is needed, |
440 | /* NOTE : This function should not be modified, when the callback is needed, |
366 | the HAL_SMARTCARD_MspDeInit could be implemented in the user file |
441 | the HAL_SMARTCARD_MspDeInit can be implemented in the user file |
367 | */ |
442 | */ |
368 | } |
443 | } |
369 | 444 | ||
- | 445 | #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1) |
|
- | 446 | /** |
|
- | 447 | * @brief Register a User SMARTCARD Callback |
|
- | 448 | * To be used instead of the weak predefined callback |
|
- | 449 | * @param hsc smartcard handle |
|
- | 450 | * @param CallbackID ID of the callback to be registered |
|
- | 451 | * This parameter can be one of the following values: |
|
- | 452 | * @arg @ref HAL_SMARTCARD_TX_COMPLETE_CB_ID Tx Complete Callback ID |
|
- | 453 | * @arg @ref HAL_SMARTCARD_RX_COMPLETE_CB_ID Rx Complete Callback ID |
|
- | 454 | * @arg @ref HAL_SMARTCARD_ERROR_CB_ID Error Callback ID |
|
- | 455 | * @arg @ref HAL_SMARTCARD_ABORT_COMPLETE_CB_ID Abort Complete Callback ID |
|
- | 456 | * @arg @ref HAL_SMARTCARD_ABORT_TRANSMIT_COMPLETE_CB_ID Abort Transmit Complete Callback ID |
|
- | 457 | * @arg @ref HAL_SMARTCARD_ABORT_RECEIVE_COMPLETE_CB_ID Abort Receive Complete Callback ID |
|
- | 458 | * @arg @ref HAL_SMARTCARD_MSPINIT_CB_ID MspInit Callback ID |
|
- | 459 | * @arg @ref HAL_SMARTCARD_MSPDEINIT_CB_ID MspDeInit Callback ID |
|
- | 460 | * @param pCallback pointer to the Callback function |
|
- | 461 | * @retval HAL status |
|
- | 462 | */ |
|
- | 463 | HAL_StatusTypeDef HAL_SMARTCARD_RegisterCallback(SMARTCARD_HandleTypeDef *hsc, HAL_SMARTCARD_CallbackIDTypeDef CallbackID, pSMARTCARD_CallbackTypeDef pCallback) |
|
- | 464 | { |
|
- | 465 | HAL_StatusTypeDef status = HAL_OK; |
|
- | 466 | ||
- | 467 | if (pCallback == NULL) |
|
- | 468 | { |
|
- | 469 | /* Update the error code */ |
|
- | 470 | hsc->ErrorCode |= HAL_SMARTCARD_ERROR_INVALID_CALLBACK; |
|
- | 471 | ||
- | 472 | return HAL_ERROR; |
|
- | 473 | } |
|
- | 474 | /* Process locked */ |
|
- | 475 | __HAL_LOCK(hsc); |
|
- | 476 | ||
- | 477 | if (hsc->gState == HAL_SMARTCARD_STATE_READY) |
|
- | 478 | { |
|
- | 479 | switch (CallbackID) |
|
- | 480 | { |
|
- | 481 | ||
- | 482 | case HAL_SMARTCARD_TX_COMPLETE_CB_ID : |
|
- | 483 | hsc->TxCpltCallback = pCallback; |
|
- | 484 | break; |
|
- | 485 | ||
- | 486 | case HAL_SMARTCARD_RX_COMPLETE_CB_ID : |
|
- | 487 | hsc->RxCpltCallback = pCallback; |
|
- | 488 | break; |
|
- | 489 | ||
- | 490 | case HAL_SMARTCARD_ERROR_CB_ID : |
|
- | 491 | hsc->ErrorCallback = pCallback; |
|
- | 492 | break; |
|
- | 493 | ||
- | 494 | case HAL_SMARTCARD_ABORT_COMPLETE_CB_ID : |
|
- | 495 | hsc->AbortCpltCallback = pCallback; |
|
- | 496 | break; |
|
- | 497 | ||
- | 498 | case HAL_SMARTCARD_ABORT_TRANSMIT_COMPLETE_CB_ID : |
|
- | 499 | hsc->AbortTransmitCpltCallback = pCallback; |
|
- | 500 | break; |
|
- | 501 | ||
- | 502 | case HAL_SMARTCARD_ABORT_RECEIVE_COMPLETE_CB_ID : |
|
- | 503 | hsc->AbortReceiveCpltCallback = pCallback; |
|
- | 504 | break; |
|
- | 505 | ||
- | 506 | ||
- | 507 | case HAL_SMARTCARD_MSPINIT_CB_ID : |
|
- | 508 | hsc->MspInitCallback = pCallback; |
|
- | 509 | break; |
|
- | 510 | ||
- | 511 | case HAL_SMARTCARD_MSPDEINIT_CB_ID : |
|
- | 512 | hsc->MspDeInitCallback = pCallback; |
|
- | 513 | break; |
|
- | 514 | ||
- | 515 | default : |
|
- | 516 | /* Update the error code */ |
|
- | 517 | hsc->ErrorCode |= HAL_SMARTCARD_ERROR_INVALID_CALLBACK; |
|
- | 518 | ||
- | 519 | /* Return error status */ |
|
- | 520 | status = HAL_ERROR; |
|
- | 521 | break; |
|
- | 522 | } |
|
- | 523 | } |
|
- | 524 | else if (hsc->gState == HAL_SMARTCARD_STATE_RESET) |
|
- | 525 | { |
|
- | 526 | switch (CallbackID) |
|
- | 527 | { |
|
- | 528 | case HAL_SMARTCARD_MSPINIT_CB_ID : |
|
- | 529 | hsc->MspInitCallback = pCallback; |
|
- | 530 | break; |
|
- | 531 | ||
- | 532 | case HAL_SMARTCARD_MSPDEINIT_CB_ID : |
|
- | 533 | hsc->MspDeInitCallback = pCallback; |
|
- | 534 | break; |
|
- | 535 | ||
- | 536 | default : |
|
- | 537 | /* Update the error code */ |
|
- | 538 | hsc->ErrorCode |= HAL_SMARTCARD_ERROR_INVALID_CALLBACK; |
|
- | 539 | ||
- | 540 | /* Return error status */ |
|
- | 541 | status = HAL_ERROR; |
|
- | 542 | break; |
|
- | 543 | } |
|
- | 544 | } |
|
- | 545 | else |
|
- | 546 | { |
|
- | 547 | /* Update the error code */ |
|
- | 548 | hsc->ErrorCode |= HAL_SMARTCARD_ERROR_INVALID_CALLBACK; |
|
- | 549 | ||
- | 550 | /* Return error status */ |
|
- | 551 | status = HAL_ERROR; |
|
- | 552 | } |
|
- | 553 | ||
- | 554 | /* Release Lock */ |
|
- | 555 | __HAL_UNLOCK(hsc); |
|
- | 556 | ||
- | 557 | return status; |
|
- | 558 | } |
|
- | 559 | ||
- | 560 | /** |
|
- | 561 | * @brief Unregister an SMARTCARD callback |
|
- | 562 | * SMARTCARD callback is redirected to the weak predefined callback |
|
- | 563 | * @param hsc smartcard handle |
|
- | 564 | * @param CallbackID ID of the callback to be unregistered |
|
- | 565 | * This parameter can be one of the following values: |
|
- | 566 | * @arg @ref HAL_SMARTCARD_TX_COMPLETE_CB_ID Tx Complete Callback ID |
|
- | 567 | * @arg @ref HAL_SMARTCARD_RX_COMPLETE_CB_ID Rx Complete Callback ID |
|
- | 568 | * @arg @ref HAL_SMARTCARD_ERROR_CB_ID Error Callback ID |
|
- | 569 | * @arg @ref HAL_SMARTCARD_ABORT_COMPLETE_CB_ID Abort Complete Callback ID |
|
- | 570 | * @arg @ref HAL_SMARTCARD_ABORT_TRANSMIT_COMPLETE_CB_ID Abort Transmit Complete Callback ID |
|
- | 571 | * @arg @ref HAL_SMARTCARD_ABORT_RECEIVE_COMPLETE_CB_ID Abort Receive Complete Callback ID |
|
- | 572 | * @arg @ref HAL_SMARTCARD_MSPINIT_CB_ID MspInit Callback ID |
|
- | 573 | * @arg @ref HAL_SMARTCARD_MSPDEINIT_CB_ID MspDeInit Callback ID |
|
- | 574 | * @retval HAL status |
|
- | 575 | */ |
|
- | 576 | HAL_StatusTypeDef HAL_SMARTCARD_UnRegisterCallback(SMARTCARD_HandleTypeDef *hsc, HAL_SMARTCARD_CallbackIDTypeDef CallbackID) |
|
- | 577 | { |
|
- | 578 | HAL_StatusTypeDef status = HAL_OK; |
|
- | 579 | ||
- | 580 | /* Process locked */ |
|
- | 581 | __HAL_LOCK(hsc); |
|
- | 582 | ||
- | 583 | if (HAL_SMARTCARD_STATE_READY == hsc->gState) |
|
- | 584 | { |
|
- | 585 | switch (CallbackID) |
|
- | 586 | { |
|
- | 587 | case HAL_SMARTCARD_TX_COMPLETE_CB_ID : |
|
- | 588 | hsc->TxCpltCallback = HAL_SMARTCARD_TxCpltCallback; /* Legacy weak TxCpltCallback */ |
|
- | 589 | break; |
|
- | 590 | ||
- | 591 | case HAL_SMARTCARD_RX_COMPLETE_CB_ID : |
|
- | 592 | hsc->RxCpltCallback = HAL_SMARTCARD_RxCpltCallback; /* Legacy weak RxCpltCallback */ |
|
- | 593 | break; |
|
- | 594 | ||
- | 595 | case HAL_SMARTCARD_ERROR_CB_ID : |
|
- | 596 | hsc->ErrorCallback = HAL_SMARTCARD_ErrorCallback; /* Legacy weak ErrorCallback */ |
|
- | 597 | break; |
|
- | 598 | ||
- | 599 | case HAL_SMARTCARD_ABORT_COMPLETE_CB_ID : |
|
- | 600 | hsc->AbortCpltCallback = HAL_SMARTCARD_AbortCpltCallback; /* Legacy weak AbortCpltCallback */ |
|
- | 601 | break; |
|
- | 602 | ||
- | 603 | case HAL_SMARTCARD_ABORT_TRANSMIT_COMPLETE_CB_ID : |
|
- | 604 | hsc->AbortTransmitCpltCallback = HAL_SMARTCARD_AbortTransmitCpltCallback; /* Legacy weak AbortTransmitCpltCallback */ |
|
- | 605 | break; |
|
- | 606 | ||
- | 607 | case HAL_SMARTCARD_ABORT_RECEIVE_COMPLETE_CB_ID : |
|
- | 608 | hsc->AbortReceiveCpltCallback = HAL_SMARTCARD_AbortReceiveCpltCallback; /* Legacy weak AbortReceiveCpltCallback */ |
|
- | 609 | break; |
|
- | 610 | ||
- | 611 | ||
- | 612 | case HAL_SMARTCARD_MSPINIT_CB_ID : |
|
- | 613 | hsc->MspInitCallback = HAL_SMARTCARD_MspInit; /* Legacy weak MspInitCallback */ |
|
- | 614 | break; |
|
- | 615 | ||
- | 616 | case HAL_SMARTCARD_MSPDEINIT_CB_ID : |
|
- | 617 | hsc->MspDeInitCallback = HAL_SMARTCARD_MspDeInit; /* Legacy weak MspDeInitCallback */ |
|
- | 618 | break; |
|
- | 619 | ||
- | 620 | default : |
|
- | 621 | /* Update the error code */ |
|
- | 622 | hsc->ErrorCode |= HAL_SMARTCARD_ERROR_INVALID_CALLBACK; |
|
- | 623 | ||
- | 624 | /* Return error status */ |
|
- | 625 | status = HAL_ERROR; |
|
- | 626 | break; |
|
- | 627 | } |
|
- | 628 | } |
|
- | 629 | else if (HAL_SMARTCARD_STATE_RESET == hsc->gState) |
|
- | 630 | { |
|
- | 631 | switch (CallbackID) |
|
- | 632 | { |
|
- | 633 | case HAL_SMARTCARD_MSPINIT_CB_ID : |
|
- | 634 | hsc->MspInitCallback = HAL_SMARTCARD_MspInit; |
|
- | 635 | break; |
|
- | 636 | ||
- | 637 | case HAL_SMARTCARD_MSPDEINIT_CB_ID : |
|
- | 638 | hsc->MspDeInitCallback = HAL_SMARTCARD_MspDeInit; |
|
- | 639 | break; |
|
- | 640 | ||
- | 641 | default : |
|
- | 642 | /* Update the error code */ |
|
- | 643 | hsc->ErrorCode |= HAL_SMARTCARD_ERROR_INVALID_CALLBACK; |
|
- | 644 | ||
- | 645 | /* Return error status */ |
|
- | 646 | status = HAL_ERROR; |
|
- | 647 | break; |
|
- | 648 | } |
|
- | 649 | } |
|
- | 650 | else |
|
- | 651 | { |
|
- | 652 | /* Update the error code */ |
|
- | 653 | hsc->ErrorCode |= HAL_SMARTCARD_ERROR_INVALID_CALLBACK; |
|
- | 654 | ||
- | 655 | /* Return error status */ |
|
- | 656 | status = HAL_ERROR; |
|
- | 657 | } |
|
- | 658 | ||
- | 659 | /* Release Lock */ |
|
- | 660 | __HAL_UNLOCK(hsc); |
|
- | 661 | ||
- | 662 | return status; |
|
- | 663 | } |
|
- | 664 | #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACKS */ |
|
- | 665 | ||
370 | /** |
666 | /** |
371 | * @} |
667 | * @} |
372 | */ |
668 | */ |
373 | 669 | ||
374 | /** @defgroup SMARTCARD_Exported_Functions_Group2 IO operation functions |
670 | /** @defgroup SMARTCARD_Exported_Functions_Group2 IO operation functions |
375 | * @brief SMARTCARD Transmit and Receive functions |
671 | * @brief SMARTCARD Transmit and Receive functions |
376 | * |
672 | * |
377 | @verbatim |
673 | @verbatim |
378 | =============================================================================== |
674 | =============================================================================== |
379 | ##### IO operation functions ##### |
675 | ##### IO operation functions ##### |
380 | =============================================================================== |
676 | =============================================================================== |
Line 418... | Line 714... | ||
418 | (#) A set of Transfer Complete Callbacks are provided in non Blocking mode: |
714 | (#) A set of Transfer Complete Callbacks are provided in non Blocking mode: |
419 | (++) HAL_SMARTCARD_TxCpltCallback() |
715 | (++) HAL_SMARTCARD_TxCpltCallback() |
420 | (++) HAL_SMARTCARD_RxCpltCallback() |
716 | (++) HAL_SMARTCARD_RxCpltCallback() |
421 | (++) HAL_SMARTCARD_ErrorCallback() |
717 | (++) HAL_SMARTCARD_ErrorCallback() |
422 | 718 | ||
- | 719 | (#) Non-Blocking mode transfers could be aborted using Abort API's : |
|
- | 720 | (+) HAL_SMARTCARD_Abort() |
|
- | 721 | (+) HAL_SMARTCARD_AbortTransmit() |
|
- | 722 | (+) HAL_SMARTCARD_AbortReceive() |
|
- | 723 | (+) HAL_SMARTCARD_Abort_IT() |
|
- | 724 | (+) HAL_SMARTCARD_AbortTransmit_IT() |
|
- | 725 | (+) HAL_SMARTCARD_AbortReceive_IT() |
|
- | 726 | ||
- | 727 | (#) For Abort services based on interrupts (HAL_SMARTCARD_Abortxxx_IT), a set of Abort Complete Callbacks are provided: |
|
- | 728 | (+) HAL_SMARTCARD_AbortCpltCallback() |
|
- | 729 | (+) HAL_SMARTCARD_AbortTransmitCpltCallback() |
|
- | 730 | (+) HAL_SMARTCARD_AbortReceiveCpltCallback() |
|
- | 731 | ||
- | 732 | (#) In Non-Blocking mode transfers, possible errors are split into 2 categories. |
|
- | 733 | Errors are handled as follows : |
|
- | 734 | (+) Error is considered as Recoverable and non blocking : Transfer could go till end, but error severity is |
|
- | 735 | to be evaluated by user : this concerns Frame Error, Parity Error or Noise Error in Interrupt mode reception . |
|
- | 736 | Received character is then retrieved and stored in Rx buffer, Error code is set to allow user to identify error type, |
|
- | 737 | and HAL_SMARTCARD_ErrorCallback() user callback is executed. Transfer is kept ongoing on SMARTCARD side. |
|
- | 738 | If user wants to abort it, Abort services should be called by user. |
|
- | 739 | (+) Error is considered as Blocking : Transfer could not be completed properly and is aborted. |
|
- | 740 | This concerns Frame Error in Interrupt mode tranmission, Overrun Error in Interrupt mode reception and all errors in DMA mode. |
|
- | 741 | Error code is set to allow user to identify error type, and HAL_SMARTCARD_ErrorCallback() user callback is executed. |
|
- | 742 | ||
423 | @endverbatim |
743 | @endverbatim |
424 | * @{ |
744 | * @{ |
425 | */ |
745 | */ |
426 | 746 | ||
427 | /** |
747 | /** |
428 | * @brief Send an amount of data in blocking mode |
748 | * @brief Send an amount of data in blocking mode |
429 | * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains |
749 | * @param hsc Pointer to a SMARTCARD_HandleTypeDef structure that contains |
430 | * the configuration information for SMARTCARD module. |
750 | * the configuration information for SMARTCARD module. |
431 | * @param pData: pointer to data buffer |
751 | * @param pData Pointer to data buffer |
432 | * @param Size: amount of data to be sent |
752 | * @param Size Amount of data to be sent |
433 | * @param Timeout: Timeout duration |
753 | * @param Timeout Timeout duration |
434 | * @retval HAL status |
754 | * @retval HAL status |
435 | */ |
755 | */ |
436 | HAL_StatusTypeDef HAL_SMARTCARD_Transmit(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size, uint32_t Timeout) |
756 | HAL_StatusTypeDef HAL_SMARTCARD_Transmit(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size, uint32_t Timeout) |
437 | { |
757 | { |
- | 758 | uint8_t *tmp = pData; |
|
438 | uint32_t tickstart = 0U; |
759 | uint32_t tickstart = 0U; |
439 | 760 | ||
440 | if (hsc->gState == HAL_SMARTCARD_STATE_READY) |
761 | if(hsc->gState == HAL_SMARTCARD_STATE_READY) |
441 | { |
762 | { |
442 | if ((pData == NULL) || (Size == 0U)) |
763 | if((pData == NULL) || (Size == 0U)) |
443 | { |
764 | { |
444 | return HAL_ERROR; |
765 | return HAL_ERROR; |
445 | } |
766 | } |
446 | 767 | ||
447 | /* Process Locked */ |
768 | /* Process Locked */ |
Line 453... | Line 774... | ||
453 | /* Init tickstart for timeout managment */ |
774 | /* Init tickstart for timeout managment */ |
454 | tickstart = HAL_GetTick(); |
775 | tickstart = HAL_GetTick(); |
455 | 776 | ||
456 | hsc->TxXferSize = Size; |
777 | hsc->TxXferSize = Size; |
457 | hsc->TxXferCount = Size; |
778 | hsc->TxXferCount = Size; |
458 | while (hsc->TxXferCount > 0U) |
779 | while(hsc->TxXferCount > 0U) |
459 | { |
780 | { |
460 | hsc->TxXferCount--; |
781 | hsc->TxXferCount--; |
461 | if (SMARTCARD_WaitOnFlagUntilTimeout(hsc, SMARTCARD_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK) |
782 | if(SMARTCARD_WaitOnFlagUntilTimeout(hsc, SMARTCARD_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK) |
462 | { |
783 | { |
463 | return HAL_TIMEOUT; |
784 | return HAL_TIMEOUT; |
464 | } |
785 | } |
465 | hsc->Instance->DR = *(uint8_t *) pData; |
786 | hsc->Instance->DR = (uint8_t)(*tmp & 0xFFU); |
466 | pData += 1U; |
787 | tmp++; |
467 | } |
788 | } |
468 | 789 | ||
469 | if (SMARTCARD_WaitOnFlagUntilTimeout(hsc, SMARTCARD_FLAG_TC, RESET, tickstart, Timeout) != HAL_OK) |
790 | if(SMARTCARD_WaitOnFlagUntilTimeout(hsc, SMARTCARD_FLAG_TC, RESET, tickstart, Timeout) != HAL_OK) |
470 | { |
791 | { |
471 | return HAL_TIMEOUT; |
792 | return HAL_TIMEOUT; |
472 | } |
793 | } |
473 | 794 | ||
474 | /* At end of Tx process, restore hsc->gState to Ready */ |
795 | /* At end of Tx process, restore hsc->gState to Ready */ |
475 | hsc->gState = HAL_SMARTCARD_STATE_READY; |
796 | hsc->gState = HAL_SMARTCARD_STATE_READY; |
476 | 797 | ||
477 | /* Process Unlocked */ |
798 | /* Process Unlocked */ |
478 | __HAL_UNLOCK(hsc); |
799 | __HAL_UNLOCK(hsc); |
479 | 800 | ||
Line 485... | Line 806... | ||
485 | } |
806 | } |
486 | } |
807 | } |
487 | 808 | ||
488 | /** |
809 | /** |
489 | * @brief Receive an amount of data in blocking mode |
810 | * @brief Receive an amount of data in blocking mode |
490 | * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains |
811 | * @param hsc Pointer to a SMARTCARD_HandleTypeDef structure that contains |
491 | * the configuration information for SMARTCARD module. |
812 | * the configuration information for SMARTCARD module. |
492 | * @param pData: pointer to data buffer |
813 | * @param pData Pointer to data buffer |
493 | * @param Size: amount of data to be received |
814 | * @param Size Amount of data to be received |
494 | * @param Timeout: Timeout duration |
815 | * @param Timeout Timeout duration |
495 | * @retval HAL status |
816 | * @retval HAL status |
496 | */ |
817 | */ |
497 | HAL_StatusTypeDef HAL_SMARTCARD_Receive(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size, uint32_t Timeout) |
818 | HAL_StatusTypeDef HAL_SMARTCARD_Receive(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size, uint32_t Timeout) |
498 | { |
819 | { |
- | 820 | uint8_t *tmp = pData; |
|
499 | uint32_t tickstart = 0U; |
821 | uint32_t tickstart = 0U; |
500 | 822 | ||
501 | if (hsc->RxState == HAL_SMARTCARD_STATE_READY) |
823 | if(hsc->RxState == HAL_SMARTCARD_STATE_READY) |
502 | { |
824 | { |
503 | if ((pData == NULL) || (Size == 0U)) |
825 | if((pData == NULL) || (Size == 0U)) |
504 | { |
826 | { |
505 | return HAL_ERROR; |
827 | return HAL_ERROR; |
506 | } |
828 | } |
507 | 829 | ||
508 | /* Process Locked */ |
830 | /* Process Locked */ |
Line 516... | Line 838... | ||
516 | 838 | ||
517 | hsc->RxXferSize = Size; |
839 | hsc->RxXferSize = Size; |
518 | hsc->RxXferCount = Size; |
840 | hsc->RxXferCount = Size; |
519 | 841 | ||
520 | /* Check the remain data to be received */ |
842 | /* Check the remain data to be received */ |
521 | while (hsc->RxXferCount > 0U) |
843 | while(hsc->RxXferCount > 0U) |
522 | { |
844 | { |
523 | hsc->RxXferCount--; |
845 | hsc->RxXferCount--; |
524 | if (SMARTCARD_WaitOnFlagUntilTimeout(hsc, SMARTCARD_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK) |
846 | if(SMARTCARD_WaitOnFlagUntilTimeout(hsc, SMARTCARD_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK) |
525 | { |
847 | { |
526 | return HAL_TIMEOUT; |
848 | return HAL_TIMEOUT; |
527 | } |
849 | } |
528 | *(uint8_t *) pData = (uint8_t)hsc->Instance->DR; |
850 | *tmp = (uint8_t)(hsc->Instance->DR & (uint8_t)0xFFU); |
529 | pData += 1U; |
851 | tmp++; |
530 | } |
852 | } |
531 | 853 | ||
532 | /* At end of Rx process, restore hsc->RxState to Ready */ |
854 | /* At end of Rx process, restore hsc->RxState to Ready */ |
533 | hsc->RxState = HAL_SMARTCARD_STATE_READY; |
855 | hsc->RxState = HAL_SMARTCARD_STATE_READY; |
534 | 856 | ||
Line 543... | Line 865... | ||
543 | } |
865 | } |
544 | } |
866 | } |
545 | 867 | ||
546 | /** |
868 | /** |
547 | * @brief Send an amount of data in non blocking mode |
869 | * @brief Send an amount of data in non blocking mode |
548 | * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains |
870 | * @param hsc Pointer to a SMARTCARD_HandleTypeDef structure that contains |
549 | * the configuration information for SMARTCARD module. |
871 | * the configuration information for SMARTCARD module. |
550 | * @param pData: pointer to data buffer |
872 | * @param pData Pointer to data buffer |
551 | * @param Size: amount of data to be sent |
873 | * @param Size Amount of data to be sent |
552 | * @retval HAL status |
874 | * @retval HAL status |
553 | */ |
875 | */ |
554 | HAL_StatusTypeDef HAL_SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size) |
876 | HAL_StatusTypeDef HAL_SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size) |
555 | { |
877 | { |
556 | /* Check that a Tx process is not already ongoing */ |
878 | /* Check that a Tx process is not already ongoing */ |
557 | if (hsc->gState == HAL_SMARTCARD_STATE_READY) |
879 | if(hsc->gState == HAL_SMARTCARD_STATE_READY) |
558 | { |
880 | { |
559 | if ((pData == NULL) || (Size == 0U)) |
881 | if((pData == NULL) || (Size == 0U)) |
560 | { |
882 | { |
561 | return HAL_ERROR; |
883 | return HAL_ERROR; |
562 | } |
884 | } |
- | 885 | ||
563 | /* Process Locked */ |
886 | /* Process Locked */ |
564 | __HAL_LOCK(hsc); |
887 | __HAL_LOCK(hsc); |
565 | 888 | ||
566 | hsc->pTxBuffPtr = pData; |
889 | hsc->pTxBuffPtr = pData; |
567 | hsc->TxXferSize = Size; |
890 | hsc->TxXferSize = Size; |
Line 590... | Line 913... | ||
590 | } |
913 | } |
591 | } |
914 | } |
592 | 915 | ||
593 | /** |
916 | /** |
594 | * @brief Receive an amount of data in non blocking mode |
917 | * @brief Receive an amount of data in non blocking mode |
595 | * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains |
918 | * @param hsc Pointer to a SMARTCARD_HandleTypeDef structure that contains |
596 | * the configuration information for SMARTCARD module. |
919 | * the configuration information for SMARTCARD module. |
597 | * @param pData: pointer to data buffer |
920 | * @param pData Pointer to data buffer |
598 | * @param Size: amount of data to be received |
921 | * @param Size Amount of data to be received |
599 | * @retval HAL status |
922 | * @retval HAL status |
600 | */ |
923 | */ |
601 | HAL_StatusTypeDef HAL_SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size) |
924 | HAL_StatusTypeDef HAL_SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size) |
602 | { |
925 | { |
603 | /* Check that a Rx process is not already ongoing */ |
926 | /* Check that a Rx process is not already ongoing */ |
604 | if (hsc->RxState == HAL_SMARTCARD_STATE_READY) |
927 | if(hsc->RxState == HAL_SMARTCARD_STATE_READY) |
605 | { |
928 | { |
606 | if ((pData == NULL) || (Size == 0U)) |
929 | if((pData == NULL) || (Size == 0U)) |
607 | { |
930 | { |
608 | return HAL_ERROR; |
931 | return HAL_ERROR; |
609 | } |
932 | } |
610 | 933 | ||
611 | /* Process Locked */ |
934 | /* Process Locked */ |
Line 620... | Line 943... | ||
620 | 943 | ||
621 | /* Process Unlocked */ |
944 | /* Process Unlocked */ |
622 | __HAL_UNLOCK(hsc); |
945 | __HAL_UNLOCK(hsc); |
623 | 946 | ||
624 | /* Enable the SMARTCARD Parity Error and Data Register not empty Interrupts */ |
947 | /* Enable the SMARTCARD Parity Error and Data Register not empty Interrupts */ |
625 | SET_BIT(hsc->Instance->CR1, USART_CR1_PEIE | USART_CR1_RXNEIE); |
948 | SET_BIT(hsc->Instance->CR1, USART_CR1_PEIE| USART_CR1_RXNEIE); |
626 | 949 | ||
627 | /* Enable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */ |
950 | /* Enable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */ |
628 | SET_BIT(hsc->Instance->CR3, USART_CR3_EIE); |
951 | SET_BIT(hsc->Instance->CR3, USART_CR3_EIE); |
629 | 952 | ||
630 | return HAL_OK; |
953 | return HAL_OK; |
Line 635... | Line 958... | ||
635 | } |
958 | } |
636 | } |
959 | } |
637 | 960 | ||
638 | /** |
961 | /** |
639 | * @brief Send an amount of data in non blocking mode |
962 | * @brief Send an amount of data in non blocking mode |
640 | * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains |
963 | * @param hsc Pointer to a SMARTCARD_HandleTypeDef structure that contains |
641 | * the configuration information for SMARTCARD module. |
964 | * the configuration information for SMARTCARD module. |
642 | * @param pData: pointer to data buffer |
965 | * @param pData Pointer to data buffer |
643 | * @param Size: amount of data to be sent |
966 | * @param Size Amount of data to be sent |
644 | * @retval HAL status |
967 | * @retval HAL status |
645 | */ |
968 | */ |
646 | HAL_StatusTypeDef HAL_SMARTCARD_Transmit_DMA(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size) |
969 | HAL_StatusTypeDef HAL_SMARTCARD_Transmit_DMA(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size) |
647 | { |
970 | { |
648 | uint32_t *tmp; |
971 | uint32_t *tmp; |
649 | 972 | ||
650 | /* Check that a Tx process is not already ongoing */ |
973 | /* Check that a Tx process is not already ongoing */ |
651 | if (hsc->gState == HAL_SMARTCARD_STATE_READY) |
974 | if(hsc->gState == HAL_SMARTCARD_STATE_READY) |
652 | { |
975 | { |
653 | if ((pData == NULL) || (Size == 0U)) |
976 | if((pData == NULL) || (Size == 0U)) |
654 | { |
977 | { |
655 | return HAL_ERROR; |
978 | return HAL_ERROR; |
656 | } |
979 | } |
657 | 980 | ||
658 | /* Process Locked */ |
981 | /* Process Locked */ |
Line 672... | Line 995... | ||
672 | hsc->hdmatx->XferErrorCallback = SMARTCARD_DMAError; |
995 | hsc->hdmatx->XferErrorCallback = SMARTCARD_DMAError; |
673 | 996 | ||
674 | /* Set the DMA abort callback */ |
997 | /* Set the DMA abort callback */ |
675 | hsc->hdmatx->XferAbortCallback = NULL; |
998 | hsc->hdmatx->XferAbortCallback = NULL; |
676 | 999 | ||
677 | /* Enable the SMARTCARD transmit DMA Channel */ |
1000 | /* Enable the SMARTCARD transmit DMA channel */ |
678 | tmp = (uint32_t *)&pData; |
1001 | tmp = (uint32_t*)&pData; |
679 | HAL_DMA_Start_IT(hsc->hdmatx, *(uint32_t *)tmp, (uint32_t)&hsc->Instance->DR, Size); |
1002 | HAL_DMA_Start_IT(hsc->hdmatx, *(uint32_t*)tmp, (uint32_t)&hsc->Instance->DR, Size); |
680 | 1003 | ||
681 | /* Clear the TC flag in the SR register by writing 0 to it */ |
1004 | /* Clear the TC flag in the SR register by writing 0 to it */ |
682 | __HAL_SMARTCARD_CLEAR_FLAG(hsc, SMARTCARD_FLAG_TC); |
1005 | __HAL_SMARTCARD_CLEAR_FLAG(hsc, SMARTCARD_FLAG_TC); |
683 | 1006 | ||
684 | /* Process Unlocked */ |
1007 | /* Process Unlocked */ |
685 | __HAL_UNLOCK(hsc); |
1008 | __HAL_UNLOCK(hsc); |
686 | 1009 | ||
Line 696... | Line 1019... | ||
696 | } |
1019 | } |
697 | } |
1020 | } |
698 | 1021 | ||
699 | /** |
1022 | /** |
700 | * @brief Receive an amount of data in non blocking mode |
1023 | * @brief Receive an amount of data in non blocking mode |
701 | * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains |
1024 | * @param hsc Pointer to a SMARTCARD_HandleTypeDef structure that contains |
702 | * the configuration information for SMARTCARD module. |
1025 | * the configuration information for SMARTCARD module. |
703 | * @param pData: pointer to data buffer |
1026 | * @param pData Pointer to data buffer |
704 | * @param Size: amount of data to be received |
1027 | * @param Size Amount of data to be received |
705 | * @note When the SMARTCARD parity is enabled (PCE = 1) the data received contain the parity bit.s |
1028 | * @note When the SMARTCARD parity is enabled (PCE = 1) the data received contain the parity bit.s |
706 | * @retval HAL status |
1029 | * @retval HAL status |
707 | */ |
1030 | */ |
708 | HAL_StatusTypeDef HAL_SMARTCARD_Receive_DMA(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size) |
1031 | HAL_StatusTypeDef HAL_SMARTCARD_Receive_DMA(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size) |
709 | { |
1032 | { |
710 | uint32_t *tmp; |
1033 | uint32_t *tmp; |
711 | 1034 | ||
712 | /* Check that a Rx process is not already ongoing */ |
1035 | /* Check that a Rx process is not already ongoing */ |
713 | if (hsc->RxState == HAL_SMARTCARD_STATE_READY) |
1036 | if(hsc->RxState == HAL_SMARTCARD_STATE_READY) |
714 | { |
1037 | { |
715 | if ((pData == NULL) || (Size == 0U)) |
1038 | if((pData == NULL) || (Size == 0U)) |
716 | { |
1039 | { |
717 | return HAL_ERROR; |
1040 | return HAL_ERROR; |
718 | } |
1041 | } |
719 | 1042 | ||
720 | /* Process Locked */ |
1043 | /* Process Locked */ |
Line 733... | Line 1056... | ||
733 | hsc->hdmarx->XferErrorCallback = SMARTCARD_DMAError; |
1056 | hsc->hdmarx->XferErrorCallback = SMARTCARD_DMAError; |
734 | 1057 | ||
735 | /* Set the DMA abort callback */ |
1058 | /* Set the DMA abort callback */ |
736 | hsc->hdmatx->XferAbortCallback = NULL; |
1059 | hsc->hdmatx->XferAbortCallback = NULL; |
737 | 1060 | ||
738 | /* Enable the DMA Channel */ |
1061 | /* Enable the DMA channel */ |
739 | tmp = (uint32_t *)&pData; |
1062 | tmp = (uint32_t*)&pData; |
740 | HAL_DMA_Start_IT(hsc->hdmarx, (uint32_t)&hsc->Instance->DR, *(uint32_t *)tmp, Size); |
1063 | HAL_DMA_Start_IT(hsc->hdmarx, (uint32_t)&hsc->Instance->DR, *(uint32_t*)tmp, Size); |
741 | 1064 | ||
742 | /* Clear the Overrun flag just before enabling the DMA Rx request: can be mandatory for the second transfer */ |
1065 | /* Clear the Overrun flag just before enabling the DMA Rx request: can be mandatory for the second transfer */ |
743 | __HAL_SMARTCARD_CLEAR_OREFLAG(hsc); |
1066 | __HAL_SMARTCARD_CLEAR_OREFLAG(hsc); |
744 | 1067 | ||
745 | /* Process Unlocked */ |
1068 | /* Process Unlocked */ |
Line 780... | Line 1103... | ||
780 | /* Disable TXEIE, TCIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */ |
1103 | /* Disable TXEIE, TCIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */ |
781 | CLEAR_BIT(hsc->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE)); |
1104 | CLEAR_BIT(hsc->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE)); |
782 | CLEAR_BIT(hsc->Instance->CR3, USART_CR3_EIE); |
1105 | CLEAR_BIT(hsc->Instance->CR3, USART_CR3_EIE); |
783 | 1106 | ||
784 | /* Disable the SMARTCARD DMA Tx request if enabled */ |
1107 | /* Disable the SMARTCARD DMA Tx request if enabled */ |
785 | if (HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAT)) |
1108 | if(HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAT)) |
786 | { |
1109 | { |
787 | CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAT); |
1110 | CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAT); |
788 | 1111 | ||
789 | /* Abort the SMARTCARD DMA Tx channel: use blocking DMA Abort API (no callback) */ |
1112 | /* Abort the SMARTCARD DMA Tx channel : use blocking DMA Abort API (no callback) */ |
790 | if (hsc->hdmatx != NULL) |
1113 | if(hsc->hdmatx != NULL) |
791 | { |
1114 | { |
792 | /* Set the SMARTCARD DMA Abort callback to Null. |
1115 | /* Set the SMARTCARD DMA Abort callback to Null. |
793 | No call back execution at end of DMA abort procedure */ |
1116 | No call back execution at end of DMA abort procedure */ |
794 | hsc->hdmatx->XferAbortCallback = NULL; |
1117 | hsc->hdmatx->XferAbortCallback = NULL; |
795 | 1118 | ||
796 | HAL_DMA_Abort(hsc->hdmatx); |
1119 | HAL_DMA_Abort(hsc->hdmatx); |
797 | } |
1120 | } |
798 | } |
1121 | } |
799 | 1122 | ||
800 | /* Disable the SMARTCARD DMA Rx request if enabled */ |
1123 | /* Disable the SMARTCARD DMA Rx request if enabled */ |
801 | if (HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAR)) |
1124 | if(HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAR)) |
802 | { |
1125 | { |
803 | CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAR); |
1126 | CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAR); |
804 | 1127 | ||
805 | /* Abort the SMARTCARD DMA Rx channel: use blocking DMA Abort API (no callback) */ |
1128 | /* Abort the SMARTCARD DMA Rx channel : use blocking DMA Abort API (no callback) */ |
806 | if (hsc->hdmarx != NULL) |
1129 | if(hsc->hdmarx != NULL) |
807 | { |
1130 | { |
808 | /* Set the SMARTCARD DMA Abort callback to Null. |
1131 | /* Set the SMARTCARD DMA Abort callback to Null. |
809 | No call back execution at end of DMA abort procedure */ |
1132 | No call back execution at end of DMA abort procedure */ |
810 | hsc->hdmarx->XferAbortCallback = NULL; |
1133 | hsc->hdmarx->XferAbortCallback = NULL; |
811 | 1134 | ||
Line 830... | Line 1153... | ||
830 | /** |
1153 | /** |
831 | * @brief Abort ongoing Transmit transfer (blocking mode). |
1154 | * @brief Abort ongoing Transmit transfer (blocking mode). |
832 | * @param hsc SMARTCARD handle. |
1155 | * @param hsc SMARTCARD handle. |
833 | * @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode. |
1156 | * @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode. |
834 | * This procedure performs following operations : |
1157 | * This procedure performs following operations : |
835 | * - Disable PPP Interrupts |
1158 | * - Disable SMARTCARD Interrupts (Tx) |
836 | * - Disable the DMA transfer in the peripheral register (if enabled) |
1159 | * - Disable the DMA transfer in the peripheral register (if enabled) |
837 | * - Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode) |
1160 | * - Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode) |
838 | * - Set handle State to READY |
1161 | * - Set handle State to READY |
839 | * @note This procedure is executed in blocking mode : when exiting function, Abort is considered as completed. |
1162 | * @note This procedure is executed in blocking mode : when exiting function, Abort is considered as completed. |
840 | * @retval HAL status |
1163 | * @retval HAL status |
Line 843... | Line 1166... | ||
843 | { |
1166 | { |
844 | /* Disable TXEIE and TCIE interrupts */ |
1167 | /* Disable TXEIE and TCIE interrupts */ |
845 | CLEAR_BIT(hsc->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE)); |
1168 | CLEAR_BIT(hsc->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE)); |
846 | 1169 | ||
847 | /* Disable the SMARTCARD DMA Tx request if enabled */ |
1170 | /* Disable the SMARTCARD DMA Tx request if enabled */ |
848 | if (HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAT)) |
1171 | if(HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAT)) |
849 | { |
1172 | { |
850 | CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAT); |
1173 | CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAT); |
851 | 1174 | ||
852 | /* Abort the SMARTCARD DMA Tx channel: use blocking DMA Abort API (no callback) */ |
1175 | /* Abort the SMARTCARD DMA Tx channel : use blocking DMA Abort API (no callback) */ |
853 | if (hsc->hdmatx != NULL) |
1176 | if(hsc->hdmatx != NULL) |
854 | { |
1177 | { |
855 | /* Set the SMARTCARD DMA Abort callback to Null. |
1178 | /* Set the SMARTCARD DMA Abort callback to Null. |
856 | No call back execution at end of DMA abort procedure */ |
1179 | No call back execution at end of DMA abort procedure */ |
857 | hsc->hdmatx->XferAbortCallback = NULL; |
1180 | hsc->hdmatx->XferAbortCallback = NULL; |
858 | 1181 | ||
Line 886... | Line 1209... | ||
886 | /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */ |
1209 | /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */ |
887 | CLEAR_BIT(hsc->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE)); |
1210 | CLEAR_BIT(hsc->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE)); |
888 | CLEAR_BIT(hsc->Instance->CR3, USART_CR3_EIE); |
1211 | CLEAR_BIT(hsc->Instance->CR3, USART_CR3_EIE); |
889 | 1212 | ||
890 | /* Disable the SMARTCARD DMA Rx request if enabled */ |
1213 | /* Disable the SMARTCARD DMA Rx request if enabled */ |
891 | if (HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAR)) |
1214 | if(HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAR)) |
892 | { |
1215 | { |
893 | CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAR); |
1216 | CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAR); |
894 | 1217 | ||
895 | /* Abort the SMARTCARD DMA Rx channel: use blocking DMA Abort API (no callback) */ |
1218 | /* Abort the SMARTCARD DMA Rx channel : use blocking DMA Abort API (no callback) */ |
896 | if (hsc->hdmarx != NULL) |
1219 | if(hsc->hdmarx != NULL) |
897 | { |
1220 | { |
898 | /* Set the SMARTCARD DMA Abort callback to Null. |
1221 | /* Set the SMARTCARD DMA Abort callback to Null. |
899 | No call back execution at end of DMA abort procedure */ |
1222 | No call back execution at end of DMA abort procedure */ |
900 | hsc->hdmarx->XferAbortCallback = NULL; |
1223 | hsc->hdmarx->XferAbortCallback = NULL; |
901 | 1224 | ||
Line 935... | Line 1258... | ||
935 | CLEAR_BIT(hsc->Instance->CR3, USART_CR3_EIE); |
1258 | CLEAR_BIT(hsc->Instance->CR3, USART_CR3_EIE); |
936 | 1259 | ||
937 | /* If DMA Tx and/or DMA Rx Handles are associated to SMARTCARD Handle, DMA Abort complete callbacks should be initialised |
1260 | /* If DMA Tx and/or DMA Rx Handles are associated to SMARTCARD Handle, DMA Abort complete callbacks should be initialised |
938 | before any call to DMA Abort functions */ |
1261 | before any call to DMA Abort functions */ |
939 | /* DMA Tx Handle is valid */ |
1262 | /* DMA Tx Handle is valid */ |
940 | if (hsc->hdmatx != NULL) |
1263 | if(hsc->hdmatx != NULL) |
941 | { |
1264 | { |
942 | /* Set DMA Abort Complete callback if SMARTCARD DMA Tx request if enabled. |
1265 | /* Set DMA Abort Complete callback if SMARTCARD DMA Tx request if enabled. |
943 | Otherwise, set it to NULL */ |
1266 | Otherwise, set it to NULL */ |
944 | if (HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAT)) |
1267 | if(HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAT)) |
945 | { |
1268 | { |
946 | hsc->hdmatx->XferAbortCallback = SMARTCARD_DMATxAbortCallback; |
1269 | hsc->hdmatx->XferAbortCallback = SMARTCARD_DMATxAbortCallback; |
947 | } |
1270 | } |
948 | else |
1271 | else |
949 | { |
1272 | { |
950 | hsc->hdmatx->XferAbortCallback = NULL; |
1273 | hsc->hdmatx->XferAbortCallback = NULL; |
951 | } |
1274 | } |
952 | } |
1275 | } |
953 | /* DMA Rx Handle is valid */ |
1276 | /* DMA Rx Handle is valid */ |
954 | if (hsc->hdmarx != NULL) |
1277 | if(hsc->hdmarx != NULL) |
955 | { |
1278 | { |
956 | /* Set DMA Abort Complete callback if SMARTCARD DMA Rx request if enabled. |
1279 | /* Set DMA Abort Complete callback if SMARTCARD DMA Rx request if enabled. |
957 | Otherwise, set it to NULL */ |
1280 | Otherwise, set it to NULL */ |
958 | if (HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAR)) |
1281 | if(HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAR)) |
959 | { |
1282 | { |
960 | hsc->hdmarx->XferAbortCallback = SMARTCARD_DMARxAbortCallback; |
1283 | hsc->hdmarx->XferAbortCallback = SMARTCARD_DMARxAbortCallback; |
961 | } |
1284 | } |
962 | else |
1285 | else |
963 | { |
1286 | { |
964 | hsc->hdmarx->XferAbortCallback = NULL; |
1287 | hsc->hdmarx->XferAbortCallback = NULL; |
965 | } |
1288 | } |
966 | } |
1289 | } |
967 | 1290 | ||
968 | /* Disable the SMARTCARD DMA Tx request if enabled */ |
1291 | /* Disable the SMARTCARD DMA Tx request if enabled */ |
969 | if (HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAT)) |
1292 | if(HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAT)) |
970 | { |
1293 | { |
971 | /* Disable DMA Tx at SMARTCARD level */ |
1294 | /* Disable DMA Tx at SMARTCARD level */ |
972 | CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAT); |
1295 | CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAT); |
973 | 1296 | ||
974 | /* Abort the SMARTCARD DMA Tx channel : use non blocking DMA Abort API (callback) */ |
1297 | /* Abort the SMARTCARD DMA Tx channel : use non blocking DMA Abort API (callback) */ |
975 | if (hsc->hdmatx != NULL) |
1298 | if(hsc->hdmatx != NULL) |
976 | { |
1299 | { |
977 | /* SMARTCARD Tx DMA Abort callback has already been initialised : |
1300 | /* SMARTCARD Tx DMA Abort callback has already been initialised : |
978 | will lead to call HAL_SMARTCARD_AbortCpltCallback() at end of DMA abort procedure */ |
1301 | will lead to call HAL_SMARTCARD_AbortCpltCallback() at end of DMA abort procedure */ |
979 | 1302 | ||
980 | /* Abort DMA TX */ |
1303 | /* Abort DMA TX */ |
981 | if (HAL_DMA_Abort_IT(hsc->hdmatx) != HAL_OK) |
1304 | if(HAL_DMA_Abort_IT(hsc->hdmatx) != HAL_OK) |
982 | { |
1305 | { |
983 | hsc->hdmatx->XferAbortCallback = NULL; |
1306 | hsc->hdmatx->XferAbortCallback = NULL; |
984 | } |
1307 | } |
985 | else |
1308 | else |
986 | { |
1309 | { |
Line 988... | Line 1311... | ||
988 | } |
1311 | } |
989 | } |
1312 | } |
990 | } |
1313 | } |
991 | 1314 | ||
992 | /* Disable the SMARTCARD DMA Rx request if enabled */ |
1315 | /* Disable the SMARTCARD DMA Rx request if enabled */ |
993 | if (HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAR)) |
1316 | if(HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAR)) |
994 | { |
1317 | { |
995 | CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAR); |
1318 | CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAR); |
996 | 1319 | ||
997 | /* Abort the SMARTCARD DMA Rx channel : use non blocking DMA Abort API (callback) */ |
1320 | /* Abort the SMARTCARD DMA Rx channel : use non blocking DMA Abort API (callback) */ |
998 | if (hsc->hdmarx != NULL) |
1321 | if(hsc->hdmarx != NULL) |
999 | { |
1322 | { |
1000 | /* SMARTCARD Rx DMA Abort callback has already been initialised : |
1323 | /* SMARTCARD Rx DMA Abort callback has already been initialised : |
1001 | will lead to call HAL_SMARTCARD_AbortCpltCallback() at end of DMA abort procedure */ |
1324 | will lead to call HAL_SMARTCARD_AbortCpltCallback() at end of DMA abort procedure */ |
1002 | 1325 | ||
1003 | /* Abort DMA RX */ |
1326 | /* Abort DMA RX */ |
1004 | if (HAL_DMA_Abort_IT(hsc->hdmarx) != HAL_OK) |
1327 | if(HAL_DMA_Abort_IT(hsc->hdmarx) != HAL_OK) |
1005 | { |
1328 | { |
1006 | hsc->hdmarx->XferAbortCallback = NULL; |
1329 | hsc->hdmarx->XferAbortCallback = NULL; |
1007 | AbortCplt = 0x01U; |
1330 | AbortCplt = 0x01U; |
1008 | } |
1331 | } |
1009 | else |
1332 | else |
Line 1012... | Line 1335... | ||
1012 | } |
1335 | } |
1013 | } |
1336 | } |
1014 | } |
1337 | } |
1015 | 1338 | ||
1016 | /* if no DMA abort complete callback execution is required => call user Abort Complete callback */ |
1339 | /* if no DMA abort complete callback execution is required => call user Abort Complete callback */ |
1017 | if (AbortCplt == 0x01U) |
1340 | if(AbortCplt == 0x01U) |
1018 | { |
1341 | { |
1019 | /* Reset Tx and Rx transfer counters */ |
1342 | /* Reset Tx and Rx transfer counters */ |
1020 | hsc->TxXferCount = 0x00U; |
1343 | hsc->TxXferCount = 0x00U; |
1021 | hsc->RxXferCount = 0x00U; |
1344 | hsc->RxXferCount = 0x00U; |
1022 | 1345 | ||
Line 1026... | Line 1349... | ||
1026 | /* Restore hsc->gState and hsc->RxState to Ready */ |
1349 | /* Restore hsc->gState and hsc->RxState to Ready */ |
1027 | hsc->gState = HAL_SMARTCARD_STATE_READY; |
1350 | hsc->gState = HAL_SMARTCARD_STATE_READY; |
1028 | hsc->RxState = HAL_SMARTCARD_STATE_READY; |
1351 | hsc->RxState = HAL_SMARTCARD_STATE_READY; |
1029 | 1352 | ||
1030 | /* As no DMA to be aborted, call directly user Abort complete callback */ |
1353 | /* As no DMA to be aborted, call directly user Abort complete callback */ |
- | 1354 | #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1) |
|
- | 1355 | /* Call registered Abort complete callback */ |
|
- | 1356 | hsc->AbortCpltCallback(hsc); |
|
- | 1357 | #else |
|
- | 1358 | /* Call legacy weak Abort complete callback */ |
|
1031 | HAL_SMARTCARD_AbortCpltCallback(hsc); |
1359 | HAL_SMARTCARD_AbortCpltCallback(hsc); |
- | 1360 | #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */ |
|
1032 | } |
1361 | } |
1033 | return HAL_OK; |
1362 | return HAL_OK; |
1034 | } |
1363 | } |
1035 | 1364 | ||
1036 | /** |
1365 | /** |
1037 | * @brief Abort ongoing Transmit transfer (Interrupt mode). |
1366 | * @brief Abort ongoing Transmit transfer (Interrupt mode). |
1038 | * @param hsc SMARTCARD handle. |
1367 | * @param hsc SMARTCARD handle. |
1039 | * @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode. |
1368 | * @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode. |
1040 | * This procedure performs following operations : |
1369 | * This procedure performs following operations : |
1041 | * - Disable PPP Interrupts |
1370 | * - Disable SMARTCARD Interrupts (Tx) |
1042 | * - Disable the DMA transfer in the peripheral register (if enabled) |
1371 | * - Disable the DMA transfer in the peripheral register (if enabled) |
1043 | * - Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode) |
1372 | * - Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode) |
1044 | * - Set handle State to READY |
1373 | * - Set handle State to READY |
1045 | * - At abort completion, call user abort complete callback |
1374 | * - At abort completion, call user abort complete callback |
1046 | * @note This procedure is executed in Interrupt mode, meaning that abort procedure could be |
1375 | * @note This procedure is executed in Interrupt mode, meaning that abort procedure could be |
Line 1051... | Line 1380... | ||
1051 | { |
1380 | { |
1052 | /* Disable TXEIE and TCIE interrupts */ |
1381 | /* Disable TXEIE and TCIE interrupts */ |
1053 | CLEAR_BIT(hsc->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE)); |
1382 | CLEAR_BIT(hsc->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE)); |
1054 | 1383 | ||
1055 | /* Disable the SMARTCARD DMA Tx request if enabled */ |
1384 | /* Disable the SMARTCARD DMA Tx request if enabled */ |
1056 | if (HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAT)) |
1385 | if(HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAT)) |
1057 | { |
1386 | { |
1058 | CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAT); |
1387 | CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAT); |
1059 | 1388 | ||
1060 | /* Abort the SMARTCARD DMA Tx channel : use blocking DMA Abort API (no callback) */ |
1389 | /* Abort the SMARTCARD DMA Tx channel : use blocking DMA Abort API (no callback) */ |
1061 | if (hsc->hdmatx != NULL) |
1390 | if(hsc->hdmatx != NULL) |
1062 | { |
1391 | { |
1063 | /* Set the SMARTCARD DMA Abort callback : |
1392 | /* Set the SMARTCARD DMA Abort callback : |
1064 | will lead to call HAL_SMARTCARD_AbortCpltCallback() at end of DMA abort procedure */ |
1393 | will lead to call HAL_SMARTCARD_AbortCpltCallback() at end of DMA abort procedure */ |
1065 | hsc->hdmatx->XferAbortCallback = SMARTCARD_DMATxOnlyAbortCallback; |
1394 | hsc->hdmatx->XferAbortCallback = SMARTCARD_DMATxOnlyAbortCallback; |
1066 | 1395 | ||
1067 | /* Abort DMA TX */ |
1396 | /* Abort DMA TX */ |
1068 | if (HAL_DMA_Abort_IT(hsc->hdmatx) != HAL_OK) |
1397 | if(HAL_DMA_Abort_IT(hsc->hdmatx) != HAL_OK) |
1069 | { |
1398 | { |
1070 | /* Call Directly hsc->hdmatx->XferAbortCallback function in case of error */ |
1399 | /* Call Directly hsc->hdmatx->XferAbortCallback function in case of error */ |
1071 | hsc->hdmatx->XferAbortCallback(hsc->hdmatx); |
1400 | hsc->hdmatx->XferAbortCallback(hsc->hdmatx); |
1072 | } |
1401 | } |
1073 | } |
1402 | } |
Line 1078... | Line 1407... | ||
1078 | 1407 | ||
1079 | /* Restore hsc->gState to Ready */ |
1408 | /* Restore hsc->gState to Ready */ |
1080 | hsc->gState = HAL_SMARTCARD_STATE_READY; |
1409 | hsc->gState = HAL_SMARTCARD_STATE_READY; |
1081 | 1410 | ||
1082 | /* As no DMA to be aborted, call directly user Abort complete callback */ |
1411 | /* As no DMA to be aborted, call directly user Abort complete callback */ |
- | 1412 | #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1) |
|
- | 1413 | /* Call registered Abort Transmit Complete Callback */ |
|
- | 1414 | hsc->AbortTransmitCpltCallback(hsc); |
|
- | 1415 | #else |
|
- | 1416 | /* Call legacy weak Abort Transmit Complete Callback */ |
|
1083 | HAL_SMARTCARD_AbortTransmitCpltCallback(hsc); |
1417 | HAL_SMARTCARD_AbortTransmitCpltCallback(hsc); |
- | 1418 | #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */ |
|
1084 | } |
1419 | } |
1085 | } |
1420 | } |
1086 | else |
1421 | else |
1087 | { |
1422 | { |
1088 | /* Reset Tx transfer counter */ |
1423 | /* Reset Tx transfer counter */ |
Line 1090... | Line 1425... | ||
1090 | 1425 | ||
1091 | /* Restore hsc->gState to Ready */ |
1426 | /* Restore hsc->gState to Ready */ |
1092 | hsc->gState = HAL_SMARTCARD_STATE_READY; |
1427 | hsc->gState = HAL_SMARTCARD_STATE_READY; |
1093 | 1428 | ||
1094 | /* As no DMA to be aborted, call directly user Abort complete callback */ |
1429 | /* As no DMA to be aborted, call directly user Abort complete callback */ |
- | 1430 | #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1) |
|
- | 1431 | /* Call registered Abort Transmit Complete Callback */ |
|
- | 1432 | hsc->AbortTransmitCpltCallback(hsc); |
|
- | 1433 | #else |
|
- | 1434 | /* Call legacy weak Abort Transmit Complete Callback */ |
|
1095 | HAL_SMARTCARD_AbortTransmitCpltCallback(hsc); |
1435 | HAL_SMARTCARD_AbortTransmitCpltCallback(hsc); |
- | 1436 | #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */ |
|
1096 | } |
1437 | } |
1097 | 1438 | ||
1098 | return HAL_OK; |
1439 | return HAL_OK; |
1099 | } |
1440 | } |
1100 | 1441 | ||
1101 | /** |
1442 | /** |
1102 | * @brief Abort ongoing Receive transfer (Interrupt mode). |
1443 | * @brief Abort ongoing Receive transfer (Interrupt mode). |
1103 | * @param hsc SMARTCARD handle. |
1444 | * @param hsc SMARTCARD handle. |
1104 | * @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode. |
1445 | * @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode. |
1105 | * This procedure performs following operations : |
1446 | * This procedure performs following operations : |
1106 | * - Disable PPP Interrupts |
1447 | * - Disable SMARTCARD Interrupts (Rx) |
1107 | * - Disable the DMA transfer in the peripheral register (if enabled) |
1448 | * - Disable the DMA transfer in the peripheral register (if enabled) |
1108 | * - Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode) |
1449 | * - Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode) |
1109 | * - Set handle State to READY |
1450 | * - Set handle State to READY |
1110 | * - At abort completion, call user abort complete callback |
1451 | * - At abort completion, call user abort complete callback |
1111 | * @note This procedure is executed in Interrupt mode, meaning that abort procedure could be |
1452 | * @note This procedure is executed in Interrupt mode, meaning that abort procedure could be |
Line 1117... | Line 1458... | ||
1117 | /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */ |
1458 | /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */ |
1118 | CLEAR_BIT(hsc->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE)); |
1459 | CLEAR_BIT(hsc->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE)); |
1119 | CLEAR_BIT(hsc->Instance->CR3, USART_CR3_EIE); |
1460 | CLEAR_BIT(hsc->Instance->CR3, USART_CR3_EIE); |
1120 | 1461 | ||
1121 | /* Disable the SMARTCARD DMA Rx request if enabled */ |
1462 | /* Disable the SMARTCARD DMA Rx request if enabled */ |
1122 | if (HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAR)) |
1463 | if(HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAR)) |
1123 | { |
1464 | { |
1124 | CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAR); |
1465 | CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAR); |
1125 | 1466 | ||
1126 | /* Abort the SMARTCARD DMA Rx channel : use blocking DMA Abort API (no callback) */ |
1467 | /* Abort the SMARTCARD DMA Rx channel : use blocking DMA Abort API (no callback) */ |
1127 | if (hsc->hdmarx != NULL) |
1468 | if(hsc->hdmarx != NULL) |
1128 | { |
1469 | { |
1129 | /* Set the SMARTCARD DMA Abort callback : |
1470 | /* Set the SMARTCARD DMA Abort callback : |
1130 | will lead to call HAL_SMARTCARD_AbortCpltCallback() at end of DMA abort procedure */ |
1471 | will lead to call HAL_SMARTCARD_AbortCpltCallback() at end of DMA abort procedure */ |
1131 | hsc->hdmarx->XferAbortCallback = SMARTCARD_DMARxOnlyAbortCallback; |
1472 | hsc->hdmarx->XferAbortCallback = SMARTCARD_DMARxOnlyAbortCallback; |
1132 | 1473 | ||
1133 | /* Abort DMA RX */ |
1474 | /* Abort DMA RX */ |
1134 | if (HAL_DMA_Abort_IT(hsc->hdmarx) != HAL_OK) |
1475 | if(HAL_DMA_Abort_IT(hsc->hdmarx) != HAL_OK) |
1135 | { |
1476 | { |
1136 | /* Call Directly hsc->hdmarx->XferAbortCallback function in case of error */ |
1477 | /* Call Directly hsc->hdmarx->XferAbortCallback function in case of error */ |
1137 | hsc->hdmarx->XferAbortCallback(hsc->hdmarx); |
1478 | hsc->hdmarx->XferAbortCallback(hsc->hdmarx); |
1138 | } |
1479 | } |
1139 | } |
1480 | } |
Line 1144... | Line 1485... | ||
1144 | 1485 | ||
1145 | /* Restore hsc->RxState to Ready */ |
1486 | /* Restore hsc->RxState to Ready */ |
1146 | hsc->RxState = HAL_SMARTCARD_STATE_READY; |
1487 | hsc->RxState = HAL_SMARTCARD_STATE_READY; |
1147 | 1488 | ||
1148 | /* As no DMA to be aborted, call directly user Abort complete callback */ |
1489 | /* As no DMA to be aborted, call directly user Abort complete callback */ |
- | 1490 | #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1) |
|
- | 1491 | /* Call registered Abort Receive Complete Callback */ |
|
- | 1492 | hsc->AbortReceiveCpltCallback(hsc); |
|
- | 1493 | #else |
|
- | 1494 | /* Call legacy weak Abort Receive Complete Callback */ |
|
1149 | HAL_SMARTCARD_AbortReceiveCpltCallback(hsc); |
1495 | HAL_SMARTCARD_AbortReceiveCpltCallback(hsc); |
- | 1496 | #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */ |
|
1150 | } |
1497 | } |
1151 | } |
1498 | } |
1152 | else |
1499 | else |
1153 | { |
1500 | { |
1154 | /* Reset Rx transfer counter */ |
1501 | /* Reset Rx transfer counter */ |
Line 1156... | Line 1503... | ||
1156 | 1503 | ||
1157 | /* Restore hsc->RxState to Ready */ |
1504 | /* Restore hsc->RxState to Ready */ |
1158 | hsc->RxState = HAL_SMARTCARD_STATE_READY; |
1505 | hsc->RxState = HAL_SMARTCARD_STATE_READY; |
1159 | 1506 | ||
1160 | /* As no DMA to be aborted, call directly user Abort complete callback */ |
1507 | /* As no DMA to be aborted, call directly user Abort complete callback */ |
- | 1508 | #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1) |
|
- | 1509 | /* Call registered Abort Receive Complete Callback */ |
|
- | 1510 | hsc->AbortReceiveCpltCallback(hsc); |
|
- | 1511 | #else |
|
- | 1512 | /* Call legacy weak Abort Receive Complete Callback */ |
|
1161 | HAL_SMARTCARD_AbortReceiveCpltCallback(hsc); |
1513 | HAL_SMARTCARD_AbortReceiveCpltCallback(hsc); |
- | 1514 | #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */ |
|
1162 | } |
1515 | } |
1163 | 1516 | ||
1164 | return HAL_OK; |
1517 | return HAL_OK; |
1165 | } |
1518 | } |
1166 | 1519 | ||
1167 | /** |
1520 | /** |
1168 | * @brief This function handles SMARTCARD interrupt request. |
1521 | * @brief This function handles SMARTCARD interrupt request. |
1169 | * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains |
1522 | * @param hsc Pointer to a SMARTCARD_HandleTypeDef structure that contains |
1170 | * the configuration information for SMARTCARD module. |
1523 | * the configuration information for SMARTCARD module. |
1171 | * @retval None |
1524 | * @retval None |
1172 | */ |
1525 | */ |
1173 | void HAL_SMARTCARD_IRQHandler(SMARTCARD_HandleTypeDef *hsc) |
1526 | void HAL_SMARTCARD_IRQHandler(SMARTCARD_HandleTypeDef *hsc) |
1174 | { |
1527 | { |
Line 1178... | Line 1531... | ||
1178 | uint32_t dmarequest = 0x00U; |
1531 | uint32_t dmarequest = 0x00U; |
1179 | uint32_t errorflags = 0x00U; |
1532 | uint32_t errorflags = 0x00U; |
1180 | 1533 | ||
1181 | /* If no error occurs */ |
1534 | /* If no error occurs */ |
1182 | errorflags = (isrflags & (uint32_t)(USART_SR_PE | USART_SR_FE | USART_SR_ORE | USART_SR_NE)); |
1535 | errorflags = (isrflags & (uint32_t)(USART_SR_PE | USART_SR_FE | USART_SR_ORE | USART_SR_NE)); |
1183 | if (errorflags == RESET) |
1536 | if(errorflags == RESET) |
1184 | { |
1537 | { |
1185 | /* SMARTCARD in mode Receiver -------------------------------------------------*/ |
1538 | /* SMARTCARD in mode Receiver -------------------------------------------------*/ |
1186 | if (((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET)) |
1539 | if(((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET)) |
1187 | { |
1540 | { |
1188 | SMARTCARD_Receive_IT(hsc); |
1541 | SMARTCARD_Receive_IT(hsc); |
1189 | return; |
1542 | return; |
1190 | } |
1543 | } |
1191 | } |
1544 | } |
1192 | 1545 | ||
1193 | /* If some errors occur */ |
1546 | /* If some errors occur */ |
1194 | if ((errorflags != RESET) && (((cr3its & USART_CR3_EIE) != RESET) || ((cr1its & (USART_CR1_RXNEIE | USART_CR1_PEIE)) != RESET))) |
1547 | if((errorflags != RESET) && (((cr3its & USART_CR3_EIE) != RESET) || ((cr1its & (USART_CR1_RXNEIE | USART_CR1_PEIE)) != RESET))) |
1195 | { |
1548 | { |
1196 | /* SMARTCARD parity error interrupt occurred ---------------------------*/ |
1549 | /* SMARTCARD parity error interrupt occurred ---------------------------*/ |
1197 | if (((isrflags & SMARTCARD_FLAG_PE) != RESET) && ((cr1its & USART_CR1_PEIE) != RESET)) |
1550 | if(((isrflags & SMARTCARD_FLAG_PE) != RESET) && ((cr1its & USART_CR1_PEIE) != RESET)) |
1198 | { |
1551 | { |
1199 | hsc->ErrorCode |= HAL_SMARTCARD_ERROR_PE; |
1552 | hsc->ErrorCode |= HAL_SMARTCARD_ERROR_PE; |
1200 | } |
1553 | } |
1201 | 1554 | ||
1202 | /* SMARTCARD noise error interrupt occurred ----------------------------*/ |
1555 | /* SMARTCARD frame error interrupt occurred ----------------------------*/ |
1203 | if (((isrflags & SMARTCARD_FLAG_NE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET)) |
1556 | if(((isrflags & SMARTCARD_FLAG_FE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET)) |
1204 | { |
1557 | { |
1205 | hsc->ErrorCode |= HAL_SMARTCARD_ERROR_NE; |
1558 | hsc->ErrorCode |= HAL_SMARTCARD_ERROR_FE; |
1206 | } |
1559 | } |
1207 | 1560 | ||
1208 | /* SMARTCARD frame error interrupt occurred ----------------------------*/ |
1561 | /* SMARTCARD noise error interrupt occurred ----------------------------*/ |
1209 | if (((isrflags & SMARTCARD_FLAG_FE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET)) |
1562 | if(((isrflags & SMARTCARD_FLAG_NE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET)) |
1210 | { |
1563 | { |
1211 | hsc->ErrorCode |= HAL_SMARTCARD_ERROR_FE; |
1564 | hsc->ErrorCode |= HAL_SMARTCARD_ERROR_NE; |
1212 | } |
1565 | } |
1213 | 1566 | ||
1214 | /* SMARTCARD Over-Run interrupt occurred -------------------------------*/ |
1567 | /* SMARTCARD Over-Run interrupt occurred -------------------------------*/ |
1215 | if (((isrflags & SMARTCARD_FLAG_ORE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET)) |
1568 | if(((isrflags & SMARTCARD_FLAG_ORE) != RESET) && (((cr1its & USART_CR1_RXNEIE) != RESET) || ((cr3its & USART_CR3_EIE) != RESET))) |
1216 | { |
1569 | { |
1217 | hsc->ErrorCode |= HAL_SMARTCARD_ERROR_ORE; |
1570 | hsc->ErrorCode |= HAL_SMARTCARD_ERROR_ORE; |
1218 | } |
1571 | } |
1219 | - | ||
1220 | /* Call SMARTCARD Error Call back function if need be ------------------*/ |
1572 | /* Call the Error call Back in case of Errors --------------------------*/ |
1221 | if (hsc->ErrorCode != HAL_SMARTCARD_ERROR_NONE) |
1573 | if(hsc->ErrorCode != HAL_SMARTCARD_ERROR_NONE) |
1222 | { |
1574 | { |
1223 | /* SMARTCARD in mode Receiver ----------------------------------------*/ |
1575 | /* SMARTCARD in mode Receiver ----------------------------------------*/ |
1224 | if (((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET)) |
1576 | if(((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET)) |
1225 | { |
1577 | { |
1226 | SMARTCARD_Receive_IT(hsc); |
1578 | SMARTCARD_Receive_IT(hsc); |
1227 | } |
1579 | } |
1228 | 1580 | ||
1229 | /* If Overrun error occurs, or if any error occurs in DMA mode reception, |
1581 | /* If Overrun error occurs, or if any error occurs in DMA mode reception, |
1230 | consider error as blocking */ |
1582 | consider error as blocking */ |
1231 | dmarequest = HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAR); |
1583 | dmarequest = HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAR); |
1232 | if (((hsc->ErrorCode & HAL_SMARTCARD_ERROR_ORE) != RESET) || dmarequest) |
1584 | if(((hsc->ErrorCode & HAL_SMARTCARD_ERROR_ORE) != RESET) || dmarequest) |
1233 | { |
1585 | { |
1234 | /* Blocking error : transfer is aborted |
1586 | /* Blocking error : transfer is aborted |
1235 | Set the SMARTCARD state ready to be able to start again the process, |
1587 | Set the SMARTCARD state ready to be able to start again the process, |
1236 | Disable Rx Interrupts, and disable Rx DMA request, if ongoing */ |
1588 | Disable Rx Interrupts, and disable Rx DMA request, if ongoing */ |
1237 | SMARTCARD_EndRxTransfer(hsc); |
1589 | SMARTCARD_EndRxTransfer(hsc); |
1238 | - | ||
1239 | /* Disable the SMARTCARD DMA Rx request if enabled */ |
1590 | /* Disable the SMARTCARD DMA Rx request if enabled */ |
1240 | if (HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAR)) |
1591 | if(HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAR)) |
1241 | { |
1592 | { |
1242 | CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAR); |
1593 | CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAR); |
1243 | 1594 | ||
1244 | /* Abort the SMARTCARD DMA Rx channel */ |
1595 | /* Abort the SMARTCARD DMA Rx channel */ |
1245 | if (hsc->hdmarx != NULL) |
1596 | if(hsc->hdmarx != NULL) |
1246 | { |
1597 | { |
1247 | /* Set the SMARTCARD DMA Abort callback : |
1598 | /* Set the SMARTCARD DMA Abort callback : |
1248 | will lead to call HAL_SMARTCARD_ErrorCallback() at end of DMA abort procedure */ |
1599 | will lead to call HAL_SMARTCARD_ErrorCallback() at end of DMA abort procedure */ |
1249 | hsc->hdmarx->XferAbortCallback = SMARTCARD_DMAAbortOnError; |
1600 | hsc->hdmarx->XferAbortCallback = SMARTCARD_DMAAbortOnError; |
- | 1601 | ||
1250 | if (HAL_DMA_Abort_IT(hsc->hdmarx) != HAL_OK) |
1602 | if(HAL_DMA_Abort_IT(hsc->hdmarx) != HAL_OK) |
1251 | { |
1603 | { |
1252 | /* Call Directly XferAbortCallback function in case of error */ |
1604 | /* Call Directly XferAbortCallback function in case of error */ |
1253 | hsc->hdmarx->XferAbortCallback(hsc->hdmarx); |
1605 | hsc->hdmarx->XferAbortCallback(hsc->hdmarx); |
1254 | } |
1606 | } |
1255 | } |
1607 | } |
1256 | else |
1608 | else |
1257 | { |
1609 | { |
- | 1610 | #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1) |
|
1258 | /* Call user error callback */ |
1611 | /* Call registered user error callback */ |
- | 1612 | hsc->ErrorCallback(hsc); |
|
- | 1613 | #else |
|
- | 1614 | /* Call legacy weak user error callback */ |
|
1259 | HAL_SMARTCARD_ErrorCallback(hsc); |
1615 | HAL_SMARTCARD_ErrorCallback(hsc); |
- | 1616 | #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */ |
|
1260 | } |
1617 | } |
1261 | } |
1618 | } |
1262 | else |
1619 | else |
1263 | { |
1620 | { |
- | 1621 | #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1) |
|
1264 | /* Call user error callback */ |
1622 | /* Call registered user error callback */ |
- | 1623 | hsc->ErrorCallback(hsc); |
|
- | 1624 | #else |
|
- | 1625 | /* Call legacy weak user error callback */ |
|
1265 | HAL_SMARTCARD_ErrorCallback(hsc); |
1626 | HAL_SMARTCARD_ErrorCallback(hsc); |
- | 1627 | #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */ |
|
1266 | } |
1628 | } |
1267 | } |
1629 | } |
1268 | else |
1630 | else |
1269 | { |
1631 | { |
1270 | /* Non Blocking error : transfer could go on. |
1632 | /* Non Blocking error : transfer could go on. |
1271 | Error is notified to user through user error callback */ |
1633 | Error is notified to user through user error callback */ |
- | 1634 | #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1) |
|
- | 1635 | /* Call registered user error callback */ |
|
- | 1636 | hsc->ErrorCallback(hsc); |
|
- | 1637 | #else |
|
- | 1638 | /* Call legacy weak user error callback */ |
|
1272 | HAL_SMARTCARD_ErrorCallback(hsc); |
1639 | HAL_SMARTCARD_ErrorCallback(hsc); |
- | 1640 | #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */ |
|
1273 | hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE; |
1641 | hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE; |
1274 | } |
1642 | } |
1275 | } |
1643 | } |
1276 | return; |
1644 | return; |
1277 | } /* End if some error occurs */ |
1645 | } /* End if some error occurs */ |
1278 | 1646 | ||
1279 | /* SMARTCARD in mode Transmitter -------------------------------------------*/ |
1647 | /* SMARTCARD in mode Transmitter ------------------------------------------*/ |
1280 | if (((isrflags & SMARTCARD_FLAG_TXE) != RESET) && ((cr1its & USART_CR1_TXEIE) != RESET)) |
1648 | if(((isrflags & SMARTCARD_FLAG_TXE) != RESET) && ((cr1its & USART_CR1_TXEIE) != RESET)) |
1281 | { |
1649 | { |
1282 | SMARTCARD_Transmit_IT(hsc); |
1650 | SMARTCARD_Transmit_IT(hsc); |
1283 | return; |
1651 | return; |
1284 | } |
1652 | } |
1285 | 1653 | ||
1286 | /* SMARTCARD in mode Transmitter (transmission end) ------------------------*/ |
1654 | /* SMARTCARD in mode Transmitter (transmission end) -----------------------*/ |
1287 | if (((isrflags & SMARTCARD_FLAG_TC) != RESET) && ((cr1its & USART_CR1_TCIE) != RESET)) |
1655 | if(((isrflags & SMARTCARD_FLAG_TC) != RESET) && ((cr1its & USART_CR1_TCIE) != RESET)) |
1288 | { |
1656 | { |
1289 | SMARTCARD_EndTransmit_IT(hsc); |
1657 | SMARTCARD_EndTransmit_IT(hsc); |
1290 | return; |
1658 | return; |
1291 | } |
1659 | } |
1292 | } |
1660 | } |
1293 | 1661 | ||
1294 | /** |
1662 | /** |
1295 | * @brief Tx Transfer completed callbacks |
1663 | * @brief Tx Transfer completed callbacks |
1296 | * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains |
1664 | * @param hsc Pointer to a SMARTCARD_HandleTypeDef structure that contains |
1297 | * the configuration information for SMARTCARD module. |
1665 | * the configuration information for SMARTCARD module. |
1298 | * @retval None |
1666 | * @retval None |
1299 | */ |
1667 | */ |
1300 | __weak void HAL_SMARTCARD_TxCpltCallback(SMARTCARD_HandleTypeDef *hsc) |
1668 | __weak void HAL_SMARTCARD_TxCpltCallback(SMARTCARD_HandleTypeDef *hsc) |
1301 | { |
1669 | { |
1302 | /* Prevent unused argument(s) compilation warning */ |
1670 | /* Prevent unused argument(s) compilation warning */ |
1303 | UNUSED(hsc); |
1671 | UNUSED(hsc); |
- | 1672 | ||
1304 | /* NOTE : This function Should not be modified, when the callback is needed, |
1673 | /* NOTE : This function should not be modified, when the callback is needed, |
1305 | the HAL_SMARTCARD_TxCpltCallback could be implemented in the user file |
1674 | the HAL_SMARTCARD_TxCpltCallback can be implemented in the user file. |
1306 | */ |
1675 | */ |
1307 | } |
1676 | } |
1308 | 1677 | ||
1309 | /** |
1678 | /** |
1310 | * @brief Rx Transfer completed callbacks |
1679 | * @brief Rx Transfer completed callback |
1311 | * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains |
1680 | * @param hsc Pointer to a SMARTCARD_HandleTypeDef structure that contains |
1312 | * the configuration information for SMARTCARD module. |
1681 | * the configuration information for SMARTCARD module. |
1313 | * @retval None |
1682 | * @retval None |
1314 | */ |
1683 | */ |
1315 | __weak void HAL_SMARTCARD_RxCpltCallback(SMARTCARD_HandleTypeDef *hsc) |
1684 | __weak void HAL_SMARTCARD_RxCpltCallback(SMARTCARD_HandleTypeDef *hsc) |
1316 | { |
1685 | { |
1317 | /* Prevent unused argument(s) compilation warning */ |
1686 | /* Prevent unused argument(s) compilation warning */ |
1318 | UNUSED(hsc); |
1687 | UNUSED(hsc); |
- | 1688 | ||
1319 | /* NOTE : This function Should not be modified, when the callback is needed, |
1689 | /* NOTE : This function should not be modified, when the callback is needed, |
1320 | the HAL_SMARTCARD_RxCpltCallback could be implemented in the user file |
1690 | the HAL_SMARTCARD_RxCpltCallback can be implemented in the user file. |
1321 | */ |
1691 | */ |
1322 | } |
1692 | } |
1323 | 1693 | ||
1324 | /** |
1694 | /** |
1325 | * @brief SMARTCARD error callbacks |
1695 | * @brief SMARTCARD error callback |
1326 | * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains |
1696 | * @param hsc Pointer to a SMARTCARD_HandleTypeDef structure that contains |
1327 | * the configuration information for SMARTCARD module. |
1697 | * the configuration information for SMARTCARD module. |
1328 | * @retval None |
1698 | * @retval None |
1329 | */ |
1699 | */ |
1330 | __weak void HAL_SMARTCARD_ErrorCallback(SMARTCARD_HandleTypeDef *hsc) |
1700 | __weak void HAL_SMARTCARD_ErrorCallback(SMARTCARD_HandleTypeDef *hsc) |
1331 | { |
1701 | { |
1332 | /* Prevent unused argument(s) compilation warning */ |
1702 | /* Prevent unused argument(s) compilation warning */ |
1333 | UNUSED(hsc); |
1703 | UNUSED(hsc); |
- | 1704 | ||
1334 | /* NOTE : This function Should not be modified, when the callback is needed, |
1705 | /* NOTE : This function should not be modified, when the callback is needed, |
1335 | the HAL_SMARTCARD_ErrorCallback could be implemented in the user file |
1706 | the HAL_SMARTCARD_ErrorCallback can be implemented in the user file. |
1336 | */ |
1707 | */ |
1337 | } |
1708 | } |
1338 | 1709 | ||
1339 | /** |
1710 | /** |
1340 | * @brief SMARTCARD Abort Complete callback. |
1711 | * @brief SMARTCARD Abort Complete callback. |
1341 | * @param hsc SMARTCARD handle. |
1712 | * @param hsc SMARTCARD handle. |
1342 | * @retval None |
1713 | * @retval None |
1343 | */ |
1714 | */ |
1344 | __weak void HAL_SMARTCARD_AbortCpltCallback(SMARTCARD_HandleTypeDef *hsc) |
1715 | __weak void HAL_SMARTCARD_AbortCpltCallback (SMARTCARD_HandleTypeDef *hsc) |
1345 | { |
1716 | { |
1346 | /* Prevent unused argument(s) compilation warning */ |
1717 | /* Prevent unused argument(s) compilation warning */ |
1347 | UNUSED(hsc); |
1718 | UNUSED(hsc); |
1348 | 1719 | ||
1349 | /* NOTE : This function should not be modified, when the callback is needed, |
1720 | /* NOTE : This function should not be modified, when the callback is needed, |
Line 1354... | Line 1725... | ||
1354 | /** |
1725 | /** |
1355 | * @brief SMARTCARD Abort Transmit Complete callback. |
1726 | * @brief SMARTCARD Abort Transmit Complete callback. |
1356 | * @param hsc SMARTCARD handle. |
1727 | * @param hsc SMARTCARD handle. |
1357 | * @retval None |
1728 | * @retval None |
1358 | */ |
1729 | */ |
1359 | __weak void HAL_SMARTCARD_AbortTransmitCpltCallback(SMARTCARD_HandleTypeDef *hsc) |
1730 | __weak void HAL_SMARTCARD_AbortTransmitCpltCallback (SMARTCARD_HandleTypeDef *hsc) |
1360 | { |
1731 | { |
1361 | /* Prevent unused argument(s) compilation warning */ |
1732 | /* Prevent unused argument(s) compilation warning */ |
1362 | UNUSED(hsc); |
1733 | UNUSED(hsc); |
1363 | 1734 | ||
1364 | /* NOTE : This function should not be modified, when the callback is needed, |
1735 | /* NOTE : This function should not be modified, when the callback is needed, |
1365 | the HAL_SMARTCARD_AbortTransmitCpltCallback can be implemented in the user file. |
1736 | the HAL_SMARTCARD_AbortTransmitCpltCallback can be implemented in the user file. |
1366 | */ |
1737 | */ |
1367 | } |
1738 | } |
1368 | 1739 | ||
1369 | /** |
1740 | /** |
1370 | * @brief SMARTCARD Abort ReceiveComplete callback. |
1741 | * @brief SMARTCARD Abort Receive Complete callback. |
1371 | * @param hsc SMARTCARD handle. |
1742 | * @param hsc SMARTCARD handle. |
1372 | * @retval None |
1743 | * @retval None |
1373 | */ |
1744 | */ |
1374 | __weak void HAL_SMARTCARD_AbortReceiveCpltCallback(SMARTCARD_HandleTypeDef *hsc) |
1745 | __weak void HAL_SMARTCARD_AbortReceiveCpltCallback (SMARTCARD_HandleTypeDef *hsc) |
1375 | { |
1746 | { |
1376 | /* Prevent unused argument(s) compilation warning */ |
1747 | /* Prevent unused argument(s) compilation warning */ |
1377 | UNUSED(hsc); |
1748 | UNUSED(hsc); |
1378 | 1749 | ||
1379 | /* NOTE : This function should not be modified, when the callback is needed, |
1750 | /* NOTE : This function should not be modified, when the callback is needed, |
1380 | the HAL_SMARTCARD_AbortReceiveCpltCallback can be implemented in the user file. |
1751 | the HAL_SMARTCARD_AbortReceiveCpltCallback can be implemented in the user file. |
1381 | */ |
1752 | */ |
1382 | } |
1753 | } |
Line 1399... | Line 1770... | ||
1399 | @endverbatim |
1770 | @endverbatim |
1400 | * @{ |
1771 | * @{ |
1401 | */ |
1772 | */ |
1402 | 1773 | ||
1403 | /** |
1774 | /** |
1404 | * @brief return the SMARTCARD state |
1775 | * @brief Return the SMARTCARD handle state |
1405 | * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains |
1776 | * @param hsc Pointer to a SMARTCARD_HandleTypeDef structure that contains |
1406 | * the configuration information for SMARTCARD module. |
1777 | * the configuration information for SMARTCARD module. |
1407 | * @retval HAL state |
1778 | * @retval HAL state |
1408 | */ |
1779 | */ |
1409 | HAL_SMARTCARD_StateTypeDef HAL_SMARTCARD_GetState(SMARTCARD_HandleTypeDef *hsc) |
1780 | HAL_SMARTCARD_StateTypeDef HAL_SMARTCARD_GetState(SMARTCARD_HandleTypeDef *hsc) |
1410 | { |
1781 | { |
1411 | uint32_t temp1 = 0x00U, temp2 = 0x00U; |
1782 | uint32_t temp1= 0x00U, temp2 = 0x00U; |
1412 | temp1 = hsc->gState; |
1783 | temp1 = hsc->gState; |
1413 | temp2 = hsc->RxState; |
1784 | temp2 = hsc->RxState; |
1414 | 1785 | ||
1415 | return (HAL_SMARTCARD_StateTypeDef)(temp1 | temp2); |
1786 | return (HAL_SMARTCARD_StateTypeDef)(temp1 | temp2); |
1416 | } |
1787 | } |
1417 | 1788 | ||
1418 | /** |
1789 | /** |
1419 | * @brief Return the SMARTCARD error code |
1790 | * @brief Return the SMARTCARD error code |
1420 | * @param hsc : pointer to a SMARTCARD_HandleTypeDef structure that contains |
1791 | * @param hsc Pointer to a SMARTCARD_HandleTypeDef structure that contains |
1421 | * the configuration information for the specified SMARTCARD. |
1792 | * the configuration information for the specified SMARTCARD. |
1422 | * @retval SMARTCARD Error Code |
1793 | * @retval SMARTCARD Error Code |
1423 | */ |
1794 | */ |
1424 | uint32_t HAL_SMARTCARD_GetError(SMARTCARD_HandleTypeDef *hsc) |
1795 | uint32_t HAL_SMARTCARD_GetError(SMARTCARD_HandleTypeDef *hsc) |
1425 | { |
1796 | { |
Line 1429... | Line 1800... | ||
1429 | /** |
1800 | /** |
1430 | * @} |
1801 | * @} |
1431 | */ |
1802 | */ |
1432 | 1803 | ||
1433 | /** |
1804 | /** |
- | 1805 | * @} |
|
- | 1806 | */ |
|
- | 1807 | ||
- | 1808 | /** @defgroup SMARTCARD_Private_Functions SMARTCARD Private Functions |
|
- | 1809 | * @{ |
|
- | 1810 | */ |
|
- | 1811 | ||
- | 1812 | #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1) |
|
- | 1813 | /** |
|
- | 1814 | * @brief Initialize the callbacks to their default values. |
|
- | 1815 | * @param hsc SMARTCARD handle. |
|
- | 1816 | * @retval none |
|
- | 1817 | */ |
|
- | 1818 | void SMARTCARD_InitCallbacksToDefault(SMARTCARD_HandleTypeDef *hsc) |
|
- | 1819 | { |
|
- | 1820 | /* Init the SMARTCARD Callback settings */ |
|
- | 1821 | hsc->TxCpltCallback = HAL_SMARTCARD_TxCpltCallback; /* Legacy weak TxCpltCallback */ |
|
- | 1822 | hsc->RxCpltCallback = HAL_SMARTCARD_RxCpltCallback; /* Legacy weak RxCpltCallback */ |
|
- | 1823 | hsc->ErrorCallback = HAL_SMARTCARD_ErrorCallback; /* Legacy weak ErrorCallback */ |
|
- | 1824 | hsc->AbortCpltCallback = HAL_SMARTCARD_AbortCpltCallback; /* Legacy weak AbortCpltCallback */ |
|
- | 1825 | hsc->AbortTransmitCpltCallback = HAL_SMARTCARD_AbortTransmitCpltCallback; /* Legacy weak AbortTransmitCpltCallback */ |
|
- | 1826 | hsc->AbortReceiveCpltCallback = HAL_SMARTCARD_AbortReceiveCpltCallback; /* Legacy weak AbortReceiveCpltCallback */ |
|
- | 1827 | ||
- | 1828 | } |
|
- | 1829 | #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACKS */ |
|
- | 1830 | ||
- | 1831 | /** |
|
1434 | * @brief DMA SMARTCARD transmit process complete callback |
1832 | * @brief DMA SMARTCARD transmit process complete callback |
1435 | * @param hdma: pointer to a DMA_HandleTypeDef structure that contains |
1833 | * @param hdma Pointer to a DMA_HandleTypeDef structure that contains |
1436 | * the configuration information for the specified DMA module. |
1834 | * the configuration information for the specified DMA module. |
1437 | * @retval None |
1835 | * @retval None |
1438 | */ |
1836 | */ |
1439 | static void SMARTCARD_DMATransmitCplt(DMA_HandleTypeDef *hdma) |
1837 | static void SMARTCARD_DMATransmitCplt(DMA_HandleTypeDef *hdma) |
1440 | { |
1838 | { |
1441 | SMARTCARD_HandleTypeDef *hsc = (SMARTCARD_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
1839 | SMARTCARD_HandleTypeDef* hsc = ( SMARTCARD_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
1442 | 1840 | ||
1443 | hsc->TxXferCount = 0U; |
1841 | hsc->TxXferCount = 0U; |
1444 | 1842 | ||
1445 | /* Disable the DMA transfer for transmit request by setting the DMAT bit |
1843 | /* Disable the DMA transfer for transmit request by setting the DMAT bit |
1446 | in the USART CR3 register */ |
1844 | in the USART CR3 register */ |
Line 1450... | Line 1848... | ||
1450 | SET_BIT(hsc->Instance->CR1, USART_CR1_TCIE); |
1848 | SET_BIT(hsc->Instance->CR1, USART_CR1_TCIE); |
1451 | } |
1849 | } |
1452 | 1850 | ||
1453 | /** |
1851 | /** |
1454 | * @brief DMA SMARTCARD receive process complete callback |
1852 | * @brief DMA SMARTCARD receive process complete callback |
1455 | * @param hdma: pointer to a DMA_HandleTypeDef structure that contains |
1853 | * @param hdma Pointer to a DMA_HandleTypeDef structure that contains |
1456 | * the configuration information for the specified DMA module. |
1854 | * the configuration information for the specified DMA module. |
1457 | * @retval None |
1855 | * @retval None |
1458 | */ |
1856 | */ |
1459 | static void SMARTCARD_DMAReceiveCplt(DMA_HandleTypeDef *hdma) |
1857 | static void SMARTCARD_DMAReceiveCplt(DMA_HandleTypeDef *hdma) |
1460 | { |
1858 | { |
1461 | SMARTCARD_HandleTypeDef *hsc = (SMARTCARD_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
1859 | SMARTCARD_HandleTypeDef* hsc = ( SMARTCARD_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
1462 | 1860 | ||
1463 | hsc->RxXferCount = 0U; |
1861 | hsc->RxXferCount = 0U; |
1464 | 1862 | ||
1465 | /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */ |
1863 | /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */ |
1466 | CLEAR_BIT(hsc->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE)); |
1864 | CLEAR_BIT(hsc->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE)); |
1467 | CLEAR_BIT(hsc->Instance->CR3, USART_CR3_EIE); |
1865 | CLEAR_BIT(hsc->Instance->CR3, USART_CR3_EIE); |
1468 | 1866 | ||
1469 | /* Disable the DMA transfer for the receiver request by setting the DMAR bit |
1867 | /* Disable the DMA transfer for the receiver request by setting the DMAR bit |
1470 | in the USART CR3 register */ |
1868 | in the USART CR3 register */ |
1471 | CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAR); |
1869 | CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAR); |
1472 | 1870 | ||
1473 | /* At end of Rx process, restore hsc->RxState to Ready */ |
1871 | /* At end of Rx process, restore hsc->RxState to Ready */ |
1474 | hsc->RxState = HAL_SMARTCARD_STATE_READY; |
1872 | hsc->RxState = HAL_SMARTCARD_STATE_READY; |
1475 | 1873 | ||
- | 1874 | #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1) |
|
- | 1875 | /* Call registered Rx complete callback */ |
|
- | 1876 | hsc->RxCpltCallback(hsc); |
|
- | 1877 | #else |
|
- | 1878 | /* Call legacy weak Rx complete callback */ |
|
1476 | HAL_SMARTCARD_RxCpltCallback(hsc); |
1879 | HAL_SMARTCARD_RxCpltCallback(hsc); |
- | 1880 | #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */ |
|
1477 | } |
1881 | } |
1478 | 1882 | ||
1479 | /** |
1883 | /** |
1480 | * @brief DMA SMARTCARD communication error callback |
1884 | * @brief DMA SMARTCARD communication error callback |
1481 | * @param hdma: pointer to a DMA_HandleTypeDef structure that contains |
1885 | * @param hdma Pointer to a DMA_HandleTypeDef structure that contains |
1482 | * the configuration information for the specified DMA module. |
1886 | * the configuration information for the specified DMA module. |
1483 | * @retval None |
1887 | * @retval None |
1484 | */ |
1888 | */ |
1485 | static void SMARTCARD_DMAError(DMA_HandleTypeDef *hdma) |
1889 | static void SMARTCARD_DMAError(DMA_HandleTypeDef *hdma) |
1486 | { |
1890 | { |
1487 | uint32_t dmarequest = 0x00U; |
1891 | uint32_t dmarequest = 0x00U; |
1488 | SMARTCARD_HandleTypeDef *hsc = (SMARTCARD_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
1892 | SMARTCARD_HandleTypeDef* hsc = ( SMARTCARD_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
1489 | hsc->RxXferCount = 0U; |
1893 | hsc->RxXferCount = 0U; |
1490 | hsc->TxXferCount = 0U; |
1894 | hsc->TxXferCount = 0U; |
1491 | hsc->ErrorCode = HAL_SMARTCARD_ERROR_DMA; |
1895 | hsc->ErrorCode = HAL_SMARTCARD_ERROR_DMA; |
1492 | 1896 | ||
1493 | /* Stop SMARTCARD DMA Tx request if ongoing */ |
1897 | /* Stop SMARTCARD DMA Tx request if ongoing */ |
1494 | dmarequest = HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAT); |
1898 | dmarequest = HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAT); |
1495 | if ((hsc->gState == HAL_SMARTCARD_STATE_BUSY_TX) && dmarequest) |
1899 | if((hsc->gState == HAL_SMARTCARD_STATE_BUSY_TX) && dmarequest) |
1496 | { |
1900 | { |
1497 | SMARTCARD_EndTxTransfer(hsc); |
1901 | SMARTCARD_EndTxTransfer(hsc); |
1498 | } |
1902 | } |
1499 | 1903 | ||
1500 | /* Stop SMARTCARD DMA Rx request if ongoing */ |
1904 | /* Stop SMARTCARD DMA Rx request if ongoing */ |
1501 | dmarequest = HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAR); |
1905 | dmarequest = HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAR); |
1502 | if ((hsc->RxState == HAL_SMARTCARD_STATE_BUSY_RX) && dmarequest) |
1906 | if((hsc->RxState == HAL_SMARTCARD_STATE_BUSY_RX) && dmarequest) |
1503 | { |
1907 | { |
1504 | SMARTCARD_EndRxTransfer(hsc); |
1908 | SMARTCARD_EndRxTransfer(hsc); |
1505 | } |
1909 | } |
1506 | 1910 | ||
- | 1911 | #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1) |
|
- | 1912 | /* Call registered user error callback */ |
|
- | 1913 | hsc->ErrorCallback(hsc); |
|
- | 1914 | #else |
|
- | 1915 | /* Call legacy weak user error callback */ |
|
1507 | HAL_SMARTCARD_ErrorCallback(hsc); |
1916 | HAL_SMARTCARD_ErrorCallback(hsc); |
- | 1917 | #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */ |
|
1508 | } |
1918 | } |
1509 | 1919 | ||
1510 | /** |
1920 | /** |
1511 | * @brief This function handles SMARTCARD Communication Timeout. |
1921 | * @brief This function handles SMARTCARD Communication Timeout. |
1512 | * @param hsc: SMARTCARD handle |
1922 | * @param hsc Pointer to a SMARTCARD_HandleTypeDef structure that contains |
- | 1923 | * the configuration information for SMARTCARD module. |
|
1513 | * @param Flag: specifies the SMARTCARD flag to check. |
1924 | * @param Flag Specifies the SMARTCARD flag to check. |
1514 | * @param Status: The new Flag status (SET or RESET). |
1925 | * @param Status The new Flag status (SET or RESET). |
1515 | * @param Timeout: Timeout duration |
1926 | * @param Timeout Timeout duration |
1516 | * @param Tickstart: tick start value |
1927 | * @param Tickstart Tick start value |
1517 | * @retval HAL status |
1928 | * @retval HAL status |
1518 | */ |
1929 | */ |
1519 | static HAL_StatusTypeDef SMARTCARD_WaitOnFlagUntilTimeout(SMARTCARD_HandleTypeDef *hsc, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout) |
1930 | static HAL_StatusTypeDef SMARTCARD_WaitOnFlagUntilTimeout(SMARTCARD_HandleTypeDef *hsc, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout) |
1520 | { |
1931 | { |
1521 | /* Wait until flag is set */ |
1932 | /* Wait until flag is set */ |
1522 | while ((__HAL_SMARTCARD_GET_FLAG(hsc, Flag) ? SET : RESET) == Status) |
1933 | while((__HAL_SMARTCARD_GET_FLAG(hsc, Flag) ? SET : RESET) == Status) |
1523 | { |
1934 | { |
1524 | /* Check for the Timeout */ |
1935 | /* Check for the Timeout */ |
1525 | if (Timeout != HAL_MAX_DELAY) |
1936 | if(Timeout != HAL_MAX_DELAY) |
1526 | { |
1937 | { |
1527 | if ((Timeout == 0U) || ((HAL_GetTick() - Tickstart) > Timeout)) |
1938 | if((Timeout == 0U)||((HAL_GetTick() - Tickstart ) > Timeout)) |
1528 | { |
1939 | { |
1529 | /* Disable TXE and RXNE interrupts for the interrupt process */ |
1940 | /* Disable TXE and RXNE interrupts for the interrupt process */ |
1530 | CLEAR_BIT(hsc->Instance->CR1, USART_CR1_TXEIE); |
1941 | CLEAR_BIT(hsc->Instance->CR1, USART_CR1_TXEIE); |
1531 | CLEAR_BIT(hsc->Instance->CR1, USART_CR1_RXNEIE); |
1942 | CLEAR_BIT(hsc->Instance->CR1, USART_CR1_RXNEIE); |
1532 | 1943 | ||
1533 | hsc->gState = HAL_SMARTCARD_STATE_READY; |
1944 | hsc->gState= HAL_SMARTCARD_STATE_READY; |
1534 | hsc->RxState = HAL_SMARTCARD_STATE_READY; |
1945 | hsc->RxState= HAL_SMARTCARD_STATE_READY; |
1535 | 1946 | ||
1536 | /* Process Unlocked */ |
1947 | /* Process Unlocked */ |
1537 | __HAL_UNLOCK(hsc); |
1948 | __HAL_UNLOCK(hsc); |
1538 | 1949 | ||
1539 | return HAL_TIMEOUT; |
1950 | return HAL_TIMEOUT; |
Line 1543... | Line 1954... | ||
1543 | return HAL_OK; |
1954 | return HAL_OK; |
1544 | } |
1955 | } |
1545 | 1956 | ||
1546 | /** |
1957 | /** |
1547 | * @brief End ongoing Tx transfer on SMARTCARD peripheral (following error detection or Transmit completion). |
1958 | * @brief End ongoing Tx transfer on SMARTCARD peripheral (following error detection or Transmit completion). |
1548 | * @param hsc: SMARTCARD handle. |
1959 | * @param hsc Pointer to a SMARTCARD_HandleTypeDef structure that contains |
- | 1960 | * the configuration information for SMARTCARD module. |
|
1549 | * @retval None |
1961 | * @retval None |
1550 | */ |
1962 | */ |
1551 | static void SMARTCARD_EndTxTransfer(SMARTCARD_HandleTypeDef *hsc) |
1963 | static void SMARTCARD_EndTxTransfer(SMARTCARD_HandleTypeDef *hsc) |
1552 | { |
1964 | { |
1553 | /* At end of Tx process, restore hsc->gState to Ready */ |
1965 | /* At end of Tx process, restore hsc->gState to Ready */ |
Line 1558... | Line 1970... | ||
1558 | } |
1970 | } |
1559 | 1971 | ||
1560 | 1972 | ||
1561 | /** |
1973 | /** |
1562 | * @brief End ongoing Rx transfer on SMARTCARD peripheral (following error detection or Reception completion). |
1974 | * @brief End ongoing Rx transfer on SMARTCARD peripheral (following error detection or Reception completion). |
1563 | * @param hsc: SMARTCARD handle. |
1975 | * @param hsc Pointer to a SMARTCARD_HandleTypeDef structure that contains |
- | 1976 | * the configuration information for SMARTCARD module. |
|
1564 | * @retval None |
1977 | * @retval None |
1565 | */ |
1978 | */ |
1566 | static void SMARTCARD_EndRxTransfer(SMARTCARD_HandleTypeDef *hsc) |
1979 | static void SMARTCARD_EndRxTransfer(SMARTCARD_HandleTypeDef *hsc) |
1567 | { |
1980 | { |
1568 | /* At end of Rx process, restore hsc->RxState to Ready */ |
1981 | /* At end of Rx process, restore hsc->RxState to Ready */ |
Line 1571... | Line 1984... | ||
1571 | /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */ |
1984 | /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */ |
1572 | CLEAR_BIT(hsc->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE)); |
1985 | CLEAR_BIT(hsc->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE)); |
1573 | CLEAR_BIT(hsc->Instance->CR3, USART_CR3_EIE); |
1986 | CLEAR_BIT(hsc->Instance->CR3, USART_CR3_EIE); |
1574 | } |
1987 | } |
1575 | 1988 | ||
- | 1989 | /** |
|
- | 1990 | * @brief Send an amount of data in non blocking mode |
|
- | 1991 | * @param hsc Pointer to a SMARTCARD_HandleTypeDef structure that contains |
|
- | 1992 | * the configuration information for SMARTCARD module. |
|
- | 1993 | * @retval HAL status |
|
- | 1994 | */ |
|
- | 1995 | static HAL_StatusTypeDef SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsc) |
|
- | 1996 | { |
|
- | 1997 | ||
- | 1998 | /* Check that a Tx process is ongoing */ |
|
- | 1999 | if(hsc->gState == HAL_SMARTCARD_STATE_BUSY_TX) |
|
- | 2000 | { |
|
- | 2001 | hsc->Instance->DR = (uint8_t)(*hsc->pTxBuffPtr & 0xFFU); |
|
- | 2002 | hsc->pTxBuffPtr++; |
|
1576 | 2003 | ||
- | 2004 | if(--hsc->TxXferCount == 0U) |
|
- | 2005 | { |
|
- | 2006 | /* Disable the SMARTCARD Transmit data register empty Interrupt */ |
|
- | 2007 | CLEAR_BIT(hsc->Instance->CR1, USART_CR1_TXEIE); |
|
- | 2008 | ||
- | 2009 | /* Enable the SMARTCARD Transmit Complete Interrupt */ |
|
- | 2010 | SET_BIT(hsc->Instance->CR1, USART_CR1_TCIE); |
|
- | 2011 | } |
|
- | 2012 | ||
- | 2013 | return HAL_OK; |
|
- | 2014 | } |
|
- | 2015 | else |
|
- | 2016 | { |
|
- | 2017 | return HAL_BUSY; |
|
- | 2018 | } |
|
- | 2019 | } |
|
- | 2020 | ||
- | 2021 | /** |
|
- | 2022 | * @brief Wraps up transmission in non blocking mode. |
|
- | 2023 | * @param hsc Pointer to a SMARTCARD_HandleTypeDef structure that contains |
|
- | 2024 | * the configuration information for the specified SMARTCARD module. |
|
- | 2025 | * @retval HAL status |
|
- | 2026 | */ |
|
- | 2027 | static HAL_StatusTypeDef SMARTCARD_EndTransmit_IT(SMARTCARD_HandleTypeDef *hsc) |
|
- | 2028 | { |
|
- | 2029 | /* Disable the SMARTCARD Transmit Complete Interrupt */ |
|
- | 2030 | CLEAR_BIT(hsc->Instance->CR1, USART_CR1_TCIE); |
|
- | 2031 | ||
- | 2032 | /* Disable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */ |
|
- | 2033 | CLEAR_BIT(hsc->Instance->CR3, USART_CR3_EIE); |
|
- | 2034 | ||
- | 2035 | /* Tx process is ended, restore hsc->gState to Ready */ |
|
- | 2036 | hsc->gState = HAL_SMARTCARD_STATE_READY; |
|
- | 2037 | ||
- | 2038 | #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1) |
|
- | 2039 | /* Call registered Tx complete callback */ |
|
- | 2040 | hsc->TxCpltCallback(hsc); |
|
- | 2041 | #else |
|
- | 2042 | /* Call legacy weak Tx complete callback */ |
|
- | 2043 | HAL_SMARTCARD_TxCpltCallback(hsc); |
|
- | 2044 | #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */ |
|
- | 2045 | ||
- | 2046 | return HAL_OK; |
|
- | 2047 | } |
|
- | 2048 | ||
- | 2049 | /** |
|
- | 2050 | * @brief Receive an amount of data in non blocking mode |
|
- | 2051 | * @param hsc Pointer to a SMARTCARD_HandleTypeDef structure that contains |
|
- | 2052 | * the configuration information for SMARTCARD module. |
|
- | 2053 | * @retval HAL status |
|
- | 2054 | */ |
|
- | 2055 | static HAL_StatusTypeDef SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsc) |
|
- | 2056 | { |
|
- | 2057 | ||
- | 2058 | /* Check that a Rx process is ongoing */ |
|
- | 2059 | if(hsc->RxState == HAL_SMARTCARD_STATE_BUSY_RX) |
|
- | 2060 | { |
|
- | 2061 | *hsc->pRxBuffPtr = (uint8_t)(hsc->Instance->DR & (uint8_t)0xFFU); |
|
- | 2062 | hsc->pRxBuffPtr++; |
|
- | 2063 | ||
- | 2064 | if(--hsc->RxXferCount == 0U) |
|
- | 2065 | { |
|
- | 2066 | CLEAR_BIT(hsc->Instance->CR1, USART_CR1_RXNEIE); |
|
- | 2067 | ||
- | 2068 | /* Disable the SMARTCARD Parity Error Interrupt */ |
|
- | 2069 | CLEAR_BIT(hsc->Instance->CR1, USART_CR1_PEIE); |
|
- | 2070 | ||
- | 2071 | /* Disable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */ |
|
- | 2072 | CLEAR_BIT(hsc->Instance->CR3, USART_CR3_EIE); |
|
- | 2073 | ||
- | 2074 | /* Rx process is completed, restore hsc->RxState to Ready */ |
|
- | 2075 | hsc->RxState = HAL_SMARTCARD_STATE_READY; |
|
- | 2076 | ||
- | 2077 | #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1) |
|
- | 2078 | /* Call registered Rx complete callback */ |
|
- | 2079 | hsc->RxCpltCallback(hsc); |
|
- | 2080 | #else |
|
- | 2081 | /* Call legacy weak Rx complete callback */ |
|
- | 2082 | HAL_SMARTCARD_RxCpltCallback(hsc); |
|
- | 2083 | #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */ |
|
- | 2084 | ||
- | 2085 | return HAL_OK; |
|
- | 2086 | } |
|
- | 2087 | return HAL_OK; |
|
- | 2088 | } |
|
- | 2089 | else |
|
- | 2090 | { |
|
- | 2091 | return HAL_BUSY; |
|
- | 2092 | } |
|
- | 2093 | } |
|
1577 | 2094 | ||
1578 | /** |
2095 | /** |
1579 | * @brief DMA SMARTCARD communication abort callback, when initiated by HAL services on Error |
2096 | * @brief DMA SMARTCARD communication abort callback, when initiated by HAL services on Error |
1580 | * (To be called at end of DMA Abort procedure following error occurrence). |
2097 | * (To be called at end of DMA Abort procedure following error occurrence). |
1581 | * @param hdma DMA handle. |
2098 | * @param hdma DMA handle. |
1582 | * @retval None |
2099 | * @retval None |
1583 | */ |
2100 | */ |
1584 | static void SMARTCARD_DMAAbortOnError(DMA_HandleTypeDef *hdma) |
2101 | static void SMARTCARD_DMAAbortOnError(DMA_HandleTypeDef *hdma) |
1585 | { |
2102 | { |
1586 | SMARTCARD_HandleTypeDef *hsc = (SMARTCARD_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
2103 | SMARTCARD_HandleTypeDef* hsc = (SMARTCARD_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
1587 | hsc->RxXferCount = 0x00U; |
2104 | hsc->RxXferCount = 0x00U; |
1588 | hsc->TxXferCount = 0x00U; |
2105 | hsc->TxXferCount = 0x00U; |
1589 | 2106 | ||
- | 2107 | #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1) |
|
- | 2108 | /* Call registered user error callback */ |
|
- | 2109 | hsc->ErrorCallback(hsc); |
|
- | 2110 | #else |
|
- | 2111 | /* Call legacy weak user error callback */ |
|
1590 | HAL_SMARTCARD_ErrorCallback(hsc); |
2112 | HAL_SMARTCARD_ErrorCallback(hsc); |
- | 2113 | #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */ |
|
1591 | } |
2114 | } |
1592 | 2115 | ||
1593 | /** |
2116 | /** |
1594 | * @brief DMA SMARTCARD Tx communication abort callback, when initiated by user |
2117 | * @brief DMA SMARTCARD Tx communication abort callback, when initiated by user |
1595 | * (To be called at end of DMA Tx Abort procedure following user abort request). |
2118 | * (To be called at end of DMA Tx Abort procedure following user abort request). |
Line 1598... | Line 2121... | ||
1598 | * @param hdma DMA handle. |
2121 | * @param hdma DMA handle. |
1599 | * @retval None |
2122 | * @retval None |
1600 | */ |
2123 | */ |
1601 | static void SMARTCARD_DMATxAbortCallback(DMA_HandleTypeDef *hdma) |
2124 | static void SMARTCARD_DMATxAbortCallback(DMA_HandleTypeDef *hdma) |
1602 | { |
2125 | { |
1603 | SMARTCARD_HandleTypeDef *hsc = (SMARTCARD_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
2126 | SMARTCARD_HandleTypeDef* hsc = ( SMARTCARD_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
1604 | 2127 | ||
1605 | hsc->hdmatx->XferAbortCallback = NULL; |
2128 | hsc->hdmatx->XferAbortCallback = NULL; |
1606 | 2129 | ||
1607 | /* Check if an Abort process is still ongoing */ |
2130 | /* Check if an Abort process is still ongoing */ |
1608 | if (hsc->hdmarx != NULL) |
2131 | if(hsc->hdmarx != NULL) |
1609 | { |
2132 | { |
1610 | if (hsc->hdmarx->XferAbortCallback != NULL) |
2133 | if(hsc->hdmarx->XferAbortCallback != NULL) |
1611 | { |
2134 | { |
1612 | return; |
2135 | return; |
1613 | } |
2136 | } |
1614 | } |
2137 | } |
1615 | 2138 | ||
Line 1622... | Line 2145... | ||
1622 | 2145 | ||
1623 | /* Restore hsc->gState and hsc->RxState to Ready */ |
2146 | /* Restore hsc->gState and hsc->RxState to Ready */ |
1624 | hsc->gState = HAL_SMARTCARD_STATE_READY; |
2147 | hsc->gState = HAL_SMARTCARD_STATE_READY; |
1625 | hsc->RxState = HAL_SMARTCARD_STATE_READY; |
2148 | hsc->RxState = HAL_SMARTCARD_STATE_READY; |
1626 | 2149 | ||
- | 2150 | #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1) |
|
1627 | /* Call user Abort complete callback */ |
2151 | /* Call registered Abort complete callback */ |
- | 2152 | hsc->AbortCpltCallback(hsc); |
|
- | 2153 | #else |
|
- | 2154 | /* Call legacy weak Abort complete callback */ |
|
1628 | HAL_SMARTCARD_AbortCpltCallback(hsc); |
2155 | HAL_SMARTCARD_AbortCpltCallback(hsc); |
- | 2156 | #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */ |
|
1629 | } |
2157 | } |
1630 | 2158 | ||
1631 | /** |
2159 | /** |
1632 | * @brief DMA SMARTCARD Rx communication abort callback, when initiated by user |
2160 | * @brief DMA SMARTCARD Rx communication abort callback, when initiated by user |
1633 | * (To be called at end of DMA Rx Abort procedure following user abort request). |
2161 | * (To be called at end of DMA Rx Abort procedure following user abort request). |
Line 1636... | Line 2164... | ||
1636 | * @param hdma DMA handle. |
2164 | * @param hdma DMA handle. |
1637 | * @retval None |
2165 | * @retval None |
1638 | */ |
2166 | */ |
1639 | static void SMARTCARD_DMARxAbortCallback(DMA_HandleTypeDef *hdma) |
2167 | static void SMARTCARD_DMARxAbortCallback(DMA_HandleTypeDef *hdma) |
1640 | { |
2168 | { |
1641 | SMARTCARD_HandleTypeDef *hsc = (SMARTCARD_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
2169 | SMARTCARD_HandleTypeDef* hsc = ( SMARTCARD_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
1642 | 2170 | ||
1643 | hsc->hdmarx->XferAbortCallback = NULL; |
2171 | hsc->hdmarx->XferAbortCallback = NULL; |
1644 | 2172 | ||
1645 | /* Check if an Abort process is still ongoing */ |
2173 | /* Check if an Abort process is still ongoing */ |
1646 | if (hsc->hdmatx != NULL) |
2174 | if(hsc->hdmatx != NULL) |
1647 | { |
2175 | { |
1648 | if (hsc->hdmatx->XferAbortCallback != NULL) |
2176 | if(hsc->hdmatx->XferAbortCallback != NULL) |
1649 | { |
2177 | { |
1650 | return; |
2178 | return; |
1651 | } |
2179 | } |
1652 | } |
2180 | } |
1653 | 2181 | ||
Line 1660... | Line 2188... | ||
1660 | 2188 | ||
1661 | /* Restore hsc->gState and hsc->RxState to Ready */ |
2189 | /* Restore hsc->gState and hsc->RxState to Ready */ |
1662 | hsc->gState = HAL_SMARTCARD_STATE_READY; |
2190 | hsc->gState = HAL_SMARTCARD_STATE_READY; |
1663 | hsc->RxState = HAL_SMARTCARD_STATE_READY; |
2191 | hsc->RxState = HAL_SMARTCARD_STATE_READY; |
1664 | 2192 | ||
- | 2193 | #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1) |
|
1665 | /* Call user Abort complete callback */ |
2194 | /* Call registered Abort complete callback */ |
- | 2195 | hsc->AbortCpltCallback(hsc); |
|
- | 2196 | #else |
|
- | 2197 | /* Call legacy weak Abort complete callback */ |
|
1666 | HAL_SMARTCARD_AbortCpltCallback(hsc); |
2198 | HAL_SMARTCARD_AbortCpltCallback(hsc); |
- | 2199 | #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */ |
|
1667 | } |
2200 | } |
1668 | 2201 | ||
1669 | /** |
2202 | /** |
1670 | * @brief DMA SMARTCARD Tx communication abort callback, when initiated by user by a call to |
2203 | * @brief DMA SMARTCARD Tx communication abort callback, when initiated by user by a call to |
1671 | * HAL_SMARTCARD_AbortTransmit_IT API (Abort only Tx transfer) |
2204 | * HAL_SMARTCARD_AbortTransmit_IT API (Abort only Tx transfer) |
Line 1674... | Line 2207... | ||
1674 | * @param hdma DMA handle. |
2207 | * @param hdma DMA handle. |
1675 | * @retval None |
2208 | * @retval None |
1676 | */ |
2209 | */ |
1677 | static void SMARTCARD_DMATxOnlyAbortCallback(DMA_HandleTypeDef *hdma) |
2210 | static void SMARTCARD_DMATxOnlyAbortCallback(DMA_HandleTypeDef *hdma) |
1678 | { |
2211 | { |
1679 | SMARTCARD_HandleTypeDef *hsc = (SMARTCARD_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
2212 | SMARTCARD_HandleTypeDef* hsc = ( SMARTCARD_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
1680 | 2213 | ||
1681 | hsc->TxXferCount = 0x00U; |
2214 | hsc->TxXferCount = 0x00U; |
1682 | 2215 | ||
1683 | /* Restore hsc->gState to Ready */ |
2216 | /* Restore hsc->gState to Ready */ |
1684 | hsc->gState = HAL_SMARTCARD_STATE_READY; |
2217 | hsc->gState = HAL_SMARTCARD_STATE_READY; |
1685 | 2218 | ||
- | 2219 | #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1) |
|
1686 | /* Call user Abort complete callback */ |
2220 | /* Call registered Abort Transmit Complete Callback */ |
- | 2221 | hsc->AbortTransmitCpltCallback(hsc); |
|
- | 2222 | #else |
|
- | 2223 | /* Call legacy weak Abort Transmit Complete Callback */ |
|
1687 | HAL_SMARTCARD_AbortTransmitCpltCallback(hsc); |
2224 | HAL_SMARTCARD_AbortTransmitCpltCallback(hsc); |
- | 2225 | #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */ |
|
1688 | } |
2226 | } |
1689 | 2227 | ||
1690 | /** |
2228 | /** |
1691 | * @brief DMA SMARTCARD Rx communication abort callback, when initiated by user by a call to |
2229 | * @brief DMA SMARTCARD Rx communication abort callback, when initiated by user by a call to |
1692 | * HAL_SMARTCARD_AbortReceive_IT API (Abort only Rx transfer) |
2230 | * HAL_SMARTCARD_AbortReceive_IT API (Abort only Rx transfer) |
Line 1695... | Line 2233... | ||
1695 | * @param hdma DMA handle. |
2233 | * @param hdma DMA handle. |
1696 | * @retval None |
2234 | * @retval None |
1697 | */ |
2235 | */ |
1698 | static void SMARTCARD_DMARxOnlyAbortCallback(DMA_HandleTypeDef *hdma) |
2236 | static void SMARTCARD_DMARxOnlyAbortCallback(DMA_HandleTypeDef *hdma) |
1699 | { |
2237 | { |
1700 | SMARTCARD_HandleTypeDef *hsc = (SMARTCARD_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
2238 | SMARTCARD_HandleTypeDef* hsc = ( SMARTCARD_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
1701 | 2239 | ||
1702 | hsc->RxXferCount = 0x00U; |
2240 | hsc->RxXferCount = 0x00U; |
1703 | 2241 | ||
1704 | /* Restore hsc->RxState to Ready */ |
2242 | /* Restore hsc->RxState to Ready */ |
1705 | hsc->RxState = HAL_SMARTCARD_STATE_READY; |
2243 | hsc->RxState = HAL_SMARTCARD_STATE_READY; |
1706 | 2244 | ||
- | 2245 | #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1) |
|
1707 | /* Call user Abort complete callback */ |
2246 | /* Call registered Abort Receive Complete Callback */ |
- | 2247 | hsc->AbortReceiveCpltCallback(hsc); |
|
- | 2248 | #else |
|
- | 2249 | /* Call legacy weak Abort Receive Complete Callback */ |
|
1708 | HAL_SMARTCARD_AbortReceiveCpltCallback(hsc); |
2250 | HAL_SMARTCARD_AbortReceiveCpltCallback(hsc); |
1709 | } |
- | |
1710 | - | ||
1711 | /** |
- | |
1712 | * @brief Send an amount of data in non blocking mode |
- | |
1713 | * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains |
- | |
1714 | * the configuration information for SMARTCARD module. |
- | |
1715 | * @retval HAL status |
- | |
1716 | */ |
- | |
1717 | static HAL_StatusTypeDef SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsc) |
- | |
1718 | { |
- | |
1719 | /* Check that a Tx process is ongoing */ |
- | |
1720 | if (hsc->gState == HAL_SMARTCARD_STATE_BUSY_TX) |
- | |
1721 | { |
- | |
1722 | hsc->Instance->DR = *(uint8_t *) hsc->pTxBuffPtr; |
- | |
1723 | hsc->pTxBuffPtr += 1U; |
- | |
1724 | - | ||
1725 | if (--hsc->TxXferCount == 0U) |
- | |
1726 | { |
- | |
1727 | /* Disable the SMARTCARD Transmit data register empty Interrupt */ |
- | |
1728 | CLEAR_BIT(hsc->Instance->CR1, USART_CR1_TXEIE); |
- | |
1729 | - | ||
1730 | /* Enable the SMARTCARD Transmit Complete Interrupt */ |
- | |
1731 | SET_BIT(hsc->Instance->CR1, USART_CR1_TCIE); |
- | |
1732 | } |
- | |
1733 | - | ||
1734 | return HAL_OK; |
- | |
1735 | } |
- | |
1736 | else |
- | |
1737 | { |
- | |
1738 | return HAL_BUSY; |
- | |
1739 | } |
- | |
1740 | } |
- | |
1741 | - | ||
1742 | /** |
- | |
1743 | * @brief Wraps up transmission in non blocking mode. |
- | |
1744 | * @param hsmartcard: pointer to a SMARTCARD_HandleTypeDef structure that contains |
- | |
1745 | * the configuration information for the specified SMARTCARD module. |
- | |
1746 | * @retval HAL status |
- | |
1747 | */ |
- | |
1748 | static HAL_StatusTypeDef SMARTCARD_EndTransmit_IT(SMARTCARD_HandleTypeDef *hsmartcard) |
- | |
1749 | { |
- | |
1750 | /* Disable the SMARTCARD Transmit Complete Interrupt */ |
- | |
1751 | CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_TCIE); |
- | |
1752 | - | ||
1753 | /* Disable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */ |
- | |
1754 | CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE); |
- | |
1755 | - | ||
1756 | /* Tx process is ended, restore hsmartcard->gState to Ready */ |
- | |
1757 | hsmartcard->gState = HAL_SMARTCARD_STATE_READY; |
- | |
1758 | - | ||
1759 | HAL_SMARTCARD_TxCpltCallback(hsmartcard); |
- | |
1760 | - | ||
1761 | return HAL_OK; |
- | |
1762 | } |
- | |
1763 | - | ||
1764 | /** |
- | |
1765 | * @brief Receive an amount of data in non blocking mode |
- | |
1766 | * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains |
- | |
1767 | * the configuration information for SMARTCARD module. |
- | |
1768 | * @retval HAL status |
- | |
1769 | */ |
- | |
1770 | static HAL_StatusTypeDef SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsc) |
- | |
1771 | { |
- | |
1772 | /* Check that a Rx process is ongoing */ |
- | |
1773 | if (hsc->RxState == HAL_SMARTCARD_STATE_BUSY_RX) |
- | |
1774 | { |
- | |
1775 | *(uint8_t *) hsc->pRxBuffPtr = (uint8_t)hsc->Instance->DR; |
- | |
1776 | hsc->pRxBuffPtr += 1U; |
- | |
1777 | - | ||
1778 | if (--hsc->RxXferCount == 0U) |
- | |
1779 | { |
- | |
1780 | CLEAR_BIT(hsc->Instance->CR1, USART_CR1_RXNEIE); |
- | |
1781 | - | ||
1782 | /* Disable the SMARTCARD Parity Error Interrupt */ |
- | |
1783 | CLEAR_BIT(hsc->Instance->CR1, USART_CR1_PEIE); |
- | |
1784 | - | ||
1785 | /* Disable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */ |
- | |
1786 | CLEAR_BIT(hsc->Instance->CR3, USART_CR3_EIE); |
- | |
1787 | - | ||
1788 | /* Rx process is completed, restore hsc->RxState to Ready */ |
- | |
1789 | hsc->RxState = HAL_SMARTCARD_STATE_READY; |
- | |
1790 | - | ||
1791 | HAL_SMARTCARD_RxCpltCallback(hsc); |
2251 | #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */ |
1792 | - | ||
1793 | return HAL_OK; |
- | |
1794 | } |
- | |
1795 | return HAL_OK; |
- | |
1796 | } |
- | |
1797 | else |
- | |
1798 | { |
- | |
1799 | return HAL_BUSY; |
- | |
1800 | } |
- | |
1801 | } |
2252 | } |
1802 | 2253 | ||
1803 | /** |
2254 | /** |
1804 | * @brief Configure the SMARTCARD peripheral |
2255 | * @brief Configure the SMARTCARD peripheral |
1805 | * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains |
2256 | * @param hsc Pointer to a SMARTCARD_HandleTypeDef structure that contains |
1806 | * the configuration information for SMARTCARD module. |
2257 | * the configuration information for SMARTCARD module. |
1807 | * @retval None |
2258 | * @retval None |
1808 | */ |
2259 | */ |
1809 | static void SMARTCARD_SetConfig(SMARTCARD_HandleTypeDef *hsc) |
2260 | static void SMARTCARD_SetConfig(SMARTCARD_HandleTypeDef *hsc) |
1810 | { |
2261 | { |
1811 | uint32_t tmpreg = 0x00U; |
2262 | uint32_t tmpreg = 0x00U; |
- | 2263 | uint32_t pclk; |
|
1812 | 2264 | ||
1813 | /* Check the parameters */ |
2265 | /* Check the parameters */ |
1814 | assert_param(IS_SMARTCARD_INSTANCE(hsc->Instance)); |
2266 | assert_param(IS_SMARTCARD_INSTANCE(hsc->Instance)); |
1815 | assert_param(IS_SMARTCARD_POLARITY(hsc->Init.CLKPolarity)); |
2267 | assert_param(IS_SMARTCARD_POLARITY(hsc->Init.CLKPolarity)); |
1816 | assert_param(IS_SMARTCARD_PHASE(hsc->Init.CLKPhase)); |
2268 | assert_param(IS_SMARTCARD_PHASE(hsc->Init.CLKPhase)); |
Line 1820... | Line 2272... | ||
1820 | assert_param(IS_SMARTCARD_STOPBITS(hsc->Init.StopBits)); |
2272 | assert_param(IS_SMARTCARD_STOPBITS(hsc->Init.StopBits)); |
1821 | assert_param(IS_SMARTCARD_PARITY(hsc->Init.Parity)); |
2273 | assert_param(IS_SMARTCARD_PARITY(hsc->Init.Parity)); |
1822 | assert_param(IS_SMARTCARD_MODE(hsc->Init.Mode)); |
2274 | assert_param(IS_SMARTCARD_MODE(hsc->Init.Mode)); |
1823 | assert_param(IS_SMARTCARD_NACK_STATE(hsc->Init.NACKState)); |
2275 | assert_param(IS_SMARTCARD_NACK_STATE(hsc->Init.NACKState)); |
1824 | 2276 | ||
1825 | - | ||
1826 | /* The LBCL, CPOL and CPHA bits have to be selected when both the transmitter and the |
2277 | /* The LBCL, CPOL and CPHA bits have to be selected when both the transmitter and the |
1827 | receiver are disabled (TE=RE=0) to ensure that the clock pulses function correctly. */ |
2278 | receiver are disabled (TE=RE=0) to ensure that the clock pulses function correctly. */ |
1828 | CLEAR_BIT(hsc->Instance->CR1, (USART_CR1_TE | USART_CR1_RE)); |
2279 | CLEAR_BIT(hsc->Instance->CR1, (USART_CR1_TE | USART_CR1_RE)); |
1829 | 2280 | ||
1830 | /*---------------------------- USART CR2 Configuration ---------------------*/ |
2281 | /*---------------------------- USART CR2 Configuration ---------------------*/ |
Line 1835... | Line 2286... | ||
1835 | /* Set CPOL bit according to hsc->Init.CLKPolarity value */ |
2286 | /* Set CPOL bit according to hsc->Init.CLKPolarity value */ |
1836 | /* Set CPHA bit according to hsc->Init.CLKPhase value */ |
2287 | /* Set CPHA bit according to hsc->Init.CLKPhase value */ |
1837 | /* Set LBCL bit according to hsc->Init.CLKLastBit value */ |
2288 | /* Set LBCL bit according to hsc->Init.CLKLastBit value */ |
1838 | /* Set Stop Bits: Set STOP[13:12] bits according to hsc->Init.StopBits value */ |
2289 | /* Set Stop Bits: Set STOP[13:12] bits according to hsc->Init.StopBits value */ |
1839 | tmpreg |= (uint32_t)(USART_CR2_CLKEN | hsc->Init.CLKPolarity | |
2290 | tmpreg |= (uint32_t)(USART_CR2_CLKEN | hsc->Init.CLKPolarity | |
1840 | hsc->Init.CLKPhase | hsc->Init.CLKLastBit | hsc->Init.StopBits); |
2291 | hsc->Init.CLKPhase| hsc->Init.CLKLastBit | hsc->Init.StopBits); |
1841 | /* Write to USART CR2 */ |
2292 | /* Write to USART CR2 */ |
1842 | WRITE_REG(hsc->Instance->CR2, (uint32_t)tmpreg); |
2293 | WRITE_REG(hsc->Instance->CR2, (uint32_t)tmpreg); |
1843 | 2294 | ||
1844 | tmpreg = hsc->Instance->CR2; |
2295 | tmpreg = hsc->Instance->CR2; |
1845 | 2296 | ||
Line 1871... | Line 2322... | ||
1871 | /*-------------------------- USART CR3 Configuration -----------------------*/ |
2322 | /*-------------------------- USART CR3 Configuration -----------------------*/ |
1872 | /* Clear CTSE and RTSE bits */ |
2323 | /* Clear CTSE and RTSE bits */ |
1873 | CLEAR_BIT(hsc->Instance->CR3, (USART_CR3_RTSE | USART_CR3_CTSE)); |
2324 | CLEAR_BIT(hsc->Instance->CR3, (USART_CR3_RTSE | USART_CR3_CTSE)); |
1874 | 2325 | ||
1875 | /*-------------------------- USART BRR Configuration -----------------------*/ |
2326 | /*-------------------------- USART BRR Configuration -----------------------*/ |
1876 | - | ||
1877 | if (hsc->Instance == USART1) |
2327 | if(hsc->Instance == USART1) |
1878 | { |
2328 | { |
- | 2329 | pclk = HAL_RCC_GetPCLK2Freq(); |
|
1879 | hsc->Instance->BRR = SMARTCARD_BRR(HAL_RCC_GetPCLK2Freq(), hsc->Init.BaudRate); |
2330 | hsc->Instance->BRR = SMARTCARD_BRR(pclk, hsc->Init.BaudRate); |
1880 | } |
2331 | } |
1881 | else |
2332 | else |
1882 | { |
2333 | { |
- | 2334 | pclk = HAL_RCC_GetPCLK1Freq(); |
|
1883 | hsc->Instance->BRR = SMARTCARD_BRR(HAL_RCC_GetPCLK1Freq(), hsc->Init.BaudRate); |
2335 | hsc->Instance->BRR = SMARTCARD_BRR(pclk, hsc->Init.BaudRate); |
1884 | } |
2336 | } |
1885 | } |
2337 | } |
1886 | 2338 | ||
1887 | /** |
2339 | /** |
1888 | * @} |
2340 | * @} |