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.
 
 
 

1155 lines
60 KiB

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