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