Mercurial > public > ostc4
comparison Common/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_smartcard.h @ 160:e3ca52b8e7fa
Merge with FlipDisplay
author | heinrichsweikamp |
---|---|
date | Thu, 07 Mar 2019 15:06:43 +0100 |
parents | c78bcbd5deda |
children |
comparison
equal
deleted
inserted
replaced
80:cc2bb7bb8456 | 160:e3ca52b8e7fa |
---|---|
1 /** | |
2 ****************************************************************************** | |
3 * @file stm32f4xx_hal_smartcard.h | |
4 * @author MCD Application Team | |
5 * @brief Header file of SMARTCARD HAL module. | |
6 ****************************************************************************** | |
7 * @attention | |
8 * | |
9 * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2> | |
10 * | |
11 * Redistribution and use in source and binary forms, with or without modification, | |
12 * are permitted provided that the following conditions are met: | |
13 * 1. Redistributions of source code must retain the above copyright notice, | |
14 * this list of conditions and the following disclaimer. | |
15 * 2. Redistributions in binary form must reproduce the above copyright notice, | |
16 * this list of conditions and the following disclaimer in the documentation | |
17 * and/or other materials provided with the distribution. | |
18 * 3. Neither the name of STMicroelectronics nor the names of its contributors | |
19 * may be used to endorse or promote products derived from this software | |
20 * without specific prior written permission. | |
21 * | |
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
25 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
32 * | |
33 ****************************************************************************** | |
34 */ | |
35 | |
36 /* Define to prevent recursive inclusion -------------------------------------*/ | |
37 #ifndef __STM32F4xx_HAL_SMARTCARD_H | |
38 #define __STM32F4xx_HAL_SMARTCARD_H | |
39 | |
40 #ifdef __cplusplus | |
41 extern "C" { | |
42 #endif | |
43 | |
44 /* Includes ------------------------------------------------------------------*/ | |
45 #include "stm32f4xx_hal_def.h" | |
46 | |
47 /** @addtogroup STM32F4xx_HAL_Driver | |
48 * @{ | |
49 */ | |
50 | |
51 /** @addtogroup SMARTCARD | |
52 * @{ | |
53 */ | |
54 | |
55 /* Exported types ------------------------------------------------------------*/ | |
56 /** @defgroup SMARTCARD_Exported_Types SMARTCARD Exported Types | |
57 * @{ | |
58 */ | |
59 | |
60 /** | |
61 * @brief SMARTCARD Init Structure definition | |
62 */ | |
63 typedef struct | |
64 { | |
65 uint32_t BaudRate; /*!< This member configures the SmartCard communication baud rate. | |
66 The baud rate is computed using the following formula: | |
67 - IntegerDivider = ((PCLKx) / (8 * (hirda->Init.BaudRate))) | |
68 - FractionalDivider = ((IntegerDivider - ((uint32_t) IntegerDivider)) * 8) + 0.5 */ | |
69 | |
70 uint32_t WordLength; /*!< Specifies the number of data bits transmitted or received in a frame. | |
71 This parameter can be a value of @ref SMARTCARD_Word_Length */ | |
72 | |
73 uint32_t StopBits; /*!< Specifies the number of stop bits transmitted. | |
74 This parameter can be a value of @ref SMARTCARD_Stop_Bits */ | |
75 | |
76 uint32_t Parity; /*!< Specifies the parity mode. | |
77 This parameter can be a value of @ref SMARTCARD_Parity | |
78 @note When parity is enabled, the computed parity is inserted | |
79 at the MSB position of the transmitted data (9th bit when | |
80 the word length is set to 9 data bits; 8th bit when the | |
81 word length is set to 8 data bits).*/ | |
82 | |
83 uint32_t Mode; /*!< Specifies whether the Receive or Transmit mode is enabled or disabled. | |
84 This parameter can be a value of @ref SMARTCARD_Mode */ | |
85 | |
86 uint32_t CLKPolarity; /*!< Specifies the steady state of the serial clock. | |
87 This parameter can be a value of @ref SMARTCARD_Clock_Polarity */ | |
88 | |
89 uint32_t CLKPhase; /*!< Specifies the clock transition on which the bit capture is made. | |
90 This parameter can be a value of @ref SMARTCARD_Clock_Phase */ | |
91 | |
92 uint32_t CLKLastBit; /*!< Specifies whether the clock pulse corresponding to the last transmitted | |
93 data bit (MSB) has to be output on the SCLK pin in synchronous mode. | |
94 This parameter can be a value of @ref SMARTCARD_Last_Bit */ | |
95 | |
96 uint32_t Prescaler; /*!< Specifies the SmartCard Prescaler value used for dividing the system clock | |
97 to provide the smartcard clock. The value given in the register (5 significant bits) | |
98 is multiplied by 2 to give the division factor of the source clock frequency. | |
99 This parameter can be a value of @ref SMARTCARD_Prescaler */ | |
100 | |
101 uint32_t GuardTime; /*!< Specifies the SmartCard Guard Time value in terms of number of baud clocks */ | |
102 | |
103 uint32_t NACKState; /*!< Specifies the SmartCard NACK Transmission state. | |
104 This parameter can be a value of @ref SMARTCARD_NACK_State */ | |
105 }SMARTCARD_InitTypeDef; | |
106 | |
107 /** | |
108 * @brief HAL SMARTCARD State structures definition | |
109 * @note HAL SMARTCARD State value is a combination of 2 different substates: gState and RxState. | |
110 * - gState contains SMARTCARD state information related to global Handle management | |
111 * and also information related to Tx operations. | |
112 * gState value coding follow below described bitmap : | |
113 * b7-b6 Error information | |
114 * 00 : No Error | |
115 * 01 : (Not Used) | |
116 * 10 : Timeout | |
117 * 11 : Error | |
118 * b5 IP initilisation status | |
119 * 0 : Reset (IP not initialized) | |
120 * 1 : Init done (IP not initialized. HAL SMARTCARD Init function already called) | |
121 * b4-b3 (not used) | |
122 * xx : Should be set to 00 | |
123 * b2 Intrinsic process state | |
124 * 0 : Ready | |
125 * 1 : Busy (IP busy with some configuration or internal operations) | |
126 * b1 (not used) | |
127 * x : Should be set to 0 | |
128 * b0 Tx state | |
129 * 0 : Ready (no Tx operation ongoing) | |
130 * 1 : Busy (Tx operation ongoing) | |
131 * - RxState contains information related to Rx operations. | |
132 * RxState value coding follow below described bitmap : | |
133 * b7-b6 (not used) | |
134 * xx : Should be set to 00 | |
135 * b5 IP initilisation status | |
136 * 0 : Reset (IP not initialized) | |
137 * 1 : Init done (IP not initialized) | |
138 * b4-b2 (not used) | |
139 * xxx : Should be set to 000 | |
140 * b1 Rx state | |
141 * 0 : Ready (no Rx operation ongoing) | |
142 * 1 : Busy (Rx operation ongoing) | |
143 * b0 (not used) | |
144 * x : Should be set to 0. | |
145 */ | |
146 typedef enum | |
147 { | |
148 HAL_SMARTCARD_STATE_RESET = 0x00U, /*!< Peripheral is not yet Initialized | |
149 Value is allowed for gState and RxState */ | |
150 HAL_SMARTCARD_STATE_READY = 0x20U, /*!< Peripheral Initialized and ready for use | |
151 Value is allowed for gState and RxState */ | |
152 HAL_SMARTCARD_STATE_BUSY = 0x24U, /*!< an internal process is ongoing | |
153 Value is allowed for gState only */ | |
154 HAL_SMARTCARD_STATE_BUSY_TX = 0x21U, /*!< Data Transmission process is ongoing | |
155 Value is allowed for gState only */ | |
156 HAL_SMARTCARD_STATE_BUSY_RX = 0x22U, /*!< Data Reception process is ongoing | |
157 Value is allowed for RxState only */ | |
158 HAL_SMARTCARD_STATE_BUSY_TX_RX = 0x23U, /*!< Data Transmission and Reception process is ongoing | |
159 Not to be used for neither gState nor RxState. | |
160 Value is result of combination (Or) between gState and RxState values */ | |
161 HAL_SMARTCARD_STATE_TIMEOUT = 0xA0U, /*!< Timeout state | |
162 Value is allowed for gState only */ | |
163 HAL_SMARTCARD_STATE_ERROR = 0xE0U /*!< Error | |
164 Value is allowed for gState only */ | |
165 }HAL_SMARTCARD_StateTypeDef; | |
166 | |
167 /** | |
168 * @brief SMARTCARD handle Structure definition | |
169 */ | |
170 typedef struct | |
171 { | |
172 USART_TypeDef *Instance; /* USART registers base address */ | |
173 | |
174 SMARTCARD_InitTypeDef Init; /* SmartCard communication parameters */ | |
175 | |
176 uint8_t *pTxBuffPtr; /* Pointer to SmartCard Tx transfer Buffer */ | |
177 | |
178 uint16_t TxXferSize; /* SmartCard Tx Transfer size */ | |
179 | |
180 __IO uint16_t TxXferCount; /* SmartCard Tx Transfer Counter */ | |
181 | |
182 uint8_t *pRxBuffPtr; /* Pointer to SmartCard Rx transfer Buffer */ | |
183 | |
184 uint16_t RxXferSize; /* SmartCard Rx Transfer size */ | |
185 | |
186 __IO uint16_t RxXferCount; /* SmartCard Rx Transfer Counter */ | |
187 | |
188 DMA_HandleTypeDef *hdmatx; /* SmartCard Tx DMA Handle parameters */ | |
189 | |
190 DMA_HandleTypeDef *hdmarx; /* SmartCard Rx DMA Handle parameters */ | |
191 | |
192 HAL_LockTypeDef Lock; /* Locking object */ | |
193 | |
194 __IO HAL_SMARTCARD_StateTypeDef gState; /* SmartCard state information related to global Handle management | |
195 and also related to Tx operations. | |
196 This parameter can be a value of @ref HAL_SMARTCARD_StateTypeDef */ | |
197 | |
198 __IO HAL_SMARTCARD_StateTypeDef RxState; /* SmartCard state information related to Rx operations. | |
199 This parameter can be a value of @ref HAL_SMARTCARD_StateTypeDef */ | |
200 | |
201 __IO uint32_t ErrorCode; /* SmartCard Error code */ | |
202 | |
203 }SMARTCARD_HandleTypeDef; | |
204 | |
205 /** | |
206 * @} | |
207 */ | |
208 | |
209 /* Exported constants --------------------------------------------------------*/ | |
210 /** @defgroup SMARTCARD_Exported_Constants SMARTCARD Exported constants | |
211 * @{ | |
212 */ | |
213 /** @defgroup SMARTCARD_Error_Code SMARTCARD Error Code | |
214 * @brief SMARTCARD Error Code | |
215 * @{ | |
216 */ | |
217 #define HAL_SMARTCARD_ERROR_NONE 0x00000000U /*!< No error */ | |
218 #define HAL_SMARTCARD_ERROR_PE 0x00000001U /*!< Parity error */ | |
219 #define HAL_SMARTCARD_ERROR_NE 0x00000002U /*!< Noise error */ | |
220 #define HAL_SMARTCARD_ERROR_FE 0x00000004U /*!< Frame error */ | |
221 #define HAL_SMARTCARD_ERROR_ORE 0x00000008U /*!< Overrun error */ | |
222 #define HAL_SMARTCARD_ERROR_DMA 0x00000010U /*!< DMA transfer error */ | |
223 /** | |
224 * @} | |
225 */ | |
226 | |
227 /** @defgroup SMARTCARD_Word_Length SMARTCARD Word Length | |
228 * @{ | |
229 */ | |
230 #define SMARTCARD_WORDLENGTH_9B ((uint32_t)USART_CR1_M) | |
231 /** | |
232 * @} | |
233 */ | |
234 | |
235 /** @defgroup SMARTCARD_Stop_Bits SMARTCARD Number of Stop Bits | |
236 * @{ | |
237 */ | |
238 #define SMARTCARD_STOPBITS_0_5 ((uint32_t)USART_CR2_STOP_0) | |
239 #define SMARTCARD_STOPBITS_1_5 ((uint32_t)(USART_CR2_STOP_0 | USART_CR2_STOP_1)) | |
240 /** | |
241 * @} | |
242 */ | |
243 | |
244 /** @defgroup SMARTCARD_Parity SMARTCARD Parity | |
245 * @{ | |
246 */ | |
247 #define SMARTCARD_PARITY_EVEN ((uint32_t)USART_CR1_PCE) | |
248 #define SMARTCARD_PARITY_ODD ((uint32_t)(USART_CR1_PCE | USART_CR1_PS)) | |
249 /** | |
250 * @} | |
251 */ | |
252 | |
253 /** @defgroup SMARTCARD_Mode SMARTCARD Mode | |
254 * @{ | |
255 */ | |
256 #define SMARTCARD_MODE_RX ((uint32_t)USART_CR1_RE) | |
257 #define SMARTCARD_MODE_TX ((uint32_t)USART_CR1_TE) | |
258 #define SMARTCARD_MODE_TX_RX ((uint32_t)(USART_CR1_TE |USART_CR1_RE)) | |
259 /** | |
260 * @} | |
261 */ | |
262 | |
263 /** @defgroup SMARTCARD_Clock_Polarity SMARTCARD Clock Polarity | |
264 * @{ | |
265 */ | |
266 #define SMARTCARD_POLARITY_LOW 0x00000000U | |
267 #define SMARTCARD_POLARITY_HIGH ((uint32_t)USART_CR2_CPOL) | |
268 /** | |
269 * @} | |
270 */ | |
271 | |
272 /** @defgroup SMARTCARD_Clock_Phase SMARTCARD Clock Phase | |
273 * @{ | |
274 */ | |
275 #define SMARTCARD_PHASE_1EDGE 0x00000000U | |
276 #define SMARTCARD_PHASE_2EDGE ((uint32_t)USART_CR2_CPHA) | |
277 /** | |
278 * @} | |
279 */ | |
280 | |
281 /** @defgroup SMARTCARD_Last_Bit SMARTCARD Last Bit | |
282 * @{ | |
283 */ | |
284 #define SMARTCARD_LASTBIT_DISABLE 0x00000000U | |
285 #define SMARTCARD_LASTBIT_ENABLE ((uint32_t)USART_CR2_LBCL) | |
286 /** | |
287 * @} | |
288 */ | |
289 | |
290 /** @defgroup SMARTCARD_NACK_State SMARTCARD NACK State | |
291 * @{ | |
292 */ | |
293 #define SMARTCARD_NACK_ENABLE ((uint32_t)USART_CR3_NACK) | |
294 #define SMARTCARD_NACK_DISABLE 0x00000000U | |
295 /** | |
296 * @} | |
297 */ | |
298 | |
299 /** @defgroup SMARTCARD_DMA_Requests SMARTCARD DMA requests | |
300 * @{ | |
301 */ | |
302 #define SMARTCARD_DMAREQ_TX ((uint32_t)USART_CR3_DMAT) | |
303 #define SMARTCARD_DMAREQ_RX ((uint32_t)USART_CR3_DMAR) | |
304 /** | |
305 * @} | |
306 */ | |
307 | |
308 /** @defgroup SMARTCARD_Prescaler SMARTCARD Prescaler | |
309 * @{ | |
310 */ | |
311 #define SMARTCARD_PRESCALER_SYSCLK_DIV2 0x00000001U /*!< SYSCLK divided by 2 */ | |
312 #define SMARTCARD_PRESCALER_SYSCLK_DIV4 0x00000002U /*!< SYSCLK divided by 4 */ | |
313 #define SMARTCARD_PRESCALER_SYSCLK_DIV6 0x00000003U /*!< SYSCLK divided by 6 */ | |
314 #define SMARTCARD_PRESCALER_SYSCLK_DIV8 0x00000004U /*!< SYSCLK divided by 8 */ | |
315 #define SMARTCARD_PRESCALER_SYSCLK_DIV10 0x00000005U /*!< SYSCLK divided by 10 */ | |
316 #define SMARTCARD_PRESCALER_SYSCLK_DIV12 0x00000006U /*!< SYSCLK divided by 12 */ | |
317 #define SMARTCARD_PRESCALER_SYSCLK_DIV14 0x00000007U /*!< SYSCLK divided by 14 */ | |
318 #define SMARTCARD_PRESCALER_SYSCLK_DIV16 0x00000008U /*!< SYSCLK divided by 16 */ | |
319 #define SMARTCARD_PRESCALER_SYSCLK_DIV18 0x00000009U /*!< SYSCLK divided by 18 */ | |
320 #define SMARTCARD_PRESCALER_SYSCLK_DIV20 0x0000000AU /*!< SYSCLK divided by 20 */ | |
321 #define SMARTCARD_PRESCALER_SYSCLK_DIV22 0x0000000BU /*!< SYSCLK divided by 22 */ | |
322 #define SMARTCARD_PRESCALER_SYSCLK_DIV24 0x0000000CU /*!< SYSCLK divided by 24 */ | |
323 #define SMARTCARD_PRESCALER_SYSCLK_DIV26 0x0000000DU /*!< SYSCLK divided by 26 */ | |
324 #define SMARTCARD_PRESCALER_SYSCLK_DIV28 0x0000000EU /*!< SYSCLK divided by 28 */ | |
325 #define SMARTCARD_PRESCALER_SYSCLK_DIV30 0x0000000FU /*!< SYSCLK divided by 30 */ | |
326 #define SMARTCARD_PRESCALER_SYSCLK_DIV32 0x00000010U /*!< SYSCLK divided by 32 */ | |
327 #define SMARTCARD_PRESCALER_SYSCLK_DIV34 0x00000011U /*!< SYSCLK divided by 34 */ | |
328 #define SMARTCARD_PRESCALER_SYSCLK_DIV36 0x00000012U /*!< SYSCLK divided by 36 */ | |
329 #define SMARTCARD_PRESCALER_SYSCLK_DIV38 0x00000013U /*!< SYSCLK divided by 38 */ | |
330 #define SMARTCARD_PRESCALER_SYSCLK_DIV40 0x00000014U /*!< SYSCLK divided by 40 */ | |
331 #define SMARTCARD_PRESCALER_SYSCLK_DIV42 0x00000015U /*!< SYSCLK divided by 42 */ | |
332 #define SMARTCARD_PRESCALER_SYSCLK_DIV44 0x00000016U /*!< SYSCLK divided by 44 */ | |
333 #define SMARTCARD_PRESCALER_SYSCLK_DIV46 0x00000017U /*!< SYSCLK divided by 46 */ | |
334 #define SMARTCARD_PRESCALER_SYSCLK_DIV48 0x00000018U /*!< SYSCLK divided by 48 */ | |
335 #define SMARTCARD_PRESCALER_SYSCLK_DIV50 0x00000019U /*!< SYSCLK divided by 50 */ | |
336 #define SMARTCARD_PRESCALER_SYSCLK_DIV52 0x0000001AU /*!< SYSCLK divided by 52 */ | |
337 #define SMARTCARD_PRESCALER_SYSCLK_DIV54 0x0000001BU /*!< SYSCLK divided by 54 */ | |
338 #define SMARTCARD_PRESCALER_SYSCLK_DIV56 0x0000001CU /*!< SYSCLK divided by 56 */ | |
339 #define SMARTCARD_PRESCALER_SYSCLK_DIV58 0x0000001DU /*!< SYSCLK divided by 58 */ | |
340 #define SMARTCARD_PRESCALER_SYSCLK_DIV60 0x0000001EU /*!< SYSCLK divided by 60 */ | |
341 #define SMARTCARD_PRESCALER_SYSCLK_DIV62 0x0000001FU /*!< SYSCLK divided by 62 */ | |
342 /** | |
343 * @} | |
344 */ | |
345 | |
346 /** @defgroup SmartCard_Flags SMARTCARD Flags | |
347 * Elements values convention: 0xXXXX | |
348 * - 0xXXXX : Flag mask in the SR register | |
349 * @{ | |
350 */ | |
351 #define SMARTCARD_FLAG_TXE 0x00000080U | |
352 #define SMARTCARD_FLAG_TC 0x00000040U | |
353 #define SMARTCARD_FLAG_RXNE 0x00000020U | |
354 #define SMARTCARD_FLAG_IDLE 0x00000010U | |
355 #define SMARTCARD_FLAG_ORE 0x00000008U | |
356 #define SMARTCARD_FLAG_NE 0x00000004U | |
357 #define SMARTCARD_FLAG_FE 0x00000002U | |
358 #define SMARTCARD_FLAG_PE 0x00000001U | |
359 /** | |
360 * @} | |
361 */ | |
362 | |
363 /** @defgroup SmartCard_Interrupt_definition SMARTCARD Interrupts Definition | |
364 * Elements values convention: 0xY000XXXX | |
365 * - XXXX : Interrupt mask in the XX register | |
366 * - Y : Interrupt source register (2bits) | |
367 * - 01: CR1 register | |
368 * - 10: CR3 register | |
369 * @{ | |
370 */ | |
371 #define SMARTCARD_IT_PE ((uint32_t)(SMARTCARD_CR1_REG_INDEX << 28U | USART_CR1_PEIE)) | |
372 #define SMARTCARD_IT_TXE ((uint32_t)(SMARTCARD_CR1_REG_INDEX << 28U | USART_CR1_TXEIE)) | |
373 #define SMARTCARD_IT_TC ((uint32_t)(SMARTCARD_CR1_REG_INDEX << 28U | USART_CR1_TCIE)) | |
374 #define SMARTCARD_IT_RXNE ((uint32_t)(SMARTCARD_CR1_REG_INDEX << 28U | USART_CR1_RXNEIE)) | |
375 #define SMARTCARD_IT_IDLE ((uint32_t)(SMARTCARD_CR1_REG_INDEX << 28U | USART_CR1_IDLEIE)) | |
376 #define SMARTCARD_IT_ERR ((uint32_t)(SMARTCARD_CR3_REG_INDEX << 28U | USART_CR3_EIE)) | |
377 /** | |
378 * @} | |
379 */ | |
380 | |
381 /** | |
382 * @} | |
383 */ | |
384 | |
385 /* Exported macro ------------------------------------------------------------*/ | |
386 /** @defgroup SMARTCARD_Exported_Macros SMARTCARD Exported Macros | |
387 * @{ | |
388 */ | |
389 | |
390 /** @brief Reset SMARTCARD handle gstate & RxState | |
391 * @param __HANDLE__ specifies the SMARTCARD Handle. | |
392 * @retval None | |
393 */ | |
394 #define __HAL_SMARTCARD_RESET_HANDLE_STATE(__HANDLE__) do{ \ | |
395 (__HANDLE__)->gState = HAL_SMARTCARD_STATE_RESET; \ | |
396 (__HANDLE__)->RxState = HAL_SMARTCARD_STATE_RESET; \ | |
397 } while(0U) | |
398 | |
399 /** @brief Flushs the Smartcard DR register | |
400 * @param __HANDLE__ specifies the SMARTCARD Handle. | |
401 */ | |
402 #define __HAL_SMARTCARD_FLUSH_DRREGISTER(__HANDLE__) ((__HANDLE__)->Instance->DR) | |
403 | |
404 /** @brief Checks whether the specified Smartcard flag is set or not. | |
405 * @param __HANDLE__ specifies the SMARTCARD Handle. | |
406 * @param __FLAG__ specifies the flag to check. | |
407 * This parameter can be one of the following values: | |
408 * @arg SMARTCARD_FLAG_TXE: Transmit data register empty flag | |
409 * @arg SMARTCARD_FLAG_TC: Transmission Complete flag | |
410 * @arg SMARTCARD_FLAG_RXNE: Receive data register not empty flag | |
411 * @arg SMARTCARD_FLAG_IDLE: Idle Line detection flag | |
412 * @arg SMARTCARD_FLAG_ORE: Overrun Error flag | |
413 * @arg SMARTCARD_FLAG_NE: Noise Error flag | |
414 * @arg SMARTCARD_FLAG_FE: Framing Error flag | |
415 * @arg SMARTCARD_FLAG_PE: Parity Error flag | |
416 * @retval The new state of __FLAG__ (TRUE or FALSE). | |
417 */ | |
418 #define __HAL_SMARTCARD_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__)) | |
419 | |
420 /** @brief Clears the specified Smartcard pending flags. | |
421 * @param __HANDLE__ specifies the SMARTCARD Handle. | |
422 * @param __FLAG__ specifies the flag to check. | |
423 * This parameter can be any combination of the following values: | |
424 * @arg SMARTCARD_FLAG_TC: Transmission Complete flag. | |
425 * @arg SMARTCARD_FLAG_RXNE: Receive data register not empty flag. | |
426 * | |
427 * @note PE (Parity error), FE (Framing error), NE (Noise error) and ORE (Overrun | |
428 * error) flags are cleared by software sequence: a read operation to | |
429 * USART_SR register followed by a read operation to USART_DR register. | |
430 * @note RXNE flag can be also cleared by a read to the USART_DR register. | |
431 * @note TC flag can be also cleared by software sequence: a read operation to | |
432 * USART_SR register followed by a write operation to USART_DR register. | |
433 * @note TXE flag is cleared only by a write to the USART_DR register. | |
434 */ | |
435 #define __HAL_SMARTCARD_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR = ~(__FLAG__)) | |
436 | |
437 /** @brief Clear the SMARTCARD PE pending flag. | |
438 * @param __HANDLE__ specifies the USART Handle. | |
439 * This parameter can be USARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or | |
440 * SMARTCARD peripheral. | |
441 * @retval None | |
442 */ | |
443 #define __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__) \ | |
444 do{ \ | |
445 __IO uint32_t tmpreg = 0x00U; \ | |
446 tmpreg = (__HANDLE__)->Instance->SR; \ | |
447 tmpreg = (__HANDLE__)->Instance->DR; \ | |
448 UNUSED(tmpreg); \ | |
449 } while(0U) | |
450 | |
451 /** @brief Clear the SMARTCARD FE pending flag. | |
452 * @param __HANDLE__ specifies the USART Handle. | |
453 * This parameter can be USARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or | |
454 * SMARTCARD peripheral. | |
455 * @retval None | |
456 */ | |
457 #define __HAL_SMARTCARD_CLEAR_FEFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__) | |
458 | |
459 /** @brief Clear the SMARTCARD NE pending flag. | |
460 * @param __HANDLE__ specifies the USART Handle. | |
461 * This parameter can be USARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or | |
462 * SMARTCARD peripheral. | |
463 * @retval None | |
464 */ | |
465 #define __HAL_SMARTCARD_CLEAR_NEFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__) | |
466 | |
467 /** @brief Clear the SMARTCARD ORE pending flag. | |
468 * @param __HANDLE__ specifies the USART Handle. | |
469 * This parameter can be USARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or | |
470 * SMARTCARD peripheral. | |
471 * @retval None | |
472 */ | |
473 #define __HAL_SMARTCARD_CLEAR_OREFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__) | |
474 | |
475 /** @brief Clear the SMARTCARD IDLE pending flag. | |
476 * @param __HANDLE__ specifies the USART Handle. | |
477 * This parameter can be USARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or | |
478 * SMARTCARD peripheral. | |
479 * @retval None | |
480 */ | |
481 #define __HAL_SMARTCARD_CLEAR_IDLEFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__) | |
482 | |
483 /** @brief Enables or disables the specified SmartCard interrupts. | |
484 * @param __HANDLE__ specifies the SMARTCARD Handle. | |
485 * @param __INTERRUPT__ specifies the SMARTCARD interrupt source to check. | |
486 * This parameter can be one of the following values: | |
487 * @arg SMARTCARD_IT_TXE: Transmit Data Register empty interrupt | |
488 * @arg SMARTCARD_IT_TC: Transmission complete interrupt | |
489 * @arg SMARTCARD_IT_RXNE: Receive Data register not empty interrupt | |
490 * @arg SMARTCARD_IT_IDLE: Idle line detection interrupt | |
491 * @arg SMARTCARD_IT_PE: Parity Error interrupt | |
492 * @arg SMARTCARD_IT_ERR: Error interrupt(Frame error, noise error, overrun error) | |
493 */ | |
494 #define __HAL_SMARTCARD_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28U) == 1U)? ((__HANDLE__)->Instance->CR1 |= ((__INTERRUPT__) & SMARTCARD_IT_MASK)): \ | |
495 ((__HANDLE__)->Instance->CR3 |= ((__INTERRUPT__) & SMARTCARD_IT_MASK))) | |
496 #define __HAL_SMARTCARD_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28U) == 1U)? ((__HANDLE__)->Instance->CR1 &= ~((__INTERRUPT__) & SMARTCARD_IT_MASK)): \ | |
497 ((__HANDLE__)->Instance->CR3 &= ~ ((__INTERRUPT__) & SMARTCARD_IT_MASK))) | |
498 | |
499 /** @brief Checks whether the specified SmartCard interrupt has occurred or not. | |
500 * @param __HANDLE__ specifies the SmartCard Handle. | |
501 * @param __IT__ specifies the SMARTCARD interrupt source to check. | |
502 * This parameter can be one of the following values: | |
503 * @arg SMARTCARD_IT_TXE: Transmit Data Register empty interrupt | |
504 * @arg SMARTCARD_IT_TC: Transmission complete interrupt | |
505 * @arg SMARTCARD_IT_RXNE: Receive Data register not empty interrupt | |
506 * @arg SMARTCARD_IT_IDLE: Idle line detection interrupt | |
507 * @arg SMARTCARD_IT_ERR: Error interrupt | |
508 * @arg SMARTCARD_IT_PE: Parity Error interrupt | |
509 * @retval The new state of __IT__ (TRUE or FALSE). | |
510 */ | |
511 #define __HAL_SMARTCARD_GET_IT_SOURCE(__HANDLE__, __IT__) (((((__IT__) >> 28U) == 1U)? (__HANDLE__)->Instance->CR1: (__HANDLE__)->Instance->CR3) & (((uint32_t)(__IT__)) & SMARTCARD_IT_MASK)) | |
512 | |
513 /** @brief Macro to enable the SMARTCARD's one bit sample method | |
514 * @param __HANDLE__ specifies the SMARTCARD Handle. | |
515 * @retval None | |
516 */ | |
517 #define __HAL_SMARTCARD_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT) | |
518 | |
519 /** @brief Macro to disable the SMARTCARD's one bit sample method | |
520 * @param __HANDLE__ specifies the SMARTCARD Handle. | |
521 * @retval None | |
522 */ | |
523 #define __HAL_SMARTCARD_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 &= (uint16_t)~((uint16_t)USART_CR3_ONEBIT)) | |
524 | |
525 /** @brief Enable the USART associated to the SMARTCARD Handle | |
526 * @param __HANDLE__ specifies the SMARTCARD Handle. | |
527 * SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device). | |
528 * @retval None | |
529 */ | |
530 #define __HAL_SMARTCARD_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= USART_CR1_UE) | |
531 | |
532 /** @brief Disable the USART associated to the SMARTCARD Handle | |
533 * @param __HANDLE__ specifies the SMARTCARD Handle. | |
534 * SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device). | |
535 * @retval None | |
536 */ | |
537 #define __HAL_SMARTCARD_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~USART_CR1_UE) | |
538 | |
539 /** @brief Macros to enable or disable the SmartCard DMA request. | |
540 * @param __HANDLE__ specifies the SmartCard Handle. | |
541 * @param __REQUEST__ specifies the SmartCard DMA request. | |
542 * This parameter can be one of the following values: | |
543 * @arg SMARTCARD_DMAREQ_TX: SmartCard DMA transmit request | |
544 * @arg SMARTCARD_DMAREQ_RX: SmartCard DMA receive request | |
545 */ | |
546 #define __HAL_SMARTCARD_DMA_REQUEST_ENABLE(__HANDLE__, __REQUEST__) ((__HANDLE__)->Instance->CR3 |= (__REQUEST__)) | |
547 #define __HAL_SMARTCARD_DMA_REQUEST_DISABLE(__HANDLE__, __REQUEST__) ((__HANDLE__)->Instance->CR3 &= ~(__REQUEST__)) | |
548 | |
549 /** | |
550 * @} | |
551 */ | |
552 | |
553 /* Exported functions --------------------------------------------------------*/ | |
554 /** @addtogroup SMARTCARD_Exported_Functions | |
555 * @{ | |
556 */ | |
557 | |
558 /** @addtogroup SMARTCARD_Exported_Functions_Group1 | |
559 * @{ | |
560 */ | |
561 /* Initialization/de-initialization functions **********************************/ | |
562 HAL_StatusTypeDef HAL_SMARTCARD_Init(SMARTCARD_HandleTypeDef *hsc); | |
563 HAL_StatusTypeDef HAL_SMARTCARD_ReInit(SMARTCARD_HandleTypeDef *hsc); | |
564 HAL_StatusTypeDef HAL_SMARTCARD_DeInit(SMARTCARD_HandleTypeDef *hsc); | |
565 void HAL_SMARTCARD_MspInit(SMARTCARD_HandleTypeDef *hsc); | |
566 void HAL_SMARTCARD_MspDeInit(SMARTCARD_HandleTypeDef *hsc); | |
567 /** | |
568 * @} | |
569 */ | |
570 | |
571 /** @addtogroup SMARTCARD_Exported_Functions_Group2 | |
572 * @{ | |
573 */ | |
574 /* IO operation functions *******************************************************/ | |
575 HAL_StatusTypeDef HAL_SMARTCARD_Transmit(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size, uint32_t Timeout); | |
576 HAL_StatusTypeDef HAL_SMARTCARD_Receive(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size, uint32_t Timeout); | |
577 HAL_StatusTypeDef HAL_SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size); | |
578 HAL_StatusTypeDef HAL_SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size); | |
579 HAL_StatusTypeDef HAL_SMARTCARD_Transmit_DMA(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size); | |
580 HAL_StatusTypeDef HAL_SMARTCARD_Receive_DMA(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size); | |
581 /* Transfer Abort functions */ | |
582 HAL_StatusTypeDef HAL_SMARTCARD_Abort(SMARTCARD_HandleTypeDef *hsc); | |
583 HAL_StatusTypeDef HAL_SMARTCARD_AbortTransmit(SMARTCARD_HandleTypeDef *hsc); | |
584 HAL_StatusTypeDef HAL_SMARTCARD_AbortReceive(SMARTCARD_HandleTypeDef *hsc); | |
585 HAL_StatusTypeDef HAL_SMARTCARD_Abort_IT(SMARTCARD_HandleTypeDef *hsc); | |
586 HAL_StatusTypeDef HAL_SMARTCARD_AbortTransmit_IT(SMARTCARD_HandleTypeDef *hsc); | |
587 HAL_StatusTypeDef HAL_SMARTCARD_AbortReceive_IT(SMARTCARD_HandleTypeDef *hsc); | |
588 | |
589 void HAL_SMARTCARD_IRQHandler(SMARTCARD_HandleTypeDef *hsc); | |
590 void HAL_SMARTCARD_TxCpltCallback(SMARTCARD_HandleTypeDef *hsc); | |
591 void HAL_SMARTCARD_RxCpltCallback(SMARTCARD_HandleTypeDef *hsc); | |
592 void HAL_SMARTCARD_ErrorCallback(SMARTCARD_HandleTypeDef *hsc); | |
593 void HAL_SMARTCARD_AbortCpltCallback(SMARTCARD_HandleTypeDef *hsc); | |
594 void HAL_SMARTCARD_AbortTransmitCpltCallback(SMARTCARD_HandleTypeDef *hsc); | |
595 void HAL_SMARTCARD_AbortReceiveCpltCallback(SMARTCARD_HandleTypeDef *hsc); | |
596 /** | |
597 * @} | |
598 */ | |
599 | |
600 /** @addtogroup SMARTCARD_Exported_Functions_Group3 | |
601 * @{ | |
602 */ | |
603 /* Peripheral State functions **************************************************/ | |
604 HAL_SMARTCARD_StateTypeDef HAL_SMARTCARD_GetState(SMARTCARD_HandleTypeDef *hsc); | |
605 uint32_t HAL_SMARTCARD_GetError(SMARTCARD_HandleTypeDef *hsc); | |
606 | |
607 /** | |
608 * @} | |
609 */ | |
610 | |
611 /** | |
612 * @} | |
613 */ | |
614 /* Private types -------------------------------------------------------------*/ | |
615 /* Private variables ---------------------------------------------------------*/ | |
616 /* Private constants ---------------------------------------------------------*/ | |
617 /** @defgroup SMARTCARD_Private_Constants SMARTCARD Private Constants | |
618 * @{ | |
619 */ | |
620 | |
621 /** @brief SMARTCARD interruptions flag mask | |
622 * | |
623 */ | |
624 #define SMARTCARD_IT_MASK ((uint32_t) USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE | USART_CR1_RXNEIE | \ | |
625 USART_CR1_IDLEIE | USART_CR3_EIE ) | |
626 | |
627 #define SMARTCARD_DIV(_PCLK_, _BAUD_) (((_PCLK_)*25U)/(4U*(_BAUD_))) | |
628 #define SMARTCARD_DIVMANT(_PCLK_, _BAUD_) (SMARTCARD_DIV((_PCLK_), (_BAUD_))/100U) | |
629 #define SMARTCARD_DIVFRAQ(_PCLK_, _BAUD_) (((SMARTCARD_DIV((_PCLK_), (_BAUD_)) - (SMARTCARD_DIVMANT((_PCLK_), (_BAUD_)) * 100U)) * 16U + 50U) / 100U) | |
630 /* SMARTCARD BRR = mantissa + overflow + fraction | |
631 = (SMARTCARD DIVMANT << 4) + (SMARTCARD DIVFRAQ & 0xF0) + (SMARTCARD DIVFRAQ & 0x0FU) */ | |
632 #define SMARTCARD_BRR(_PCLK_, _BAUD_) (((SMARTCARD_DIVMANT((_PCLK_), (_BAUD_)) << 4U) + \ | |
633 (SMARTCARD_DIVFRAQ((_PCLK_), (_BAUD_)) & 0xF0U)) + \ | |
634 (SMARTCARD_DIVFRAQ((_PCLK_), (_BAUD_)) & 0x0FU)) | |
635 | |
636 #define SMARTCARD_CR1_REG_INDEX 1U | |
637 #define SMARTCARD_CR3_REG_INDEX 3U | |
638 /** | |
639 * @} | |
640 */ | |
641 | |
642 /* Private macros --------------------------------------------------------*/ | |
643 /** @defgroup SMARTCARD_Private_Macros SMARTCARD Private Macros | |
644 * @{ | |
645 */ | |
646 #define IS_SMARTCARD_WORD_LENGTH(LENGTH) ((LENGTH) == SMARTCARD_WORDLENGTH_9B) | |
647 #define IS_SMARTCARD_STOPBITS(STOPBITS) (((STOPBITS) == SMARTCARD_STOPBITS_0_5) || \ | |
648 ((STOPBITS) == SMARTCARD_STOPBITS_1_5)) | |
649 #define IS_SMARTCARD_PARITY(PARITY) (((PARITY) == SMARTCARD_PARITY_EVEN) || \ | |
650 ((PARITY) == SMARTCARD_PARITY_ODD)) | |
651 #define IS_SMARTCARD_MODE(MODE) ((((MODE) & 0x0000FFF3U) == 0x00U) && ((MODE) != 0x000000U)) | |
652 #define IS_SMARTCARD_POLARITY(CPOL) (((CPOL) == SMARTCARD_POLARITY_LOW) || ((CPOL) == SMARTCARD_POLARITY_HIGH)) | |
653 #define IS_SMARTCARD_PHASE(CPHA) (((CPHA) == SMARTCARD_PHASE_1EDGE) || ((CPHA) == SMARTCARD_PHASE_2EDGE)) | |
654 #define IS_SMARTCARD_LASTBIT(LASTBIT) (((LASTBIT) == SMARTCARD_LASTBIT_DISABLE) || \ | |
655 ((LASTBIT) == SMARTCARD_LASTBIT_ENABLE)) | |
656 #define IS_SMARTCARD_NACK_STATE(NACK) (((NACK) == SMARTCARD_NACK_ENABLE) || \ | |
657 ((NACK) == SMARTCARD_NACK_DISABLE)) | |
658 #define IS_SMARTCARD_BAUDRATE(BAUDRATE) ((BAUDRATE) < 10500001U) | |
659 /** | |
660 * @} | |
661 */ | |
662 | |
663 /* Private functions ---------------------------------------------------------*/ | |
664 /** @defgroup SMARTCARD_Private_Functions SMARTCARD Private Functions | |
665 * @{ | |
666 */ | |
667 | |
668 /** | |
669 * @} | |
670 */ | |
671 | |
672 /** | |
673 * @} | |
674 */ | |
675 | |
676 /** | |
677 * @} | |
678 */ | |
679 #ifdef __cplusplus | |
680 } | |
681 #endif | |
682 | |
683 #endif /* __STM32F4xx_HAL_SMARTCARD_H */ | |
684 | |
685 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |