]> git.gir.st - tmk_keyboard.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F3/stm32f3xx_hal_smartcard.h
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[tmk_keyboard.git] / tool / mbed / mbed-sdk / libraries / mbed / targets / cmsis / TARGET_STM / TARGET_STM32F3 / stm32f3xx_hal_smartcard.h
1 /**
2 ******************************************************************************
3 * @file stm32f3xx_hal_smartcard.h
4 * @author MCD Application Team
5 * @version V1.1.0
6 * @date 12-Sept-2014
7 * @brief Header file of SMARTCARD HAL module.
8 ******************************************************************************
9 * @attention
10 *
11 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
12 *
13 * Redistribution and use in source and binary forms, with or without modification,
14 * are permitted provided that the following conditions are met:
15 * 1. Redistributions of source code must retain the above copyright notice,
16 * this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *
35 ******************************************************************************
36 */
37
38 /* Define to prevent recursive inclusion -------------------------------------*/
39 #ifndef __STM32F3xx_HAL_SMARTCARD_H
40 #define __STM32F3xx_HAL_SMARTCARD_H
41
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32f3xx_hal_def.h"
48
49 /** @addtogroup STM32F3xx_HAL_Driver
50 * @{
51 */
52
53 /** @addtogroup SMARTCARD
54 * @{
55 */
56
57 /* Exported types ------------------------------------------------------------*/
58 /** @defgroup SMARTCARD_Exported_Types SMARTCARD Exported Types
59 * @{
60 */
61
62 /**
63 * @brief SMARTCARD Init Structure definition
64 */
65 typedef struct
66 {
67 uint32_t BaudRate; /*!< Configures the SmartCard communication baud rate.
68 The baud rate register is computed using the following formula:
69 Baud Rate Register = ((PCLKx) / ((hsmartcard->Init.BaudRate))) */
70
71 uint32_t WordLength; /*!< Specifies the number of data bits transmitted or received in a frame.
72 This parameter @ref SMARTCARD_Word_Length can only be set to 9 (8 data + 1 parity bits). */
73
74 uint32_t StopBits; /*!< Specifies the number of stop bits @ref SMARTCARD_Stop_Bits.
75 Only 1.5 stop bits are authorized in SmartCard mode. */
76
77 uint16_t Parity; /*!< Specifies the parity mode.
78 This parameter can be a value of @ref SMARTCARD_Parity
79 @note The parity is enabled by default (PCE is forced to 1).
80 Since the WordLength is forced to 8 bits + parity, M is
81 forced to 1 and the parity bit is the 9th bit. */
82
83 uint16_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 uint16_t CLKPolarity; /*!< Specifies the steady state of the serial clock.
87 This parameter can be a value of @ref SMARTCARD_Clock_Polarity */
88
89 uint16_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 uint16_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 uint16_t OneBitSampling; /*!< Specifies whether a single sample or three samples' majority vote is selected.
97 Selecting the single sample method increases the receiver tolerance to clock
98 deviations. This parameter can be a value of @ref SMARTCARD_OneBit_Sampling. */
99
100 uint8_t Prescaler; /*!< Specifies the SmartCard Prescaler */
101
102 uint8_t GuardTime; /*!< Specifies the SmartCard Guard Time */
103
104 uint16_t NACKEnable; /*!< Specifies whether the SmartCard NACK transmission is enabled
105 in case of parity error.
106 This parameter can be a value of @ref SMARTCARD_NACK_Enable */
107
108 uint32_t TimeOutEnable; /*!< Specifies whether the receiver timeout is enabled.
109 This parameter can be a value of @ref SMARTCARD_Timeout_Enable*/
110
111 uint32_t TimeOutValue; /*!< Specifies the receiver time out value in number of baud blocks:
112 it is used to implement the Character Wait Time (CWT) and
113 Block Wait Time (BWT). It is coded over 24 bits. */
114
115 uint8_t BlockLength; /*!< Specifies the SmartCard Block Length in T=1 Reception mode.
116 This parameter can be any value from 0x0 to 0xFF */
117
118 uint8_t AutoRetryCount; /*!< Specifies the SmartCard auto-retry count (number of retries in
119 receive and transmit mode). When set to 0, retransmission is
120 disabled. Otherwise, its maximum value is 7 (before signalling
121 an error) */
122
123 }SMARTCARD_InitTypeDef;
124
125 /**
126 * @brief SMARTCARD advanced features initalization structure definition
127 */
128 typedef struct
129 {
130 uint32_t AdvFeatureInit; /*!< Specifies which advanced SMARTCARD features is initialized. Several
131 advanced features may be initialized at the same time. This parameter
132 can be a value of @ref SMARTCARD_Advanced_Features_Initialization_Type */
133
134 uint32_t TxPinLevelInvert; /*!< Specifies whether the TX pin active level is inverted.
135 This parameter can be a value of @ref SMARTCARD_Tx_Inv */
136
137 uint32_t RxPinLevelInvert; /*!< Specifies whether the RX pin active level is inverted.
138 This parameter can be a value of @ref SMARTCARD_Rx_Inv */
139
140 uint32_t DataInvert; /*!< Specifies whether data are inverted (positive/direct logic
141 vs negative/inverted logic).
142 This parameter can be a value of @ref SMARTCARD_Data_Inv */
143
144 uint32_t Swap; /*!< Specifies whether TX and RX pins are swapped.
145 This parameter can be a value of @ref SMARTCARD_Rx_Tx_Swap */
146
147 uint32_t OverrunDisable; /*!< Specifies whether the reception overrun detection is disabled.
148 This parameter can be a value of @ref SMARTCARD_Overrun_Disable */
149
150 uint32_t DMADisableonRxError; /*!< Specifies whether the DMA is disabled in case of reception error.
151 This parameter can be a value of @ref SMARTCARD_DMA_Disable_on_Rx_Error */
152
153 uint32_t MSBFirst; /*!< Specifies whether MSB is sent first on UART line.
154 This parameter can be a value of @ref SMARTCARD_MSB_First */
155 }SMARTCARD_AdvFeatureInitTypeDef;
156
157 /**
158 * @brief HAL State structures definition
159 */
160 typedef enum
161 {
162 HAL_SMARTCARD_STATE_RESET = 0x00, /*!< Peripheral is not initialized */
163 HAL_SMARTCARD_STATE_READY = 0x01, /*!< Peripheral Initialized and ready for use */
164 HAL_SMARTCARD_STATE_BUSY = 0x02, /*!< an internal process is ongoing */
165 HAL_SMARTCARD_STATE_BUSY_TX = 0x12, /*!< Data Transmission process is ongoing */
166 HAL_SMARTCARD_STATE_BUSY_RX = 0x22, /*!< Data Reception process is ongoing */
167 HAL_SMARTCARD_STATE_BUSY_TX_RX = 0x32, /*!< Data Transmission and Reception process is ongoing */
168 HAL_SMARTCARD_STATE_TIMEOUT = 0x03, /*!< Timeout state */
169 HAL_SMARTCARD_STATE_ERROR = 0x04 /*!< Error */
170 }HAL_SMARTCARD_StateTypeDef;
171
172 /**
173 * @brief HAL SMARTCARD Error Code structure definition
174 */
175 typedef enum
176 {
177 HAL_SMARTCARD_ERROR_NONE = 0x00, /*!< No error */
178 HAL_SMARTCARD_ERROR_PE = 0x01, /*!< Parity error */
179 HAL_SMARTCARD_ERROR_NE = 0x02, /*!< Noise error */
180 HAL_SMARTCARD_ERROR_FE = 0x04, /*!< frame error */
181 HAL_SMARTCARD_ERROR_ORE = 0x08, /*!< Overrun error */
182 HAL_SMARTCARD_ERROR_DMA = 0x10, /*!< DMA transfer error */
183 HAL_SMARTCARD_ERROR_RTO = 0x20 /*!< Receiver TimeOut error */
184 }HAL_SMARTCARD_ErrorTypeDef;
185
186 /**
187 * @brief SMARTCARD handle Structure definition
188 */
189 typedef struct
190 {
191 USART_TypeDef *Instance; /* USART registers base address */
192
193 SMARTCARD_InitTypeDef Init; /* SmartCard communication parameters */
194
195 SMARTCARD_AdvFeatureInitTypeDef AdvancedInit; /* SmartCard advanced features initialization parameters */
196
197 uint8_t *pTxBuffPtr; /* Pointer to SmartCard Tx transfer Buffer */
198
199 uint16_t TxXferSize; /* SmartCard Tx Transfer size */
200
201 uint16_t TxXferCount; /* SmartCard Tx Transfer Counter */
202
203 uint8_t *pRxBuffPtr; /* Pointer to SmartCard Rx transfer Buffer */
204
205 uint16_t RxXferSize; /* SmartCard Rx Transfer size */
206
207 uint16_t RxXferCount; /* SmartCard Rx Transfer Counter */
208
209 DMA_HandleTypeDef *hdmatx; /* SmartCard Tx DMA Handle parameters */
210
211 DMA_HandleTypeDef *hdmarx; /* SmartCard Rx DMA Handle parameters */
212
213 HAL_LockTypeDef Lock; /* Locking object */
214
215 HAL_SMARTCARD_StateTypeDef State; /* SmartCard communication state */
216
217 HAL_SMARTCARD_ErrorTypeDef ErrorCode; /* SmartCard Error code */
218
219 }SMARTCARD_HandleTypeDef;
220
221 /**
222 * @brief SMARTCARD clock sources
223 */
224 typedef enum
225 {
226 SMARTCARD_CLOCKSOURCE_PCLK1 = 0x00, /*!< PCLK1 clock source */
227 SMARTCARD_CLOCKSOURCE_PCLK2 = 0x01, /*!< PCLK2 clock source */
228 SMARTCARD_CLOCKSOURCE_HSI = 0x02, /*!< HSI clock source */
229 SMARTCARD_CLOCKSOURCE_SYSCLK = 0x04, /*!< SYSCLK clock source */
230 SMARTCARD_CLOCKSOURCE_LSE = 0x08, /*!< LSE clock source */
231 SMARTCARD_CLOCKSOURCE_UNDEFINED = 0x10 /*!< undefined clock source */
232 }SMARTCARD_ClockSourceTypeDef;
233
234 /**
235 * @}
236 */
237
238 /* Exported constants --------------------------------------------------------*/
239 /** @defgroup SMARTCARD_Exported_Constants SMARTCARD Exported Constants
240 * @{
241 */
242
243 /** @defgroup SMARTCARD_Word_Length SMARTCARD Word Length
244 * @{
245 */
246 #define SMARTCARD_WORDLENGTH_9B ((uint32_t)USART_CR1_M0)
247 #define IS_SMARTCARD_WORD_LENGTH(LENGTH) ((LENGTH) == SMARTCARD_WORDLENGTH_9B)
248 /**
249 * @}
250 */
251
252 /** @defgroup SMARTCARD_Stop_Bits SMARTCARD Stop Bits
253 * @{
254 */
255 #define SMARTCARD_STOPBITS_1_5 ((uint32_t)(USART_CR2_STOP))
256 #define IS_SMARTCARD_STOPBITS(STOPBITS) ((STOPBITS) == SMARTCARD_STOPBITS_1_5)
257 /**
258 * @}
259 */
260
261 /** @defgroup SMARTCARD_Parity SMARTCARD Parity
262 * @{
263 */
264 #define SMARTCARD_PARITY_EVEN ((uint16_t)USART_CR1_PCE)
265 #define SMARTCARD_PARITY_ODD ((uint16_t)(USART_CR1_PCE | USART_CR1_PS))
266 #define IS_SMARTCARD_PARITY(PARITY) (((PARITY) == SMARTCARD_PARITY_EVEN) || \
267 ((PARITY) == SMARTCARD_PARITY_ODD))
268 /**
269 * @}
270 */
271
272 /** @defgroup SMARTCARD_Mode SMARTCARD Transfer Mode
273 * @{
274 */
275 #define SMARTCARD_MODE_RX ((uint16_t)USART_CR1_RE)
276 #define SMARTCARD_MODE_TX ((uint16_t)USART_CR1_TE)
277 #define SMARTCARD_MODE_TX_RX ((uint16_t)(USART_CR1_TE |USART_CR1_RE))
278 #define IS_SMARTCARD_MODE(MODE) ((((MODE) & (uint16_t)0xFFF3) == 0x00) && ((MODE) != (uint16_t)0x00))
279 /**
280 * @}
281 */
282
283 /** @defgroup SMARTCARD_Clock_Polarity SMARTCARD Clock Polarity
284 * @{
285 */
286 #define SMARTCARD_POLARITY_LOW ((uint16_t)0x0000)
287 #define SMARTCARD_POLARITY_HIGH ((uint16_t)USART_CR2_CPOL)
288 #define IS_SMARTCARD_POLARITY(CPOL) (((CPOL) == SMARTCARD_POLARITY_LOW) || ((CPOL) == SMARTCARD_POLARITY_HIGH))
289 /**
290 * @}
291 */
292
293 /** @defgroup SMARTCARD_Clock_Phase SMARTCARD Clock Phase
294 * @{
295 */
296 #define SMARTCARD_PHASE_1EDGE ((uint16_t)0x0000)
297 #define SMARTCARD_PHASE_2EDGE ((uint16_t)USART_CR2_CPHA)
298 #define IS_SMARTCARD_PHASE(CPHA) (((CPHA) == SMARTCARD_PHASE_1EDGE) || ((CPHA) == SMARTCARD_PHASE_2EDGE))
299 /**
300 * @}
301 */
302
303 /** @defgroup SMARTCARD_Last_Bit SMARTCARD Last Bit
304 * @{
305 */
306 #define SMARTCARD_LASTBIT_DISABLED ((uint16_t)0x0000)
307 #define SMARTCARD_LASTBIT_ENABLED ((uint16_t)USART_CR2_LBCL)
308 #define IS_SMARTCARD_LASTBIT(LASTBIT) (((LASTBIT) == SMARTCARD_LASTBIT_DISABLED) || \
309 ((LASTBIT) == SMARTCARD_LASTBIT_ENABLED))
310 /**
311 * @}
312 */
313
314 /** @defgroup SMARTCARD_OneBit_Sampling SMARTCARD One Bit Sampling Method
315 * @{
316 */
317 #define SMARTCARD_ONEBIT_SAMPLING_DISABLED ((uint16_t)0x0000)
318 #define SMARTCARD_ONEBIT_SAMPLING_ENABLED ((uint16_t)USART_CR3_ONEBIT)
319 #define IS_SMARTCARD_ONEBIT_SAMPLING(ONEBIT) (((ONEBIT) == SMARTCARD_ONEBIT_SAMPLING_DISABLED) || \
320 ((ONEBIT) == SMARTCARD_ONEBIT_SAMPLING_ENABLED))
321 /**
322 * @}
323 */
324
325
326 /** @defgroup SMARTCARD_NACK_Enable SMARTCARD NACK Enable
327 * @{
328 */
329 #define SMARTCARD_NACK_ENABLED ((uint16_t)USART_CR3_NACK)
330 #define SMARTCARD_NACK_DISABLED ((uint16_t)0x0000)
331 #define IS_SMARTCARD_NACK(NACK) (((NACK) == SMARTCARD_NACK_ENABLED) || \
332 ((NACK) == SMARTCARD_NACK_DISABLED))
333 /**
334 * @}
335 */
336
337 /** @defgroup SMARTCARD_Timeout_Enable SMARTCARD Timeout Enable
338 * @{
339 */
340 #define SMARTCARD_TIMEOUT_DISABLED ((uint32_t)0x00000000)
341 #define SMARTCARD_TIMEOUT_ENABLED ((uint32_t)USART_CR2_RTOEN)
342 #define IS_SMARTCARD_TIMEOUT(TIMEOUT) (((TIMEOUT) == SMARTCARD_TIMEOUT_DISABLED) || \
343 ((TIMEOUT) == SMARTCARD_TIMEOUT_ENABLED))
344 /**
345 * @}
346 */
347
348 /** @defgroup SMARTCARD_Advanced_Features_Initialization_Type SMARTCARD advanced feature initialization type
349 * @{
350 */
351 #define SMARTCARD_ADVFEATURE_NO_INIT ((uint32_t)0x00000000)
352 #define SMARTCARD_ADVFEATURE_TXINVERT_INIT ((uint32_t)0x00000001)
353 #define SMARTCARD_ADVFEATURE_RXINVERT_INIT ((uint32_t)0x00000002)
354 #define SMARTCARD_ADVFEATURE_DATAINVERT_INIT ((uint32_t)0x00000004)
355 #define SMARTCARD_ADVFEATURE_SWAP_INIT ((uint32_t)0x00000008)
356 #define SMARTCARD_ADVFEATURE_RXOVERRUNDISABLE_INIT ((uint32_t)0x00000010)
357 #define SMARTCARD_ADVFEATURE_DMADISABLEONERROR_INIT ((uint32_t)0x00000020)
358 #define SMARTCARD_ADVFEATURE_MSBFIRST_INIT ((uint32_t)0x00000080)
359 #define IS_SMARTCARD_ADVFEATURE_INIT(INIT) ((INIT) <= (SMARTCARD_ADVFEATURE_NO_INIT | \
360 SMARTCARD_ADVFEATURE_TXINVERT_INIT | \
361 SMARTCARD_ADVFEATURE_RXINVERT_INIT | \
362 SMARTCARD_ADVFEATURE_DATAINVERT_INIT | \
363 SMARTCARD_ADVFEATURE_SWAP_INIT | \
364 SMARTCARD_ADVFEATURE_RXOVERRUNDISABLE_INIT | \
365 SMARTCARD_ADVFEATURE_DMADISABLEONERROR_INIT | \
366 SMARTCARD_ADVFEATURE_MSBFIRST_INIT))
367 /**
368 * @}
369 */
370
371 /** @defgroup SMARTCARD_Tx_Inv SMARTCARD advanced feature TX pin active level inversion
372 * @{
373 */
374 #define SMARTCARD_ADVFEATURE_TXINV_DISABLE ((uint32_t)0x00000000)
375 #define SMARTCARD_ADVFEATURE_TXINV_ENABLE ((uint32_t)USART_CR2_TXINV)
376 #define IS_SMARTCARD_ADVFEATURE_TXINV(TXINV) (((TXINV) == SMARTCARD_ADVFEATURE_TXINV_DISABLE) || \
377 ((TXINV) == SMARTCARD_ADVFEATURE_TXINV_ENABLE))
378 /**
379 * @}
380 */
381
382 /** @defgroup SMARTCARD_Rx_Inv SMARTCARD advanced feature RX pin active level inversion
383 * @{
384 */
385 #define SMARTCARD_ADVFEATURE_RXINV_DISABLE ((uint32_t)0x00000000)
386 #define SMARTCARD_ADVFEATURE_RXINV_ENABLE ((uint32_t)USART_CR2_RXINV)
387 #define IS_SMARTCARD_ADVFEATURE_RXINV(RXINV) (((RXINV) == SMARTCARD_ADVFEATURE_RXINV_DISABLE) || \
388 ((RXINV) == SMARTCARD_ADVFEATURE_RXINV_ENABLE))
389 /**
390 * @}
391 */
392
393 /** @defgroup SMARTCARD_Data_Inv SMARTCARD advanced feature Binary Data inversion
394 * @{
395 */
396 #define SMARTCARD_ADVFEATURE_DATAINV_DISABLE ((uint32_t)0x00000000)
397 #define SMARTCARD_ADVFEATURE_DATAINV_ENABLE ((uint32_t)USART_CR2_DATAINV)
398 #define IS_SMARTCARD_ADVFEATURE_DATAINV(DATAINV) (((DATAINV) == SMARTCARD_ADVFEATURE_DATAINV_DISABLE) || \
399 ((DATAINV) == SMARTCARD_ADVFEATURE_DATAINV_ENABLE))
400 /**
401 * @}
402 */
403
404 /** @defgroup SMARTCARD_Rx_Tx_Swap SMARTCARD advanced feature RX TX pins swap
405 * @{
406 */
407 #define SMARTCARD_ADVFEATURE_SWAP_DISABLE ((uint32_t)0x00000000)
408 #define SMARTCARD_ADVFEATURE_SWAP_ENABLE ((uint32_t)USART_CR2_SWAP)
409 #define IS_SMARTCARD_ADVFEATURE_SWAP(SWAP) (((SWAP) == SMARTCARD_ADVFEATURE_SWAP_DISABLE) || \
410 ((SWAP) == SMARTCARD_ADVFEATURE_SWAP_ENABLE))
411 /**
412 * @}
413 */
414
415 /** @defgroup SMARTCARD_Overrun_Disable SMARTCARD advanced feature Overrun Disable
416 * @{
417 */
418 #define SMARTCARD_ADVFEATURE_OVERRUN_ENABLE ((uint32_t)0x00000000)
419 #define SMARTCARD_ADVFEATURE_OVERRUN_DISABLE ((uint32_t)USART_CR3_OVRDIS)
420 #define IS_SMARTCARD_OVERRUN(OVERRUN) (((OVERRUN) == SMARTCARD_ADVFEATURE_OVERRUN_ENABLE) || \
421 ((OVERRUN) == SMARTCARD_ADVFEATURE_OVERRUN_DISABLE))
422 /**
423 * @}
424 */
425
426 /** @defgroup SMARTCARD_DMA_Disable_on_Rx_Error SMARTCARD advanced feature DMA Disable on Rx Error
427 * @{
428 */
429 #define SMARTCARD_ADVFEATURE_DMA_ENABLEONRXERROR ((uint32_t)0x00000000)
430 #define SMARTCARD_ADVFEATURE_DMA_DISABLEONRXERROR ((uint32_t)USART_CR3_DDRE)
431 #define IS_SMARTCARD_ADVFEATURE_DMAONRXERROR(DMA) (((DMA) == SMARTCARD_ADVFEATURE_DMA_ENABLEONRXERROR) || \
432 ((DMA) == SMARTCARD_ADVFEATURE_DMA_DISABLEONRXERROR))
433 /**
434 * @}
435 */
436
437 /** @defgroup SMARTCARD_MSB_First SMARTCARD advanced feature MSB first
438 * @{
439 */
440 #define SMARTCARD_ADVFEATURE_MSBFIRST_DISABLE ((uint32_t)0x00000000)
441 #define SMARTCARD_ADVFEATURE_MSBFIRST_ENABLE ((uint32_t)USART_CR2_MSBFIRST)
442 #define IS_SMARTCARD_ADVFEATURE_MSBFIRST(MSBFIRST) (((MSBFIRST) == SMARTCARD_ADVFEATURE_MSBFIRST_DISABLE) || \
443 ((MSBFIRST) == SMARTCARD_ADVFEATURE_MSBFIRST_ENABLE))
444 /**
445 * @}
446 */
447
448 /** @defgroup SmartCard_Flags SMARTCARD Flags
449 * Elements values convention: 0xXXXX
450 * - 0xXXXX : Flag mask in the ISR register
451 * @{
452 */
453 #define SMARTCARD_FLAG_REACK ((uint32_t)0x00400000)
454 #define SMARTCARD_FLAG_TEACK ((uint32_t)0x00200000)
455 #define SMARTCARD_FLAG_BUSY ((uint32_t)0x00010000)
456 #define SMARTCARD_FLAG_EOBF ((uint32_t)0x00001000)
457 #define SMARTCARD_FLAG_RTOF ((uint32_t)0x00000800)
458 #define SMARTCARD_FLAG_TXE ((uint32_t)0x00000080)
459 #define SMARTCARD_FLAG_TC ((uint32_t)0x00000040)
460 #define SMARTCARD_FLAG_RXNE ((uint32_t)0x00000020)
461 #define SMARTCARD_FLAG_ORE ((uint32_t)0x00000008)
462 #define SMARTCARD_FLAG_NE ((uint32_t)0x00000004)
463 #define SMARTCARD_FLAG_FE ((uint32_t)0x00000002)
464 #define SMARTCARD_FLAG_PE ((uint32_t)0x00000001)
465 /**
466 * @}
467 */
468
469 /** @defgroup SMARTCARD_Interrupt_definition SMARTCARD Interrupts Definition
470 * Elements values convention: 0000ZZZZ0XXYYYYYb
471 * - YYYYY : Interrupt source position in the XX register (5bits)
472 * - XX : Interrupt source register (2bits)
473 * - 01: CR1 register
474 * - 10: CR2 register
475 * - 11: CR3 register
476 * - ZZZZ : Flag position in the ISR register(4bits)
477 * @{
478 */
479
480 #define SMARTCARD_IT_PE ((uint16_t)0x0028)
481 #define SMARTCARD_IT_TXE ((uint16_t)0x0727)
482 #define SMARTCARD_IT_TC ((uint16_t)0x0626)
483 #define SMARTCARD_IT_RXNE ((uint16_t)0x0525)
484
485 #define SMARTCARD_IT_ERR ((uint16_t)0x0060)
486 #define SMARTCARD_IT_ORE ((uint16_t)0x0300)
487 #define SMARTCARD_IT_NE ((uint16_t)0x0200)
488 #define SMARTCARD_IT_FE ((uint16_t)0x0100)
489
490 #define SMARTCARD_IT_EOB ((uint16_t)0x0C3B)
491 #define SMARTCARD_IT_RTO ((uint16_t)0x0B3A)
492 /**
493 * @}
494 */
495
496
497 /** @defgroup SMARTCARD_IT_CLEAR_Flags SMARTCARD Interruption Clear Flags
498 * @{
499 */
500 #define SMARTCARD_CLEAR_PEF USART_ICR_PECF /*!< Parity Error Clear Flag */
501 #define SMARTCARD_CLEAR_FEF USART_ICR_FECF /*!< Framing Error Clear Flag */
502 #define SMARTCARD_CLEAR_NEF USART_ICR_NCF /*!< Noise detected Clear Flag */
503 #define SMARTCARD_CLEAR_OREF USART_ICR_ORECF /*!< OverRun Error Clear Flag */
504 #define SMARTCARD_CLEAR_TCF USART_ICR_TCCF /*!< Transmission Complete Clear Flag */
505 #define SMARTCARD_CLEAR_RTOF USART_ICR_RTOCF /*!< Receiver Time Out Clear Flag */
506 #define SMARTCARD_CLEAR_EOBF USART_ICR_EOBCF /*!< End Of Block Clear Flag */
507 /**
508 * @}
509 */
510
511 /** @defgroup SMARTCARD_Request_Parameters SMARTCARD Request Parameters
512 * @{
513 */
514 #define SMARTCARD_RXDATA_FLUSH_REQUEST ((uint16_t)USART_RQR_RXFRQ) /*!< Receive Data flush Request */
515 #define SMARTCARD_TXDATA_FLUSH_REQUEST ((uint16_t)USART_RQR_TXFRQ) /*!< Transmit data flush Request */
516 #define IS_SMARTCARD_REQUEST_PARAMETER(PARAM) (((PARAM) == SMARTCARD_RXDATA_FLUSH_REQUEST) || \
517 ((PARAM) == SMARTCARD_TXDATA_FLUSH_REQUEST))
518 /**
519 * @}
520 */
521
522
523 /** @defgroup SMARTCARD_CR3_SCARCNT_LSB_POS SMARTCARD auto retry counter LSB position in CR3 register
524 * @{
525 */
526 #define SMARTCARD_CR3_SCARCNT_LSB_POS ((uint32_t) 17)
527 /**
528 * @}
529 */
530
531 /** @defgroup SMARTCARD_GTPR_GT_LSB_POS SMARTCARD guard time value LSB position in GTPR register
532 * @{
533 */
534 #define SMARTCARD_GTPR_GT_LSB_POS ((uint32_t) 8)
535 /**
536 * @}
537 */
538
539 /** @defgroup SMARTCARD_RTOR_BLEN_LSB_POS SMARTCARD block length LSB position in RTOR register
540 * @{
541 */
542 #define SMARTCARD_RTOR_BLEN_LSB_POS ((uint32_t) 24)
543 /**
544 * @}
545 */
546
547 /** @defgroup SMARTCARD_Interruption_Mask SMARTCARD interruptions flag mask
548 * @{
549 */
550 #define SMARTCARD_IT_MASK ((uint16_t)0x001F)
551 /**
552 * @}
553 */
554
555 /**
556 * @}
557 */
558
559 /* Exported macros -----------------------------------------------------------*/
560 /** @defgroup SMARTCARD_Exported_Macros SMARTCARD Exported Macros
561 * @{
562 */
563
564 /** @brief Reset SMARTCARD handle state
565 * @param __HANDLE__: SMARTCARD handle.
566 * @retval None
567 */
568 #define __HAL_SMARTCARD_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_SMARTCARD_STATE_RESET)
569
570 /** @brief Checks whether the specified Smartcard flag is set or not.
571 * @param __HANDLE__: specifies the SMARTCARD Handle.
572 * The Handle Instance can be USARTx where x: 1, 2 or 3 to select the USART peripheral.
573 * @param __FLAG__: specifies the flag to check.
574 * This parameter can be one of the following values:
575 * @arg SMARTCARD_FLAG_REACK: Receive enable ackowledge flag
576 * @arg SMARTCARD_FLAG_TEACK: Transmit enable ackowledge flag
577 * @arg SMARTCARD_FLAG_BUSY: Busy flag
578 * @arg SMARTCARD_FLAG_EOBF: End of block flag
579 * @arg SMARTCARD_FLAG_RTOF: Receiver timeout flag
580 * @arg SMARTCARD_FLAG_TXE: Transmit data register empty flag
581 * @arg SMARTCARD_FLAG_TC: Transmission Complete flag
582 * @arg SMARTCARD_FLAG_RXNE: Receive data register not empty flag
583 * @arg SMARTCARD_FLAG_ORE: OverRun Error flag
584 * @arg SMARTCARD_FLAG_NE: Noise Error flag
585 * @arg SMARTCARD_FLAG_FE: Framing Error flag
586 * @arg SMARTCARD_FLAG_PE: Parity Error flag
587 * @retval The new state of __FLAG__ (TRUE or FALSE).
588 */
589 #define __HAL_SMARTCARD_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->ISR & (__FLAG__)) == (__FLAG__))
590
591
592 /** @brief Enables the specified SmartCard interrupt.
593 * @param __HANDLE__: specifies the SMARTCARD Handle.
594 * The Handle Instance can be USARTx where x: 1, 2 or 3 to select the USART peripheral.
595 * @param __INTERRUPT__: specifies the SMARTCARD interrupt to enable.
596 * This parameter can be one of the following values:
597 * @arg SMARTCARD_IT_EOBF: End Of Block interrupt
598 * @arg SMARTCARD_IT_RTOF: Receive TimeOut interrupt
599 * @arg SMARTCARD_IT_TXE: Transmit Data Register empty interrupt
600 * @arg SMARTCARD_IT_TC: Transmission complete interrupt
601 * @arg SMARTCARD_IT_RXNE: Receive Data register not empty interrupt
602 * @arg SMARTCARD_IT_PE: Parity Error interrupt
603 * @arg SMARTCARD_IT_ERR: Error interrupt(Frame error, noise error, overrun error)
604 * @retval None
605 */
606 #define __HAL_SMARTCARD_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((((uint8_t)(__INTERRUPT__)) >> 5U) == 1)? ((__HANDLE__)->Instance->CR1 |= (1U << ((__INTERRUPT__) & SMARTCARD_IT_MASK))): \
607 ((((uint8_t)(__INTERRUPT__)) >> 5U) == 2)? ((__HANDLE__)->Instance->CR2 |= (1U << ((__INTERRUPT__) & SMARTCARD_IT_MASK))): \
608 ((__HANDLE__)->Instance->CR3 |= (1U << ((__INTERRUPT__) & SMARTCARD_IT_MASK))))
609
610 /** @brief Disables the specified SmartCard interrupt.
611 * @param __HANDLE__: specifies the SMARTCARD Handle.
612 * The Handle Instance can be USARTx where x: 1, 2 or 3 to select the USART peripheral.
613 * @param __INTERRUPT__: specifies the SMARTCARD interrupt to disable.
614 * This parameter can be one of the following values:
615 * @arg SMARTCARD_IT_EOBF: End Of Block interrupt
616 * @arg SMARTCARD_IT_RTOF: Receive TimeOut interrupt
617 * @arg SMARTCARD_IT_TXE: Transmit Data Register empty interrupt
618 * @arg SMARTCARD_IT_TC: Transmission complete interrupt
619 * @arg SMARTCARD_IT_RXNE: Receive Data register not empty interrupt
620 * @arg SMARTCARD_IT_PE: Parity Error interrupt
621 * @arg SMARTCARD_IT_ERR: Error interrupt(Frame error, noise error, overrun error)
622 * @retval None
623 */
624 #define __HAL_SMARTCARD_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((((uint8_t)(__INTERRUPT__)) >> 5U) == 1)? ((__HANDLE__)->Instance->CR1 &= ~ (1U << ((__INTERRUPT__) & SMARTCARD_IT_MASK))): \
625 ((((uint8_t)(__INTERRUPT__)) >> 5U) == 2)? ((__HANDLE__)->Instance->CR2 &= ~ (1U << ((__INTERRUPT__) & SMARTCARD_IT_MASK))): \
626 ((__HANDLE__)->Instance->CR3 &= ~ (1U << ((__INTERRUPT__) & SMARTCARD_IT_MASK))))
627
628
629 /** @brief Checks whether the specified SmartCard interrupt has occurred or not.
630 * @param __HANDLE__: specifies the SMARTCARD Handle.
631 * The Handle Instance can be USARTx where x: 1, 2 or 3 to select the USART peripheral.
632 * @param __IT__: specifies the SMARTCARD interrupt to check.
633 * This parameter can be one of the following values:
634 * @arg SMARTCARD_IT_EOBF: End Of Block interrupt
635 * @arg SMARTCARD_IT_RTOF: Receive TimeOut interrupt
636 * @arg SMARTCARD_IT_TXE: Transmit Data Register empty interrupt
637 * @arg SMARTCARD_IT_TC: Transmission complete interrupt
638 * @arg SMARTCARD_IT_RXNE: Receive Data register not empty interrupt
639 * @arg SMARTCARD_IT_ORE: OverRun Error interrupt
640 * @arg SMARTCARD_IT_NE: Noise Error interrupt
641 * @arg SMARTCARD_IT_FE: Framing Error interrupt
642 * @arg SMARTCARD_IT_PE: Parity Error interrupt
643 * @retval The new state of __IT__ (TRUE or FALSE).
644 */
645 #define __HAL_SMARTCARD_GET_IT(__HANDLE__, __IT__) ((__HANDLE__)->Instance->ISR & ((uint32_t)1 << ((__IT__)>> 0x08)))
646
647 /** @brief Checks whether the specified SmartCard interrupt interrupt source is enabled.
648 * @param __HANDLE__: specifies the SMARTCARD Handle.
649 * The Handle Instance can be USARTx where x: 1, 2 or 3 to select the USART peripheral.
650 * @param __IT__: specifies the SMARTCARD interrupt source to check.
651 * This parameter can be one of the following values:
652 * @arg SMARTCARD_IT_EOBF: End Of Block interrupt
653 * @arg SMARTCARD_IT_RTOF: Receive TimeOut interrupt
654 * @arg SMARTCARD_IT_TXE: Transmit Data Register empty interrupt
655 * @arg SMARTCARD_IT_TC: Transmission complete interrupt
656 * @arg SMARTCARD_IT_RXNE: Receive Data register not empty interrupt
657 * @arg SMARTCARD_IT_ORE: OverRun Error interrupt
658 * @arg SMARTCARD_IT_NE: Noise Error interrupt
659 * @arg SMARTCARD_IT_FE: Framing Error interrupt
660 * @arg SMARTCARD_IT_PE: Parity Error interrupt
661 * @retval The new state of __IT__ (TRUE or FALSE).
662 */
663 #define __HAL_SMARTCARD_GET_IT_SOURCE(__HANDLE__, __IT__) ((((((uint8_t)(__IT__)) >> 5U) == 1)? (__HANDLE__)->Instance->CR1 : \
664 (((((uint8_t)(__IT__)) >> 5U) == 2)? (__HANDLE__)->Instance->CR2 : \
665 (__HANDLE__)->Instance->CR3)) & ((uint32_t)1 << (((uint16_t)(__IT__)) & SMARTCARD_IT_MASK)))
666
667
668 /** @brief Clears the specified SMARTCARD ISR flag, in setting the proper ICR register flag.
669 * @param __HANDLE__: specifies the SMARTCARD Handle.
670 * The Handle Instance can be USARTx where x: 1, 2 or 3 to select the USART peripheral.
671 * @param __IT_CLEAR__: specifies the interrupt clear register flag that needs to be set
672 * to clear the corresponding interrupt
673 * This parameter can be one of the following values:
674 * @arg USART_CLEAR_PEF: Parity Error Clear Flag
675 * @arg USART_CLEAR_FEF: Framing Error Clear Flag
676 * @arg USART_CLEAR_NEF: Noise detected Clear Flag
677 * @arg USART_CLEAR_OREF: OverRun Error Clear Flag
678 * @arg USART_CLEAR_TCF: Transmission Complete Clear Flag
679 * @arg USART_CLEAR_RTOF: Receiver Time Out Clear Flag
680 * @arg USART_CLEAR_EOBF: End Of Block Clear Flag
681 * @retval None
682 */
683 #define __HAL_SMARTCARD_CLEAR_IT(__HANDLE__, __IT_CLEAR__) ((__HANDLE__)->Instance->ICR = (uint32_t)(__IT_CLEAR__))
684
685 /** @brief Set a specific SMARTCARD request flag.
686 * @param __HANDLE__: specifies the SMARTCARD Handle.
687 * The Handle Instance can be USARTx where x: 1, 2 or 3 to select the USART peripheral.
688 * @param __REQ__: specifies the request flag to set
689 * This parameter can be one of the following values:
690 * @arg SMARTCARD_RXDATA_FLUSH_REQUEST: Receive Data flush Request
691 * @arg SMARTCARD_TXDATA_FLUSH_REQUEST: Transmit data flush Request
692 *
693 * @retval None
694 */
695 #define __HAL_SMARTCARD_SEND_REQ(__HANDLE__, __REQ__) ((__HANDLE__)->Instance->RQR |= (uint16_t)(__REQ__))
696
697 /** @brief Enable the USART associated to the SMARTCARD Handle
698 * @param __HANDLE__: specifies the SMARTCARD Handle.
699 * The Handle Instance can be UARTx where x: 1, 2, 3 to select the USART peripheral
700 * @retval None
701 */
702 #define __HAL_SMARTCARD_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= USART_CR1_UE)
703
704 /** @brief Disable the USART associated to the SMARTCARD Handle
705 * @param __HANDLE__: specifies the SMARTCARD Handle.
706 * The Handle Instance can be UARTx where x: 1, 2, 3 to select the USART peripheral
707 * @retval None
708 */
709 #define __HAL_SMARTCARD_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~USART_CR1_UE)
710
711 /** @brief Check the Baud rate range. The maximum Baud Rate is derived from the
712 * maximum clock on F3 (i.e. 72 MHz) divided by the oversampling used
713 * on the SMARTCARD (i.e. 16)
714 * @param __BAUDRATE__: Baud rate set by the configuration function.
715 * @retval Test result (TRUE or FALSE)
716 */
717 #define IS_SMARTCARD_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) < 4500001)
718
719 /** @brief Check the block length range. The maximum SMARTCARD block length is 0xFF.
720 * @param __LENGTH__: block length.
721 * @retval Test result (TRUE or FALSE)
722 */
723 #define IS_SMARTCARD_BLOCKLENGTH(__LENGTH__) ((__LENGTH__) <= 0xFF)
724
725 /** @brief Check the receiver timeout value. The maximum SMARTCARD receiver timeout
726 * value is 0xFFFFFF.
727 * @param __TIMEOUTVALUE__: receiver timeout value.
728 * @retval Test result (TRUE or FALSE)
729 */
730 #define IS_SMARTCARD_TIMEOUT_VALUE(__TIMEOUTVALUE__) ((__TIMEOUTVALUE__) <= 0xFFFFFF)
731
732 /** @brief Check the SMARTCARD autoretry counter value. The maximum number of
733 * retransmissions is 0x7.
734 * @param __COUNT__: number of retransmissions
735 * @retval Test result (TRUE or FALSE)
736 */
737 #define IS_SMARTCARD_AUTORETRY_COUNT(__COUNT__) ((__COUNT__) <= 0x7)
738
739
740
741 /**
742 * @}
743 */
744
745 /* Include SMARTCARD HAL Extended module */
746 #include "stm32f3xx_hal_smartcard_ex.h"
747
748
749 /* Exported functions --------------------------------------------------------*/
750 /** @addtogroup SMARTCARD_Exported_Functions SMARTCARD Exported Functions
751 * @{
752 */
753
754 /** @addtogroup SMARTCARD_Exported_Functions_Group1 Initialization and de-initialization functions
755 * @{
756 */
757
758 /* Initialization and de-initialization functions ****************************/
759 HAL_StatusTypeDef HAL_SMARTCARD_Init(SMARTCARD_HandleTypeDef *hsmartcard);
760 HAL_StatusTypeDef HAL_SMARTCARD_DeInit(SMARTCARD_HandleTypeDef *hsmartcard);
761 void HAL_SMARTCARD_MspInit(SMARTCARD_HandleTypeDef *hsmartcard);
762 void HAL_SMARTCARD_MspDeInit(SMARTCARD_HandleTypeDef *hsmartcard);
763
764 /**
765 * @}
766 */
767
768 /** @addtogroup SMARTCARD_Exported_Functions_Group2 Input and Output operation functions
769 * @{
770 */
771
772 /* IO operation functions *****************************************************/
773 HAL_StatusTypeDef HAL_SMARTCARD_Transmit(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size, uint32_t Timeout);
774 HAL_StatusTypeDef HAL_SMARTCARD_Receive(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size, uint32_t Timeout);
775 HAL_StatusTypeDef HAL_SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size);
776 HAL_StatusTypeDef HAL_SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size);
777 HAL_StatusTypeDef HAL_SMARTCARD_Transmit_DMA(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size);
778 HAL_StatusTypeDef HAL_SMARTCARD_Receive_DMA(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size);
779 void HAL_SMARTCARD_IRQHandler(SMARTCARD_HandleTypeDef *hsmartcard);
780 void HAL_SMARTCARD_TxCpltCallback(SMARTCARD_HandleTypeDef *hsmartcard);
781 void HAL_SMARTCARD_RxCpltCallback(SMARTCARD_HandleTypeDef *hsmartcard);
782 void HAL_SMARTCARD_ErrorCallback(SMARTCARD_HandleTypeDef *hsmartcard);
783
784 /**
785 * @}
786 */
787
788 /** @defgroup SMARTCARD_Exported_Functions_Group3 Peripheral Control functions
789 * @{
790 */
791
792 /* Peripheral State and Error functions ***************************************/
793 HAL_SMARTCARD_StateTypeDef HAL_SMARTCARD_GetState(SMARTCARD_HandleTypeDef *hsmartcard);
794 uint32_t HAL_SMARTCARD_GetError(SMARTCARD_HandleTypeDef *hsmartcard);
795 /**
796 * @}
797 */
798
799 /**
800 * @}
801 */
802
803 /**
804 * @}
805 */
806
807 /**
808 * @}
809 */
810
811 #ifdef __cplusplus
812 }
813 #endif
814
815 #endif /* __STM32F3xx_HAL_SMARTCARD_H */
816
817 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Imprint / Impressum