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