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.
 
 
 

950 lines
45 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f7xx_hal_smartcard.h
  4. * @author MCD Application Team
  5. * @version V1.1.2
  6. * @date 23-September-2016
  7. * @brief Header file of SMARTCARD HAL module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2016 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 __STM32F7xx_HAL_SMARTCARD_H
  39. #define __STM32F7xx_HAL_SMARTCARD_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32f7xx_hal_def.h"
  45. /** @addtogroup STM32F7xx_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. uint32_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. uint32_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. uint32_t CLKPolarity; /*!< Specifies the steady state of the serial clock.
  75. This parameter can be a value of @ref SMARTCARD_Clock_Polarity */
  76. uint32_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. uint32_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. uint32_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. uint32_t Prescaler; /*!< Specifies the SmartCard Prescaler */
  85. uint32_t GuardTime; /*!< Specifies the SmartCard Guard Time */
  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_State */
  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. uint32_t BlockLength; /*!< Specifies the SmartCard Block Length in T=1 Reception mode.
  95. This parameter can be any value from 0x0 to 0xFF */
  96. uint32_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 SMARTCARD clock sources definition
  189. */
  190. typedef enum
  191. {
  192. SMARTCARD_CLOCKSOURCE_PCLK1 = 0x00U, /*!< PCLK1 clock source */
  193. SMARTCARD_CLOCKSOURCE_PCLK2 = 0x01U, /*!< PCLK2 clock source */
  194. SMARTCARD_CLOCKSOURCE_HSI = 0x02U, /*!< HSI clock source */
  195. SMARTCARD_CLOCKSOURCE_SYSCLK = 0x04U, /*!< SYSCLK clock source */
  196. SMARTCARD_CLOCKSOURCE_LSE = 0x08U, /*!< LSE clock source */
  197. SMARTCARD_CLOCKSOURCE_UNDEFINED = 0x10 /*!< undefined clock source */
  198. }SMARTCARD_ClockSourceTypeDef;
  199. /**
  200. * @brief SMARTCARD handle Structure definition
  201. */
  202. typedef struct
  203. {
  204. USART_TypeDef *Instance; /*!< USART registers base address */
  205. SMARTCARD_InitTypeDef Init; /*!< SmartCard communication parameters */
  206. SMARTCARD_AdvFeatureInitTypeDef AdvancedInit; /*!< SmartCard advanced features initialization parameters */
  207. uint8_t *pTxBuffPtr; /*!< Pointer to SmartCard Tx transfer Buffer */
  208. uint16_t TxXferSize; /*!< SmartCard Tx Transfer size */
  209. __IO uint16_t TxXferCount; /*!< SmartCard Tx Transfer Counter */
  210. uint8_t *pRxBuffPtr; /*!< Pointer to SmartCard Rx transfer Buffer */
  211. uint16_t RxXferSize; /*!< SmartCard Rx Transfer size */
  212. __IO uint16_t RxXferCount; /*!< SmartCard Rx Transfer Counter */
  213. DMA_HandleTypeDef *hdmatx; /*!< SmartCard Tx DMA Handle parameters */
  214. DMA_HandleTypeDef *hdmarx; /*!< SmartCard Rx DMA Handle parameters */
  215. HAL_LockTypeDef Lock; /*!< Locking object */
  216. __IO HAL_SMARTCARD_StateTypeDef gState; /*!< SmartCard state information related to global Handle management
  217. and also related to Tx operations.
  218. This parameter can be a value of @ref HAL_SMARTCARD_StateTypeDef */
  219. __IO HAL_SMARTCARD_StateTypeDef RxState; /*!< SmartCard state information related to Rx operations.
  220. This parameter can be a value of @ref HAL_SMARTCARD_StateTypeDef */
  221. __IO uint32_t ErrorCode; /* SmartCard Error code */
  222. }SMARTCARD_HandleTypeDef;
  223. /**
  224. * @}
  225. */
  226. /* Exported constants --------------------------------------------------------*/
  227. /** @defgroup SMARTCARD_Exported_Constants SMARTCARD Exported constants
  228. * @{
  229. */
  230. /** @defgroup SMARTCARD_Error_Code SMARTCARD Error Code
  231. * @brief SMARTCARD Error Code
  232. * @{
  233. */
  234. #define HAL_SMARTCARD_ERROR_NONE ((uint32_t)0x00U) /*!< No error */
  235. #define HAL_SMARTCARD_ERROR_PE ((uint32_t)0x01U) /*!< Parity error */
  236. #define HAL_SMARTCARD_ERROR_NE ((uint32_t)0x02U) /*!< Noise error */
  237. #define HAL_SMARTCARD_ERROR_FE ((uint32_t)0x04U) /*!< frame error */
  238. #define HAL_SMARTCARD_ERROR_ORE ((uint32_t)0x08U) /*!< Overrun error */
  239. #define HAL_SMARTCARD_ERROR_DMA ((uint32_t)0x10U) /*!< DMA transfer error */
  240. #define HAL_SMARTCARD_ERROR_RTO ((uint32_t)0x20U) /*!< Receiver TimeOut error */
  241. /**
  242. * @}
  243. */
  244. /** @defgroup SMARTCARD_Word_Length SMARTCARD Word Length
  245. * @{
  246. */
  247. #define SMARTCARD_WORDLENGTH_9B ((uint32_t)USART_CR1_M_0)
  248. /**
  249. * @}
  250. */
  251. /** @defgroup SMARTCARD_Stop_Bits SMARTCARD Number of Stop Bits
  252. * @{
  253. */
  254. #define SMARTCARD_STOPBITS_1_5 ((uint32_t)(USART_CR2_STOP))
  255. /**
  256. * @}
  257. */
  258. /** @defgroup SMARTCARD_Parity SMARTCARD Parity
  259. * @{
  260. */
  261. #define SMARTCARD_PARITY_EVEN ((uint32_t)USART_CR1_PCE)
  262. #define SMARTCARD_PARITY_ODD ((uint32_t)(USART_CR1_PCE | USART_CR1_PS))
  263. /**
  264. * @}
  265. */
  266. /** @defgroup SMARTCARD_Mode SMARTCARD Mode
  267. * @{
  268. */
  269. #define SMARTCARD_MODE_RX ((uint32_t)USART_CR1_RE)
  270. #define SMARTCARD_MODE_TX ((uint32_t)USART_CR1_TE)
  271. #define SMARTCARD_MODE_TX_RX ((uint32_t)(USART_CR1_TE |USART_CR1_RE))
  272. /**
  273. * @}
  274. */
  275. /** @defgroup SMARTCARD_Clock_Polarity SMARTCARD Clock Polarity
  276. * @{
  277. */
  278. #define SMARTCARD_POLARITY_LOW ((uint32_t)0x0000U)
  279. #define SMARTCARD_POLARITY_HIGH ((uint32_t)USART_CR2_CPOL)
  280. /**
  281. * @}
  282. */
  283. /** @defgroup SMARTCARD_Clock_Phase SMARTCARD Clock Phase
  284. * @{
  285. */
  286. #define SMARTCARD_PHASE_1EDGE ((uint32_t)0x0000U)
  287. #define SMARTCARD_PHASE_2EDGE ((uint32_t)USART_CR2_CPHA)
  288. /**
  289. * @}
  290. */
  291. /** @defgroup SMARTCARD_Last_Bit SMARTCARD Last Bit
  292. * @{
  293. */
  294. #define SMARTCARD_LASTBIT_DISABLE ((uint32_t)0x0000U)
  295. #define SMARTCARD_LASTBIT_ENABLE ((uint32_t)USART_CR2_LBCL)
  296. /**
  297. * @}
  298. */
  299. /** @defgroup SMARTCARD_OneBit_Sampling SMARTCARD OneBit Sampling
  300. * @{
  301. */
  302. #define SMARTCARD_ONE_BIT_SAMPLE_DISABLE ((uint32_t)0x0000U)
  303. #define SMARTCARD_ONE_BIT_SAMPLE_ENABLE ((uint32_t)USART_CR3_ONEBIT)
  304. /**
  305. * @}
  306. */
  307. /** @defgroup SMARTCARD_NACK_State SMARTCARD NACK State
  308. * @{
  309. */
  310. #define SMARTCARD_NACK_ENABLE ((uint32_t)USART_CR3_NACK)
  311. #define SMARTCARD_NACK_DISABLE ((uint32_t)0x0000U)
  312. /**
  313. * @}
  314. */
  315. /** @defgroup SMARTCARD_Timeout_Enable SMARTCARD Timeout Enable
  316. * @{
  317. */
  318. #define SMARTCARD_TIMEOUT_DISABLE ((uint32_t)0x00000000U)
  319. #define SMARTCARD_TIMEOUT_ENABLE ((uint32_t)USART_CR2_RTOEN)
  320. /**
  321. * @}
  322. */
  323. /** @defgroup SMARTCARD_DMA_Requests SMARTCARD DMA requests
  324. * @{
  325. */
  326. #define SMARTCARD_DMAREQ_TX ((uint32_t)USART_CR3_DMAT)
  327. #define SMARTCARD_DMAREQ_RX ((uint32_t)USART_CR3_DMAR)
  328. /**
  329. * @}
  330. */
  331. /** @defgroup SMARTCARD_Advanced_Features_Initialization_Type SMARTCARD Advanced Features Initialization Type
  332. * @{
  333. */
  334. #define SMARTCARD_ADVFEATURE_NO_INIT ((uint32_t)0x00000000U)
  335. #define SMARTCARD_ADVFEATURE_TXINVERT_INIT ((uint32_t)0x00000001U)
  336. #define SMARTCARD_ADVFEATURE_RXINVERT_INIT ((uint32_t)0x00000002U)
  337. #define SMARTCARD_ADVFEATURE_DATAINVERT_INIT ((uint32_t)0x00000004U)
  338. #define SMARTCARD_ADVFEATURE_SWAP_INIT ((uint32_t)0x00000008U)
  339. #define SMARTCARD_ADVFEATURE_RXOVERRUNDISABLE_INIT ((uint32_t)0x00000010U)
  340. #define SMARTCARD_ADVFEATURE_DMADISABLEONERROR_INIT ((uint32_t)0x00000020U)
  341. #define SMARTCARD_ADVFEATURE_MSBFIRST_INIT ((uint32_t)0x00000080U)
  342. /**
  343. * @}
  344. */
  345. /** @defgroup SMARTCARD_Tx_Inv SMARTCARD Tx Inv
  346. * @{
  347. */
  348. #define SMARTCARD_ADVFEATURE_TXINV_DISABLE ((uint32_t)0x00000000U)
  349. #define SMARTCARD_ADVFEATURE_TXINV_ENABLE ((uint32_t)USART_CR2_TXINV)
  350. /**
  351. * @}
  352. */
  353. /** @defgroup SMARTCARD_Rx_Inv SMARTCARD Rx Inv
  354. * @{
  355. */
  356. #define SMARTCARD_ADVFEATURE_RXINV_DISABLE ((uint32_t)0x00000000U)
  357. #define SMARTCARD_ADVFEATURE_RXINV_ENABLE ((uint32_t)USART_CR2_RXINV)
  358. /**
  359. * @}
  360. */
  361. /** @defgroup SMARTCARD_Data_Inv SMARTCARD Data Inv
  362. * @{
  363. */
  364. #define SMARTCARD_ADVFEATURE_DATAINV_DISABLE ((uint32_t)0x00000000U)
  365. #define SMARTCARD_ADVFEATURE_DATAINV_ENABLE ((uint32_t)USART_CR2_DATAINV)
  366. /**
  367. * @}
  368. */
  369. /** @defgroup SMARTCARD_Rx_Tx_Swap SMARTCARD Rx Tx Swap
  370. * @{
  371. */
  372. #define SMARTCARD_ADVFEATURE_SWAP_DISABLE ((uint32_t)0x00000000U)
  373. #define SMARTCARD_ADVFEATURE_SWAP_ENABLE ((uint32_t)USART_CR2_SWAP)
  374. /**
  375. * @}
  376. */
  377. /** @defgroup SMARTCARD_Overrun_Disable SMARTCARD Overrun Disable
  378. * @{
  379. */
  380. #define SMARTCARD_ADVFEATURE_OVERRUN_ENABLE ((uint32_t)0x00000000U)
  381. #define SMARTCARD_ADVFEATURE_OVERRUN_DISABLE ((uint32_t)USART_CR3_OVRDIS)
  382. /**
  383. * @}
  384. */
  385. /** @defgroup SMARTCARD_DMA_Disable_on_Rx_Error SMARTCARD DMA Disable on Rx Error
  386. * @{
  387. */
  388. #define SMARTCARD_ADVFEATURE_DMA_ENABLEONRXERROR ((uint32_t)0x00000000U)
  389. #define SMARTCARD_ADVFEATURE_DMA_DISABLEONRXERROR ((uint32_t)USART_CR3_DDRE)
  390. /**
  391. * @}
  392. */
  393. /** @defgroup SMARTCARD_MSB_First SMARTCARD MSB First
  394. * @{
  395. */
  396. #define SMARTCARD_ADVFEATURE_MSBFIRST_DISABLE ((uint32_t)0x00000000U)
  397. #define SMARTCARD_ADVFEATURE_MSBFIRST_ENABLE ((uint32_t)USART_CR2_MSBFIRST)
  398. /**
  399. * @}
  400. */
  401. /** @defgroup SmartCard_Flags SMARTCARD Flags
  402. * Elements values convention: 0xXXXX
  403. * - 0xXXXX : Flag mask in the ISR register
  404. * @{
  405. */
  406. #define SMARTCARD_FLAG_REACK ((uint32_t)0x00400000U)
  407. #define SMARTCARD_FLAG_TEACK ((uint32_t)0x00200000U)
  408. #define SMARTCARD_FLAG_BUSY ((uint32_t)0x00010000U)
  409. #define SMARTCARD_FLAG_EOBF ((uint32_t)0x00001000U)
  410. #define SMARTCARD_FLAG_RTOF ((uint32_t)0x00000800U)
  411. #define SMARTCARD_FLAG_TXE ((uint32_t)0x00000080U)
  412. #define SMARTCARD_FLAG_TC ((uint32_t)0x00000040U)
  413. #define SMARTCARD_FLAG_RXNE ((uint32_t)0x00000020U)
  414. #define SMARTCARD_FLAG_IDLE ((uint32_t)0x00000010U)
  415. #define SMARTCARD_FLAG_ORE ((uint32_t)0x00000008U)
  416. #define SMARTCARD_FLAG_NE ((uint32_t)0x00000004U)
  417. #define SMARTCARD_FLAG_FE ((uint32_t)0x00000002U)
  418. #define SMARTCARD_FLAG_PE ((uint32_t)0x00000001U)
  419. /**
  420. * @}
  421. */
  422. /** @defgroup SMARTCARD_Interrupt_definition SMARTCARD Interrupt definition
  423. * Elements values convention: 0000ZZZZ0XXYYYYYb
  424. * - YYYYY : Interrupt source position in the XX register (5bits)
  425. * - XX : Interrupt source register (2bits)
  426. * - 01: CR1 register
  427. * - 10: CR2 register
  428. * - 11: CR3 register
  429. * - ZZZZ : Flag position in the ISR register(4bits)
  430. * @{
  431. */
  432. #define SMARTCARD_IT_PE ((uint16_t)0x0028U)
  433. #define SMARTCARD_IT_TXE ((uint16_t)0x0727U)
  434. #define SMARTCARD_IT_TC ((uint16_t)0x0626U)
  435. #define SMARTCARD_IT_RXNE ((uint16_t)0x0525U)
  436. #define SMARTCARD_IT_IDLE ((uint16_t)0x0424U)
  437. #define SMARTCARD_IT_ERR ((uint16_t)0x0060U)
  438. #define SMARTCARD_IT_ORE ((uint16_t)0x0300U)
  439. #define SMARTCARD_IT_NE ((uint16_t)0x0200U)
  440. #define SMARTCARD_IT_FE ((uint16_t)0x0100U)
  441. #define SMARTCARD_IT_EOB ((uint16_t)0x0C3BU)
  442. #define SMARTCARD_IT_RTO ((uint16_t)0x0B3AU)
  443. /**
  444. * @}
  445. */
  446. /** @defgroup SMARTCARD_IT_CLEAR_Flags SMARTCARD IT CLEAR Flags
  447. * @{
  448. */
  449. #define SMARTCARD_CLEAR_PEF USART_ICR_PECF /*!< Parity Error Clear Flag */
  450. #define SMARTCARD_CLEAR_FEF USART_ICR_FECF /*!< Framing Error Clear Flag */
  451. #define SMARTCARD_CLEAR_NEF USART_ICR_NCF /*!< Noise detected Clear Flag */
  452. #define SMARTCARD_CLEAR_OREF USART_ICR_ORECF /*!< OverRun Error Clear Flag */
  453. #define SMARTCARD_CLEAR_IDLEF USART_ICR_IDLECF /*!< Idle line detected clear Flag */
  454. #define SMARTCARD_CLEAR_TCF USART_ICR_TCCF /*!< Transmission Complete Clear Flag */
  455. #define SMARTCARD_CLEAR_RTOF USART_ICR_RTOCF /*!< Receiver Time Out Clear Flag */
  456. #define SMARTCARD_CLEAR_EOBF USART_ICR_EOBCF /*!< End Of Block Clear Flag */
  457. /**
  458. * @}
  459. */
  460. /** @defgroup SMARTCARD_Request_Parameters SMARTCARD Request Parameters
  461. * @{
  462. */
  463. #define SMARTCARD_RXDATA_FLUSH_REQUEST ((uint32_t)USART_RQR_RXFRQ) /*!< Receive Data flush Request */
  464. #define SMARTCARD_TXDATA_FLUSH_REQUEST ((uint32_t)USART_RQR_TXFRQ) /*!< Transmit data flush Request */
  465. /**
  466. * @}
  467. */
  468. /** @defgroup SMARTCARD_CR3_SCAR_CNT_LSB_POS SMARTCARD CR3 SCAR CNT LSB POS
  469. * @{
  470. */
  471. #define SMARTCARD_CR3_SCARCNT_LSB_POS ((uint32_t) 17U)
  472. /**
  473. * @}
  474. */
  475. /** @defgroup SMARTCARD_GTPR_GT_LSBPOS SMARTCARD GTPR GT LSBPOS
  476. * @{
  477. */
  478. #define SMARTCARD_GTPR_GT_LSB_POS ((uint32_t) 8U)
  479. /**
  480. * @}
  481. */
  482. /** @defgroup SMARTCARD_RTOR_BLEN_LSBPOS SMARTCARD RTOR BLEN LSBPOS
  483. * @{
  484. */
  485. #define SMARTCARD_RTOR_BLEN_LSB_POS ((uint32_t) 24U)
  486. /**
  487. * @}
  488. */
  489. /** @defgroup SMARTCARD_Interruption_Mask SMARTCARD Interruption Mask
  490. * @{
  491. */
  492. #define SMARTCARD_IT_MASK ((uint16_t)0x001FU)
  493. /**
  494. * @}
  495. */
  496. /**
  497. * @}
  498. */
  499. /* Exported macro ------------------------------------------------------------*/
  500. /** @defgroup SMARTCARD_Exported_Macros SMARTCARD Exported Macros
  501. * @{
  502. */
  503. /** @brief Reset SMARTCARD handle state
  504. * @param __HANDLE__: specifies the SMARTCARD Handle.
  505. * The Handle Instance which can be USART1 or USART2
  506. * @retval None
  507. */
  508. #define __HAL_SMARTCARD_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_SMARTCARD_STATE_RESET)
  509. /** @brief Flush the Smartcard DR register
  510. * @param __HANDLE__: specifies the SMARTCARD Handle.
  511. * The Handle Instance which can be USART1 or USART2.
  512. * @retval None
  513. */
  514. #define __HAL_SMARTCARD_FLUSH_DRREGISTER(__HANDLE__) (__HAL_SMARTCARD_SEND_REQ((__HANDLE__), SMARTCARD_RXDATA_FLUSH_REQUEST))
  515. /** @brief Checks whether the specified Smartcard flag is set or not.
  516. * @param __HANDLE__: specifies the SMARTCARD Handle.
  517. * The Handle Instance which can be USART1 or USART2.
  518. * @param __FLAG__: specifies the flag to check.
  519. * This parameter can be one of the following values:
  520. * @arg SMARTCARD_FLAG_REACK: Receive enable acknowledge flag
  521. * @arg SMARTCARD_FLAG_TEACK: Transmit enable acknowledge flag
  522. * @arg SMARTCARD_FLAG_BUSY: Busy flag
  523. * @arg SMARTCARD_FLAG_EOBF: End of block flag
  524. * @arg SMARTCARD_FLAG_RTOF: Receiver timeout flag
  525. * @arg SMARTCARD_FLAG_TXE: Transmit data register empty flag
  526. * @arg SMARTCARD_FLAG_TC: Transmission Complete flag
  527. * @arg SMARTCARD_FLAG_RXNE: Receive data register not empty flag
  528. * @arg SMARTCARD_FLAG_ORE: OverRun Error flag
  529. * @arg SMARTCARD_FLAG_NE: Noise Error flag
  530. * @arg SMARTCARD_FLAG_FE: Framing Error flag
  531. * @arg SMARTCARD_FLAG_PE: Parity Error flag
  532. * @retval The new state of __FLAG__ (TRUE or FALSE).
  533. */
  534. #define __HAL_SMARTCARD_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->ISR & (__FLAG__)) == (__FLAG__))
  535. /** @brief Clear the specified SMARTCARD pending flag.
  536. * @param __HANDLE__: specifies the SMARTCARD Handle.
  537. * @param __FLAG__: specifies the flag to check.
  538. * This parameter can be any combination of the following values:
  539. * @arg @ref SMARTCARD_CLEAR_PEF Parity error clear flag
  540. * @arg @ref SMARTCARD_CLEAR_FEF Framing error clear flag
  541. * @arg @ref SMARTCARD_CLEAR_NEF Noise detected clear flag
  542. * @arg @ref SMARTCARD_CLEAR_OREF OverRun error clear flag
  543. * @arg @ref SMARTCARD_CLEAR_IDLEF Idle line detected clear flag
  544. * @arg @ref SMARTCARD_CLEAR_TCF Transmission complete clear flag
  545. @if STM32L443xx
  546. * @arg @ref SMARTCARD_CLEAR_TCBGTF Transmission complete before guard time clear flag (when flag available)
  547. @endif
  548. * @arg @ref SMARTCARD_CLEAR_RTOF Receiver timeout clear flag
  549. * @arg @ref SMARTCARD_CLEAR_EOBF End of block clear flag
  550. * @retval None
  551. */
  552. #define __HAL_SMARTCARD_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ICR = (__FLAG__))
  553. /** @brief Clear the SMARTCARD PE pending flag.
  554. * @param __HANDLE__: specifies the SMARTCARD Handle.
  555. * @retval None
  556. */
  557. #define __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_FLAG((__HANDLE__), SMARTCARD_CLEAR_PEF)
  558. /** @brief Clear the SMARTCARD FE pending flag.
  559. * @param __HANDLE__: specifies the SMARTCARD Handle.
  560. * @retval None
  561. */
  562. #define __HAL_SMARTCARD_CLEAR_FEFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_FLAG((__HANDLE__), SMARTCARD_CLEAR_FEF)
  563. /** @brief Clear the SMARTCARD NE pending flag.
  564. * @param __HANDLE__: specifies the SMARTCARD Handle.
  565. * @retval None
  566. */
  567. #define __HAL_SMARTCARD_CLEAR_NEFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_FLAG((__HANDLE__), SMARTCARD_CLEAR_NEF)
  568. /** @brief Clear the SMARTCARD ORE pending flag.
  569. * @param __HANDLE__: specifies the SMARTCARD Handle.
  570. * @retval None
  571. */
  572. #define __HAL_SMARTCARD_CLEAR_OREFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_FLAG((__HANDLE__), SMARTCARD_CLEAR_OREF)
  573. /** @brief Clear the SMARTCARD IDLE pending flag.
  574. * @param __HANDLE__: specifies the SMARTCARD Handle.
  575. * @retval None
  576. */
  577. #define __HAL_SMARTCARD_CLEAR_IDLEFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_FLAG((__HANDLE__), SMARTCARD_CLEAR_IDLEF)
  578. /** @brief Enables the specified SmartCard interrupt.
  579. * @param __HANDLE__: specifies the SMARTCARD Handle.
  580. * The Handle Instance which can be USART1 or USART2.
  581. * @param __INTERRUPT__: specifies the SMARTCARD interrupt to enable.
  582. * This parameter can be one of the following values:
  583. * @arg SMARTCARD_IT_EOBF: End Of Block interrupt
  584. * @arg SMARTCARD_IT_RTOF: Receive TimeOut interrupt
  585. * @arg SMARTCARD_IT_TXE: Transmit Data Register empty interrupt
  586. * @arg SMARTCARD_IT_TC: Transmission complete interrupt
  587. * @arg SMARTCARD_IT_RXNE: Receive Data register not empty interrupt
  588. * @arg SMARTCARD_IT_PE: Parity Error interrupt
  589. * @arg SMARTCARD_IT_ERR: Error interrupt(Frame error, noise error, overrun error)
  590. * @retval None
  591. */
  592. #define __HAL_SMARTCARD_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((((uint8_t)(__INTERRUPT__)) >> 5) == 1)? ((__HANDLE__)->Instance->CR1 |= (1 << ((__INTERRUPT__) & SMARTCARD_IT_MASK))): \
  593. ((((uint8_t)(__INTERRUPT__)) >> 5) == 2)? ((__HANDLE__)->Instance->CR2 |= (1 << ((__INTERRUPT__) & SMARTCARD_IT_MASK))): \
  594. ((__HANDLE__)->Instance->CR3 |= (1 << ((__INTERRUPT__) & SMARTCARD_IT_MASK))))
  595. /** @brief Disables the specified SmartCard interrupt.
  596. * @param __HANDLE__: specifies the SMARTCARD Handle.
  597. * The Handle Instance which can be USART1 or USART2.
  598. * @param __INTERRUPT__: specifies the SMARTCARD interrupt to enable.
  599. * This parameter can be one of the following values:
  600. * @arg SMARTCARD_IT_EOBF: End Of Block interrupt
  601. * @arg SMARTCARD_IT_RTOF: Receive TimeOut interrupt
  602. * @arg SMARTCARD_IT_TXE: Transmit Data Register empty interrupt
  603. * @arg SMARTCARD_IT_TC: Transmission complete interrupt
  604. * @arg SMARTCARD_IT_RXNE: Receive Data register not empty interrupt
  605. * @arg SMARTCARD_IT_PE: Parity Error interrupt
  606. * @arg SMARTCARD_IT_ERR: Error interrupt(Frame error, noise error, overrun error)
  607. * @retval None
  608. */
  609. #define __HAL_SMARTCARD_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((((uint8_t)(__INTERRUPT__)) >> 5) == 1)? ((__HANDLE__)->Instance->CR1 &= ~ ((uint32_t)1 << ((__INTERRUPT__) & SMARTCARD_IT_MASK))): \
  610. ((((uint8_t)(__INTERRUPT__)) >> 5) == 2)? ((__HANDLE__)->Instance->CR2 &= ~ ((uint32_t)1 << ((__INTERRUPT__) & SMARTCARD_IT_MASK))): \
  611. ((__HANDLE__)->Instance->CR3 &= ~ ((uint32_t)1 << ((__INTERRUPT__) & SMARTCARD_IT_MASK))))
  612. /** @brief Checks whether the specified SmartCard interrupt has occurred or not.
  613. * @param __HANDLE__: specifies the SMARTCARD Handle.
  614. * The Handle Instance which can be USART1 or USART2.
  615. * @param __IT__: specifies the SMARTCARD interrupt to check.
  616. * This parameter can be one of the following values:
  617. * @arg SMARTCARD_IT_EOBF: End Of Block interrupt
  618. * @arg SMARTCARD_IT_RTOF: Receive TimeOut interrupt
  619. * @arg SMARTCARD_IT_TXE: Transmit Data Register empty interrupt
  620. * @arg SMARTCARD_IT_TC: Transmission complete interrupt
  621. * @arg SMARTCARD_IT_RXNE: Receive Data register not empty interrupt
  622. * @arg SMARTCARD_IT_ORE: OverRun Error interrupt
  623. * @arg SMARTCARD_IT_NE: Noise Error interrupt
  624. * @arg SMARTCARD_IT_FE: Framing Error interrupt
  625. * @arg SMARTCARD_IT_PE: Parity Error interrupt
  626. * @retval The new state of __IT__ (TRUE or FALSE).
  627. */
  628. #define __HAL_SMARTCARD_GET_IT(__HANDLE__, __IT__) ((__HANDLE__)->Instance->ISR & ((uint32_t)1 << ((__IT__)>> 0x08)))
  629. /** @brief Checks whether the specified SmartCard interrupt interrupt source is enabled.
  630. * @param __HANDLE__: specifies the SMARTCARD Handle.
  631. * The Handle Instance which can be USART1 or USART2.
  632. * @param __IT__: specifies the SMARTCARD interrupt source to check.
  633. * This parameter can be one of the following values:
  634. * @arg SMARTCARD_IT_EOBF: End Of Block interrupt
  635. * @arg SMARTCARD_IT_RTOF: Receive TimeOut interrupt
  636. * @arg SMARTCARD_IT_TXE: Transmit Data Register empty interrupt
  637. * @arg SMARTCARD_IT_TC: Transmission complete interrupt
  638. * @arg SMARTCARD_IT_RXNE: Receive Data register not empty interrupt
  639. * @arg SMARTCARD_IT_ORE: OverRun Error interrupt
  640. * @arg SMARTCARD_IT_NE: Noise Error interrupt
  641. * @arg SMARTCARD_IT_FE: Framing Error interrupt
  642. * @arg SMARTCARD_IT_PE: Parity Error interrupt
  643. * @retval The new state of __IT__ (TRUE or FALSE).
  644. */
  645. #define __HAL_SMARTCARD_GET_IT_SOURCE(__HANDLE__, __IT__) ((((((uint8_t)(__IT__)) >> 5) == 1)? (__HANDLE__)->Instance->CR1:(((((uint8_t)(__IT__)) >> 5) == 2)? \
  646. (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & ((uint32_t)1 << \
  647. (((uint16_t)(__IT__)) & SMARTCARD_IT_MASK)))
  648. /** @brief Clears the specified SMARTCARD ISR flag, in setting the proper ICR register flag.
  649. * @param __HANDLE__: specifies the SMARTCARD Handle.
  650. * The Handle Instance which can be USART1 or USART2.
  651. * @param __IT_CLEAR__: specifies the interrupt clear register flag that needs to be set
  652. * to clear the corresponding interrupt
  653. * This parameter can be one of the following values:
  654. * @arg USART_CLEAR_PEF: Parity Error Clear Flag
  655. * @arg USART_CLEAR_FEF: Framing Error Clear Flag
  656. * @arg USART_CLEAR_NEF: Noise detected Clear Flag
  657. * @arg USART_CLEAR_OREF: OverRun Error Clear Flag
  658. * @arg USART_CLEAR_TCF: Transmission Complete Clear Flag
  659. * @arg USART_CLEAR_RTOF: Receiver Time Out Clear Flag
  660. * @arg USART_CLEAR_EOBF: End Of Block Clear Flag
  661. * @retval None
  662. */
  663. #define __HAL_SMARTCARD_CLEAR_IT(__HANDLE__, __IT_CLEAR__) ((__HANDLE__)->Instance->ICR = (uint32_t)(__IT_CLEAR__))
  664. /** @brief Set a specific SMARTCARD request flag.
  665. * @param __HANDLE__: specifies the SMARTCARD Handle.
  666. * The Handle Instance which can be USART1 or USART2.
  667. * @param __REQ__: specifies the request flag to set
  668. * This parameter can be one of the following values:
  669. * @arg SMARTCARD_RXDATA_FLUSH_REQUEST: Receive Data flush Request
  670. * @arg SMARTCARD_TXDATA_FLUSH_REQUEST: Transmit data flush Request
  671. *
  672. * @retval None
  673. */
  674. #define __HAL_SMARTCARD_SEND_REQ(__HANDLE__, __REQ__) ((__HANDLE__)->Instance->RQR |= (uint32_t)(__REQ__))
  675. /** @brief Enable the USART associated to the SMARTCARD Handle
  676. * @param __HANDLE__: specifies the SMARTCARD Handle.
  677. * The Handle Instance which can be USART1 or USART2.
  678. * @retval None
  679. */
  680. #define __HAL_SMARTCARD_ENABLE(__HANDLE__) ( (__HANDLE__)->Instance->CR1 |= USART_CR1_UE)
  681. /** @brief Disable the USART associated to the SMARTCARD Handle
  682. * @param __HANDLE__: specifies the SMARTCARD Handle.
  683. * The Handle Instance which can be USART1 or USART2.
  684. * @retval None
  685. */
  686. #define __HAL_SMARTCARD_DISABLE(__HANDLE__) ( (__HANDLE__)->Instance->CR1 &= ~USART_CR1_UE)
  687. /** @brief Macros to enable or disable the SmartCard DMA request.
  688. * @param __HANDLE__: specifies the SMARTCARD Handle.
  689. * The Handle Instance which can be USART1 or USART2.
  690. * @param __REQUEST__: specifies the SmartCard DMA request.
  691. * This parameter can be one of the following values:
  692. * @arg SMARTCARD_DMAREQ_TX: SmartCard DMA transmit request
  693. * @arg SMARTCARD_DMAREQ_RX: SmartCard DMA receive request
  694. */
  695. #define __HAL_SMARTCARD_DMA_REQUEST_ENABLE(__HANDLE__, __REQUEST__) ((__HANDLE__)->Instance->CR3 |= (__REQUEST__))
  696. #define __HAL_SMARTCARD_DMA_REQUEST_DISABLE(__HANDLE__, __REQUEST__) ((__HANDLE__)->Instance->CR3 &= ~(__REQUEST__))
  697. /**
  698. * @}
  699. */
  700. /* Include SMARTCARD HAL Extension module */
  701. #include "stm32f7xx_hal_smartcard_ex.h"
  702. /* Exported functions --------------------------------------------------------*/
  703. /** @addtogroup SMARTCARD_Exported_Functions
  704. * @{
  705. */
  706. /** @addtogroup SMARTCARD_Exported_Functions_Group1
  707. * @{
  708. */
  709. /* Initialization/de-initialization functions **********************************/
  710. HAL_StatusTypeDef HAL_SMARTCARD_Init(SMARTCARD_HandleTypeDef *hsc);
  711. HAL_StatusTypeDef HAL_SMARTCARD_DeInit(SMARTCARD_HandleTypeDef *hsc);
  712. void HAL_SMARTCARD_MspInit(SMARTCARD_HandleTypeDef *hsc);
  713. void HAL_SMARTCARD_MspDeInit(SMARTCARD_HandleTypeDef *hsc);
  714. /**
  715. * @}
  716. */
  717. /** @addtogroup SMARTCARD_Exported_Functions_Group2
  718. * @{
  719. */
  720. /* IO operation functions *******************************************************/
  721. HAL_StatusTypeDef HAL_SMARTCARD_Transmit(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size, uint32_t Timeout);
  722. HAL_StatusTypeDef HAL_SMARTCARD_Receive(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size, uint32_t Timeout);
  723. HAL_StatusTypeDef HAL_SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size);
  724. HAL_StatusTypeDef HAL_SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size);
  725. HAL_StatusTypeDef HAL_SMARTCARD_Transmit_DMA(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size);
  726. HAL_StatusTypeDef HAL_SMARTCARD_Receive_DMA(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size);
  727. /* Transfer Abort functions */
  728. HAL_StatusTypeDef HAL_SMARTCARD_Abort(SMARTCARD_HandleTypeDef *hsmartcard);
  729. HAL_StatusTypeDef HAL_SMARTCARD_AbortTransmit(SMARTCARD_HandleTypeDef *hsmartcard);
  730. HAL_StatusTypeDef HAL_SMARTCARD_AbortReceive(SMARTCARD_HandleTypeDef *hsmartcard);
  731. HAL_StatusTypeDef HAL_SMARTCARD_Abort_IT(SMARTCARD_HandleTypeDef *hsmartcard);
  732. HAL_StatusTypeDef HAL_SMARTCARD_AbortTransmit_IT(SMARTCARD_HandleTypeDef *hsmartcard);
  733. HAL_StatusTypeDef HAL_SMARTCARD_AbortReceive_IT(SMARTCARD_HandleTypeDef *hsmartcard);
  734. void HAL_SMARTCARD_IRQHandler(SMARTCARD_HandleTypeDef *hsmartcard);
  735. void HAL_SMARTCARD_TxCpltCallback(SMARTCARD_HandleTypeDef *hsmartcard);
  736. void HAL_SMARTCARD_RxCpltCallback(SMARTCARD_HandleTypeDef *hsmartcard);
  737. void HAL_SMARTCARD_ErrorCallback(SMARTCARD_HandleTypeDef *hsmartcard);
  738. void HAL_SMARTCARD_AbortCpltCallback (SMARTCARD_HandleTypeDef *hsmartcard);
  739. void HAL_SMARTCARD_AbortTransmitCpltCallback (SMARTCARD_HandleTypeDef *hsmartcard);
  740. void HAL_SMARTCARD_AbortReceiveCpltCallback (SMARTCARD_HandleTypeDef *hsmartcard);
  741. /**
  742. * @}
  743. */
  744. /** @addtogroup SMARTCARD_Exported_Functions_Group3
  745. * @{
  746. */
  747. /* Peripheral State functions **************************************************/
  748. HAL_SMARTCARD_StateTypeDef HAL_SMARTCARD_GetState(SMARTCARD_HandleTypeDef *hsc);
  749. uint32_t HAL_SMARTCARD_GetError(SMARTCARD_HandleTypeDef *hsc);
  750. /**
  751. * @}
  752. */
  753. /**
  754. * @}
  755. */
  756. /* Private types -------------------------------------------------------------*/
  757. /* Private variables ---------------------------------------------------------*/
  758. /* Private constants ---------------------------------------------------------*/
  759. /** @defgroup SMARTCARD_Private_Constants SMARTCARD Private Constants
  760. * @{
  761. */
  762. #define IS_SMARTCARD_WORD_LENGTH(__LENGTH__) ((__LENGTH__) == SMARTCARD_WORDLENGTH_9B)
  763. #define IS_SMARTCARD_STOPBITS(__STOPBITS__) ((__STOPBITS__) == SMARTCARD_STOPBITS_1_5)
  764. #define IS_SMARTCARD_PARITY(__PARITY__) (((__PARITY__) == SMARTCARD_PARITY_EVEN) || \
  765. ((__PARITY__) == SMARTCARD_PARITY_ODD))
  766. #define IS_SMARTCARD_MODE(__MODE__) ((((__MODE__) & (uint32_t)0xFFF3) == 0x00) && ((__MODE__) != (uint32_t)0x00))
  767. #define IS_SMARTCARD_POLARITY(__CPOL__) (((__CPOL__) == SMARTCARD_POLARITY_LOW) || ((__CPOL__) == SMARTCARD_POLARITY_HIGH))
  768. #define IS_SMARTCARD_PHASE(__CPHA__) (((__CPHA__) == SMARTCARD_PHASE_1EDGE) || ((__CPHA__) == SMARTCARD_PHASE_2EDGE))
  769. #define IS_SMARTCARD_LASTBIT(__LASTBIT__) (((__LASTBIT__) == SMARTCARD_LASTBIT_DISABLE) || \
  770. ((__LASTBIT__) == SMARTCARD_LASTBIT_ENABLE))
  771. #define IS_SMARTCARD_ONE_BIT_SAMPLE(__ONEBIT__) (((__ONEBIT__) == SMARTCARD_ONE_BIT_SAMPLE_DISABLE) || \
  772. ((__ONEBIT__) == SMARTCARD_ONE_BIT_SAMPLE_ENABLE))
  773. #define IS_SMARTCARD_NACK(__NACK__) (((__NACK__) == SMARTCARD_NACK_ENABLE) || \
  774. ((__NACK__) == SMARTCARD_NACK_DISABLE))
  775. #define IS_SMARTCARD_TIMEOUT(__TIMEOUT__) (((__TIMEOUT__) == SMARTCARD_TIMEOUT_DISABLE) || \
  776. ((__TIMEOUT__) == SMARTCARD_TIMEOUT_ENABLE))
  777. #define IS_SMARTCARD_ADVFEATURE_INIT(INIT) ((INIT) <= (SMARTCARD_ADVFEATURE_NO_INIT | \
  778. SMARTCARD_ADVFEATURE_TXINVERT_INIT | \
  779. SMARTCARD_ADVFEATURE_RXINVERT_INIT | \
  780. SMARTCARD_ADVFEATURE_DATAINVERT_INIT | \
  781. SMARTCARD_ADVFEATURE_SWAP_INIT | \
  782. SMARTCARD_ADVFEATURE_RXOVERRUNDISABLE_INIT | \
  783. SMARTCARD_ADVFEATURE_DMADISABLEONERROR_INIT | \
  784. SMARTCARD_ADVFEATURE_MSBFIRST_INIT))
  785. #define IS_SMARTCARD_ADVFEATURE_TXINV(TXINV) (((TXINV) == SMARTCARD_ADVFEATURE_TXINV_DISABLE) || \
  786. ((TXINV) == SMARTCARD_ADVFEATURE_TXINV_ENABLE))
  787. #define IS_SMARTCARD_ADVFEATURE_RXINV(RXINV) (((RXINV) == SMARTCARD_ADVFEATURE_RXINV_DISABLE) || \
  788. ((RXINV) == SMARTCARD_ADVFEATURE_RXINV_ENABLE))
  789. #define IS_SMARTCARD_ADVFEATURE_DATAINV(DATAINV) (((DATAINV) == SMARTCARD_ADVFEATURE_DATAINV_DISABLE) || \
  790. ((DATAINV) == SMARTCARD_ADVFEATURE_DATAINV_ENABLE))
  791. #define IS_SMARTCARD_ADVFEATURE_SWAP(SWAP) (((SWAP) == SMARTCARD_ADVFEATURE_SWAP_DISABLE) || \
  792. ((SWAP) == SMARTCARD_ADVFEATURE_SWAP_ENABLE))
  793. #define IS_SMARTCARD_OVERRUN(OVERRUN) (((OVERRUN) == SMARTCARD_ADVFEATURE_OVERRUN_ENABLE) || \
  794. ((OVERRUN) == SMARTCARD_ADVFEATURE_OVERRUN_DISABLE))
  795. #define IS_SMARTCARD_ADVFEATURE_DMAONRXERROR(DMA) (((DMA) == SMARTCARD_ADVFEATURE_DMA_ENABLEONRXERROR) || \
  796. ((DMA) == SMARTCARD_ADVFEATURE_DMA_DISABLEONRXERROR))
  797. #define IS_SMARTCARD_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) < 4500001)
  798. #define IS_SMARTCARD_BLOCKLENGTH(__LENGTH__) ((__LENGTH__) <= 0xFF)
  799. #define IS_SMARTCARD_TIMEOUT_VALUE(__TIMEOUTVALUE__) ((__TIMEOUTVALUE__) <= 0xFFFFFF)
  800. #define IS_SMARTCARD_AUTORETRY_COUNT(__COUNT__) ((__COUNT__) <= 0x7)
  801. #define IS_SMARTCARD_ADVFEATURE_MSBFIRST(MSBFIRST) (((MSBFIRST) == SMARTCARD_ADVFEATURE_MSBFIRST_DISABLE) || \
  802. ((MSBFIRST) == SMARTCARD_ADVFEATURE_MSBFIRST_ENABLE))
  803. #define IS_SMARTCARD_REQUEST_PARAMETER(PARAM) (((PARAM) == SMARTCARD_RXDATA_FLUSH_REQUEST) || \
  804. ((PARAM) == SMARTCARD_TXDATA_FLUSH_REQUEST))
  805. /**
  806. * @}
  807. */
  808. /* Private functions ---------------------------------------------------------*/
  809. /** @defgroup SMARTCARD_Private_Functions SMARTCARD Private Functions
  810. * @{
  811. */
  812. /**
  813. * @}
  814. */
  815. /**
  816. * @}
  817. */
  818. /**
  819. * @}
  820. */
  821. #ifdef __cplusplus
  822. }
  823. #endif
  824. #endif /* __STM32F7xx_HAL_SMARTCARD_H */
  825. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/