You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

1018 lines
49 KiB

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