stm32f0xx_hal_smartcard.h 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057
  1. /**
  2. ******************************************************************************
  3. * @file stm32f0xx_hal_smartcard.h
  4. * @author MCD Application Team
  5. * @brief Header file of SMARTCARD HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2016 STMicroelectronics.
  10. * All rights reserved.
  11. *
  12. * This software is licensed under terms that can be found in the LICENSE file
  13. * in the root directory of this software component.
  14. * If no LICENSE file comes with this software, it is provided AS-IS.
  15. *
  16. ******************************************************************************
  17. */
  18. /* Define to prevent recursive inclusion -------------------------------------*/
  19. #ifndef STM32F0xx_HAL_SMARTCARD_H
  20. #define STM32F0xx_HAL_SMARTCARD_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. #if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) \
  25. && !defined(STM32F070xB) && !defined(STM32F030xC)
  26. /* Includes ------------------------------------------------------------------*/
  27. #include "stm32f0xx_hal_def.h"
  28. /** @addtogroup STM32F0xx_HAL_Driver
  29. * @{
  30. */
  31. /** @addtogroup SMARTCARD
  32. * @{
  33. */
  34. /* Exported types ------------------------------------------------------------*/
  35. /** @defgroup SMARTCARD_Exported_Types SMARTCARD Exported Types
  36. * @{
  37. */
  38. /**
  39. * @brief SMARTCARD Init Structure definition
  40. */
  41. typedef struct
  42. {
  43. uint32_t BaudRate; /*!< Configures the SmartCard communication baud rate.
  44. The baud rate register is computed using the following formula:
  45. Baud Rate Register = ((usart_ker_ckpres) / ((hsmartcard->Init.BaudRate)))
  46. where usart_ker_ckpres is the USART input clock divided by a prescaler */
  47. uint32_t WordLength; /*!< Specifies the number of data bits transmitted or received in a frame.
  48. This parameter @ref SMARTCARD_Word_Length can only be
  49. set to 9 (8 data + 1 parity bits). */
  50. uint32_t StopBits; /*!< Specifies the number of stop bits.
  51. This parameter can be a value of @ref SMARTCARD_Stop_Bits. */
  52. uint16_t Parity; /*!< Specifies the parity mode.
  53. This parameter can be a value of @ref SMARTCARD_Parity
  54. @note The parity is enabled by default (PCE is forced to 1).
  55. Since the WordLength is forced to 8 bits + parity, M is
  56. forced to 1 and the parity bit is the 9th bit. */
  57. uint16_t Mode; /*!< Specifies whether the Receive or Transmit mode is enabled or disabled.
  58. This parameter can be a value of @ref SMARTCARD_Mode */
  59. uint16_t CLKPolarity; /*!< Specifies the steady state of the serial clock.
  60. This parameter can be a value of @ref SMARTCARD_Clock_Polarity */
  61. uint16_t CLKPhase; /*!< Specifies the clock transition on which the bit capture is made.
  62. This parameter can be a value of @ref SMARTCARD_Clock_Phase */
  63. uint16_t CLKLastBit; /*!< Specifies whether the clock pulse corresponding to the last transmitted
  64. data bit (MSB) has to be output on the SCLK pin in synchronous mode.
  65. This parameter can be a value of @ref SMARTCARD_Last_Bit */
  66. uint16_t OneBitSampling; /*!< Specifies whether a single sample or three samples' majority vote
  67. is selected. Selecting the single sample method increases
  68. the receiver tolerance to clock deviations. This parameter can be a value
  69. of @ref SMARTCARD_OneBit_Sampling. */
  70. uint8_t Prescaler; /*!< Specifies the SmartCard Prescaler.
  71. This parameter can be any value from 0x01 to 0x1F. Prescaler value is
  72. multiplied by 2 to give the division factor of the source clock frequency */
  73. uint8_t GuardTime; /*!< Specifies the SmartCard Guard Time applied after stop bits. */
  74. uint16_t NACKEnable; /*!< Specifies whether the SmartCard NACK transmission is enabled
  75. in case of parity error.
  76. This parameter can be a value of @ref SMARTCARD_NACK_Enable */
  77. uint32_t TimeOutEnable; /*!< Specifies whether the receiver timeout is enabled.
  78. This parameter can be a value of @ref SMARTCARD_Timeout_Enable*/
  79. uint32_t TimeOutValue; /*!< Specifies the receiver time out value in number of baud blocks:
  80. it is used to implement the Character Wait Time (CWT) and
  81. Block Wait Time (BWT). It is coded over 24 bits. */
  82. uint8_t BlockLength; /*!< Specifies the SmartCard Block Length in T=1 Reception mode.
  83. This parameter can be any value from 0x0 to 0xFF */
  84. uint8_t AutoRetryCount; /*!< Specifies the SmartCard auto-retry count (number of retries in
  85. receive and transmit mode). When set to 0, retransmission is
  86. disabled. Otherwise, its maximum value is 7 (before signalling
  87. an error) */
  88. } SMARTCARD_InitTypeDef;
  89. /**
  90. * @brief SMARTCARD advanced features initialization structure definition
  91. */
  92. typedef struct
  93. {
  94. uint32_t AdvFeatureInit; /*!< Specifies which advanced SMARTCARD features is initialized. Several
  95. advanced features may be initialized at the same time. This parameter
  96. can be a value of @ref SMARTCARDEx_Advanced_Features_Initialization_Type */
  97. uint32_t TxPinLevelInvert; /*!< Specifies whether the TX pin active level is inverted.
  98. This parameter can be a value of @ref SMARTCARD_Tx_Inv */
  99. uint32_t RxPinLevelInvert; /*!< Specifies whether the RX pin active level is inverted.
  100. This parameter can be a value of @ref SMARTCARD_Rx_Inv */
  101. uint32_t DataInvert; /*!< Specifies whether data are inverted (positive/direct logic
  102. vs negative/inverted logic).
  103. This parameter can be a value of @ref SMARTCARD_Data_Inv */
  104. uint32_t Swap; /*!< Specifies whether TX and RX pins are swapped.
  105. This parameter can be a value of @ref SMARTCARD_Rx_Tx_Swap */
  106. uint32_t OverrunDisable; /*!< Specifies whether the reception overrun detection is disabled.
  107. This parameter can be a value of @ref SMARTCARD_Overrun_Disable */
  108. uint32_t DMADisableonRxError; /*!< Specifies whether the DMA is disabled in case of reception error.
  109. This parameter can be a value of @ref SMARTCARD_DMA_Disable_on_Rx_Error */
  110. uint32_t MSBFirst; /*!< Specifies whether MSB is sent first on UART line.
  111. This parameter can be a value of @ref SMARTCARD_MSB_First */
  112. uint16_t TxCompletionIndication; /*!< Specifies which transmission completion indication is used: before (when
  113. relevant flag is available) or once guard time period has elapsed.
  114. This parameter can be a value
  115. of @ref SMARTCARDEx_Transmission_Completion_Indication. */
  116. } SMARTCARD_AdvFeatureInitTypeDef;
  117. /**
  118. * @brief HAL SMARTCARD State definition
  119. * @note HAL SMARTCARD State value is a combination of 2 different substates:
  120. * gState and RxState (see @ref SMARTCARD_State_Definition).
  121. * - gState contains SMARTCARD state information related to global Handle management
  122. * and also information related to Tx operations.
  123. * gState value coding follow below described bitmap :
  124. * b7-b6 Error information
  125. * 00 : No Error
  126. * 01 : (Not Used)
  127. * 10 : Timeout
  128. * 11 : Error
  129. * b5 Peripheral initialization status
  130. * 0 : Reset (Peripheral not initialized)
  131. * 1 : Init done (Peripheral initialized. HAL SMARTCARD Init function already called)
  132. * b4-b3 (not used)
  133. * xx : Should be set to 00
  134. * b2 Intrinsic process state
  135. * 0 : Ready
  136. * 1 : Busy (Peripheral busy with some configuration or internal operations)
  137. * b1 (not used)
  138. * x : Should be set to 0
  139. * b0 Tx state
  140. * 0 : Ready (no Tx operation ongoing)
  141. * 1 : Busy (Tx operation ongoing)
  142. * - RxState contains information related to Rx operations.
  143. * RxState value coding follow below described bitmap :
  144. * b7-b6 (not used)
  145. * xx : Should be set to 00
  146. * b5 Peripheral initialization status
  147. * 0 : Reset (Peripheral not initialized)
  148. * 1 : Init done (Peripheral initialized)
  149. * b4-b2 (not used)
  150. * xxx : Should be set to 000
  151. * b1 Rx state
  152. * 0 : Ready (no Rx operation ongoing)
  153. * 1 : Busy (Rx operation ongoing)
  154. * b0 (not used)
  155. * x : Should be set to 0.
  156. */
  157. typedef uint32_t HAL_SMARTCARD_StateTypeDef;
  158. /**
  159. * @brief SMARTCARD handle Structure definition
  160. */
  161. typedef struct __SMARTCARD_HandleTypeDef
  162. {
  163. USART_TypeDef *Instance; /*!< USART registers base address */
  164. SMARTCARD_InitTypeDef Init; /*!< SmartCard communication parameters */
  165. SMARTCARD_AdvFeatureInitTypeDef AdvancedInit; /*!< SmartCard advanced features initialization parameters */
  166. const uint8_t *pTxBuffPtr; /*!< Pointer to SmartCard Tx transfer Buffer */
  167. uint16_t TxXferSize; /*!< SmartCard Tx Transfer size */
  168. __IO uint16_t TxXferCount; /*!< SmartCard Tx Transfer Counter */
  169. uint8_t *pRxBuffPtr; /*!< Pointer to SmartCard Rx transfer Buffer */
  170. uint16_t RxXferSize; /*!< SmartCard Rx Transfer size */
  171. __IO uint16_t RxXferCount; /*!< SmartCard Rx Transfer Counter */
  172. void (*RxISR)(struct __SMARTCARD_HandleTypeDef *huart); /*!< Function pointer on Rx IRQ handler */
  173. void (*TxISR)(struct __SMARTCARD_HandleTypeDef *huart); /*!< Function pointer on Tx IRQ handler */
  174. DMA_HandleTypeDef *hdmatx; /*!< SmartCard Tx DMA Handle parameters */
  175. DMA_HandleTypeDef *hdmarx; /*!< SmartCard Rx DMA Handle parameters */
  176. HAL_LockTypeDef Lock; /*!< Locking object */
  177. __IO HAL_SMARTCARD_StateTypeDef gState; /*!< SmartCard state information related to global
  178. Handle management and also related to Tx operations.
  179. This parameter can be a value
  180. of @ref HAL_SMARTCARD_StateTypeDef */
  181. __IO HAL_SMARTCARD_StateTypeDef RxState; /*!< SmartCard state information related to Rx operations.
  182. This parameter can be a value
  183. of @ref HAL_SMARTCARD_StateTypeDef */
  184. __IO uint32_t ErrorCode; /*!< SmartCard Error code */
  185. #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
  186. void (* TxCpltCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard); /*!< SMARTCARD Tx Complete Callback */
  187. void (* RxCpltCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard); /*!< SMARTCARD Rx Complete Callback */
  188. void (* ErrorCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard); /*!< SMARTCARD Error Callback */
  189. void (* AbortCpltCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard); /*!< SMARTCARD Abort Complete Callback */
  190. void (* AbortTransmitCpltCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard); /*!< SMARTCARD Abort Transmit Complete Callback */
  191. void (* AbortReceiveCpltCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard); /*!< SMARTCARD Abort Receive Complete Callback */
  192. void (* MspInitCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard); /*!< SMARTCARD Msp Init callback */
  193. void (* MspDeInitCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard); /*!< SMARTCARD Msp DeInit callback */
  194. #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACKS */
  195. } SMARTCARD_HandleTypeDef;
  196. #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
  197. /**
  198. * @brief HAL SMARTCARD Callback ID enumeration definition
  199. */
  200. typedef enum
  201. {
  202. HAL_SMARTCARD_TX_COMPLETE_CB_ID = 0x00U, /*!< SMARTCARD Tx Complete Callback ID */
  203. HAL_SMARTCARD_RX_COMPLETE_CB_ID = 0x01U, /*!< SMARTCARD Rx Complete Callback ID */
  204. HAL_SMARTCARD_ERROR_CB_ID = 0x02U, /*!< SMARTCARD Error Callback ID */
  205. HAL_SMARTCARD_ABORT_COMPLETE_CB_ID = 0x03U, /*!< SMARTCARD Abort Complete Callback ID */
  206. HAL_SMARTCARD_ABORT_TRANSMIT_COMPLETE_CB_ID = 0x04U, /*!< SMARTCARD Abort Transmit Complete Callback ID */
  207. HAL_SMARTCARD_ABORT_RECEIVE_COMPLETE_CB_ID = 0x05U, /*!< SMARTCARD Abort Receive Complete Callback ID */
  208. HAL_SMARTCARD_MSPINIT_CB_ID = 0x08U, /*!< SMARTCARD MspInit callback ID */
  209. HAL_SMARTCARD_MSPDEINIT_CB_ID = 0x09U /*!< SMARTCARD MspDeInit callback ID */
  210. } HAL_SMARTCARD_CallbackIDTypeDef;
  211. /**
  212. * @brief HAL SMARTCARD Callback pointer definition
  213. */
  214. typedef void (*pSMARTCARD_CallbackTypeDef)(SMARTCARD_HandleTypeDef *hsmartcard); /*!< pointer to an SMARTCARD callback function */
  215. #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACKS */
  216. /**
  217. * @brief SMARTCARD clock sources
  218. */
  219. typedef enum
  220. {
  221. SMARTCARD_CLOCKSOURCE_PCLK1 = 0x00U, /*!< PCLK1 clock source */
  222. SMARTCARD_CLOCKSOURCE_HSI = 0x02U, /*!< HSI clock source */
  223. SMARTCARD_CLOCKSOURCE_SYSCLK = 0x04U, /*!< SYSCLK clock source */
  224. SMARTCARD_CLOCKSOURCE_LSE = 0x08U, /*!< LSE clock source */
  225. SMARTCARD_CLOCKSOURCE_UNDEFINED = 0x10U /*!< undefined clock source */
  226. } SMARTCARD_ClockSourceTypeDef;
  227. /**
  228. * @}
  229. */
  230. /* Exported constants --------------------------------------------------------*/
  231. /** @defgroup SMARTCARD_Exported_Constants SMARTCARD Exported Constants
  232. * @{
  233. */
  234. /** @defgroup SMARTCARD_State_Definition SMARTCARD State Code Definition
  235. * @{
  236. */
  237. #define HAL_SMARTCARD_STATE_RESET 0x00000000U /*!< Peripheral is not initialized. Value
  238. is allowed for gState and RxState */
  239. #define HAL_SMARTCARD_STATE_READY 0x00000020U /*!< Peripheral Initialized and ready for
  240. use. Value is allowed for gState
  241. and RxState */
  242. #define HAL_SMARTCARD_STATE_BUSY 0x00000024U /*!< an internal process is ongoing
  243. Value is allowed for gState only */
  244. #define HAL_SMARTCARD_STATE_BUSY_TX 0x00000021U /*!< Data Transmission process is ongoing
  245. Value is allowed for gState only */
  246. #define HAL_SMARTCARD_STATE_BUSY_RX 0x00000022U /*!< Data Reception process is ongoing
  247. Value is allowed for RxState only */
  248. #define HAL_SMARTCARD_STATE_BUSY_TX_RX 0x00000023U /*!< Data Transmission and Reception
  249. process is ongoing Not to be used for
  250. neither gState nor RxState.
  251. Value is result of combination (Or)
  252. between gState and RxState values */
  253. #define HAL_SMARTCARD_STATE_TIMEOUT 0x000000A0U /*!< Timeout state
  254. Value is allowed for gState only */
  255. #define HAL_SMARTCARD_STATE_ERROR 0x000000E0U /*!< Error
  256. Value is allowed for gState only */
  257. /**
  258. * @}
  259. */
  260. /** @defgroup SMARTCARD_Error_Definition SMARTCARD Error Code Definition
  261. * @{
  262. */
  263. #define HAL_SMARTCARD_ERROR_NONE (0x00000000U) /*!< No error */
  264. #define HAL_SMARTCARD_ERROR_PE (0x00000001U) /*!< Parity error */
  265. #define HAL_SMARTCARD_ERROR_NE (0x00000002U) /*!< Noise error */
  266. #define HAL_SMARTCARD_ERROR_FE (0x00000004U) /*!< frame error */
  267. #define HAL_SMARTCARD_ERROR_ORE (0x00000008U) /*!< Overrun error */
  268. #define HAL_SMARTCARD_ERROR_DMA (0x00000010U) /*!< DMA transfer error */
  269. #define HAL_SMARTCARD_ERROR_RTO (0x00000020U) /*!< Receiver TimeOut error */
  270. #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
  271. #define HAL_SMARTCARD_ERROR_INVALID_CALLBACK (0x00000040U) /*!< Invalid Callback error */
  272. #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACKS */
  273. /**
  274. * @}
  275. */
  276. /** @defgroup SMARTCARD_Word_Length SMARTCARD Word Length
  277. * @{
  278. */
  279. #if defined(USART_CR1_M0)
  280. #define SMARTCARD_WORDLENGTH_9B USART_CR1_M0 /*!< SMARTCARD frame length */
  281. #else
  282. #define SMARTCARD_WORDLENGTH_9B USART_CR1_M /*!< SMARTCARD frame length */
  283. #endif /* USART_CR1_M0 */
  284. /**
  285. * @}
  286. */
  287. /** @defgroup SMARTCARD_Stop_Bits SMARTCARD Number of Stop Bits
  288. * @{
  289. */
  290. #define SMARTCARD_STOPBITS_0_5 USART_CR2_STOP_0 /*!< SMARTCARD frame with 0.5 stop bit */
  291. #define SMARTCARD_STOPBITS_1_5 USART_CR2_STOP /*!< SMARTCARD frame with 1.5 stop bits */
  292. /**
  293. * @}
  294. */
  295. /** @defgroup SMARTCARD_Parity SMARTCARD Parity
  296. * @{
  297. */
  298. #define SMARTCARD_PARITY_EVEN USART_CR1_PCE /*!< SMARTCARD frame even parity */
  299. #define SMARTCARD_PARITY_ODD (USART_CR1_PCE | USART_CR1_PS) /*!< SMARTCARD frame odd parity */
  300. /**
  301. * @}
  302. */
  303. /** @defgroup SMARTCARD_Mode SMARTCARD Transfer Mode
  304. * @{
  305. */
  306. #define SMARTCARD_MODE_RX USART_CR1_RE /*!< SMARTCARD RX mode */
  307. #define SMARTCARD_MODE_TX USART_CR1_TE /*!< SMARTCARD TX mode */
  308. #define SMARTCARD_MODE_TX_RX (USART_CR1_TE |USART_CR1_RE) /*!< SMARTCARD RX and TX mode */
  309. /**
  310. * @}
  311. */
  312. /** @defgroup SMARTCARD_Clock_Polarity SMARTCARD Clock Polarity
  313. * @{
  314. */
  315. #define SMARTCARD_POLARITY_LOW 0x00000000U /*!< SMARTCARD frame low polarity */
  316. #define SMARTCARD_POLARITY_HIGH USART_CR2_CPOL /*!< SMARTCARD frame high polarity */
  317. /**
  318. * @}
  319. */
  320. /** @defgroup SMARTCARD_Clock_Phase SMARTCARD Clock Phase
  321. * @{
  322. */
  323. #define SMARTCARD_PHASE_1EDGE 0x00000000U /*!< SMARTCARD frame phase on first clock transition */
  324. #define SMARTCARD_PHASE_2EDGE USART_CR2_CPHA /*!< SMARTCARD frame phase on second clock transition */
  325. /**
  326. * @}
  327. */
  328. /** @defgroup SMARTCARD_Last_Bit SMARTCARD Last Bit
  329. * @{
  330. */
  331. #define SMARTCARD_LASTBIT_DISABLE 0x00000000U /*!< SMARTCARD frame last data bit clock pulse not output to SCLK pin */
  332. #define SMARTCARD_LASTBIT_ENABLE USART_CR2_LBCL /*!< SMARTCARD frame last data bit clock pulse output to SCLK pin */
  333. /**
  334. * @}
  335. */
  336. /** @defgroup SMARTCARD_OneBit_Sampling SMARTCARD One Bit Sampling Method
  337. * @{
  338. */
  339. #define SMARTCARD_ONE_BIT_SAMPLE_DISABLE 0x00000000U /*!< SMARTCARD frame one-bit sample disabled */
  340. #define SMARTCARD_ONE_BIT_SAMPLE_ENABLE USART_CR3_ONEBIT /*!< SMARTCARD frame one-bit sample enabled */
  341. /**
  342. * @}
  343. */
  344. /** @defgroup SMARTCARD_NACK_Enable SMARTCARD NACK Enable
  345. * @{
  346. */
  347. #define SMARTCARD_NACK_DISABLE 0x00000000U /*!< SMARTCARD NACK transmission disabled */
  348. #define SMARTCARD_NACK_ENABLE USART_CR3_NACK /*!< SMARTCARD NACK transmission enabled */
  349. /**
  350. * @}
  351. */
  352. /** @defgroup SMARTCARD_Timeout_Enable SMARTCARD Timeout Enable
  353. * @{
  354. */
  355. #define SMARTCARD_TIMEOUT_DISABLE 0x00000000U /*!< SMARTCARD receiver timeout disabled */
  356. #define SMARTCARD_TIMEOUT_ENABLE USART_CR2_RTOEN /*!< SMARTCARD receiver timeout enabled */
  357. /**
  358. * @}
  359. */
  360. /** @defgroup SMARTCARD_Tx_Inv SMARTCARD advanced feature TX pin active level inversion
  361. * @{
  362. */
  363. #define SMARTCARD_ADVFEATURE_TXINV_DISABLE 0x00000000U /*!< TX pin active level inversion disable */
  364. #define SMARTCARD_ADVFEATURE_TXINV_ENABLE USART_CR2_TXINV /*!< TX pin active level inversion enable */
  365. /**
  366. * @}
  367. */
  368. /** @defgroup SMARTCARD_Rx_Inv SMARTCARD advanced feature RX pin active level inversion
  369. * @{
  370. */
  371. #define SMARTCARD_ADVFEATURE_RXINV_DISABLE 0x00000000U /*!< RX pin active level inversion disable */
  372. #define SMARTCARD_ADVFEATURE_RXINV_ENABLE USART_CR2_RXINV /*!< RX pin active level inversion enable */
  373. /**
  374. * @}
  375. */
  376. /** @defgroup SMARTCARD_Data_Inv SMARTCARD advanced feature Binary Data inversion
  377. * @{
  378. */
  379. #define SMARTCARD_ADVFEATURE_DATAINV_DISABLE 0x00000000U /*!< Binary data inversion disable */
  380. #define SMARTCARD_ADVFEATURE_DATAINV_ENABLE USART_CR2_DATAINV /*!< Binary data inversion enable */
  381. /**
  382. * @}
  383. */
  384. /** @defgroup SMARTCARD_Rx_Tx_Swap SMARTCARD advanced feature RX TX pins swap
  385. * @{
  386. */
  387. #define SMARTCARD_ADVFEATURE_SWAP_DISABLE 0x00000000U /*!< TX/RX pins swap disable */
  388. #define SMARTCARD_ADVFEATURE_SWAP_ENABLE USART_CR2_SWAP /*!< TX/RX pins swap enable */
  389. /**
  390. * @}
  391. */
  392. /** @defgroup SMARTCARD_Overrun_Disable SMARTCARD advanced feature Overrun Disable
  393. * @{
  394. */
  395. #define SMARTCARD_ADVFEATURE_OVERRUN_ENABLE 0x00000000U /*!< RX overrun enable */
  396. #define SMARTCARD_ADVFEATURE_OVERRUN_DISABLE USART_CR3_OVRDIS /*!< RX overrun disable */
  397. /**
  398. * @}
  399. */
  400. /** @defgroup SMARTCARD_DMA_Disable_on_Rx_Error SMARTCARD advanced feature DMA Disable on Rx Error
  401. * @{
  402. */
  403. #define SMARTCARD_ADVFEATURE_DMA_ENABLEONRXERROR 0x00000000U /*!< DMA enable on Reception Error */
  404. #define SMARTCARD_ADVFEATURE_DMA_DISABLEONRXERROR USART_CR3_DDRE /*!< DMA disable on Reception Error */
  405. /**
  406. * @}
  407. */
  408. /** @defgroup SMARTCARD_MSB_First SMARTCARD advanced feature MSB first
  409. * @{
  410. */
  411. #define SMARTCARD_ADVFEATURE_MSBFIRST_DISABLE 0x00000000U /*!< Most significant bit sent/received first disable */
  412. #define SMARTCARD_ADVFEATURE_MSBFIRST_ENABLE USART_CR2_MSBFIRST /*!< Most significant bit sent/received first enable */
  413. /**
  414. * @}
  415. */
  416. /** @defgroup SMARTCARD_Request_Parameters SMARTCARD Request Parameters
  417. * @{
  418. */
  419. #define SMARTCARD_RXDATA_FLUSH_REQUEST USART_RQR_RXFRQ /*!< Receive data flush request */
  420. #define SMARTCARD_TXDATA_FLUSH_REQUEST USART_RQR_TXFRQ /*!< Transmit data flush request */
  421. /**
  422. * @}
  423. */
  424. /** @defgroup SMARTCARD_Interruption_Mask SMARTCARD interruptions flags mask
  425. * @{
  426. */
  427. #define SMARTCARD_IT_MASK 0x001FU /*!< SMARTCARD interruptions flags mask */
  428. #define SMARTCARD_CR_MASK 0x00E0U /*!< SMARTCARD control register mask */
  429. #define SMARTCARD_CR_POS 5U /*!< SMARTCARD control register position */
  430. #define SMARTCARD_ISR_MASK 0x1F00U /*!< SMARTCARD ISR register mask */
  431. #define SMARTCARD_ISR_POS 8U /*!< SMARTCARD ISR register position */
  432. /**
  433. * @}
  434. */
  435. /**
  436. * @}
  437. */
  438. /* Exported macros -----------------------------------------------------------*/
  439. /** @defgroup SMARTCARD_Exported_Macros SMARTCARD Exported Macros
  440. * @{
  441. */
  442. /** @brief Reset SMARTCARD handle states.
  443. * @param __HANDLE__ SMARTCARD handle.
  444. * @retval None
  445. */
  446. #if USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1
  447. #define __HAL_SMARTCARD_RESET_HANDLE_STATE(__HANDLE__) do{ \
  448. (__HANDLE__)->gState = HAL_SMARTCARD_STATE_RESET; \
  449. (__HANDLE__)->RxState = HAL_SMARTCARD_STATE_RESET; \
  450. (__HANDLE__)->MspInitCallback = NULL; \
  451. (__HANDLE__)->MspDeInitCallback = NULL; \
  452. } while(0U)
  453. #else
  454. #define __HAL_SMARTCARD_RESET_HANDLE_STATE(__HANDLE__) do{ \
  455. (__HANDLE__)->gState = HAL_SMARTCARD_STATE_RESET; \
  456. (__HANDLE__)->RxState = HAL_SMARTCARD_STATE_RESET; \
  457. } while(0U)
  458. #endif /*USE_HAL_SMARTCARD_REGISTER_CALLBACKS */
  459. /** @brief Flush the Smartcard Data registers.
  460. * @param __HANDLE__ specifies the SMARTCARD Handle.
  461. * @retval None
  462. */
  463. #define __HAL_SMARTCARD_FLUSH_DRREGISTER(__HANDLE__) \
  464. do{ \
  465. SET_BIT((__HANDLE__)->Instance->RQR, SMARTCARD_RXDATA_FLUSH_REQUEST); \
  466. SET_BIT((__HANDLE__)->Instance->RQR, SMARTCARD_TXDATA_FLUSH_REQUEST); \
  467. } while(0U)
  468. /** @brief Clear the specified SMARTCARD pending flag.
  469. * @param __HANDLE__ specifies the SMARTCARD Handle.
  470. * @param __FLAG__ specifies the flag to check.
  471. * This parameter can be any combination of the following values:
  472. * @arg @ref SMARTCARD_CLEAR_PEF Parity error clear flag
  473. * @arg @ref SMARTCARD_CLEAR_FEF Framing error clear flag
  474. * @arg @ref SMARTCARD_CLEAR_NEF Noise detected clear flag
  475. * @arg @ref SMARTCARD_CLEAR_OREF OverRun error clear flag
  476. * @arg @ref SMARTCARD_CLEAR_IDLEF Idle line detected clear flag
  477. * @arg @ref SMARTCARD_CLEAR_TCF Transmission complete clear flag
  478. * @arg @ref SMARTCARD_CLEAR_TCBGTF Transmission complete before guard time clear flag
  479. * @arg @ref SMARTCARD_CLEAR_RTOF Receiver timeout clear flag
  480. * @arg @ref SMARTCARD_CLEAR_EOBF End of block clear flag
  481. * @retval None
  482. */
  483. #define __HAL_SMARTCARD_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ICR = (__FLAG__))
  484. /** @brief Clear the SMARTCARD PE pending flag.
  485. * @param __HANDLE__ specifies the SMARTCARD Handle.
  486. * @retval None
  487. */
  488. #define __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_FLAG((__HANDLE__), SMARTCARD_CLEAR_PEF)
  489. /** @brief Clear the SMARTCARD FE pending flag.
  490. * @param __HANDLE__ specifies the SMARTCARD Handle.
  491. * @retval None
  492. */
  493. #define __HAL_SMARTCARD_CLEAR_FEFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_FLAG((__HANDLE__), SMARTCARD_CLEAR_FEF)
  494. /** @brief Clear the SMARTCARD NE pending flag.
  495. * @param __HANDLE__ specifies the SMARTCARD Handle.
  496. * @retval None
  497. */
  498. #define __HAL_SMARTCARD_CLEAR_NEFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_FLAG((__HANDLE__), SMARTCARD_CLEAR_NEF)
  499. /** @brief Clear the SMARTCARD ORE pending flag.
  500. * @param __HANDLE__ specifies the SMARTCARD Handle.
  501. * @retval None
  502. */
  503. #define __HAL_SMARTCARD_CLEAR_OREFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_FLAG((__HANDLE__), SMARTCARD_CLEAR_OREF)
  504. /** @brief Clear the SMARTCARD IDLE pending flag.
  505. * @param __HANDLE__ specifies the SMARTCARD Handle.
  506. * @retval None
  507. */
  508. #define __HAL_SMARTCARD_CLEAR_IDLEFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_FLAG((__HANDLE__), SMARTCARD_CLEAR_IDLEF)
  509. /** @brief Check whether the specified Smartcard flag is set or not.
  510. * @param __HANDLE__ specifies the SMARTCARD Handle.
  511. * @param __FLAG__ specifies the flag to check.
  512. * This parameter can be one of the following values:
  513. * @arg @ref SMARTCARD_FLAG_TCBGT Transmission complete before guard time flag (when flag available)
  514. * @arg @ref SMARTCARD_FLAG_REACK Receive enable acknowledge flag
  515. * @arg @ref SMARTCARD_FLAG_TEACK Transmit enable acknowledge flag
  516. * @arg @ref SMARTCARD_FLAG_BUSY Busy flag
  517. * @arg @ref SMARTCARD_FLAG_EOBF End of block flag
  518. * @arg @ref SMARTCARD_FLAG_RTOF Receiver timeout flag
  519. * @arg @ref SMARTCARD_FLAG_TXE Transmit data register empty flag
  520. * @arg @ref SMARTCARD_FLAG_TC Transmission complete flag
  521. * @arg @ref SMARTCARD_FLAG_RXNE Receive data register not empty flag
  522. * @arg @ref SMARTCARD_FLAG_IDLE Idle line detection flag
  523. * @arg @ref SMARTCARD_FLAG_ORE Overrun error flag
  524. * @arg @ref SMARTCARD_FLAG_NE Noise error flag
  525. * @arg @ref SMARTCARD_FLAG_FE Framing error flag
  526. * @arg @ref SMARTCARD_FLAG_PE Parity error flag
  527. * @retval The new state of __FLAG__ (TRUE or FALSE).
  528. */
  529. #define __HAL_SMARTCARD_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->ISR & (__FLAG__)) == (__FLAG__))
  530. /** @brief Enable the specified SmartCard interrupt.
  531. * @param __HANDLE__ specifies the SMARTCARD Handle.
  532. * @param __INTERRUPT__ specifies the SMARTCARD interrupt to enable.
  533. * This parameter can be one of the following values:
  534. * @arg @ref SMARTCARD_IT_EOB End of block interrupt
  535. * @arg @ref SMARTCARD_IT_RTO Receive timeout interrupt
  536. * @arg @ref SMARTCARD_IT_TXE Transmit data register empty interrupt
  537. * @arg @ref SMARTCARD_IT_TC Transmission complete interrupt
  538. * @arg @ref SMARTCARD_IT_TCBGT Transmission complete before
  539. * guard time interrupt (when interruption available)
  540. * @arg @ref SMARTCARD_IT_RXNE Receive data register not empty interrupt
  541. * @arg @ref SMARTCARD_IT_IDLE Idle line detection interrupt
  542. * @arg @ref SMARTCARD_IT_PE Parity error interrupt
  543. * @arg @ref SMARTCARD_IT_ERR Error interrupt(frame error, noise error, overrun error)
  544. * @retval None
  545. */
  546. #define __HAL_SMARTCARD_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((((__INTERRUPT__) & SMARTCARD_CR_MASK) >>\
  547. SMARTCARD_CR_POS) == 1U)?\
  548. ((__HANDLE__)->Instance->CR1 |= (1UL <<\
  549. ((__INTERRUPT__) & SMARTCARD_IT_MASK))):\
  550. ((((__INTERRUPT__) & SMARTCARD_CR_MASK) >>\
  551. SMARTCARD_CR_POS) == 2U)?\
  552. ((__HANDLE__)->Instance->CR2 |= (1UL <<\
  553. ((__INTERRUPT__) & SMARTCARD_IT_MASK))): \
  554. ((__HANDLE__)->Instance->CR3 |= (1UL <<\
  555. ((__INTERRUPT__) & SMARTCARD_IT_MASK))))
  556. /** @brief Disable the specified SmartCard interrupt.
  557. * @param __HANDLE__ specifies the SMARTCARD Handle.
  558. * @param __INTERRUPT__ specifies the SMARTCARD interrupt to disable.
  559. * This parameter can be one of the following values:
  560. * @arg @ref SMARTCARD_IT_EOB End of block interrupt
  561. * @arg @ref SMARTCARD_IT_RTO Receive timeout interrupt
  562. * @arg @ref SMARTCARD_IT_TXE Transmit data register empty interrupt
  563. * @arg @ref SMARTCARD_IT_TC Transmission complete interrupt
  564. * @arg @ref SMARTCARD_IT_TCBGT Transmission complete before guard
  565. * time interrupt (when interruption available)
  566. * @arg @ref SMARTCARD_IT_RXNE Receive data register not empty interrupt
  567. * @arg @ref SMARTCARD_IT_IDLE Idle line detection interrupt
  568. * @arg @ref SMARTCARD_IT_PE Parity error interrupt
  569. * @arg @ref SMARTCARD_IT_ERR Error interrupt(frame error, noise error, overrun error)
  570. * @retval None
  571. */
  572. #define __HAL_SMARTCARD_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((((__INTERRUPT__) & SMARTCARD_CR_MASK) >>\
  573. SMARTCARD_CR_POS) == 1U)?\
  574. ((__HANDLE__)->Instance->CR1 &= ~ (1U <<\
  575. ((__INTERRUPT__) & SMARTCARD_IT_MASK))): \
  576. ((((__INTERRUPT__) & SMARTCARD_CR_MASK) >>\
  577. SMARTCARD_CR_POS) == 2U)?\
  578. ((__HANDLE__)->Instance->CR2 &= ~ (1U <<\
  579. ((__INTERRUPT__) & SMARTCARD_IT_MASK))): \
  580. ((__HANDLE__)->Instance->CR3 &= ~ (1U <<\
  581. ((__INTERRUPT__) & SMARTCARD_IT_MASK))))
  582. /** @brief Check whether the specified SmartCard interrupt has occurred or not.
  583. * @param __HANDLE__ specifies the SMARTCARD Handle.
  584. * @param __INTERRUPT__ specifies the SMARTCARD interrupt to check.
  585. * This parameter can be one of the following values:
  586. * @arg @ref SMARTCARD_IT_EOB End of block interrupt
  587. * @arg @ref SMARTCARD_IT_RTO Receive timeout interrupt
  588. * @arg @ref SMARTCARD_IT_TXE Transmit data register empty interrupt
  589. * @arg @ref SMARTCARD_IT_TC Transmission complete interrupt
  590. * @arg @ref SMARTCARD_IT_TCBGT Transmission complete before guard time
  591. * interrupt (when interruption available)
  592. * @arg @ref SMARTCARD_IT_RXNE Receive data register not empty interrupt
  593. * @arg @ref SMARTCARD_IT_IDLE Idle line detection interrupt
  594. * @arg @ref SMARTCARD_IT_PE Parity error interrupt
  595. * @arg @ref SMARTCARD_IT_ERR Error interrupt(frame error, noise error, overrun error)
  596. * @retval The new state of __INTERRUPT__ (SET or RESET).
  597. */
  598. #define __HAL_SMARTCARD_GET_IT(__HANDLE__, __INTERRUPT__) (\
  599. (((__HANDLE__)->Instance->ISR & (0x01UL << (((__INTERRUPT__)\
  600. & SMARTCARD_ISR_MASK)>> SMARTCARD_ISR_POS)))!= 0U)\
  601. ? SET : RESET)
  602. /** @brief Check whether the specified SmartCard interrupt source is enabled or not.
  603. * @param __HANDLE__ specifies the SMARTCARD Handle.
  604. * @param __INTERRUPT__ specifies the SMARTCARD interrupt source to check.
  605. * This parameter can be one of the following values:
  606. * @arg @ref SMARTCARD_IT_EOB End of block interrupt
  607. * @arg @ref SMARTCARD_IT_RTO Receive timeout interrupt
  608. * @arg @ref SMARTCARD_IT_TXE Transmit data register empty interrupt
  609. * @arg @ref SMARTCARD_IT_TC Transmission complete interrupt
  610. * @arg @ref SMARTCARD_IT_TCBGT Transmission complete before guard time
  611. * interrupt (when interruption available)
  612. * @arg @ref SMARTCARD_IT_RXNE Receive data register not empty interrupt
  613. * @arg @ref SMARTCARD_IT_IDLE Idle line detection interrupt
  614. * @arg @ref SMARTCARD_IT_PE Parity error interrupt
  615. * @arg @ref SMARTCARD_IT_ERR Error interrupt(frame error, noise error, overrun error)
  616. * @retval The new state of __INTERRUPT__ (SET or RESET).
  617. */
  618. #define __HAL_SMARTCARD_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((((((__INTERRUPT__) & SMARTCARD_CR_MASK) >>\
  619. SMARTCARD_CR_POS) == 0x01U)?\
  620. (__HANDLE__)->Instance->CR1 : \
  621. (((((__INTERRUPT__) & SMARTCARD_CR_MASK) >>\
  622. SMARTCARD_CR_POS) == 0x02U)?\
  623. (__HANDLE__)->Instance->CR2 : \
  624. (__HANDLE__)->Instance->CR3)) &\
  625. (0x01UL << (((uint16_t)(__INTERRUPT__))\
  626. & SMARTCARD_IT_MASK))) != 0U)\
  627. ? SET : RESET)
  628. /** @brief Clear the specified SMARTCARD ISR flag, in setting the proper ICR register flag.
  629. * @param __HANDLE__ specifies the SMARTCARD Handle.
  630. * @param __IT_CLEAR__ specifies the interrupt clear register flag that needs to be set
  631. * to clear the corresponding interrupt.
  632. * This parameter can be one of the following values:
  633. * @arg @ref SMARTCARD_CLEAR_PEF Parity error clear flag
  634. * @arg @ref SMARTCARD_CLEAR_FEF Framing error clear flag
  635. * @arg @ref SMARTCARD_CLEAR_NEF Noise detected clear flag
  636. * @arg @ref SMARTCARD_CLEAR_OREF OverRun error clear flag
  637. * @arg @ref SMARTCARD_CLEAR_IDLEF Idle line detection clear flag
  638. * @arg @ref SMARTCARD_CLEAR_TCF Transmission complete clear flag
  639. * @arg @ref SMARTCARD_CLEAR_TCBGTF Transmission complete before guard time clear flag (when flag available)
  640. * @arg @ref SMARTCARD_CLEAR_RTOF Receiver timeout clear flag
  641. * @arg @ref SMARTCARD_CLEAR_EOBF End of block clear flag
  642. * @retval None
  643. */
  644. #define __HAL_SMARTCARD_CLEAR_IT(__HANDLE__, __IT_CLEAR__) ((__HANDLE__)->Instance->ICR |= (uint32_t)(__IT_CLEAR__))
  645. /** @brief Set a specific SMARTCARD request flag.
  646. * @param __HANDLE__ specifies the SMARTCARD Handle.
  647. * @param __REQ__ specifies the request flag to set
  648. * This parameter can be one of the following values:
  649. * @arg @ref SMARTCARD_RXDATA_FLUSH_REQUEST Receive data flush Request
  650. * @arg @ref SMARTCARD_TXDATA_FLUSH_REQUEST Transmit data flush Request
  651. * @retval None
  652. */
  653. #define __HAL_SMARTCARD_SEND_REQ(__HANDLE__, __REQ__) ((__HANDLE__)->Instance->RQR |= (uint16_t)(__REQ__))
  654. /** @brief Enable the SMARTCARD one bit sample method.
  655. * @param __HANDLE__ specifies the SMARTCARD Handle.
  656. * @retval None
  657. */
  658. #define __HAL_SMARTCARD_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT)
  659. /** @brief Disable the SMARTCARD one bit sample method.
  660. * @param __HANDLE__ specifies the SMARTCARD Handle.
  661. * @retval None
  662. */
  663. #define __HAL_SMARTCARD_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3\
  664. &= (uint32_t)~((uint32_t)USART_CR3_ONEBIT))
  665. /** @brief Enable the USART associated to the SMARTCARD Handle.
  666. * @param __HANDLE__ specifies the SMARTCARD Handle.
  667. * @retval None
  668. */
  669. #define __HAL_SMARTCARD_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= USART_CR1_UE)
  670. /** @brief Disable the USART associated to the SMARTCARD Handle
  671. * @param __HANDLE__ specifies the SMARTCARD Handle.
  672. * @retval None
  673. */
  674. #define __HAL_SMARTCARD_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~USART_CR1_UE)
  675. /**
  676. * @}
  677. */
  678. /* Private macros -------------------------------------------------------------*/
  679. /** @defgroup SMARTCARD_Private_Macros SMARTCARD Private Macros
  680. * @{
  681. */
  682. /** @brief Check the Baud rate range.
  683. * @note The maximum Baud Rate is derived from the maximum clock on F0 (48 MHz)
  684. * divided by the oversampling used on the SMARTCARD (i.e. 16).
  685. * @param __BAUDRATE__ Baud rate set by the configuration function.
  686. * @retval Test result (TRUE or FALSE)
  687. */
  688. #define IS_SMARTCARD_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) < 6000000U)
  689. /** @brief Check the block length range.
  690. * @note The maximum SMARTCARD block length is 0xFF.
  691. * @param __LENGTH__ block length.
  692. * @retval Test result (TRUE or FALSE)
  693. */
  694. #define IS_SMARTCARD_BLOCKLENGTH(__LENGTH__) ((__LENGTH__) <= 0xFFU)
  695. /** @brief Check the receiver timeout value.
  696. * @note The maximum SMARTCARD receiver timeout value is 0xFFFFFF.
  697. * @param __TIMEOUTVALUE__ receiver timeout value.
  698. * @retval Test result (TRUE or FALSE)
  699. */
  700. #define IS_SMARTCARD_TIMEOUT_VALUE(__TIMEOUTVALUE__) ((__TIMEOUTVALUE__) <= 0xFFFFFFU)
  701. /** @brief Check the SMARTCARD autoretry counter value.
  702. * @note The maximum number of retransmissions is 0x7.
  703. * @param __COUNT__ number of retransmissions.
  704. * @retval Test result (TRUE or FALSE)
  705. */
  706. #define IS_SMARTCARD_AUTORETRY_COUNT(__COUNT__) ((__COUNT__) <= 0x7U)
  707. /** @brief Ensure that SMARTCARD frame length is valid.
  708. * @param __LENGTH__ SMARTCARD frame length.
  709. * @retval SET (__LENGTH__ is valid) or RESET (__LENGTH__ is invalid)
  710. */
  711. #define IS_SMARTCARD_WORD_LENGTH(__LENGTH__) ((__LENGTH__) == SMARTCARD_WORDLENGTH_9B)
  712. /** @brief Ensure that SMARTCARD frame number of stop bits is valid.
  713. * @param __STOPBITS__ SMARTCARD frame number of stop bits.
  714. * @retval SET (__STOPBITS__ is valid) or RESET (__STOPBITS__ is invalid)
  715. */
  716. #define IS_SMARTCARD_STOPBITS(__STOPBITS__) (((__STOPBITS__) == SMARTCARD_STOPBITS_0_5) ||\
  717. ((__STOPBITS__) == SMARTCARD_STOPBITS_1_5))
  718. /** @brief Ensure that SMARTCARD frame parity is valid.
  719. * @param __PARITY__ SMARTCARD frame parity.
  720. * @retval SET (__PARITY__ is valid) or RESET (__PARITY__ is invalid)
  721. */
  722. #define IS_SMARTCARD_PARITY(__PARITY__) (((__PARITY__) == SMARTCARD_PARITY_EVEN) || \
  723. ((__PARITY__) == SMARTCARD_PARITY_ODD))
  724. /** @brief Ensure that SMARTCARD communication mode is valid.
  725. * @param __MODE__ SMARTCARD communication mode.
  726. * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
  727. */
  728. #define IS_SMARTCARD_MODE(__MODE__) ((((__MODE__) & 0xFFF3U) == 0x00U) && ((__MODE__) != 0x00U))
  729. /** @brief Ensure that SMARTCARD frame polarity is valid.
  730. * @param __CPOL__ SMARTCARD frame polarity.
  731. * @retval SET (__CPOL__ is valid) or RESET (__CPOL__ is invalid)
  732. */
  733. #define IS_SMARTCARD_POLARITY(__CPOL__) (((__CPOL__) == SMARTCARD_POLARITY_LOW)\
  734. || ((__CPOL__) == SMARTCARD_POLARITY_HIGH))
  735. /** @brief Ensure that SMARTCARD frame phase is valid.
  736. * @param __CPHA__ SMARTCARD frame phase.
  737. * @retval SET (__CPHA__ is valid) or RESET (__CPHA__ is invalid)
  738. */
  739. #define IS_SMARTCARD_PHASE(__CPHA__) (((__CPHA__) == SMARTCARD_PHASE_1EDGE) || ((__CPHA__) == SMARTCARD_PHASE_2EDGE))
  740. /** @brief Ensure that SMARTCARD frame last bit clock pulse setting is valid.
  741. * @param __LASTBIT__ SMARTCARD frame last bit clock pulse setting.
  742. * @retval SET (__LASTBIT__ is valid) or RESET (__LASTBIT__ is invalid)
  743. */
  744. #define IS_SMARTCARD_LASTBIT(__LASTBIT__) (((__LASTBIT__) == SMARTCARD_LASTBIT_DISABLE) || \
  745. ((__LASTBIT__) == SMARTCARD_LASTBIT_ENABLE))
  746. /** @brief Ensure that SMARTCARD frame sampling is valid.
  747. * @param __ONEBIT__ SMARTCARD frame sampling.
  748. * @retval SET (__ONEBIT__ is valid) or RESET (__ONEBIT__ is invalid)
  749. */
  750. #define IS_SMARTCARD_ONE_BIT_SAMPLE(__ONEBIT__) (((__ONEBIT__) == SMARTCARD_ONE_BIT_SAMPLE_DISABLE) || \
  751. ((__ONEBIT__) == SMARTCARD_ONE_BIT_SAMPLE_ENABLE))
  752. /** @brief Ensure that SMARTCARD NACK transmission setting is valid.
  753. * @param __NACK__ SMARTCARD NACK transmission setting.
  754. * @retval SET (__NACK__ is valid) or RESET (__NACK__ is invalid)
  755. */
  756. #define IS_SMARTCARD_NACK(__NACK__) (((__NACK__) == SMARTCARD_NACK_ENABLE) || \
  757. ((__NACK__) == SMARTCARD_NACK_DISABLE))
  758. /** @brief Ensure that SMARTCARD receiver timeout setting is valid.
  759. * @param __TIMEOUT__ SMARTCARD receiver timeout setting.
  760. * @retval SET (__TIMEOUT__ is valid) or RESET (__TIMEOUT__ is invalid)
  761. */
  762. #define IS_SMARTCARD_TIMEOUT(__TIMEOUT__) (((__TIMEOUT__) == SMARTCARD_TIMEOUT_DISABLE) || \
  763. ((__TIMEOUT__) == SMARTCARD_TIMEOUT_ENABLE))
  764. /** @brief Ensure that SMARTCARD advanced features initialization is valid.
  765. * @param __INIT__ SMARTCARD advanced features initialization.
  766. * @retval SET (__INIT__ is valid) or RESET (__INIT__ is invalid)
  767. */
  768. #define IS_SMARTCARD_ADVFEATURE_INIT(__INIT__) ((__INIT__) <= (SMARTCARD_ADVFEATURE_NO_INIT | \
  769. SMARTCARD_ADVFEATURE_TXINVERT_INIT | \
  770. SMARTCARD_ADVFEATURE_RXINVERT_INIT | \
  771. SMARTCARD_ADVFEATURE_DATAINVERT_INIT | \
  772. SMARTCARD_ADVFEATURE_SWAP_INIT | \
  773. SMARTCARD_ADVFEATURE_RXOVERRUNDISABLE_INIT | \
  774. SMARTCARD_ADVFEATURE_DMADISABLEONERROR_INIT | \
  775. SMARTCARD_ADVFEATURE_MSBFIRST_INIT))
  776. /** @brief Ensure that SMARTCARD frame TX inversion setting is valid.
  777. * @param __TXINV__ SMARTCARD frame TX inversion setting.
  778. * @retval SET (__TXINV__ is valid) or RESET (__TXINV__ is invalid)
  779. */
  780. #define IS_SMARTCARD_ADVFEATURE_TXINV(__TXINV__) (((__TXINV__) == SMARTCARD_ADVFEATURE_TXINV_DISABLE) || \
  781. ((__TXINV__) == SMARTCARD_ADVFEATURE_TXINV_ENABLE))
  782. /** @brief Ensure that SMARTCARD frame RX inversion setting is valid.
  783. * @param __RXINV__ SMARTCARD frame RX inversion setting.
  784. * @retval SET (__RXINV__ is valid) or RESET (__RXINV__ is invalid)
  785. */
  786. #define IS_SMARTCARD_ADVFEATURE_RXINV(__RXINV__) (((__RXINV__) == SMARTCARD_ADVFEATURE_RXINV_DISABLE) || \
  787. ((__RXINV__) == SMARTCARD_ADVFEATURE_RXINV_ENABLE))
  788. /** @brief Ensure that SMARTCARD frame data inversion setting is valid.
  789. * @param __DATAINV__ SMARTCARD frame data inversion setting.
  790. * @retval SET (__DATAINV__ is valid) or RESET (__DATAINV__ is invalid)
  791. */
  792. #define IS_SMARTCARD_ADVFEATURE_DATAINV(__DATAINV__) (((__DATAINV__) == SMARTCARD_ADVFEATURE_DATAINV_DISABLE) || \
  793. ((__DATAINV__) == SMARTCARD_ADVFEATURE_DATAINV_ENABLE))
  794. /** @brief Ensure that SMARTCARD frame RX/TX pins swap setting is valid.
  795. * @param __SWAP__ SMARTCARD frame RX/TX pins swap setting.
  796. * @retval SET (__SWAP__ is valid) or RESET (__SWAP__ is invalid)
  797. */
  798. #define IS_SMARTCARD_ADVFEATURE_SWAP(__SWAP__) (((__SWAP__) == SMARTCARD_ADVFEATURE_SWAP_DISABLE) || \
  799. ((__SWAP__) == SMARTCARD_ADVFEATURE_SWAP_ENABLE))
  800. /** @brief Ensure that SMARTCARD frame overrun setting is valid.
  801. * @param __OVERRUN__ SMARTCARD frame overrun setting.
  802. * @retval SET (__OVERRUN__ is valid) or RESET (__OVERRUN__ is invalid)
  803. */
  804. #define IS_SMARTCARD_OVERRUN(__OVERRUN__) (((__OVERRUN__) == SMARTCARD_ADVFEATURE_OVERRUN_ENABLE) || \
  805. ((__OVERRUN__) == SMARTCARD_ADVFEATURE_OVERRUN_DISABLE))
  806. /** @brief Ensure that SMARTCARD DMA enabling or disabling on error setting is valid.
  807. * @param __DMA__ SMARTCARD DMA enabling or disabling on error setting.
  808. * @retval SET (__DMA__ is valid) or RESET (__DMA__ is invalid)
  809. */
  810. #define IS_SMARTCARD_ADVFEATURE_DMAONRXERROR(__DMA__) (((__DMA__) == SMARTCARD_ADVFEATURE_DMA_ENABLEONRXERROR) || \
  811. ((__DMA__) == SMARTCARD_ADVFEATURE_DMA_DISABLEONRXERROR))
  812. /** @brief Ensure that SMARTCARD frame MSB first setting is valid.
  813. * @param __MSBFIRST__ SMARTCARD frame MSB first setting.
  814. * @retval SET (__MSBFIRST__ is valid) or RESET (__MSBFIRST__ is invalid)
  815. */
  816. #define IS_SMARTCARD_ADVFEATURE_MSBFIRST(__MSBFIRST__) (((__MSBFIRST__) == SMARTCARD_ADVFEATURE_MSBFIRST_DISABLE) || \
  817. ((__MSBFIRST__) == SMARTCARD_ADVFEATURE_MSBFIRST_ENABLE))
  818. /** @brief Ensure that SMARTCARD request parameter is valid.
  819. * @param __PARAM__ SMARTCARD request parameter.
  820. * @retval SET (__PARAM__ is valid) or RESET (__PARAM__ is invalid)
  821. */
  822. #define IS_SMARTCARD_REQUEST_PARAMETER(__PARAM__) (((__PARAM__) == SMARTCARD_RXDATA_FLUSH_REQUEST) || \
  823. ((__PARAM__) == SMARTCARD_TXDATA_FLUSH_REQUEST))
  824. /**
  825. * @}
  826. */
  827. /* Include SMARTCARD HAL Extended module */
  828. #include "stm32f0xx_hal_smartcard_ex.h"
  829. /* Exported functions --------------------------------------------------------*/
  830. /** @addtogroup SMARTCARD_Exported_Functions
  831. * @{
  832. */
  833. /* Initialization and de-initialization functions ****************************/
  834. /** @addtogroup SMARTCARD_Exported_Functions_Group1
  835. * @{
  836. */
  837. HAL_StatusTypeDef HAL_SMARTCARD_Init(SMARTCARD_HandleTypeDef *hsmartcard);
  838. HAL_StatusTypeDef HAL_SMARTCARD_DeInit(SMARTCARD_HandleTypeDef *hsmartcard);
  839. void HAL_SMARTCARD_MspInit(SMARTCARD_HandleTypeDef *hsmartcard);
  840. void HAL_SMARTCARD_MspDeInit(SMARTCARD_HandleTypeDef *hsmartcard);
  841. #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
  842. /* Callbacks Register/UnRegister functions ***********************************/
  843. HAL_StatusTypeDef HAL_SMARTCARD_RegisterCallback(SMARTCARD_HandleTypeDef *hsmartcard,
  844. HAL_SMARTCARD_CallbackIDTypeDef CallbackID,
  845. pSMARTCARD_CallbackTypeDef pCallback);
  846. HAL_StatusTypeDef HAL_SMARTCARD_UnRegisterCallback(SMARTCARD_HandleTypeDef *hsmartcard,
  847. HAL_SMARTCARD_CallbackIDTypeDef CallbackID);
  848. #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACKS */
  849. /**
  850. * @}
  851. */
  852. /* IO operation functions *****************************************************/
  853. /** @addtogroup SMARTCARD_Exported_Functions_Group2
  854. * @{
  855. */
  856. HAL_StatusTypeDef HAL_SMARTCARD_Transmit(SMARTCARD_HandleTypeDef *hsmartcard, const uint8_t *pData, uint16_t Size,
  857. uint32_t Timeout);
  858. HAL_StatusTypeDef HAL_SMARTCARD_Receive(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size,
  859. uint32_t Timeout);
  860. HAL_StatusTypeDef HAL_SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsmartcard, const uint8_t *pData, uint16_t Size);
  861. HAL_StatusTypeDef HAL_SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size);
  862. HAL_StatusTypeDef HAL_SMARTCARD_Transmit_DMA(SMARTCARD_HandleTypeDef *hsmartcard, const uint8_t *pData, uint16_t Size);
  863. HAL_StatusTypeDef HAL_SMARTCARD_Receive_DMA(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size);
  864. /* Transfer Abort functions */
  865. HAL_StatusTypeDef HAL_SMARTCARD_Abort(SMARTCARD_HandleTypeDef *hsmartcard);
  866. HAL_StatusTypeDef HAL_SMARTCARD_AbortTransmit(SMARTCARD_HandleTypeDef *hsmartcard);
  867. HAL_StatusTypeDef HAL_SMARTCARD_AbortReceive(SMARTCARD_HandleTypeDef *hsmartcard);
  868. HAL_StatusTypeDef HAL_SMARTCARD_Abort_IT(SMARTCARD_HandleTypeDef *hsmartcard);
  869. HAL_StatusTypeDef HAL_SMARTCARD_AbortTransmit_IT(SMARTCARD_HandleTypeDef *hsmartcard);
  870. HAL_StatusTypeDef HAL_SMARTCARD_AbortReceive_IT(SMARTCARD_HandleTypeDef *hsmartcard);
  871. void HAL_SMARTCARD_IRQHandler(SMARTCARD_HandleTypeDef *hsmartcard);
  872. void HAL_SMARTCARD_TxCpltCallback(SMARTCARD_HandleTypeDef *hsmartcard);
  873. void HAL_SMARTCARD_RxCpltCallback(SMARTCARD_HandleTypeDef *hsmartcard);
  874. void HAL_SMARTCARD_ErrorCallback(SMARTCARD_HandleTypeDef *hsmartcard);
  875. void HAL_SMARTCARD_AbortCpltCallback(SMARTCARD_HandleTypeDef *hsmartcard);
  876. void HAL_SMARTCARD_AbortTransmitCpltCallback(SMARTCARD_HandleTypeDef *hsmartcard);
  877. void HAL_SMARTCARD_AbortReceiveCpltCallback(SMARTCARD_HandleTypeDef *hsmartcard);
  878. /**
  879. * @}
  880. */
  881. /* Peripheral State and Error functions ***************************************/
  882. /** @addtogroup SMARTCARD_Exported_Functions_Group4
  883. * @{
  884. */
  885. HAL_SMARTCARD_StateTypeDef HAL_SMARTCARD_GetState(const SMARTCARD_HandleTypeDef *hsmartcard);
  886. uint32_t HAL_SMARTCARD_GetError(const SMARTCARD_HandleTypeDef *hsmartcard);
  887. /**
  888. * @}
  889. */
  890. /**
  891. * @}
  892. */
  893. /**
  894. * @}
  895. */
  896. /**
  897. * @}
  898. */
  899. #endif /* !STM32F030x6 && !STM32F030x8 && !STM32F070x6 && !STM32F070xB && !STM32F030xC */
  900. #ifdef __cplusplus
  901. }
  902. #endif
  903. #endif /* STM32F0xx_HAL_SMARTCARD_H */