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