stm32f3xx_hal_smartcard.h 54 KB

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