Merge pull request #11270 from haslinghuis/rename_attr
[betaflight.git] / lib / main / STM32F1 / Drivers / STM32F1xx_HAL_Driver / Inc / stm32f1xx_hal_smartcard.h
blob15c1720a73f5096ee2cbe2e139eb7a13f46e766e
1 /**
2 ******************************************************************************
3 * @file stm32f1xx_hal_smartcard.h
4 * @author MCD Application Team
5 * @version V1.1.1
6 * @date 12-May-2017
7 * @brief Header file of SMARTCARD HAL module.
8 ******************************************************************************
9 * @attention
11 * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
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.
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.
35 ******************************************************************************
38 /* Define to prevent recursive inclusion -------------------------------------*/
39 #ifndef __STM32F1xx_HAL_SMARTCARD_H
40 #define __STM32F1xx_HAL_SMARTCARD_H
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32f1xx_hal_def.h"
49 /** @addtogroup STM32F1xx_HAL_Driver
50 * @{
53 /** @addtogroup SMARTCARD
54 * @{
57 /* Exported types ------------------------------------------------------------*/
58 /** @defgroup SMARTCARD_Exported_Types SMARTCARD Exported Types
59 * @{
62 /**
63 * @brief SMARTCARD Init Structure definition
65 typedef struct
67 uint32_t BaudRate; /*!< This member configures the SmartCard communication baud rate.
68 The baud rate is computed using the following formula:
69 - IntegerDivider = ((PCLKx) / (16 * (hsmartcard->Init.BaudRate)))
70 - FractionalDivider = ((IntegerDivider - ((uint32_t) IntegerDivider)) * 16) + 0.5 */
72 uint32_t WordLength; /*!< Specifies the number of data bits transmitted or received in a frame.
73 This parameter can be a value of @ref SMARTCARD_Word_Length */
75 uint32_t StopBits; /*!< Specifies the number of stop bits transmitted.
76 This parameter can be a value of @ref SMARTCARD_Stop_Bits */
78 uint32_t Parity; /*!< Specifies the parity mode.
79 This parameter can be a value of @ref SMARTCARD_Parity
80 @note When parity is enabled, the computed parity is inserted
81 at the MSB position of the transmitted data (9th bit when
82 the word length is set to 9 data bits; 8th bit when the
83 word length is set to 8 data bits).*/
85 uint32_t Mode; /*!< Specifies whether the Receive or Transmit mode is enabled or disabled.
86 This parameter can be a value of @ref SMARTCARD_Mode */
88 uint32_t CLKPolarity; /*!< Specifies the steady state of the serial clock.
89 This parameter can be a value of @ref SMARTCARD_Clock_Polarity */
91 uint32_t CLKPhase; /*!< Specifies the clock transition on which the bit capture is made.
92 This parameter can be a value of @ref SMARTCARD_Clock_Phase */
94 uint32_t CLKLastBit; /*!< Specifies whether the clock pulse corresponding to the last transmitted
95 data bit (MSB) has to be output on the SCLK pin in synchronous mode.
96 This parameter can be a value of @ref SMARTCARD_Last_Bit */
98 uint32_t Prescaler; /*!< Specifies the SmartCard Prescaler value used for dividing the system clock
99 to provide the smartcard clock. The value given in the register (5 significant bits)
100 is multiplied by 2 to give the division factor of the source clock frequency.
101 This parameter can be a value of @ref SMARTCARD_Prescaler */
103 uint32_t GuardTime; /*!< Specifies the SmartCard Guard Time value in terms of number of baud clocks */
105 uint32_t NACKState; /*!< Specifies the SmartCard NACK Transmission state
106 This parameter can be a value of @ref SMARTCARD_NACK_State */
107 }SMARTCARD_InitTypeDef;
109 /**
110 * @brief HAL SMARTCARD State structures definition
111 * @note HAL SMARTCARD State value is a combination of 2 different substates: gState and RxState.
112 * - gState contains SMARTCARD state information related to global Handle management
113 * and also information related to Tx operations.
114 * gState value coding follow below described bitmap :
115 * b7-b6 Error information
116 * 00 : No Error
117 * 01 : (Not Used)
118 * 10 : Timeout
119 * 11 : Error
120 * b5 IP initilisation status
121 * 0 : Reset (IP not initialized)
122 * 1 : Init done (IP not initialized. HAL SMARTCARD Init function already called)
123 * b4-b3 (not used)
124 * xx : Should be set to 00
125 * b2 Intrinsic process state
126 * 0 : Ready
127 * 1 : Busy (IP busy with some configuration or internal operations)
128 * b1 (not used)
129 * x : Should be set to 0
130 * b0 Tx state
131 * 0 : Ready (no Tx operation ongoing)
132 * 1 : Busy (Tx operation ongoing)
133 * - RxState contains information related to Rx operations.
134 * RxState value coding follow below described bitmap :
135 * b7-b6 (not used)
136 * xx : Should be set to 00
137 * b5 IP initilisation status
138 * 0 : Reset (IP not initialized)
139 * 1 : Init done (IP not initialized)
140 * b4-b2 (not used)
141 * xxx : Should be set to 000
142 * b1 Rx state
143 * 0 : Ready (no Rx operation ongoing)
144 * 1 : Busy (Rx operation ongoing)
145 * b0 (not used)
146 * x : Should be set to 0.
148 typedef enum
150 HAL_SMARTCARD_STATE_RESET = 0x00U, /*!< Peripheral is not yet Initialized
151 Value is allowed for gState and RxState */
152 HAL_SMARTCARD_STATE_READY = 0x20U, /*!< Peripheral Initialized and ready for use
153 Value is allowed for gState and RxState */
154 HAL_SMARTCARD_STATE_BUSY = 0x24U, /*!< an internal process is ongoing
155 Value is allowed for gState only */
156 HAL_SMARTCARD_STATE_BUSY_TX = 0x21U, /*!< Data Transmission process is ongoing
157 Value is allowed for gState only */
158 HAL_SMARTCARD_STATE_BUSY_RX = 0x22U, /*!< Data Reception process is ongoing
159 Value is allowed for RxState only */
160 HAL_SMARTCARD_STATE_BUSY_TX_RX = 0x23U, /*!< Data Transmission and Reception process is ongoing
161 Not to be used for neither gState nor RxState.
162 Value is result of combination (Or) between gState and RxState values */
163 HAL_SMARTCARD_STATE_TIMEOUT = 0xA0U, /*!< Timeout state
164 Value is allowed for gState only */
165 HAL_SMARTCARD_STATE_ERROR = 0xE0U /*!< Error
166 Value is allowed for gState only */
167 }HAL_SMARTCARD_StateTypeDef;
169 /**
170 * @brief SMARTCARD handle Structure definition
172 typedef struct
174 USART_TypeDef *Instance; /*!< USART registers base address */
176 SMARTCARD_InitTypeDef Init; /*!< SmartCard communication parameters */
178 uint8_t *pTxBuffPtr; /*!< Pointer to SmartCard Tx transfer Buffer */
180 uint16_t TxXferSize; /*!< SmartCard Tx Transfer size */
182 __IO uint16_t TxXferCount; /*!< SmartCard Tx Transfer Counter */
184 uint8_t *pRxBuffPtr; /*!< Pointer to SmartCard Rx transfer Buffer */
186 uint16_t RxXferSize; /*!< SmartCard Rx Transfer size */
188 __IO uint16_t RxXferCount; /*!< SmartCard Rx Transfer Counter */
190 DMA_HandleTypeDef *hdmatx; /*!< SmartCard Tx DMA Handle parameters */
192 DMA_HandleTypeDef *hdmarx; /*!< SmartCard Rx DMA Handle parameters */
194 HAL_LockTypeDef Lock; /*!< Locking object */
196 __IO HAL_SMARTCARD_StateTypeDef gState; /*!< SmartCard state information related to global Handle management
197 and also related to Tx operations.
198 This parameter can be a value of @ref HAL_SMARTCARD_StateTypeDef */
200 __IO HAL_SMARTCARD_StateTypeDef RxState; /*!< SmartCard state information related to Rx operations.
201 This parameter can be a value of @ref HAL_SMARTCARD_StateTypeDef */
203 __IO uint32_t ErrorCode; /*!< SmartCard Error code */
204 }SMARTCARD_HandleTypeDef;
207 * @}
210 /* Exported constants --------------------------------------------------------*/
211 /** @defgroup SMARTCARD_Exported_Constants SMARTCARD Exported constants
212 * @{
215 /** @defgroup SMARTCARD_Error_Code SMARTCARD Error Code
216 * @{
218 #define HAL_SMARTCARD_ERROR_NONE 0x00000000U /*!< No error */
219 #define HAL_SMARTCARD_ERROR_PE 0x00000001U /*!< Parity error */
220 #define HAL_SMARTCARD_ERROR_NE 0x00000002U /*!< Noise error */
221 #define HAL_SMARTCARD_ERROR_FE 0x00000004U /*!< Frame error */
222 #define HAL_SMARTCARD_ERROR_ORE 0x00000008U /*!< OverRun error */
223 #define HAL_SMARTCARD_ERROR_DMA 0x00000010U /*!< DMA transfer error */
225 * @}
228 /** @defgroup SMARTCARD_Word_Length SMARTCARD Word Length
229 * @{
231 #define SMARTCARD_WORDLENGTH_9B ((uint32_t)USART_CR1_M)
233 * @}
236 /** @defgroup SMARTCARD_Stop_Bits SMARTCARD Number of Stop Bits
237 * @{
239 #define SMARTCARD_STOPBITS_0_5 ((uint32_t)USART_CR2_STOP_0)
240 #define SMARTCARD_STOPBITS_1_5 ((uint32_t)(USART_CR2_STOP_0 | USART_CR2_STOP_1))
242 * @}
245 /** @defgroup SMARTCARD_Parity SMARTCARD Parity
246 * @{
248 #define SMARTCARD_PARITY_EVEN ((uint32_t)USART_CR1_PCE)
249 #define SMARTCARD_PARITY_ODD ((uint32_t)(USART_CR1_PCE | USART_CR1_PS))
251 * @}
254 /** @defgroup SMARTCARD_Mode SMARTCARD Mode
255 * @{
257 #define SMARTCARD_MODE_RX ((uint32_t)USART_CR1_RE)
258 #define SMARTCARD_MODE_TX ((uint32_t)USART_CR1_TE)
259 #define SMARTCARD_MODE_TX_RX ((uint32_t)(USART_CR1_TE |USART_CR1_RE))
261 * @}
264 /** @defgroup SMARTCARD_Clock_Polarity SMARTCARD Clock Polarity
265 * @{
267 #define SMARTCARD_POLARITY_LOW 0x00000000U
268 #define SMARTCARD_POLARITY_HIGH ((uint32_t)USART_CR2_CPOL)
270 * @}
273 /** @defgroup SMARTCARD_Clock_Phase SMARTCARD Clock Phase
274 * @{
276 #define SMARTCARD_PHASE_1EDGE 0x00000000U
277 #define SMARTCARD_PHASE_2EDGE ((uint32_t)USART_CR2_CPHA)
279 * @}
282 /** @defgroup SMARTCARD_Last_Bit SMARTCARD Last Bit
283 * @{
285 #define SMARTCARD_LASTBIT_DISABLE 0x00000000U
286 #define SMARTCARD_LASTBIT_ENABLE ((uint32_t)USART_CR2_LBCL)
288 * @}
291 /** @defgroup SMARTCARD_NACK_State SMARTCARD NACK State
292 * @{
294 #define SMARTCARD_NACK_ENABLE ((uint32_t)USART_CR3_NACK)
295 #define SMARTCARD_NACK_DISABLE 0x00000000U
297 * @}
300 /** @defgroup SMARTCARD_DMA_Requests SMARTCARD DMA requests
301 * @{
303 #define SMARTCARD_DMAREQ_TX ((uint32_t)USART_CR3_DMAT)
304 #define SMARTCARD_DMAREQ_RX ((uint32_t)USART_CR3_DMAR)
306 * @}
309 /** @defgroup SMARTCARD_Prescaler SMARTCARD Prescaler
310 * @{
312 #define SMARTCARD_PRESCALER_SYSCLK_DIV2 0x00000001U /*!< SYSCLK divided by 2 */
313 #define SMARTCARD_PRESCALER_SYSCLK_DIV4 0x00000002U /*!< SYSCLK divided by 4 */
314 #define SMARTCARD_PRESCALER_SYSCLK_DIV6 0x00000003U /*!< SYSCLK divided by 6 */
315 #define SMARTCARD_PRESCALER_SYSCLK_DIV8 0x00000004U /*!< SYSCLK divided by 8 */
316 #define SMARTCARD_PRESCALER_SYSCLK_DIV10 0x00000005U /*!< SYSCLK divided by 10 */
317 #define SMARTCARD_PRESCALER_SYSCLK_DIV12 0x00000006U /*!< SYSCLK divided by 12 */
318 #define SMARTCARD_PRESCALER_SYSCLK_DIV14 0x00000007U /*!< SYSCLK divided by 14 */
319 #define SMARTCARD_PRESCALER_SYSCLK_DIV16 0x00000008U /*!< SYSCLK divided by 16 */
320 #define SMARTCARD_PRESCALER_SYSCLK_DIV18 0x00000009U /*!< SYSCLK divided by 18 */
321 #define SMARTCARD_PRESCALER_SYSCLK_DIV20 0x0000000AU /*!< SYSCLK divided by 20 */
322 #define SMARTCARD_PRESCALER_SYSCLK_DIV22 0x0000000BU /*!< SYSCLK divided by 22 */
323 #define SMARTCARD_PRESCALER_SYSCLK_DIV24 0x0000000CU /*!< SYSCLK divided by 24 */
324 #define SMARTCARD_PRESCALER_SYSCLK_DIV26 0x0000000DU /*!< SYSCLK divided by 26 */
325 #define SMARTCARD_PRESCALER_SYSCLK_DIV28 0x0000000EU /*!< SYSCLK divided by 28 */
326 #define SMARTCARD_PRESCALER_SYSCLK_DIV30 0x0000000FU /*!< SYSCLK divided by 30 */
327 #define SMARTCARD_PRESCALER_SYSCLK_DIV32 0x00000010U /*!< SYSCLK divided by 32 */
328 #define SMARTCARD_PRESCALER_SYSCLK_DIV34 0x00000011U /*!< SYSCLK divided by 34 */
329 #define SMARTCARD_PRESCALER_SYSCLK_DIV36 0x00000012U /*!< SYSCLK divided by 36 */
330 #define SMARTCARD_PRESCALER_SYSCLK_DIV38 0x00000013U /*!< SYSCLK divided by 38 */
331 #define SMARTCARD_PRESCALER_SYSCLK_DIV40 0x00000014U /*!< SYSCLK divided by 40 */
332 #define SMARTCARD_PRESCALER_SYSCLK_DIV42 0x00000015U /*!< SYSCLK divided by 42 */
333 #define SMARTCARD_PRESCALER_SYSCLK_DIV44 0x00000016U /*!< SYSCLK divided by 44 */
334 #define SMARTCARD_PRESCALER_SYSCLK_DIV46 0x00000017U /*!< SYSCLK divided by 46 */
335 #define SMARTCARD_PRESCALER_SYSCLK_DIV48 0x00000018U /*!< SYSCLK divided by 48 */
336 #define SMARTCARD_PRESCALER_SYSCLK_DIV50 0x00000019U /*!< SYSCLK divided by 50 */
337 #define SMARTCARD_PRESCALER_SYSCLK_DIV52 0x0000001AU /*!< SYSCLK divided by 52 */
338 #define SMARTCARD_PRESCALER_SYSCLK_DIV54 0x0000001BU /*!< SYSCLK divided by 54 */
339 #define SMARTCARD_PRESCALER_SYSCLK_DIV56 0x0000001CU /*!< SYSCLK divided by 56 */
340 #define SMARTCARD_PRESCALER_SYSCLK_DIV58 0x0000001DU /*!< SYSCLK divided by 58 */
341 #define SMARTCARD_PRESCALER_SYSCLK_DIV60 0x0000001EU /*!< SYSCLK divided by 60 */
342 #define SMARTCARD_PRESCALER_SYSCLK_DIV62 0x0000001FU /*!< SYSCLK divided by 62 */
344 * @}
347 /** @defgroup SmartCard_Flags SMARTCARD Flags
348 * Elements values convention: 0xXXXX
349 * - 0xXXXX : Flag mask in the SR register
350 * @{
352 #define SMARTCARD_FLAG_TXE ((uint32_t)USART_SR_TXE)
353 #define SMARTCARD_FLAG_TC ((uint32_t)USART_SR_TC)
354 #define SMARTCARD_FLAG_RXNE ((uint32_t)USART_SR_RXNE)
355 #define SMARTCARD_FLAG_IDLE ((uint32_t)USART_SR_IDLE)
356 #define SMARTCARD_FLAG_ORE ((uint32_t)USART_SR_ORE)
357 #define SMARTCARD_FLAG_NE ((uint32_t)USART_SR_NE)
358 #define SMARTCARD_FLAG_FE ((uint32_t)USART_SR_FE)
359 #define SMARTCARD_FLAG_PE ((uint32_t)USART_SR_PE)
361 * @}
364 /** @defgroup SmartCard_Interrupt_definition SMARTCARD Interrupts Definition
365 * Elements values convention: 0xY000XXXX
366 * - XXXX : Interrupt mask in the XX register
367 * - Y : Interrupt source register (2bits)
368 * - 01: CR1 register
369 * - 11: CR3 register
370 * @{
372 #define SMARTCARD_IT_PE ((uint32_t)(SMARTCARD_CR1_REG_INDEX << 28U | USART_CR1_PEIE))
373 #define SMARTCARD_IT_TXE ((uint32_t)(SMARTCARD_CR1_REG_INDEX << 28U | USART_CR1_TXEIE))
374 #define SMARTCARD_IT_TC ((uint32_t)(SMARTCARD_CR1_REG_INDEX << 28U | USART_CR1_TCIE))
375 #define SMARTCARD_IT_RXNE ((uint32_t)(SMARTCARD_CR1_REG_INDEX << 28U | USART_CR1_RXNEIE))
376 #define SMARTCARD_IT_IDLE ((uint32_t)(SMARTCARD_CR1_REG_INDEX << 28U | USART_CR1_IDLEIE))
377 #define SMARTCARD_IT_ERR ((uint32_t)(SMARTCARD_CR3_REG_INDEX << 28U | USART_CR3_EIE))
379 * @}
383 * @}
386 /* Exported macro ------------------------------------------------------------*/
387 /** @defgroup SMARTCARD_Exported_Macros SMARTCARD Exported Macros
388 * @{
391 /** @brief Reset SMARTCARD handle gstate & RxState
392 * @param __HANDLE__: specifies the SMARTCARD Handle.
393 * SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device).
395 #define __HAL_SMARTCARD_RESET_HANDLE_STATE(__HANDLE__) do{ \
396 (__HANDLE__)->gState = HAL_SMARTCARD_STATE_RESET; \
397 (__HANDLE__)->RxState = HAL_SMARTCARD_STATE_RESET; \
398 } while(0U)
400 /** @brief Flush the Smartcard DR register
401 * @param __HANDLE__: specifies the SMARTCARD Handle.
402 * SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device).
404 #define __HAL_SMARTCARD_FLUSH_DRREGISTER(__HANDLE__) ((__HANDLE__)->Instance->DR)
406 /** @brief Check whether the specified Smartcard flag is set or not.
407 * @param __HANDLE__: specifies the SMARTCARD Handle.
408 * SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device).
409 * @param __FLAG__: specifies the flag to check.
410 * This parameter can be one of the following values:
411 * @arg SMARTCARD_FLAG_TXE: Transmit data register empty flag
412 * @arg SMARTCARD_FLAG_TC: Transmission Complete flag
413 * @arg SMARTCARD_FLAG_RXNE: Receive data register not empty flag
414 * @arg SMARTCARD_FLAG_IDLE: Idle Line detection flag
415 * @arg SMARTCARD_FLAG_ORE: OverRun Error flag
416 * @arg SMARTCARD_FLAG_NE: Noise Error flag
417 * @arg SMARTCARD_FLAG_FE: Framing Error flag
418 * @arg SMARTCARD_FLAG_PE: Parity Error flag
419 * @retval The new state of __FLAG__ (TRUE or FALSE).
421 #define __HAL_SMARTCARD_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
423 /** @brief Clear the specified Smartcard pending flags.
424 * @param __HANDLE__: specifies the SMARTCARD Handle.
425 * SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device).
426 * @param __FLAG__: specifies the flag to check.
427 * This parameter can be any combination of the following values:
428 * @arg SMARTCARD_FLAG_TC: Transmission Complete flag.
429 * @arg SMARTCARD_FLAG_RXNE: Receive data register not empty flag.
431 * @note PE (Parity error), FE (Framing error), NE (Noise error) and ORE (OverRun
432 * error) flags are cleared by software sequence: a read operation to
433 * USART_SR register followed by a read operation to USART_DR register.
434 * @note RXNE flag can be also cleared by a read to the USART_DR register.
435 * @note TC flag can be also cleared by software sequence: a read operation to
436 * USART_SR register followed by a write operation to USART_DR register.
437 * @note TXE flag is cleared only by a write to the USART_DR register.
439 #define __HAL_SMARTCARD_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR = ~(__FLAG__))
441 /** @brief Clear the SMARTCARD PE pending flag.
442 * @param __HANDLE__: specifies the USART Handle.
443 * SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device).
445 #define __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__) \
446 do{ \
447 __IO uint32_t tmpreg = 0x00U; \
448 tmpreg = (__HANDLE__)->Instance->SR; \
449 tmpreg = (__HANDLE__)->Instance->DR; \
450 UNUSED(tmpreg); \
451 } while(0U)
453 /** @brief Clear the SMARTCARD FE pending flag.
454 * @param __HANDLE__: specifies the USART Handle.
455 * SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device).
457 #define __HAL_SMARTCARD_CLEAR_FEFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__)
459 /** @brief Clear the SMARTCARD NE pending flag.
460 * @param __HANDLE__: specifies the USART Handle.
461 * SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device).
463 #define __HAL_SMARTCARD_CLEAR_NEFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__)
465 /** @brief Clear the SMARTCARD ORE pending flag.
466 * @param __HANDLE__: specifies the USART Handle.
467 * SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device).
469 #define __HAL_SMARTCARD_CLEAR_OREFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__)
471 /** @brief Clear the SMARTCARD IDLE pending flag.
472 * @param __HANDLE__: specifies the USART Handle.
473 * SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device).
475 #define __HAL_SMARTCARD_CLEAR_IDLEFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__)
477 /** @brief Enable the specified SmartCard interrupt.
478 * @param __HANDLE__: specifies the SMARTCARD Handle.
479 * SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device).
480 * @param __INTERRUPT__: specifies the SMARTCARD interrupt to enable.
481 * This parameter can be one of the following values:
482 * @arg SMARTCARD_IT_TXE: Transmit Data Register empty interrupt
483 * @arg SMARTCARD_IT_TC: Transmission complete interrupt
484 * @arg SMARTCARD_IT_RXNE: Receive Data register not empty interrupt
485 * @arg SMARTCARD_IT_IDLE: Idle line detection interrupt
486 * @arg SMARTCARD_IT_PE: Parity Error interrupt
487 * @arg SMARTCARD_IT_ERR: Error interrupt(Frame error, noise error, overRun error)
489 #define __HAL_SMARTCARD_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28U) == SMARTCARD_CR1_REG_INDEX)? ((__HANDLE__)->Instance->CR1 |= ((__INTERRUPT__) & SMARTCARD_IT_MASK)): \
490 ((__HANDLE__)->Instance->CR3 |= ((__INTERRUPT__) & SMARTCARD_IT_MASK)))
492 /** @brief Disable the specified SmartCard interrupt.
493 * @param __HANDLE__: specifies the SMARTCARD Handle.
494 * SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device).
495 * @param __INTERRUPT__: specifies the SMARTCARD interrupt to disable.
496 * This parameter can be one of the following values:
497 * @arg SMARTCARD_IT_TXE: Transmit Data Register empty interrupt
498 * @arg SMARTCARD_IT_TC: Transmission complete interrupt
499 * @arg SMARTCARD_IT_RXNE: Receive Data register not empty interrupt
500 * @arg SMARTCARD_IT_IDLE: Idle line detection interrupt
501 * @arg SMARTCARD_IT_PE: Parity Error interrupt
502 * @arg SMARTCARD_IT_ERR: Error interrupt(Frame error, noise error, overRun error)
504 #define __HAL_SMARTCARD_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28U) == SMARTCARD_CR1_REG_INDEX)? ((__HANDLE__)->Instance->CR1 &= ~((__INTERRUPT__) & SMARTCARD_IT_MASK)): \
505 ((__HANDLE__)->Instance->CR3 &= ~ ((__INTERRUPT__) & SMARTCARD_IT_MASK)))
507 /** @brief Checks whether the specified SmartCard interrupt has occurred or not.
508 * @param __HANDLE__: specifies the SmartCard Handle.
509 * @param __IT__: specifies the SMARTCARD interrupt source to check.
510 * This parameter can be one of the following values:
511 * @arg SMARTCARD_IT_TXE: Transmit Data Register empty interrupt
512 * @arg SMARTCARD_IT_TC: Transmission complete interrupt
513 * @arg SMARTCARD_IT_RXNE: Receive Data register not empty interrupt
514 * @arg SMARTCARD_IT_IDLE: Idle line detection interrupt
515 * @arg SMARTCARD_IT_ERR: Error interrupt
516 * @arg SMARTCARD_IT_PE: Parity Error interrupt
517 * @retval The new state of __IT__ (TRUE or FALSE).
519 #define __HAL_SMARTCARD_GET_IT_SOURCE(__HANDLE__, __IT__) (((((__IT__) >> 28U) == SMARTCARD_CR1_REG_INDEX)? (__HANDLE__)->Instance->CR1: (__HANDLE__)->Instance->CR3) & (((uint32_t)(__IT__)) & SMARTCARD_IT_MASK))
521 /** @brief Enable the USART associated to the SMARTCARD Handle
522 * @param __HANDLE__: specifies the SMARTCARD Handle.
523 * SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device).
525 #define __HAL_SMARTCARD_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= USART_CR1_UE)
527 /** @brief Disable the USART associated to the SMARTCARD Handle
528 * @param __HANDLE__: specifies the SMARTCARD Handle.
529 * SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device).
531 #define __HAL_SMARTCARD_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~USART_CR1_UE)
533 /** @brief Macros to enable the SmartCard DMA request.
534 * @param __HANDLE__: specifies the SmartCard Handle.
535 * @param __REQUEST__: specifies the SmartCard DMA request.
536 * This parameter can be one of the following values:
537 * @arg SMARTCARD_DMAREQ_TX: SmartCard DMA transmit request
538 * @arg SMARTCARD_DMAREQ_RX: SmartCard DMA receive request
540 #define __HAL_SMARTCARD_DMA_REQUEST_ENABLE(__HANDLE__, __REQUEST__) ((__HANDLE__)->Instance->CR3 |= (__REQUEST__))
542 /** @brief Macros to disable the SmartCard DMA request.
543 * @param __HANDLE__: specifies the SmartCard Handle.
544 * @param __REQUEST__: specifies the SmartCard DMA request.
545 * This parameter can be one of the following values:
546 * @arg SMARTCARD_DMAREQ_TX: SmartCard DMA transmit request
547 * @arg SMARTCARD_DMAREQ_RX: SmartCard DMA receive request
549 #define __HAL_SMARTCARD_DMA_REQUEST_DISABLE(__HANDLE__, __REQUEST__) ((__HANDLE__)->Instance->CR3 &= ~(__REQUEST__))
552 * @}
554 /* Exported functions --------------------------------------------------------*/
555 /** @addtogroup SMARTCARD_Exported_Functions
556 * @{
559 /** @addtogroup SMARTCARD_Exported_Functions_Group1
560 * @{
562 /* Initialization/de-initialization functions **********************************/
563 HAL_StatusTypeDef HAL_SMARTCARD_Init(SMARTCARD_HandleTypeDef *hsc);
564 HAL_StatusTypeDef HAL_SMARTCARD_ReInit(SMARTCARD_HandleTypeDef *hsc);
565 HAL_StatusTypeDef HAL_SMARTCARD_DeInit(SMARTCARD_HandleTypeDef *hsc);
566 void HAL_SMARTCARD_MspInit(SMARTCARD_HandleTypeDef *hsc);
567 void HAL_SMARTCARD_MspDeInit(SMARTCARD_HandleTypeDef *hsc);
569 * @}
572 /** @addtogroup SMARTCARD_Exported_Functions_Group2
573 * @{
575 /* IO operation functions *******************************************************/
576 HAL_StatusTypeDef HAL_SMARTCARD_Transmit(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size, uint32_t Timeout);
577 HAL_StatusTypeDef HAL_SMARTCARD_Receive(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size, uint32_t Timeout);
578 HAL_StatusTypeDef HAL_SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size);
579 HAL_StatusTypeDef HAL_SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size);
580 HAL_StatusTypeDef HAL_SMARTCARD_Transmit_DMA(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size);
581 HAL_StatusTypeDef HAL_SMARTCARD_Receive_DMA(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size);
582 /* Transfer Abort functions */
583 HAL_StatusTypeDef HAL_SMARTCARD_Abort(SMARTCARD_HandleTypeDef *hsc);
584 HAL_StatusTypeDef HAL_SMARTCARD_AbortTransmit(SMARTCARD_HandleTypeDef *hsc);
585 HAL_StatusTypeDef HAL_SMARTCARD_AbortReceive(SMARTCARD_HandleTypeDef *hsc);
586 HAL_StatusTypeDef HAL_SMARTCARD_Abort_IT(SMARTCARD_HandleTypeDef *hsc);
587 HAL_StatusTypeDef HAL_SMARTCARD_AbortTransmit_IT(SMARTCARD_HandleTypeDef *hsc);
588 HAL_StatusTypeDef HAL_SMARTCARD_AbortReceive_IT(SMARTCARD_HandleTypeDef *hsc);
590 void HAL_SMARTCARD_IRQHandler(SMARTCARD_HandleTypeDef *hsc);
591 void HAL_SMARTCARD_TxCpltCallback(SMARTCARD_HandleTypeDef *hsc);
592 void HAL_SMARTCARD_RxCpltCallback(SMARTCARD_HandleTypeDef *hsc);
593 void HAL_SMARTCARD_ErrorCallback(SMARTCARD_HandleTypeDef *hsc);
594 void HAL_SMARTCARD_AbortCpltCallback(SMARTCARD_HandleTypeDef *hsc);
595 void HAL_SMARTCARD_AbortTransmitCpltCallback(SMARTCARD_HandleTypeDef *hsc);
596 void HAL_SMARTCARD_AbortReceiveCpltCallback(SMARTCARD_HandleTypeDef *hsc);
598 * @}
601 /** @addtogroup SMARTCARD_Exported_Functions_Group3
602 * @{
604 /* Peripheral State functions **************************************************/
605 HAL_SMARTCARD_StateTypeDef HAL_SMARTCARD_GetState(SMARTCARD_HandleTypeDef *hsc);
606 uint32_t HAL_SMARTCARD_GetError(SMARTCARD_HandleTypeDef *hsc);
608 * @}
612 * @}
614 /* Private types -------------------------------------------------------------*/
615 /* Private variables ---------------------------------------------------------*/
616 /* Private constants ---------------------------------------------------------*/
617 /** @defgroup SMARTCARD_Private_Constants SMARTCARD Private Constants
618 * @{
621 /** @brief SMARTCARD interruptions flag mask
624 #define SMARTCARD_IT_MASK 0x0000FFFFU
626 #define SMARTCARD_CR1_REG_INDEX 1U
627 #define SMARTCARD_CR3_REG_INDEX 3U
629 * @}
632 /* Private macros --------------------------------------------------------*/
633 /** @defgroup SMARTCARD_Private_Macros SMARTCARD Private Macros
634 * @{
636 #define IS_SMARTCARD_WORD_LENGTH(LENGTH) ((LENGTH) == SMARTCARD_WORDLENGTH_9B)
637 #define IS_SMARTCARD_STOPBITS(STOPBITS) (((STOPBITS) == SMARTCARD_STOPBITS_0_5) || \
638 ((STOPBITS) == SMARTCARD_STOPBITS_1_5))
639 #define IS_SMARTCARD_PARITY(PARITY) (((PARITY) == SMARTCARD_PARITY_EVEN) || \
640 ((PARITY) == SMARTCARD_PARITY_ODD))
641 #define IS_SMARTCARD_MODE(MODE) ((((MODE) & 0x0000FFF3U) == 0x00U) && ((MODE) != 0x000000U))
642 #define IS_SMARTCARD_POLARITY(CPOL) (((CPOL) == SMARTCARD_POLARITY_LOW) || ((CPOL) == SMARTCARD_POLARITY_HIGH))
643 #define IS_SMARTCARD_PHASE(CPHA) (((CPHA) == SMARTCARD_PHASE_1EDGE) || ((CPHA) == SMARTCARD_PHASE_2EDGE))
644 #define IS_SMARTCARD_LASTBIT(LASTBIT) (((LASTBIT) == SMARTCARD_LASTBIT_DISABLE) || \
645 ((LASTBIT) == SMARTCARD_LASTBIT_ENABLE))
646 #define IS_SMARTCARD_NACK_STATE(NACK) (((NACK) == SMARTCARD_NACK_ENABLE) || \
647 ((NACK) == SMARTCARD_NACK_DISABLE))
648 #define IS_SMARTCARD_BAUDRATE(BAUDRATE) ((BAUDRATE) < 4500001U)
650 #define SMARTCARD_DIV(_PCLK_, _BAUD_) (((_PCLK_)*25U)/(4U*(_BAUD_)))
651 #define SMARTCARD_DIVMANT(_PCLK_, _BAUD_) (SMARTCARD_DIV((_PCLK_), (_BAUD_))/100U)
652 #define SMARTCARD_DIVFRAQ(_PCLK_, _BAUD_) (((SMARTCARD_DIV((_PCLK_), (_BAUD_)) - (SMARTCARD_DIVMANT((_PCLK_), (_BAUD_)) * 100U)) * 16U + 50U) / 100U)
653 /* SMARTCARD BRR = mantissa + overflow + fraction
654 = (SMARTCARD DIVMANT << 4) + (SMARTCARD DIVFRAQ & 0xF0) + (SMARTCARD DIVFRAQ & 0x0FU) */
655 #define SMARTCARD_BRR(_PCLK_, _BAUD_) (((SMARTCARD_DIVMANT((_PCLK_), (_BAUD_)) << 4U) + \
656 (SMARTCARD_DIVFRAQ((_PCLK_), (_BAUD_)) & 0xF0U)) + \
657 (SMARTCARD_DIVFRAQ((_PCLK_), (_BAUD_)) & 0x0FU))
659 * @}
662 /* Private functions ---------------------------------------------------------*/
663 /** @defgroup SMARTCARD_Private_Functions SMARTCARD Private Functions
664 * @{
668 * @}
672 * @}
676 * @}
679 #ifdef __cplusplus
681 #endif
683 #endif /* __STM32F1xx_HAL_SMARTCARD_H */
685 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/