1 /** 2 ****************************************************************************** 3 * @file stm32l4xx_hal_smartcard_ex.h 4 * @author MCD Application Team 5 * @brief Header file of SMARTCARD HAL Extended module. 6 ****************************************************************************** 7 * @attention 8 * 9 * Copyright (c) 2017 STMicroelectronics. 10 * All rights reserved. 11 * 12 * This software is licensed under terms that can be found in the LICENSE file 13 * in the root directory of this software component. 14 * If no LICENSE file comes with this software, it is provided AS-IS. 15 * 16 ****************************************************************************** 17 */ 18 19 /* Define to prevent recursive inclusion -------------------------------------*/ 20 #ifndef STM32L4xx_HAL_SMARTCARD_EX_H 21 #define STM32L4xx_HAL_SMARTCARD_EX_H 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /* Includes ------------------------------------------------------------------*/ 28 #include "stm32l4xx_hal_def.h" 29 30 /** @addtogroup STM32L4xx_HAL_Driver 31 * @{ 32 */ 33 34 /** @addtogroup SMARTCARDEx 35 * @{ 36 */ 37 38 /* Exported types ------------------------------------------------------------*/ 39 /* Exported constants --------------------------------------------------------*/ 40 41 /** @addtogroup SMARTCARDEx_Exported_Constants SMARTCARD Extended Exported Constants 42 * @{ 43 */ 44 45 /** @defgroup SMARTCARDEx_Transmission_Completion_Indication SMARTCARD Transmission Completion Indication 46 * @{ 47 */ 48 #if defined(USART_TCBGT_SUPPORT) 49 #define SMARTCARD_TCBGT SMARTCARD_IT_TCBGT /*!< SMARTCARD transmission complete before guard time */ 50 #endif /* USART_TCBGT_SUPPORT */ 51 #define SMARTCARD_TC SMARTCARD_IT_TC /*!< SMARTCARD transmission complete (flag raised when guard time has elapsed) */ 52 /** 53 * @} 54 */ 55 56 /** @defgroup SMARTCARDEx_Advanced_Features_Initialization_Type SMARTCARD advanced feature initialization type 57 * @{ 58 */ 59 #define SMARTCARD_ADVFEATURE_NO_INIT 0x00000000U /*!< No advanced feature initialization */ 60 #define SMARTCARD_ADVFEATURE_TXINVERT_INIT 0x00000001U /*!< TX pin active level inversion */ 61 #define SMARTCARD_ADVFEATURE_RXINVERT_INIT 0x00000002U /*!< RX pin active level inversion */ 62 #define SMARTCARD_ADVFEATURE_DATAINVERT_INIT 0x00000004U /*!< Binary data inversion */ 63 #define SMARTCARD_ADVFEATURE_SWAP_INIT 0x00000008U /*!< TX/RX pins swap */ 64 #define SMARTCARD_ADVFEATURE_RXOVERRUNDISABLE_INIT 0x00000010U /*!< RX overrun disable */ 65 #define SMARTCARD_ADVFEATURE_DMADISABLEONERROR_INIT 0x00000020U /*!< DMA disable on Reception Error */ 66 #define SMARTCARD_ADVFEATURE_MSBFIRST_INIT 0x00000080U /*!< Most significant bit sent/received first */ 67 #if defined(USART_TCBGT_SUPPORT) 68 #define SMARTCARD_ADVFEATURE_TXCOMPLETION 0x00000100U /*!< TX completion indication before of after guard time */ 69 #endif /* USART_TCBGT_SUPPORT */ 70 /** 71 * @} 72 */ 73 74 #if defined(USART_CR1_FIFOEN) 75 /** @defgroup SMARTCARDEx_FIFO_mode SMARTCARD FIFO mode 76 * @brief SMARTCARD FIFO mode 77 * @{ 78 */ 79 #define SMARTCARD_FIFOMODE_DISABLE 0x00000000U /*!< FIFO mode disable */ 80 #define SMARTCARD_FIFOMODE_ENABLE USART_CR1_FIFOEN /*!< FIFO mode enable */ 81 /** 82 * @} 83 */ 84 85 /** @defgroup SMARTCARDEx_TXFIFO_threshold_level SMARTCARD TXFIFO threshold level 86 * @brief SMARTCARD TXFIFO level 87 * @{ 88 */ 89 #define SMARTCARD_TXFIFO_THRESHOLD_1_8 0x00000000U /*!< TXFIFO reaches 1/8 of its depth */ 90 #define SMARTCARD_TXFIFO_THRESHOLD_1_4 USART_CR3_TXFTCFG_0 /*!< TXFIFO reaches 1/4 of its depth */ 91 #define SMARTCARD_TXFIFO_THRESHOLD_1_2 USART_CR3_TXFTCFG_1 /*!< TXFIFO reaches 1/2 of its depth */ 92 #define SMARTCARD_TXFIFO_THRESHOLD_3_4 (USART_CR3_TXFTCFG_0|USART_CR3_TXFTCFG_1) /*!< TXFIFO reaches 3/4 of its depth */ 93 #define SMARTCARD_TXFIFO_THRESHOLD_7_8 USART_CR3_TXFTCFG_2 /*!< TXFIFO reaches 7/8 of its depth */ 94 #define SMARTCARD_TXFIFO_THRESHOLD_8_8 (USART_CR3_TXFTCFG_2|USART_CR3_TXFTCFG_0) /*!< TXFIFO becomes empty */ 95 /** 96 * @} 97 */ 98 99 /** @defgroup SMARTCARDEx_RXFIFO_threshold_level SMARTCARD RXFIFO threshold level 100 * @brief SMARTCARD RXFIFO level 101 * @{ 102 */ 103 #define SMARTCARD_RXFIFO_THRESHOLD_1_8 0x00000000U /*!< RXFIFO FIFO reaches 1/8 of its depth */ 104 #define SMARTCARD_RXFIFO_THRESHOLD_1_4 USART_CR3_RXFTCFG_0 /*!< RXFIFO FIFO reaches 1/4 of its depth */ 105 #define SMARTCARD_RXFIFO_THRESHOLD_1_2 USART_CR3_RXFTCFG_1 /*!< RXFIFO FIFO reaches 1/2 of its depth */ 106 #define SMARTCARD_RXFIFO_THRESHOLD_3_4 (USART_CR3_RXFTCFG_0|USART_CR3_RXFTCFG_1) /*!< RXFIFO FIFO reaches 3/4 of its depth */ 107 #define SMARTCARD_RXFIFO_THRESHOLD_7_8 USART_CR3_RXFTCFG_2 /*!< RXFIFO FIFO reaches 7/8 of its depth */ 108 #define SMARTCARD_RXFIFO_THRESHOLD_8_8 (USART_CR3_RXFTCFG_2|USART_CR3_RXFTCFG_0) /*!< RXFIFO FIFO becomes full */ 109 /** 110 * @} 111 */ 112 113 #endif /* USART_CR1_FIFOEN */ 114 /** @defgroup SMARTCARDEx_Flags SMARTCARD Flags 115 * Elements values convention: 0xXXXX 116 * - 0xXXXX : Flag mask in the ISR register 117 * @{ 118 */ 119 #if defined(USART_TCBGT_SUPPORT) 120 #define SMARTCARD_FLAG_TCBGT USART_ISR_TCBGT /*!< SMARTCARD transmission complete before guard time completion */ 121 #endif /* USART_TCBGT_SUPPORT */ 122 #define SMARTCARD_FLAG_REACK USART_ISR_REACK /*!< SMARTCARD receive enable acknowledge flag */ 123 #define SMARTCARD_FLAG_TEACK USART_ISR_TEACK /*!< SMARTCARD transmit enable acknowledge flag */ 124 #define SMARTCARD_FLAG_BUSY USART_ISR_BUSY /*!< SMARTCARD busy flag */ 125 #define SMARTCARD_FLAG_EOBF USART_ISR_EOBF /*!< SMARTCARD end of block flag */ 126 #define SMARTCARD_FLAG_RTOF USART_ISR_RTOF /*!< SMARTCARD receiver timeout flag */ 127 #if defined(USART_CR1_FIFOEN) 128 #define SMARTCARD_FLAG_TXE USART_ISR_TXE_TXFNF /*!< SMARTCARD transmit data register empty */ 129 #define SMARTCARD_FLAG_TXFNF USART_ISR_TXE_TXFNF /*!< SMARTCARD TXFIFO not full */ 130 #else 131 #define SMARTCARD_FLAG_TXE USART_ISR_TXE /*!< SMARTCARD transmit data register empty */ 132 #endif /* USART_CR1_FIFOEN */ 133 #define SMARTCARD_FLAG_TC USART_ISR_TC /*!< SMARTCARD transmission complete */ 134 #if defined(USART_CR1_FIFOEN) 135 #define SMARTCARD_FLAG_RXNE USART_ISR_RXNE_RXFNE /*!< SMARTCARD read data register not empty */ 136 #define SMARTCARD_FLAG_RXFNE USART_ISR_RXNE_RXFNE /*!< SMARTCARD RXFIFO not empty */ 137 #else 138 #define SMARTCARD_FLAG_RXNE USART_ISR_RXNE /*!< SMARTCARD read data register not empty */ 139 #endif /* USART_CR1_FIFOEN */ 140 #define SMARTCARD_FLAG_IDLE USART_ISR_IDLE /*!< SMARTCARD idle line detection */ 141 #define SMARTCARD_FLAG_ORE USART_ISR_ORE /*!< SMARTCARD overrun error */ 142 #define SMARTCARD_FLAG_NE USART_ISR_NE /*!< SMARTCARD noise error */ 143 #define SMARTCARD_FLAG_FE USART_ISR_FE /*!< SMARTCARD frame error */ 144 #define SMARTCARD_FLAG_PE USART_ISR_PE /*!< SMARTCARD parity error */ 145 #if defined(USART_CR1_FIFOEN) 146 #define SMARTCARD_FLAG_TXFE USART_ISR_TXFE /*!< SMARTCARD TXFIFO Empty flag */ 147 #define SMARTCARD_FLAG_RXFF USART_ISR_RXFF /*!< SMARTCARD RXFIFO Full flag */ 148 #define SMARTCARD_FLAG_RXFT USART_ISR_RXFT /*!< SMARTCARD RXFIFO threshold flag */ 149 #define SMARTCARD_FLAG_TXFT USART_ISR_TXFT /*!< SMARTCARD TXFIFO threshold flag */ 150 #endif /* USART_CR1_FIFOEN */ 151 /** 152 * @} 153 */ 154 155 /** @defgroup SMARTCARDEx_Interrupt_definition SMARTCARD Interrupts Definition 156 * Elements values convention: 000ZZZZZ0XXYYYYYb 157 * - YYYYY : Interrupt source position in the XX register (5 bits) 158 * - XX : Interrupt source register (2 bits) 159 * - 01: CR1 register 160 * - 10: CR2 register 161 * - 11: CR3 register 162 * - ZZZZZ : Flag position in the ISR register(5 bits) 163 * @{ 164 */ 165 #define SMARTCARD_IT_PE 0x0028U /*!< SMARTCARD parity error interruption */ 166 #define SMARTCARD_IT_TXE 0x0727U /*!< SMARTCARD transmit data register empty interruption */ 167 #if defined(USART_CR1_FIFOEN) 168 #define SMARTCARD_IT_TXFNF 0x0727U /*!< SMARTCARD TX FIFO not full interruption */ 169 #endif /* USART_CR1_FIFOEN */ 170 #define SMARTCARD_IT_TC 0x0626U /*!< SMARTCARD transmission complete interruption */ 171 #define SMARTCARD_IT_RXNE 0x0525U /*!< SMARTCARD read data register not empty interruption */ 172 #if defined(USART_CR1_FIFOEN) 173 #define SMARTCARD_IT_RXFNE 0x0525U /*!< SMARTCARD RXFIFO not empty interruption */ 174 #endif /* USART_CR1_FIFOEN */ 175 #define SMARTCARD_IT_IDLE 0x0424U /*!< SMARTCARD idle line detection interruption */ 176 177 #define SMARTCARD_IT_ERR 0x0060U /*!< SMARTCARD error interruption */ 178 #define SMARTCARD_IT_ORE 0x0300U /*!< SMARTCARD overrun error interruption */ 179 #define SMARTCARD_IT_NE 0x0200U /*!< SMARTCARD noise error interruption */ 180 #define SMARTCARD_IT_FE 0x0100U /*!< SMARTCARD frame error interruption */ 181 182 #define SMARTCARD_IT_EOB 0x0C3BU /*!< SMARTCARD end of block interruption */ 183 #define SMARTCARD_IT_RTO 0x0B3AU /*!< SMARTCARD receiver timeout interruption */ 184 #if defined(USART_TCBGT_SUPPORT) 185 #define SMARTCARD_IT_TCBGT 0x1978U /*!< SMARTCARD transmission complete before guard time completion interruption */ 186 #endif /* USART_TCBGT_SUPPORT */ 187 188 #if defined(USART_CR1_FIFOEN) 189 #define SMARTCARD_IT_RXFF 0x183FU /*!< SMARTCARD RXFIFO full interruption */ 190 #define SMARTCARD_IT_TXFE 0x173EU /*!< SMARTCARD TXFIFO empty interruption */ 191 #define SMARTCARD_IT_RXFT 0x1A7CU /*!< SMARTCARD RXFIFO threshold reached interruption */ 192 #define SMARTCARD_IT_TXFT 0x1B77U /*!< SMARTCARD TXFIFO threshold reached interruption */ 193 #endif /* USART_CR1_FIFOEN */ 194 /** 195 * @} 196 */ 197 198 /** @defgroup SMARTCARDEx_IT_CLEAR_Flags SMARTCARD Interruption Clear Flags 199 * @{ 200 */ 201 #define SMARTCARD_CLEAR_PEF USART_ICR_PECF /*!< SMARTCARD parity error clear flag */ 202 #define SMARTCARD_CLEAR_FEF USART_ICR_FECF /*!< SMARTCARD framing error clear flag */ 203 #define SMARTCARD_CLEAR_NEF USART_ICR_NECF /*!< SMARTCARD noise error detected clear flag */ 204 #define SMARTCARD_CLEAR_OREF USART_ICR_ORECF /*!< SMARTCARD overrun error clear flag */ 205 #define SMARTCARD_CLEAR_IDLEF USART_ICR_IDLECF /*!< SMARTCARD idle line detected clear flag */ 206 #if defined(USART_CR1_FIFOEN) 207 #define SMARTCARD_CLEAR_TXFECF USART_ICR_TXFECF /*!< TXFIFO empty Clear Flag */ 208 #endif /* USART_CR1_FIFOEN */ 209 #define SMARTCARD_CLEAR_TCF USART_ICR_TCCF /*!< SMARTCARD transmission complete clear flag */ 210 #if defined(USART_TCBGT_SUPPORT) 211 #define SMARTCARD_CLEAR_TCBGTF USART_ICR_TCBGTCF /*!< SMARTCARD transmission complete before guard time completion clear flag */ 212 #endif /* USART_TCBGT_SUPPORT */ 213 #define SMARTCARD_CLEAR_RTOF USART_ICR_RTOCF /*!< SMARTCARD receiver time out clear flag */ 214 #define SMARTCARD_CLEAR_EOBF USART_ICR_EOBCF /*!< SMARTCARD end of block clear flag */ 215 /** 216 * @} 217 */ 218 219 /** 220 * @} 221 */ 222 /* Exported macros -----------------------------------------------------------*/ 223 /* Private macros ------------------------------------------------------------*/ 224 /** @defgroup SMARTCARDEx_Private_Macros SMARTCARD Extended Private Macros 225 * @{ 226 */ 227 228 /** @brief Set the Transmission Completion flag 229 * @param __HANDLE__ specifies the SMARTCARD Handle. 230 * @note If TCBGT (Transmission Complete Before Guard Time) flag is not available or if 231 * AdvancedInit.TxCompletionIndication is not already filled, the latter is forced 232 * to SMARTCARD_TC (transmission completion indication when guard time has elapsed). 233 * @retval None 234 */ 235 #if defined(USART_TCBGT_SUPPORT) 236 #define SMARTCARD_TRANSMISSION_COMPLETION_SETTING(__HANDLE__) \ 237 do { \ 238 if (HAL_IS_BIT_CLR((__HANDLE__)->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_TXCOMPLETION)) \ 239 { \ 240 (__HANDLE__)->AdvancedInit.TxCompletionIndication = SMARTCARD_TC; \ 241 } \ 242 else \ 243 { \ 244 assert_param(IS_SMARTCARD_TRANSMISSION_COMPLETION((__HANDLE__)->AdvancedInit.TxCompletionIndication)); \ 245 } \ 246 } while(0U) 247 #else 248 #define SMARTCARD_TRANSMISSION_COMPLETION_SETTING(__HANDLE__) \ 249 do { \ 250 (__HANDLE__)->AdvancedInit.TxCompletionIndication = SMARTCARD_TC; \ 251 } while(0U) 252 #endif /* USART_TCBGT_SUPPORT */ 253 254 /** @brief Return the transmission completion flag. 255 * @param __HANDLE__ specifies the SMARTCARD Handle. 256 * @note Based on AdvancedInit.TxCompletionIndication setting, return TC or TCBGT flag. 257 * When TCBGT flag (Transmission Complete Before Guard Time) is not available, TC flag is 258 * reported. 259 * @retval Transmission completion flag 260 */ 261 #if defined(USART_TCBGT_SUPPORT) 262 #define SMARTCARD_TRANSMISSION_COMPLETION_FLAG(__HANDLE__) \ 263 (((__HANDLE__)->AdvancedInit.TxCompletionIndication == SMARTCARD_TC) ? (SMARTCARD_FLAG_TC) : (SMARTCARD_FLAG_TCBGT)) 264 #else 265 #define SMARTCARD_TRANSMISSION_COMPLETION_FLAG(__HANDLE__) (SMARTCARD_FLAG_TC) 266 #endif /* USART_TCBGT_SUPPORT */ 267 268 269 /** @brief Ensure that SMARTCARD frame transmission completion used flag is valid. 270 * @param __TXCOMPLETE__ SMARTCARD frame transmission completion used flag. 271 * @retval SET (__TXCOMPLETE__ is valid) or RESET (__TXCOMPLETE__ is invalid) 272 */ 273 #if defined(USART_TCBGT_SUPPORT) 274 #define IS_SMARTCARD_TRANSMISSION_COMPLETION(__TXCOMPLETE__) (((__TXCOMPLETE__) == SMARTCARD_TCBGT) || \ 275 ((__TXCOMPLETE__) == SMARTCARD_TC)) 276 #else 277 #define IS_SMARTCARD_TRANSMISSION_COMPLETION(__TXCOMPLETE__) ((__TXCOMPLETE__) == SMARTCARD_TC) 278 #endif /* USART_TCBGT_SUPPORT */ 279 280 #if defined(USART_CR1_FIFOEN) 281 /** @brief Ensure that SMARTCARD FIFO mode is valid. 282 * @param __STATE__ SMARTCARD FIFO mode. 283 * @retval SET (__STATE__ is valid) or RESET (__STATE__ is invalid) 284 */ 285 #define IS_SMARTCARD_FIFOMODE_STATE(__STATE__) (((__STATE__) == SMARTCARD_FIFOMODE_DISABLE ) || \ 286 ((__STATE__) == SMARTCARD_FIFOMODE_ENABLE)) 287 288 /** @brief Ensure that SMARTCARD TXFIFO threshold level is valid. 289 * @param __THRESHOLD__ SMARTCARD TXFIFO threshold level. 290 * @retval SET (__THRESHOLD__ is valid) or RESET (__THRESHOLD__ is invalid) 291 */ 292 #define IS_SMARTCARD_TXFIFO_THRESHOLD(__THRESHOLD__) (((__THRESHOLD__) == SMARTCARD_TXFIFO_THRESHOLD_1_8) || \ 293 ((__THRESHOLD__) == SMARTCARD_TXFIFO_THRESHOLD_1_4) || \ 294 ((__THRESHOLD__) == SMARTCARD_TXFIFO_THRESHOLD_1_2) || \ 295 ((__THRESHOLD__) == SMARTCARD_TXFIFO_THRESHOLD_3_4) || \ 296 ((__THRESHOLD__) == SMARTCARD_TXFIFO_THRESHOLD_7_8) || \ 297 ((__THRESHOLD__) == SMARTCARD_TXFIFO_THRESHOLD_8_8)) 298 299 /** @brief Ensure that SMARTCARD RXFIFO threshold level is valid. 300 * @param __THRESHOLD__ SMARTCARD RXFIFO threshold level. 301 * @retval SET (__THRESHOLD__ is valid) or RESET (__THRESHOLD__ is invalid) 302 */ 303 #define IS_SMARTCARD_RXFIFO_THRESHOLD(__THRESHOLD__) (((__THRESHOLD__) == SMARTCARD_RXFIFO_THRESHOLD_1_8) || \ 304 ((__THRESHOLD__) == SMARTCARD_RXFIFO_THRESHOLD_1_4) || \ 305 ((__THRESHOLD__) == SMARTCARD_RXFIFO_THRESHOLD_1_2) || \ 306 ((__THRESHOLD__) == SMARTCARD_RXFIFO_THRESHOLD_3_4) || \ 307 ((__THRESHOLD__) == SMARTCARD_RXFIFO_THRESHOLD_7_8) || \ 308 ((__THRESHOLD__) == SMARTCARD_RXFIFO_THRESHOLD_8_8)) 309 310 #endif /* USART_CR1_FIFOEN */ 311 /** 312 * @} 313 */ 314 315 /* Exported functions --------------------------------------------------------*/ 316 /** @addtogroup SMARTCARDEx_Exported_Functions 317 * @{ 318 */ 319 320 /* Initialization and de-initialization functions ****************************/ 321 /* IO operation methods *******************************************************/ 322 323 /** @addtogroup SMARTCARDEx_Exported_Functions_Group1 324 * @{ 325 */ 326 327 /* Peripheral Control functions ***********************************************/ 328 void HAL_SMARTCARDEx_BlockLength_Config(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t BlockLength); 329 void HAL_SMARTCARDEx_TimeOut_Config(SMARTCARD_HandleTypeDef *hsmartcard, uint32_t TimeOutValue); 330 HAL_StatusTypeDef HAL_SMARTCARDEx_EnableReceiverTimeOut(SMARTCARD_HandleTypeDef *hsmartcard); 331 HAL_StatusTypeDef HAL_SMARTCARDEx_DisableReceiverTimeOut(SMARTCARD_HandleTypeDef *hsmartcard); 332 333 /** 334 * @} 335 */ 336 337 /* Exported functions --------------------------------------------------------*/ 338 /** @addtogroup SMARTCARDEx_Exported_Functions_Group2 339 * @{ 340 */ 341 342 /* IO operation functions *****************************************************/ 343 #if defined(USART_CR1_FIFOEN) 344 void HAL_SMARTCARDEx_RxFifoFullCallback(SMARTCARD_HandleTypeDef *hsmartcard); 345 void HAL_SMARTCARDEx_TxFifoEmptyCallback(SMARTCARD_HandleTypeDef *hsmartcard); 346 #endif /* USART_CR1_FIFOEN */ 347 348 /** 349 * @} 350 */ 351 352 /** @addtogroup SMARTCARDEx_Exported_Functions_Group3 353 * @{ 354 */ 355 356 /* Peripheral Control functions ***********************************************/ 357 #if defined(USART_CR1_FIFOEN) 358 HAL_StatusTypeDef HAL_SMARTCARDEx_EnableFifoMode(SMARTCARD_HandleTypeDef *hsmartcard); 359 HAL_StatusTypeDef HAL_SMARTCARDEx_DisableFifoMode(SMARTCARD_HandleTypeDef *hsmartcard); 360 HAL_StatusTypeDef HAL_SMARTCARDEx_SetTxFifoThreshold(SMARTCARD_HandleTypeDef *hsmartcard, uint32_t Threshold); 361 HAL_StatusTypeDef HAL_SMARTCARDEx_SetRxFifoThreshold(SMARTCARD_HandleTypeDef *hsmartcard, uint32_t Threshold); 362 #endif /* USART_CR1_FIFOEN */ 363 364 /** 365 * @} 366 */ 367 368 /** 369 * @} 370 */ 371 372 /* Private functions ---------------------------------------------------------*/ 373 374 /** 375 * @} 376 */ 377 378 /** 379 * @} 380 */ 381 382 #ifdef __cplusplus 383 } 384 #endif 385 386 #endif /* STM32L4xx_HAL_SMARTCARD_EX_H */ 387 388