1 /** 2 ****************************************************************************** 3 * @file stm32f7xx_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 STM32F7xx_HAL_SMARTCARD_EX_H 21 #define STM32F7xx_HAL_SMARTCARD_EX_H 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /* Includes ------------------------------------------------------------------*/ 28 #include "stm32f7xx_hal_def.h" 29 30 /** @addtogroup STM32F7xx_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 /** @defgroup SMARTCARDEx_Flags SMARTCARD Flags 75 * Elements values convention: 0xXXXX 76 * - 0xXXXX : Flag mask in the ISR register 77 * @{ 78 */ 79 #if defined(USART_TCBGT_SUPPORT) 80 #define SMARTCARD_FLAG_TCBGT USART_ISR_TCBGT /*!< SMARTCARD transmission complete before guard time completion */ 81 #endif /* USART_TCBGT_SUPPORT */ 82 #define SMARTCARD_FLAG_TEACK USART_ISR_TEACK /*!< SMARTCARD transmit enable acknowledge flag */ 83 #define SMARTCARD_FLAG_BUSY USART_ISR_BUSY /*!< SMARTCARD busy flag */ 84 #define SMARTCARD_FLAG_EOBF USART_ISR_EOBF /*!< SMARTCARD end of block flag */ 85 #define SMARTCARD_FLAG_RTOF USART_ISR_RTOF /*!< SMARTCARD receiver timeout flag */ 86 #define SMARTCARD_FLAG_TXE USART_ISR_TXE /*!< SMARTCARD transmit data register empty */ 87 #define SMARTCARD_FLAG_TC USART_ISR_TC /*!< SMARTCARD transmission complete */ 88 #define SMARTCARD_FLAG_RXNE USART_ISR_RXNE /*!< SMARTCARD read data register not empty */ 89 #define SMARTCARD_FLAG_IDLE USART_ISR_IDLE /*!< SMARTCARD idle line detection */ 90 #define SMARTCARD_FLAG_ORE USART_ISR_ORE /*!< SMARTCARD overrun error */ 91 #define SMARTCARD_FLAG_NE USART_ISR_NE /*!< SMARTCARD noise error */ 92 #define SMARTCARD_FLAG_FE USART_ISR_FE /*!< SMARTCARD frame error */ 93 #define SMARTCARD_FLAG_PE USART_ISR_PE /*!< SMARTCARD parity error */ 94 /** 95 * @} 96 */ 97 98 /** @defgroup SMARTCARDEx_Interrupt_definition SMARTCARD Interrupts Definition 99 * Elements values convention: 000ZZZZZ0XXYYYYYb 100 * - YYYYY : Interrupt source position in the XX register (5 bits) 101 * - XX : Interrupt source register (2 bits) 102 * - 01: CR1 register 103 * - 10: CR2 register 104 * - 11: CR3 register 105 * - ZZZZZ : Flag position in the ISR register(5 bits) 106 * @{ 107 */ 108 #define SMARTCARD_IT_PE 0x0028U /*!< SMARTCARD parity error interruption */ 109 #define SMARTCARD_IT_TXE 0x0727U /*!< SMARTCARD transmit data register empty interruption */ 110 #define SMARTCARD_IT_TC 0x0626U /*!< SMARTCARD transmission complete interruption */ 111 #define SMARTCARD_IT_RXNE 0x0525U /*!< SMARTCARD read data register not empty interruption */ 112 #define SMARTCARD_IT_IDLE 0x0424U /*!< SMARTCARD idle line detection interruption */ 113 114 #define SMARTCARD_IT_ERR 0x0060U /*!< SMARTCARD error interruption */ 115 #define SMARTCARD_IT_ORE 0x0300U /*!< SMARTCARD overrun error interruption */ 116 #define SMARTCARD_IT_NE 0x0200U /*!< SMARTCARD noise error interruption */ 117 #define SMARTCARD_IT_FE 0x0100U /*!< SMARTCARD frame error interruption */ 118 119 #define SMARTCARD_IT_EOB 0x0C3BU /*!< SMARTCARD end of block interruption */ 120 #define SMARTCARD_IT_RTO 0x0B3AU /*!< SMARTCARD receiver timeout interruption */ 121 #if defined(USART_TCBGT_SUPPORT) 122 #define SMARTCARD_IT_TCBGT 0x1978U /*!< SMARTCARD transmission complete before guard time completion interruption */ 123 #endif /* USART_TCBGT_SUPPORT */ 124 125 /** 126 * @} 127 */ 128 129 /** @defgroup SMARTCARDEx_IT_CLEAR_Flags SMARTCARD Interruption Clear Flags 130 * @{ 131 */ 132 #define SMARTCARD_CLEAR_PEF USART_ICR_PECF /*!< SMARTCARD parity error clear flag */ 133 #define SMARTCARD_CLEAR_FEF USART_ICR_FECF /*!< SMARTCARD framing error clear flag */ 134 #define SMARTCARD_CLEAR_NEF USART_ICR_NCF /*!< SMARTCARD noise error detected clear flag */ 135 #define SMARTCARD_CLEAR_OREF USART_ICR_ORECF /*!< SMARTCARD overrun error clear flag */ 136 #define SMARTCARD_CLEAR_IDLEF USART_ICR_IDLECF /*!< SMARTCARD idle line detected clear flag */ 137 #define SMARTCARD_CLEAR_TCF USART_ICR_TCCF /*!< SMARTCARD transmission complete clear flag */ 138 #if defined(USART_TCBGT_SUPPORT) 139 #define SMARTCARD_CLEAR_TCBGTF USART_ICR_TCBGTCF /*!< SMARTCARD transmission complete before guard time completion clear flag */ 140 #endif /* USART_TCBGT_SUPPORT */ 141 #define SMARTCARD_CLEAR_RTOF USART_ICR_RTOCF /*!< SMARTCARD receiver time out clear flag */ 142 #define SMARTCARD_CLEAR_EOBF USART_ICR_EOBCF /*!< SMARTCARD end of block clear flag */ 143 /** 144 * @} 145 */ 146 147 /** 148 * @} 149 */ 150 /* Exported macros -----------------------------------------------------------*/ 151 /* Private macros ------------------------------------------------------------*/ 152 /** @defgroup SMARTCARDEx_Private_Macros SMARTCARD Extended Private Macros 153 * @{ 154 */ 155 156 /** @brief Set the Transmission Completion flag 157 * @param __HANDLE__ specifies the SMARTCARD Handle. 158 * @note If TCBGT (Transmission Complete Before Guard Time) flag is not available or if 159 * AdvancedInit.TxCompletionIndication is not already filled, the latter is forced 160 * to SMARTCARD_TC (transmission completion indication when guard time has elapsed). 161 * @retval None 162 */ 163 #if defined(USART_TCBGT_SUPPORT) 164 #define SMARTCARD_TRANSMISSION_COMPLETION_SETTING(__HANDLE__) \ 165 do { \ 166 if (HAL_IS_BIT_CLR((__HANDLE__)->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_TXCOMPLETION)) \ 167 { \ 168 (__HANDLE__)->AdvancedInit.TxCompletionIndication = SMARTCARD_TC; \ 169 } \ 170 else \ 171 { \ 172 assert_param(IS_SMARTCARD_TRANSMISSION_COMPLETION((__HANDLE__)->AdvancedInit.TxCompletionIndication)); \ 173 } \ 174 } while(0U) 175 #else 176 #define SMARTCARD_TRANSMISSION_COMPLETION_SETTING(__HANDLE__) \ 177 do { \ 178 (__HANDLE__)->AdvancedInit.TxCompletionIndication = SMARTCARD_TC; \ 179 } while(0U) 180 #endif /* USART_TCBGT_SUPPORT */ 181 182 /** @brief Return the transmission completion flag. 183 * @param __HANDLE__ specifies the SMARTCARD Handle. 184 * @note Based on AdvancedInit.TxCompletionIndication setting, return TC or TCBGT flag. 185 * When TCBGT flag (Transmission Complete Before Guard Time) is not available, TC flag is 186 * reported. 187 * @retval Transmission completion flag 188 */ 189 #if defined(USART_TCBGT_SUPPORT) 190 #define SMARTCARD_TRANSMISSION_COMPLETION_FLAG(__HANDLE__) \ 191 (((__HANDLE__)->AdvancedInit.TxCompletionIndication == SMARTCARD_TC) ? (SMARTCARD_FLAG_TC) : (SMARTCARD_FLAG_TCBGT)) 192 #else 193 #define SMARTCARD_TRANSMISSION_COMPLETION_FLAG(__HANDLE__) (SMARTCARD_FLAG_TC) 194 #endif /* USART_TCBGT_SUPPORT */ 195 196 197 /** @brief Ensure that SMARTCARD frame transmission completion used flag is valid. 198 * @param __TXCOMPLETE__ SMARTCARD frame transmission completion used flag. 199 * @retval SET (__TXCOMPLETE__ is valid) or RESET (__TXCOMPLETE__ is invalid) 200 */ 201 #if defined(USART_TCBGT_SUPPORT) 202 #define IS_SMARTCARD_TRANSMISSION_COMPLETION(__TXCOMPLETE__) (((__TXCOMPLETE__) == SMARTCARD_TCBGT) || \ 203 ((__TXCOMPLETE__) == SMARTCARD_TC)) 204 #else 205 #define IS_SMARTCARD_TRANSMISSION_COMPLETION(__TXCOMPLETE__) ((__TXCOMPLETE__) == SMARTCARD_TC) 206 #endif /* USART_TCBGT_SUPPORT */ 207 208 /** 209 * @} 210 */ 211 212 /* Exported functions --------------------------------------------------------*/ 213 /** @addtogroup SMARTCARDEx_Exported_Functions 214 * @{ 215 */ 216 217 /* Initialization and de-initialization functions ****************************/ 218 /* IO operation methods *******************************************************/ 219 220 /** @addtogroup SMARTCARDEx_Exported_Functions_Group1 221 * @{ 222 */ 223 224 /* Peripheral Control functions ***********************************************/ 225 void HAL_SMARTCARDEx_BlockLength_Config(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t BlockLength); 226 void HAL_SMARTCARDEx_TimeOut_Config(SMARTCARD_HandleTypeDef *hsmartcard, uint32_t TimeOutValue); 227 HAL_StatusTypeDef HAL_SMARTCARDEx_EnableReceiverTimeOut(SMARTCARD_HandleTypeDef *hsmartcard); 228 HAL_StatusTypeDef HAL_SMARTCARDEx_DisableReceiverTimeOut(SMARTCARD_HandleTypeDef *hsmartcard); 229 230 /** 231 * @} 232 */ 233 234 /* Exported functions --------------------------------------------------------*/ 235 /** @addtogroup SMARTCARDEx_Exported_Functions_Group2 236 * @{ 237 */ 238 239 /* IO operation functions *****************************************************/ 240 241 /** 242 * @} 243 */ 244 245 246 /** 247 * @} 248 */ 249 250 /* Private functions ---------------------------------------------------------*/ 251 252 /** 253 * @} 254 */ 255 256 /** 257 * @} 258 */ 259 260 #ifdef __cplusplus 261 } 262 #endif 263 264 #endif /* STM32F7xx_HAL_SMARTCARD_EX_H */ 265 266