stm32l4xx_hal_smartcard.h 57 KB

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