stm32h7xx_hal_smartcard.h 54 KB

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