The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
AnnaBridge
Date:
Wed Jun 21 17:31:38 2017 +0100
Revision:
145:64910690c574
Parent:
128:9bcdf88f62b0
Release 145 of the mbed library.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Kojto 122:f9eeca106725 1 /**
Kojto 122:f9eeca106725 2 ******************************************************************************
Kojto 122:f9eeca106725 3 * @file stm32f4xx_hal_smartcard.h
Kojto 122:f9eeca106725 4 * @author MCD Application Team
AnnaBridge 145:64910690c574 5 * @version V1.7.1
AnnaBridge 145:64910690c574 6 * @date 14-April-2017
Kojto 122:f9eeca106725 7 * @brief Header file of SMARTCARD HAL module.
Kojto 122:f9eeca106725 8 ******************************************************************************
Kojto 122:f9eeca106725 9 * @attention
Kojto 122:f9eeca106725 10 *
AnnaBridge 145:64910690c574 11 * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
Kojto 122:f9eeca106725 12 *
Kojto 122:f9eeca106725 13 * Redistribution and use in source and binary forms, with or without modification,
Kojto 122:f9eeca106725 14 * are permitted provided that the following conditions are met:
Kojto 122:f9eeca106725 15 * 1. Redistributions of source code must retain the above copyright notice,
Kojto 122:f9eeca106725 16 * this list of conditions and the following disclaimer.
Kojto 122:f9eeca106725 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
Kojto 122:f9eeca106725 18 * this list of conditions and the following disclaimer in the documentation
Kojto 122:f9eeca106725 19 * and/or other materials provided with the distribution.
Kojto 122:f9eeca106725 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
Kojto 122:f9eeca106725 21 * may be used to endorse or promote products derived from this software
Kojto 122:f9eeca106725 22 * without specific prior written permission.
Kojto 122:f9eeca106725 23 *
Kojto 122:f9eeca106725 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Kojto 122:f9eeca106725 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Kojto 122:f9eeca106725 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Kojto 122:f9eeca106725 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
Kojto 122:f9eeca106725 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Kojto 122:f9eeca106725 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Kojto 122:f9eeca106725 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Kojto 122:f9eeca106725 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Kojto 122:f9eeca106725 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Kojto 122:f9eeca106725 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Kojto 122:f9eeca106725 34 *
Kojto 122:f9eeca106725 35 ******************************************************************************
Kojto 122:f9eeca106725 36 */
Kojto 122:f9eeca106725 37
Kojto 122:f9eeca106725 38 /* Define to prevent recursive inclusion -------------------------------------*/
Kojto 122:f9eeca106725 39 #ifndef __STM32F4xx_HAL_SMARTCARD_H
Kojto 122:f9eeca106725 40 #define __STM32F4xx_HAL_SMARTCARD_H
Kojto 122:f9eeca106725 41
Kojto 122:f9eeca106725 42 #ifdef __cplusplus
Kojto 122:f9eeca106725 43 extern "C" {
Kojto 122:f9eeca106725 44 #endif
Kojto 122:f9eeca106725 45
Kojto 122:f9eeca106725 46 /* Includes ------------------------------------------------------------------*/
Kojto 122:f9eeca106725 47 #include "stm32f4xx_hal_def.h"
Kojto 122:f9eeca106725 48
Kojto 122:f9eeca106725 49 /** @addtogroup STM32F4xx_HAL_Driver
Kojto 122:f9eeca106725 50 * @{
Kojto 122:f9eeca106725 51 */
Kojto 122:f9eeca106725 52
Kojto 122:f9eeca106725 53 /** @addtogroup SMARTCARD
Kojto 122:f9eeca106725 54 * @{
Kojto 122:f9eeca106725 55 */
Kojto 122:f9eeca106725 56
Kojto 122:f9eeca106725 57 /* Exported types ------------------------------------------------------------*/
Kojto 122:f9eeca106725 58 /** @defgroup SMARTCARD_Exported_Types SMARTCARD Exported Types
Kojto 122:f9eeca106725 59 * @{
Kojto 122:f9eeca106725 60 */
Kojto 122:f9eeca106725 61
Kojto 122:f9eeca106725 62 /**
Kojto 122:f9eeca106725 63 * @brief SMARTCARD Init Structure definition
Kojto 122:f9eeca106725 64 */
Kojto 122:f9eeca106725 65 typedef struct
Kojto 122:f9eeca106725 66 {
Kojto 122:f9eeca106725 67 uint32_t BaudRate; /*!< This member configures the SmartCard communication baud rate.
Kojto 122:f9eeca106725 68 The baud rate is computed using the following formula:
Kojto 122:f9eeca106725 69 - IntegerDivider = ((PCLKx) / (8 * (hirda->Init.BaudRate)))
Kojto 122:f9eeca106725 70 - FractionalDivider = ((IntegerDivider - ((uint32_t) IntegerDivider)) * 8) + 0.5 */
Kojto 122:f9eeca106725 71
Kojto 122:f9eeca106725 72 uint32_t WordLength; /*!< Specifies the number of data bits transmitted or received in a frame.
Kojto 122:f9eeca106725 73 This parameter can be a value of @ref SMARTCARD_Word_Length */
Kojto 122:f9eeca106725 74
Kojto 122:f9eeca106725 75 uint32_t StopBits; /*!< Specifies the number of stop bits transmitted.
Kojto 122:f9eeca106725 76 This parameter can be a value of @ref SMARTCARD_Stop_Bits */
Kojto 122:f9eeca106725 77
Kojto 122:f9eeca106725 78 uint32_t Parity; /*!< Specifies the parity mode.
Kojto 122:f9eeca106725 79 This parameter can be a value of @ref SMARTCARD_Parity
Kojto 122:f9eeca106725 80 @note When parity is enabled, the computed parity is inserted
Kojto 122:f9eeca106725 81 at the MSB position of the transmitted data (9th bit when
Kojto 122:f9eeca106725 82 the word length is set to 9 data bits; 8th bit when the
Kojto 122:f9eeca106725 83 word length is set to 8 data bits).*/
Kojto 122:f9eeca106725 84
Kojto 122:f9eeca106725 85 uint32_t Mode; /*!< Specifies whether the Receive or Transmit mode is enabled or disabled.
Kojto 122:f9eeca106725 86 This parameter can be a value of @ref SMARTCARD_Mode */
Kojto 122:f9eeca106725 87
Kojto 122:f9eeca106725 88 uint32_t CLKPolarity; /*!< Specifies the steady state of the serial clock.
Kojto 122:f9eeca106725 89 This parameter can be a value of @ref SMARTCARD_Clock_Polarity */
Kojto 122:f9eeca106725 90
Kojto 122:f9eeca106725 91 uint32_t CLKPhase; /*!< Specifies the clock transition on which the bit capture is made.
Kojto 122:f9eeca106725 92 This parameter can be a value of @ref SMARTCARD_Clock_Phase */
Kojto 122:f9eeca106725 93
Kojto 122:f9eeca106725 94 uint32_t CLKLastBit; /*!< Specifies whether the clock pulse corresponding to the last transmitted
Kojto 122:f9eeca106725 95 data bit (MSB) has to be output on the SCLK pin in synchronous mode.
Kojto 122:f9eeca106725 96 This parameter can be a value of @ref SMARTCARD_Last_Bit */
Kojto 122:f9eeca106725 97
Kojto 122:f9eeca106725 98 uint32_t Prescaler; /*!< Specifies the SmartCard Prescaler value used for dividing the system clock
Kojto 122:f9eeca106725 99 to provide the smartcard clock. The value given in the register (5 significant bits)
Kojto 122:f9eeca106725 100 is multiplied by 2 to give the division factor of the source clock frequency.
Kojto 122:f9eeca106725 101 This parameter can be a value of @ref SMARTCARD_Prescaler */
Kojto 122:f9eeca106725 102
Kojto 122:f9eeca106725 103 uint32_t GuardTime; /*!< Specifies the SmartCard Guard Time value in terms of number of baud clocks */
Kojto 122:f9eeca106725 104
Kojto 122:f9eeca106725 105 uint32_t NACKState; /*!< Specifies the SmartCard NACK Transmission state.
Kojto 122:f9eeca106725 106 This parameter can be a value of @ref SMARTCARD_NACK_State */
Kojto 122:f9eeca106725 107 }SMARTCARD_InitTypeDef;
Kojto 122:f9eeca106725 108
Kojto 122:f9eeca106725 109 /**
Kojto 122:f9eeca106725 110 * @brief HAL SMARTCARD State structures definition
Kojto 122:f9eeca106725 111 * @note HAL SMARTCARD State value is a combination of 2 different substates: gState and RxState.
Kojto 122:f9eeca106725 112 * - gState contains SMARTCARD state information related to global Handle management
Kojto 122:f9eeca106725 113 * and also information related to Tx operations.
Kojto 122:f9eeca106725 114 * gState value coding follow below described bitmap :
Kojto 122:f9eeca106725 115 * b7-b6 Error information
Kojto 122:f9eeca106725 116 * 00 : No Error
Kojto 122:f9eeca106725 117 * 01 : (Not Used)
Kojto 122:f9eeca106725 118 * 10 : Timeout
Kojto 122:f9eeca106725 119 * 11 : Error
Kojto 122:f9eeca106725 120 * b5 IP initilisation status
Kojto 122:f9eeca106725 121 * 0 : Reset (IP not initialized)
Kojto 122:f9eeca106725 122 * 1 : Init done (IP not initialized. HAL SMARTCARD Init function already called)
Kojto 122:f9eeca106725 123 * b4-b3 (not used)
Kojto 122:f9eeca106725 124 * xx : Should be set to 00
Kojto 122:f9eeca106725 125 * b2 Intrinsic process state
Kojto 122:f9eeca106725 126 * 0 : Ready
Kojto 122:f9eeca106725 127 * 1 : Busy (IP busy with some configuration or internal operations)
Kojto 122:f9eeca106725 128 * b1 (not used)
Kojto 122:f9eeca106725 129 * x : Should be set to 0
Kojto 122:f9eeca106725 130 * b0 Tx state
Kojto 122:f9eeca106725 131 * 0 : Ready (no Tx operation ongoing)
Kojto 122:f9eeca106725 132 * 1 : Busy (Tx operation ongoing)
Kojto 122:f9eeca106725 133 * - RxState contains information related to Rx operations.
Kojto 122:f9eeca106725 134 * RxState value coding follow below described bitmap :
Kojto 122:f9eeca106725 135 * b7-b6 (not used)
Kojto 122:f9eeca106725 136 * xx : Should be set to 00
Kojto 122:f9eeca106725 137 * b5 IP initilisation status
Kojto 122:f9eeca106725 138 * 0 : Reset (IP not initialized)
Kojto 122:f9eeca106725 139 * 1 : Init done (IP not initialized)
Kojto 122:f9eeca106725 140 * b4-b2 (not used)
Kojto 122:f9eeca106725 141 * xxx : Should be set to 000
Kojto 122:f9eeca106725 142 * b1 Rx state
Kojto 122:f9eeca106725 143 * 0 : Ready (no Rx operation ongoing)
Kojto 122:f9eeca106725 144 * 1 : Busy (Rx operation ongoing)
Kojto 122:f9eeca106725 145 * b0 (not used)
Kojto 122:f9eeca106725 146 * x : Should be set to 0.
Kojto 122:f9eeca106725 147 */
Kojto 122:f9eeca106725 148 typedef enum
Kojto 122:f9eeca106725 149 {
Kojto 122:f9eeca106725 150 HAL_SMARTCARD_STATE_RESET = 0x00U, /*!< Peripheral is not yet Initialized
Kojto 122:f9eeca106725 151 Value is allowed for gState and RxState */
Kojto 122:f9eeca106725 152 HAL_SMARTCARD_STATE_READY = 0x20U, /*!< Peripheral Initialized and ready for use
Kojto 122:f9eeca106725 153 Value is allowed for gState and RxState */
Kojto 122:f9eeca106725 154 HAL_SMARTCARD_STATE_BUSY = 0x24U, /*!< an internal process is ongoing
Kojto 122:f9eeca106725 155 Value is allowed for gState only */
Kojto 122:f9eeca106725 156 HAL_SMARTCARD_STATE_BUSY_TX = 0x21U, /*!< Data Transmission process is ongoing
Kojto 122:f9eeca106725 157 Value is allowed for gState only */
Kojto 122:f9eeca106725 158 HAL_SMARTCARD_STATE_BUSY_RX = 0x22U, /*!< Data Reception process is ongoing
Kojto 122:f9eeca106725 159 Value is allowed for RxState only */
Kojto 122:f9eeca106725 160 HAL_SMARTCARD_STATE_BUSY_TX_RX = 0x23U, /*!< Data Transmission and Reception process is ongoing
Kojto 122:f9eeca106725 161 Not to be used for neither gState nor RxState.
Kojto 122:f9eeca106725 162 Value is result of combination (Or) between gState and RxState values */
Kojto 122:f9eeca106725 163 HAL_SMARTCARD_STATE_TIMEOUT = 0xA0U, /*!< Timeout state
Kojto 122:f9eeca106725 164 Value is allowed for gState only */
Kojto 122:f9eeca106725 165 HAL_SMARTCARD_STATE_ERROR = 0xE0U /*!< Error
Kojto 122:f9eeca106725 166 Value is allowed for gState only */
Kojto 122:f9eeca106725 167 }HAL_SMARTCARD_StateTypeDef;
Kojto 122:f9eeca106725 168
Kojto 122:f9eeca106725 169 /**
Kojto 122:f9eeca106725 170 * @brief SMARTCARD handle Structure definition
Kojto 122:f9eeca106725 171 */
Kojto 122:f9eeca106725 172 typedef struct
Kojto 122:f9eeca106725 173 {
Kojto 122:f9eeca106725 174 USART_TypeDef *Instance; /* USART registers base address */
Kojto 122:f9eeca106725 175
Kojto 122:f9eeca106725 176 SMARTCARD_InitTypeDef Init; /* SmartCard communication parameters */
Kojto 122:f9eeca106725 177
Kojto 122:f9eeca106725 178 uint8_t *pTxBuffPtr; /* Pointer to SmartCard Tx transfer Buffer */
Kojto 122:f9eeca106725 179
Kojto 122:f9eeca106725 180 uint16_t TxXferSize; /* SmartCard Tx Transfer size */
Kojto 122:f9eeca106725 181
AnnaBridge 145:64910690c574 182 __IO uint16_t TxXferCount; /* SmartCard Tx Transfer Counter */
Kojto 122:f9eeca106725 183
Kojto 122:f9eeca106725 184 uint8_t *pRxBuffPtr; /* Pointer to SmartCard Rx transfer Buffer */
Kojto 122:f9eeca106725 185
Kojto 122:f9eeca106725 186 uint16_t RxXferSize; /* SmartCard Rx Transfer size */
Kojto 122:f9eeca106725 187
AnnaBridge 145:64910690c574 188 __IO uint16_t RxXferCount; /* SmartCard Rx Transfer Counter */
Kojto 122:f9eeca106725 189
Kojto 122:f9eeca106725 190 DMA_HandleTypeDef *hdmatx; /* SmartCard Tx DMA Handle parameters */
Kojto 122:f9eeca106725 191
Kojto 122:f9eeca106725 192 DMA_HandleTypeDef *hdmarx; /* SmartCard Rx DMA Handle parameters */
Kojto 122:f9eeca106725 193
Kojto 122:f9eeca106725 194 HAL_LockTypeDef Lock; /* Locking object */
Kojto 122:f9eeca106725 195
Kojto 122:f9eeca106725 196 __IO HAL_SMARTCARD_StateTypeDef gState; /* SmartCard state information related to global Handle management
Kojto 122:f9eeca106725 197 and also related to Tx operations.
Kojto 122:f9eeca106725 198 This parameter can be a value of @ref HAL_SMARTCARD_StateTypeDef */
Kojto 122:f9eeca106725 199
Kojto 122:f9eeca106725 200 __IO HAL_SMARTCARD_StateTypeDef RxState; /* SmartCard state information related to Rx operations.
Kojto 122:f9eeca106725 201 This parameter can be a value of @ref HAL_SMARTCARD_StateTypeDef */
Kojto 122:f9eeca106725 202
Kojto 122:f9eeca106725 203 __IO uint32_t ErrorCode; /* SmartCard Error code */
Kojto 122:f9eeca106725 204
Kojto 122:f9eeca106725 205 }SMARTCARD_HandleTypeDef;
Kojto 122:f9eeca106725 206
Kojto 122:f9eeca106725 207 /**
Kojto 122:f9eeca106725 208 * @}
Kojto 122:f9eeca106725 209 */
Kojto 122:f9eeca106725 210
Kojto 122:f9eeca106725 211 /* Exported constants --------------------------------------------------------*/
Kojto 122:f9eeca106725 212 /** @defgroup SMARTCARD_Exported_Constants SMARTCARD Exported constants
Kojto 122:f9eeca106725 213 * @{
Kojto 122:f9eeca106725 214 */
Kojto 122:f9eeca106725 215 /** @defgroup SMARTCARD_Error_Code SMARTCARD Error Code
Kojto 122:f9eeca106725 216 * @brief SMARTCARD Error Code
Kojto 122:f9eeca106725 217 * @{
Kojto 122:f9eeca106725 218 */
AnnaBridge 145:64910690c574 219 #define HAL_SMARTCARD_ERROR_NONE 0x00000000U /*!< No error */
AnnaBridge 145:64910690c574 220 #define HAL_SMARTCARD_ERROR_PE 0x00000001U /*!< Parity error */
AnnaBridge 145:64910690c574 221 #define HAL_SMARTCARD_ERROR_NE 0x00000002U /*!< Noise error */
AnnaBridge 145:64910690c574 222 #define HAL_SMARTCARD_ERROR_FE 0x00000004U /*!< Frame error */
AnnaBridge 145:64910690c574 223 #define HAL_SMARTCARD_ERROR_ORE 0x00000008U /*!< Overrun error */
AnnaBridge 145:64910690c574 224 #define HAL_SMARTCARD_ERROR_DMA 0x00000010U /*!< DMA transfer error */
Kojto 122:f9eeca106725 225 /**
Kojto 122:f9eeca106725 226 * @}
Kojto 122:f9eeca106725 227 */
Kojto 122:f9eeca106725 228
Kojto 122:f9eeca106725 229 /** @defgroup SMARTCARD_Word_Length SMARTCARD Word Length
Kojto 122:f9eeca106725 230 * @{
Kojto 122:f9eeca106725 231 */
Kojto 122:f9eeca106725 232 #define SMARTCARD_WORDLENGTH_9B ((uint32_t)USART_CR1_M)
Kojto 122:f9eeca106725 233 /**
Kojto 122:f9eeca106725 234 * @}
Kojto 122:f9eeca106725 235 */
Kojto 122:f9eeca106725 236
Kojto 122:f9eeca106725 237 /** @defgroup SMARTCARD_Stop_Bits SMARTCARD Number of Stop Bits
Kojto 122:f9eeca106725 238 * @{
Kojto 122:f9eeca106725 239 */
Kojto 122:f9eeca106725 240 #define SMARTCARD_STOPBITS_0_5 ((uint32_t)USART_CR2_STOP_0)
Kojto 122:f9eeca106725 241 #define SMARTCARD_STOPBITS_1_5 ((uint32_t)(USART_CR2_STOP_0 | USART_CR2_STOP_1))
Kojto 122:f9eeca106725 242 /**
Kojto 122:f9eeca106725 243 * @}
Kojto 122:f9eeca106725 244 */
Kojto 122:f9eeca106725 245
Kojto 122:f9eeca106725 246 /** @defgroup SMARTCARD_Parity SMARTCARD Parity
Kojto 122:f9eeca106725 247 * @{
Kojto 122:f9eeca106725 248 */
Kojto 122:f9eeca106725 249 #define SMARTCARD_PARITY_EVEN ((uint32_t)USART_CR1_PCE)
Kojto 122:f9eeca106725 250 #define SMARTCARD_PARITY_ODD ((uint32_t)(USART_CR1_PCE | USART_CR1_PS))
Kojto 122:f9eeca106725 251 /**
Kojto 122:f9eeca106725 252 * @}
Kojto 122:f9eeca106725 253 */
Kojto 122:f9eeca106725 254
Kojto 122:f9eeca106725 255 /** @defgroup SMARTCARD_Mode SMARTCARD Mode
Kojto 122:f9eeca106725 256 * @{
Kojto 122:f9eeca106725 257 */
Kojto 122:f9eeca106725 258 #define SMARTCARD_MODE_RX ((uint32_t)USART_CR1_RE)
Kojto 122:f9eeca106725 259 #define SMARTCARD_MODE_TX ((uint32_t)USART_CR1_TE)
Kojto 122:f9eeca106725 260 #define SMARTCARD_MODE_TX_RX ((uint32_t)(USART_CR1_TE |USART_CR1_RE))
Kojto 122:f9eeca106725 261 /**
Kojto 122:f9eeca106725 262 * @}
Kojto 122:f9eeca106725 263 */
Kojto 122:f9eeca106725 264
Kojto 122:f9eeca106725 265 /** @defgroup SMARTCARD_Clock_Polarity SMARTCARD Clock Polarity
Kojto 122:f9eeca106725 266 * @{
Kojto 122:f9eeca106725 267 */
AnnaBridge 145:64910690c574 268 #define SMARTCARD_POLARITY_LOW 0x00000000U
Kojto 122:f9eeca106725 269 #define SMARTCARD_POLARITY_HIGH ((uint32_t)USART_CR2_CPOL)
Kojto 122:f9eeca106725 270 /**
Kojto 122:f9eeca106725 271 * @}
Kojto 122:f9eeca106725 272 */
Kojto 122:f9eeca106725 273
Kojto 122:f9eeca106725 274 /** @defgroup SMARTCARD_Clock_Phase SMARTCARD Clock Phase
Kojto 122:f9eeca106725 275 * @{
Kojto 122:f9eeca106725 276 */
AnnaBridge 145:64910690c574 277 #define SMARTCARD_PHASE_1EDGE 0x00000000U
Kojto 122:f9eeca106725 278 #define SMARTCARD_PHASE_2EDGE ((uint32_t)USART_CR2_CPHA)
Kojto 122:f9eeca106725 279 /**
Kojto 122:f9eeca106725 280 * @}
Kojto 122:f9eeca106725 281 */
Kojto 122:f9eeca106725 282
Kojto 122:f9eeca106725 283 /** @defgroup SMARTCARD_Last_Bit SMARTCARD Last Bit
Kojto 122:f9eeca106725 284 * @{
Kojto 122:f9eeca106725 285 */
AnnaBridge 145:64910690c574 286 #define SMARTCARD_LASTBIT_DISABLE 0x00000000U
Kojto 122:f9eeca106725 287 #define SMARTCARD_LASTBIT_ENABLE ((uint32_t)USART_CR2_LBCL)
Kojto 122:f9eeca106725 288 /**
Kojto 122:f9eeca106725 289 * @}
Kojto 122:f9eeca106725 290 */
Kojto 122:f9eeca106725 291
Kojto 122:f9eeca106725 292 /** @defgroup SMARTCARD_NACK_State SMARTCARD NACK State
Kojto 122:f9eeca106725 293 * @{
Kojto 122:f9eeca106725 294 */
Kojto 122:f9eeca106725 295 #define SMARTCARD_NACK_ENABLE ((uint32_t)USART_CR3_NACK)
AnnaBridge 145:64910690c574 296 #define SMARTCARD_NACK_DISABLE 0x00000000U
Kojto 122:f9eeca106725 297 /**
Kojto 122:f9eeca106725 298 * @}
Kojto 122:f9eeca106725 299 */
Kojto 122:f9eeca106725 300
Kojto 122:f9eeca106725 301 /** @defgroup SMARTCARD_DMA_Requests SMARTCARD DMA requests
Kojto 122:f9eeca106725 302 * @{
Kojto 122:f9eeca106725 303 */
Kojto 122:f9eeca106725 304 #define SMARTCARD_DMAREQ_TX ((uint32_t)USART_CR3_DMAT)
Kojto 122:f9eeca106725 305 #define SMARTCARD_DMAREQ_RX ((uint32_t)USART_CR3_DMAR)
Kojto 122:f9eeca106725 306 /**
Kojto 122:f9eeca106725 307 * @}
Kojto 122:f9eeca106725 308 */
Kojto 122:f9eeca106725 309
Kojto 122:f9eeca106725 310 /** @defgroup SMARTCARD_Prescaler SMARTCARD Prescaler
Kojto 122:f9eeca106725 311 * @{
Kojto 122:f9eeca106725 312 */
AnnaBridge 145:64910690c574 313 #define SMARTCARD_PRESCALER_SYSCLK_DIV2 0x00000001U /*!< SYSCLK divided by 2 */
AnnaBridge 145:64910690c574 314 #define SMARTCARD_PRESCALER_SYSCLK_DIV4 0x00000002U /*!< SYSCLK divided by 4 */
AnnaBridge 145:64910690c574 315 #define SMARTCARD_PRESCALER_SYSCLK_DIV6 0x00000003U /*!< SYSCLK divided by 6 */
AnnaBridge 145:64910690c574 316 #define SMARTCARD_PRESCALER_SYSCLK_DIV8 0x00000004U /*!< SYSCLK divided by 8 */
AnnaBridge 145:64910690c574 317 #define SMARTCARD_PRESCALER_SYSCLK_DIV10 0x00000005U /*!< SYSCLK divided by 10 */
AnnaBridge 145:64910690c574 318 #define SMARTCARD_PRESCALER_SYSCLK_DIV12 0x00000006U /*!< SYSCLK divided by 12 */
AnnaBridge 145:64910690c574 319 #define SMARTCARD_PRESCALER_SYSCLK_DIV14 0x00000007U /*!< SYSCLK divided by 14 */
AnnaBridge 145:64910690c574 320 #define SMARTCARD_PRESCALER_SYSCLK_DIV16 0x00000008U /*!< SYSCLK divided by 16 */
AnnaBridge 145:64910690c574 321 #define SMARTCARD_PRESCALER_SYSCLK_DIV18 0x00000009U /*!< SYSCLK divided by 18 */
AnnaBridge 145:64910690c574 322 #define SMARTCARD_PRESCALER_SYSCLK_DIV20 0x0000000AU /*!< SYSCLK divided by 20 */
AnnaBridge 145:64910690c574 323 #define SMARTCARD_PRESCALER_SYSCLK_DIV22 0x0000000BU /*!< SYSCLK divided by 22 */
AnnaBridge 145:64910690c574 324 #define SMARTCARD_PRESCALER_SYSCLK_DIV24 0x0000000CU /*!< SYSCLK divided by 24 */
AnnaBridge 145:64910690c574 325 #define SMARTCARD_PRESCALER_SYSCLK_DIV26 0x0000000DU /*!< SYSCLK divided by 26 */
AnnaBridge 145:64910690c574 326 #define SMARTCARD_PRESCALER_SYSCLK_DIV28 0x0000000EU /*!< SYSCLK divided by 28 */
AnnaBridge 145:64910690c574 327 #define SMARTCARD_PRESCALER_SYSCLK_DIV30 0x0000000FU /*!< SYSCLK divided by 30 */
AnnaBridge 145:64910690c574 328 #define SMARTCARD_PRESCALER_SYSCLK_DIV32 0x00000010U /*!< SYSCLK divided by 32 */
AnnaBridge 145:64910690c574 329 #define SMARTCARD_PRESCALER_SYSCLK_DIV34 0x00000011U /*!< SYSCLK divided by 34 */
AnnaBridge 145:64910690c574 330 #define SMARTCARD_PRESCALER_SYSCLK_DIV36 0x00000012U /*!< SYSCLK divided by 36 */
AnnaBridge 145:64910690c574 331 #define SMARTCARD_PRESCALER_SYSCLK_DIV38 0x00000013U /*!< SYSCLK divided by 38 */
AnnaBridge 145:64910690c574 332 #define SMARTCARD_PRESCALER_SYSCLK_DIV40 0x00000014U /*!< SYSCLK divided by 40 */
AnnaBridge 145:64910690c574 333 #define SMARTCARD_PRESCALER_SYSCLK_DIV42 0x00000015U /*!< SYSCLK divided by 42 */
AnnaBridge 145:64910690c574 334 #define SMARTCARD_PRESCALER_SYSCLK_DIV44 0x00000016U /*!< SYSCLK divided by 44 */
AnnaBridge 145:64910690c574 335 #define SMARTCARD_PRESCALER_SYSCLK_DIV46 0x00000017U /*!< SYSCLK divided by 46 */
AnnaBridge 145:64910690c574 336 #define SMARTCARD_PRESCALER_SYSCLK_DIV48 0x00000018U /*!< SYSCLK divided by 48 */
AnnaBridge 145:64910690c574 337 #define SMARTCARD_PRESCALER_SYSCLK_DIV50 0x00000019U /*!< SYSCLK divided by 50 */
AnnaBridge 145:64910690c574 338 #define SMARTCARD_PRESCALER_SYSCLK_DIV52 0x0000001AU /*!< SYSCLK divided by 52 */
AnnaBridge 145:64910690c574 339 #define SMARTCARD_PRESCALER_SYSCLK_DIV54 0x0000001BU /*!< SYSCLK divided by 54 */
AnnaBridge 145:64910690c574 340 #define SMARTCARD_PRESCALER_SYSCLK_DIV56 0x0000001CU /*!< SYSCLK divided by 56 */
AnnaBridge 145:64910690c574 341 #define SMARTCARD_PRESCALER_SYSCLK_DIV58 0x0000001DU /*!< SYSCLK divided by 58 */
AnnaBridge 145:64910690c574 342 #define SMARTCARD_PRESCALER_SYSCLK_DIV60 0x0000001EU /*!< SYSCLK divided by 60 */
AnnaBridge 145:64910690c574 343 #define SMARTCARD_PRESCALER_SYSCLK_DIV62 0x0000001FU /*!< SYSCLK divided by 62 */
Kojto 122:f9eeca106725 344 /**
Kojto 122:f9eeca106725 345 * @}
Kojto 122:f9eeca106725 346 */
Kojto 122:f9eeca106725 347
Kojto 122:f9eeca106725 348 /** @defgroup SmartCard_Flags SMARTCARD Flags
Kojto 122:f9eeca106725 349 * Elements values convention: 0xXXXX
Kojto 122:f9eeca106725 350 * - 0xXXXX : Flag mask in the SR register
Kojto 122:f9eeca106725 351 * @{
Kojto 122:f9eeca106725 352 */
AnnaBridge 145:64910690c574 353 #define SMARTCARD_FLAG_TXE 0x00000080U
AnnaBridge 145:64910690c574 354 #define SMARTCARD_FLAG_TC 0x00000040U
AnnaBridge 145:64910690c574 355 #define SMARTCARD_FLAG_RXNE 0x00000020U
AnnaBridge 145:64910690c574 356 #define SMARTCARD_FLAG_IDLE 0x00000010U
AnnaBridge 145:64910690c574 357 #define SMARTCARD_FLAG_ORE 0x00000008U
AnnaBridge 145:64910690c574 358 #define SMARTCARD_FLAG_NE 0x00000004U
AnnaBridge 145:64910690c574 359 #define SMARTCARD_FLAG_FE 0x00000002U
AnnaBridge 145:64910690c574 360 #define SMARTCARD_FLAG_PE 0x00000001U
Kojto 122:f9eeca106725 361 /**
Kojto 122:f9eeca106725 362 * @}
Kojto 122:f9eeca106725 363 */
Kojto 122:f9eeca106725 364
Kojto 122:f9eeca106725 365 /** @defgroup SmartCard_Interrupt_definition SMARTCARD Interrupts Definition
Kojto 122:f9eeca106725 366 * Elements values convention: 0xY000XXXX
Kojto 122:f9eeca106725 367 * - XXXX : Interrupt mask in the XX register
Kojto 122:f9eeca106725 368 * - Y : Interrupt source register (2bits)
Kojto 122:f9eeca106725 369 * - 01: CR1 register
Kojto 122:f9eeca106725 370 * - 10: CR3 register
Kojto 122:f9eeca106725 371 * @{
Kojto 122:f9eeca106725 372 */
Kojto 122:f9eeca106725 373 #define SMARTCARD_IT_PE ((uint32_t)(SMARTCARD_CR1_REG_INDEX << 28U | USART_CR1_PEIE))
Kojto 122:f9eeca106725 374 #define SMARTCARD_IT_TXE ((uint32_t)(SMARTCARD_CR1_REG_INDEX << 28U | USART_CR1_TXEIE))
Kojto 122:f9eeca106725 375 #define SMARTCARD_IT_TC ((uint32_t)(SMARTCARD_CR1_REG_INDEX << 28U | USART_CR1_TCIE))
Kojto 122:f9eeca106725 376 #define SMARTCARD_IT_RXNE ((uint32_t)(SMARTCARD_CR1_REG_INDEX << 28U | USART_CR1_RXNEIE))
Kojto 122:f9eeca106725 377 #define SMARTCARD_IT_IDLE ((uint32_t)(SMARTCARD_CR1_REG_INDEX << 28U | USART_CR1_IDLEIE))
Kojto 122:f9eeca106725 378 #define SMARTCARD_IT_ERR ((uint32_t)(SMARTCARD_CR3_REG_INDEX << 28U | USART_CR3_EIE))
Kojto 122:f9eeca106725 379 /**
Kojto 122:f9eeca106725 380 * @}
Kojto 122:f9eeca106725 381 */
Kojto 122:f9eeca106725 382
Kojto 122:f9eeca106725 383 /**
Kojto 122:f9eeca106725 384 * @}
Kojto 122:f9eeca106725 385 */
Kojto 122:f9eeca106725 386
Kojto 122:f9eeca106725 387 /* Exported macro ------------------------------------------------------------*/
Kojto 122:f9eeca106725 388 /** @defgroup SMARTCARD_Exported_Macros SMARTCARD Exported Macros
Kojto 122:f9eeca106725 389 * @{
Kojto 122:f9eeca106725 390 */
Kojto 122:f9eeca106725 391
Kojto 122:f9eeca106725 392 /** @brief Reset SMARTCARD handle gstate & RxState
Kojto 122:f9eeca106725 393 * @param __HANDLE__: specifies the SMARTCARD Handle.
Kojto 122:f9eeca106725 394 * @retval None
Kojto 122:f9eeca106725 395 */
Kojto 122:f9eeca106725 396 #define __HAL_SMARTCARD_RESET_HANDLE_STATE(__HANDLE__) do{ \
Kojto 122:f9eeca106725 397 (__HANDLE__)->gState = HAL_SMARTCARD_STATE_RESET; \
Kojto 122:f9eeca106725 398 (__HANDLE__)->RxState = HAL_SMARTCARD_STATE_RESET; \
AnnaBridge 145:64910690c574 399 } while(0U)
Kojto 122:f9eeca106725 400
Kojto 122:f9eeca106725 401 /** @brief Flushs the Smartcard DR register
Kojto 122:f9eeca106725 402 * @param __HANDLE__: specifies the SMARTCARD Handle.
Kojto 122:f9eeca106725 403 */
Kojto 122:f9eeca106725 404 #define __HAL_SMARTCARD_FLUSH_DRREGISTER(__HANDLE__) ((__HANDLE__)->Instance->DR)
Kojto 122:f9eeca106725 405
Kojto 122:f9eeca106725 406 /** @brief Checks whether the specified Smartcard flag is set or not.
Kojto 122:f9eeca106725 407 * @param __HANDLE__: specifies the SMARTCARD Handle.
Kojto 122:f9eeca106725 408 * @param __FLAG__: specifies the flag to check.
Kojto 122:f9eeca106725 409 * This parameter can be one of the following values:
Kojto 122:f9eeca106725 410 * @arg SMARTCARD_FLAG_TXE: Transmit data register empty flag
Kojto 122:f9eeca106725 411 * @arg SMARTCARD_FLAG_TC: Transmission Complete flag
Kojto 122:f9eeca106725 412 * @arg SMARTCARD_FLAG_RXNE: Receive data register not empty flag
Kojto 122:f9eeca106725 413 * @arg SMARTCARD_FLAG_IDLE: Idle Line detection flag
Kojto 122:f9eeca106725 414 * @arg SMARTCARD_FLAG_ORE: Overrun Error flag
Kojto 122:f9eeca106725 415 * @arg SMARTCARD_FLAG_NE: Noise Error flag
Kojto 122:f9eeca106725 416 * @arg SMARTCARD_FLAG_FE: Framing Error flag
Kojto 122:f9eeca106725 417 * @arg SMARTCARD_FLAG_PE: Parity Error flag
Kojto 122:f9eeca106725 418 * @retval The new state of __FLAG__ (TRUE or FALSE).
Kojto 122:f9eeca106725 419 */
Kojto 122:f9eeca106725 420 #define __HAL_SMARTCARD_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
Kojto 122:f9eeca106725 421
Kojto 122:f9eeca106725 422 /** @brief Clears the specified Smartcard pending flags.
Kojto 122:f9eeca106725 423 * @param __HANDLE__: specifies the SMARTCARD Handle.
Kojto 122:f9eeca106725 424 * @param __FLAG__: specifies the flag to check.
Kojto 122:f9eeca106725 425 * This parameter can be any combination of the following values:
Kojto 122:f9eeca106725 426 * @arg SMARTCARD_FLAG_TC: Transmission Complete flag.
Kojto 122:f9eeca106725 427 * @arg SMARTCARD_FLAG_RXNE: Receive data register not empty flag.
Kojto 122:f9eeca106725 428 *
Kojto 122:f9eeca106725 429 * @note PE (Parity error), FE (Framing error), NE (Noise error) and ORE (Overrun
Kojto 122:f9eeca106725 430 * error) flags are cleared by software sequence: a read operation to
Kojto 122:f9eeca106725 431 * USART_SR register followed by a read operation to USART_DR register.
Kojto 122:f9eeca106725 432 * @note RXNE flag can be also cleared by a read to the USART_DR register.
Kojto 122:f9eeca106725 433 * @note TC flag can be also cleared by software sequence: a read operation to
Kojto 122:f9eeca106725 434 * USART_SR register followed by a write operation to USART_DR register.
Kojto 122:f9eeca106725 435 * @note TXE flag is cleared only by a write to the USART_DR register.
Kojto 122:f9eeca106725 436 */
Kojto 122:f9eeca106725 437 #define __HAL_SMARTCARD_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR = ~(__FLAG__))
Kojto 122:f9eeca106725 438
Kojto 122:f9eeca106725 439 /** @brief Clear the SMARTCARD PE pending flag.
Kojto 122:f9eeca106725 440 * @param __HANDLE__: specifies the USART Handle.
Kojto 122:f9eeca106725 441 * This parameter can be USARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or
Kojto 122:f9eeca106725 442 * SMARTCARD peripheral.
Kojto 122:f9eeca106725 443 * @retval None
Kojto 122:f9eeca106725 444 */
Kojto 122:f9eeca106725 445 #define __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__) \
Kojto 122:f9eeca106725 446 do{ \
Kojto 122:f9eeca106725 447 __IO uint32_t tmpreg = 0x00U; \
Kojto 122:f9eeca106725 448 tmpreg = (__HANDLE__)->Instance->SR; \
Kojto 122:f9eeca106725 449 tmpreg = (__HANDLE__)->Instance->DR; \
Kojto 122:f9eeca106725 450 UNUSED(tmpreg); \
AnnaBridge 145:64910690c574 451 } while(0U)
Kojto 122:f9eeca106725 452
Kojto 122:f9eeca106725 453 /** @brief Clear the SMARTCARD FE pending flag.
Kojto 122:f9eeca106725 454 * @param __HANDLE__: specifies the USART Handle.
Kojto 122:f9eeca106725 455 * This parameter can be USARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or
Kojto 122:f9eeca106725 456 * SMARTCARD peripheral.
Kojto 122:f9eeca106725 457 * @retval None
Kojto 122:f9eeca106725 458 */
Kojto 122:f9eeca106725 459 #define __HAL_SMARTCARD_CLEAR_FEFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__)
Kojto 122:f9eeca106725 460
Kojto 122:f9eeca106725 461 /** @brief Clear the SMARTCARD NE pending flag.
Kojto 122:f9eeca106725 462 * @param __HANDLE__: specifies the USART Handle.
Kojto 122:f9eeca106725 463 * This parameter can be USARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or
Kojto 122:f9eeca106725 464 * SMARTCARD peripheral.
Kojto 122:f9eeca106725 465 * @retval None
Kojto 122:f9eeca106725 466 */
Kojto 122:f9eeca106725 467 #define __HAL_SMARTCARD_CLEAR_NEFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__)
Kojto 122:f9eeca106725 468
Kojto 122:f9eeca106725 469 /** @brief Clear the SMARTCARD ORE pending flag.
Kojto 122:f9eeca106725 470 * @param __HANDLE__: specifies the USART Handle.
Kojto 122:f9eeca106725 471 * This parameter can be USARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or
Kojto 122:f9eeca106725 472 * SMARTCARD peripheral.
Kojto 122:f9eeca106725 473 * @retval None
Kojto 122:f9eeca106725 474 */
Kojto 122:f9eeca106725 475 #define __HAL_SMARTCARD_CLEAR_OREFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__)
Kojto 122:f9eeca106725 476
Kojto 122:f9eeca106725 477 /** @brief Clear the SMARTCARD IDLE pending flag.
Kojto 122:f9eeca106725 478 * @param __HANDLE__: specifies the USART Handle.
Kojto 122:f9eeca106725 479 * This parameter can be USARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or
Kojto 122:f9eeca106725 480 * SMARTCARD peripheral.
Kojto 122:f9eeca106725 481 * @retval None
Kojto 122:f9eeca106725 482 */
Kojto 122:f9eeca106725 483 #define __HAL_SMARTCARD_CLEAR_IDLEFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__)
Kojto 122:f9eeca106725 484
Kojto 122:f9eeca106725 485 /** @brief Enables or disables the specified SmartCard interrupts.
Kojto 122:f9eeca106725 486 * @param __HANDLE__: specifies the SMARTCARD Handle.
Kojto 122:f9eeca106725 487 * @param __INTERRUPT__: specifies the SMARTCARD interrupt source to check.
Kojto 122:f9eeca106725 488 * This parameter can be one of the following values:
Kojto 122:f9eeca106725 489 * @arg SMARTCARD_IT_TXE: Transmit Data Register empty interrupt
Kojto 122:f9eeca106725 490 * @arg SMARTCARD_IT_TC: Transmission complete interrupt
Kojto 122:f9eeca106725 491 * @arg SMARTCARD_IT_RXNE: Receive Data register not empty interrupt
Kojto 122:f9eeca106725 492 * @arg SMARTCARD_IT_IDLE: Idle line detection interrupt
Kojto 122:f9eeca106725 493 * @arg SMARTCARD_IT_PE: Parity Error interrupt
Kojto 122:f9eeca106725 494 * @arg SMARTCARD_IT_ERR: Error interrupt(Frame error, noise error, overrun error)
Kojto 122:f9eeca106725 495 */
Kojto 122:f9eeca106725 496 #define __HAL_SMARTCARD_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28U) == 1U)? ((__HANDLE__)->Instance->CR1 |= ((__INTERRUPT__) & SMARTCARD_IT_MASK)): \
Kojto 122:f9eeca106725 497 ((__HANDLE__)->Instance->CR3 |= ((__INTERRUPT__) & SMARTCARD_IT_MASK)))
Kojto 122:f9eeca106725 498 #define __HAL_SMARTCARD_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28U) == 1U)? ((__HANDLE__)->Instance->CR1 &= ~((__INTERRUPT__) & SMARTCARD_IT_MASK)): \
Kojto 122:f9eeca106725 499 ((__HANDLE__)->Instance->CR3 &= ~ ((__INTERRUPT__) & SMARTCARD_IT_MASK)))
Kojto 122:f9eeca106725 500
Kojto 122:f9eeca106725 501 /** @brief Checks whether the specified SmartCard interrupt has occurred or not.
Kojto 122:f9eeca106725 502 * @param __HANDLE__: specifies the SmartCard Handle.
Kojto 122:f9eeca106725 503 * @param __IT__: specifies the SMARTCARD interrupt source to check.
Kojto 122:f9eeca106725 504 * This parameter can be one of the following values:
Kojto 122:f9eeca106725 505 * @arg SMARTCARD_IT_TXE: Transmit Data Register empty interrupt
Kojto 122:f9eeca106725 506 * @arg SMARTCARD_IT_TC: Transmission complete interrupt
Kojto 122:f9eeca106725 507 * @arg SMARTCARD_IT_RXNE: Receive Data register not empty interrupt
Kojto 122:f9eeca106725 508 * @arg SMARTCARD_IT_IDLE: Idle line detection interrupt
Kojto 122:f9eeca106725 509 * @arg SMARTCARD_IT_ERR: Error interrupt
Kojto 122:f9eeca106725 510 * @arg SMARTCARD_IT_PE: Parity Error interrupt
Kojto 122:f9eeca106725 511 * @retval The new state of __IT__ (TRUE or FALSE).
Kojto 122:f9eeca106725 512 */
Kojto 122:f9eeca106725 513 #define __HAL_SMARTCARD_GET_IT_SOURCE(__HANDLE__, __IT__) (((((__IT__) >> 28U) == 1U)? (__HANDLE__)->Instance->CR1: (__HANDLE__)->Instance->CR3) & (((uint32_t)(__IT__)) & SMARTCARD_IT_MASK))
Kojto 122:f9eeca106725 514
Kojto 122:f9eeca106725 515 /** @brief Macro to enable the SMARTCARD's one bit sample method
Kojto 122:f9eeca106725 516 * @param __HANDLE__: specifies the SMARTCARD Handle.
Kojto 122:f9eeca106725 517 * @retval None
Kojto 122:f9eeca106725 518 */
Kojto 122:f9eeca106725 519 #define __HAL_SMARTCARD_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT)
Kojto 122:f9eeca106725 520
Kojto 122:f9eeca106725 521 /** @brief Macro to disable the SMARTCARD's one bit sample method
Kojto 122:f9eeca106725 522 * @param __HANDLE__: specifies the SMARTCARD Handle.
Kojto 122:f9eeca106725 523 * @retval None
Kojto 122:f9eeca106725 524 */
Kojto 122:f9eeca106725 525 #define __HAL_SMARTCARD_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 &= (uint16_t)~((uint16_t)USART_CR3_ONEBIT))
Kojto 122:f9eeca106725 526
Kojto 122:f9eeca106725 527 /** @brief Enable the USART associated to the SMARTCARD Handle
Kojto 122:f9eeca106725 528 * @param __HANDLE__: specifies the SMARTCARD Handle.
Kojto 122:f9eeca106725 529 * SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device).
Kojto 122:f9eeca106725 530 * @retval None
Kojto 122:f9eeca106725 531 */
Kojto 122:f9eeca106725 532 #define __HAL_SMARTCARD_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= USART_CR1_UE)
Kojto 122:f9eeca106725 533
Kojto 122:f9eeca106725 534 /** @brief Disable the USART associated to the SMARTCARD Handle
Kojto 122:f9eeca106725 535 * @param __HANDLE__: specifies the SMARTCARD Handle.
Kojto 122:f9eeca106725 536 * SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device).
Kojto 122:f9eeca106725 537 * @retval None
Kojto 122:f9eeca106725 538 */
Kojto 122:f9eeca106725 539 #define __HAL_SMARTCARD_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~USART_CR1_UE)
Kojto 122:f9eeca106725 540
Kojto 122:f9eeca106725 541 /** @brief Macros to enable or disable the SmartCard DMA request.
Kojto 122:f9eeca106725 542 * @param __HANDLE__: specifies the SmartCard Handle.
Kojto 122:f9eeca106725 543 * @param __REQUEST__: specifies the SmartCard DMA request.
Kojto 122:f9eeca106725 544 * This parameter can be one of the following values:
Kojto 122:f9eeca106725 545 * @arg SMARTCARD_DMAREQ_TX: SmartCard DMA transmit request
Kojto 122:f9eeca106725 546 * @arg SMARTCARD_DMAREQ_RX: SmartCard DMA receive request
Kojto 122:f9eeca106725 547 */
Kojto 122:f9eeca106725 548 #define __HAL_SMARTCARD_DMA_REQUEST_ENABLE(__HANDLE__, __REQUEST__) ((__HANDLE__)->Instance->CR3 |= (__REQUEST__))
Kojto 122:f9eeca106725 549 #define __HAL_SMARTCARD_DMA_REQUEST_DISABLE(__HANDLE__, __REQUEST__) ((__HANDLE__)->Instance->CR3 &= ~(__REQUEST__))
Kojto 122:f9eeca106725 550
Kojto 122:f9eeca106725 551 /**
Kojto 122:f9eeca106725 552 * @}
Kojto 122:f9eeca106725 553 */
Kojto 122:f9eeca106725 554
Kojto 122:f9eeca106725 555 /* Exported functions --------------------------------------------------------*/
Kojto 122:f9eeca106725 556 /** @addtogroup SMARTCARD_Exported_Functions
Kojto 122:f9eeca106725 557 * @{
Kojto 122:f9eeca106725 558 */
Kojto 122:f9eeca106725 559
Kojto 122:f9eeca106725 560 /** @addtogroup SMARTCARD_Exported_Functions_Group1
Kojto 122:f9eeca106725 561 * @{
Kojto 122:f9eeca106725 562 */
Kojto 122:f9eeca106725 563 /* Initialization/de-initialization functions **********************************/
Kojto 122:f9eeca106725 564 HAL_StatusTypeDef HAL_SMARTCARD_Init(SMARTCARD_HandleTypeDef *hsc);
Kojto 122:f9eeca106725 565 HAL_StatusTypeDef HAL_SMARTCARD_ReInit(SMARTCARD_HandleTypeDef *hsc);
Kojto 122:f9eeca106725 566 HAL_StatusTypeDef HAL_SMARTCARD_DeInit(SMARTCARD_HandleTypeDef *hsc);
Kojto 122:f9eeca106725 567 void HAL_SMARTCARD_MspInit(SMARTCARD_HandleTypeDef *hsc);
Kojto 122:f9eeca106725 568 void HAL_SMARTCARD_MspDeInit(SMARTCARD_HandleTypeDef *hsc);
Kojto 122:f9eeca106725 569 /**
Kojto 122:f9eeca106725 570 * @}
Kojto 122:f9eeca106725 571 */
Kojto 122:f9eeca106725 572
Kojto 122:f9eeca106725 573 /** @addtogroup SMARTCARD_Exported_Functions_Group2
Kojto 122:f9eeca106725 574 * @{
Kojto 122:f9eeca106725 575 */
Kojto 122:f9eeca106725 576 /* IO operation functions *******************************************************/
Kojto 122:f9eeca106725 577 HAL_StatusTypeDef HAL_SMARTCARD_Transmit(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size, uint32_t Timeout);
Kojto 122:f9eeca106725 578 HAL_StatusTypeDef HAL_SMARTCARD_Receive(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size, uint32_t Timeout);
Kojto 122:f9eeca106725 579 HAL_StatusTypeDef HAL_SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size);
Kojto 122:f9eeca106725 580 HAL_StatusTypeDef HAL_SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size);
Kojto 122:f9eeca106725 581 HAL_StatusTypeDef HAL_SMARTCARD_Transmit_DMA(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size);
Kojto 122:f9eeca106725 582 HAL_StatusTypeDef HAL_SMARTCARD_Receive_DMA(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size);
AnnaBridge 145:64910690c574 583 /* Transfer Abort functions */
AnnaBridge 145:64910690c574 584 HAL_StatusTypeDef HAL_SMARTCARD_Abort(SMARTCARD_HandleTypeDef *hsc);
AnnaBridge 145:64910690c574 585 HAL_StatusTypeDef HAL_SMARTCARD_AbortTransmit(SMARTCARD_HandleTypeDef *hsc);
AnnaBridge 145:64910690c574 586 HAL_StatusTypeDef HAL_SMARTCARD_AbortReceive(SMARTCARD_HandleTypeDef *hsc);
AnnaBridge 145:64910690c574 587 HAL_StatusTypeDef HAL_SMARTCARD_Abort_IT(SMARTCARD_HandleTypeDef *hsc);
AnnaBridge 145:64910690c574 588 HAL_StatusTypeDef HAL_SMARTCARD_AbortTransmit_IT(SMARTCARD_HandleTypeDef *hsc);
AnnaBridge 145:64910690c574 589 HAL_StatusTypeDef HAL_SMARTCARD_AbortReceive_IT(SMARTCARD_HandleTypeDef *hsc);
Kojto 122:f9eeca106725 590
Kojto 122:f9eeca106725 591 void HAL_SMARTCARD_IRQHandler(SMARTCARD_HandleTypeDef *hsc);
Kojto 122:f9eeca106725 592 void HAL_SMARTCARD_TxCpltCallback(SMARTCARD_HandleTypeDef *hsc);
Kojto 122:f9eeca106725 593 void HAL_SMARTCARD_RxCpltCallback(SMARTCARD_HandleTypeDef *hsc);
Kojto 122:f9eeca106725 594 void HAL_SMARTCARD_ErrorCallback(SMARTCARD_HandleTypeDef *hsc);
AnnaBridge 145:64910690c574 595 void HAL_SMARTCARD_AbortCpltCallback(SMARTCARD_HandleTypeDef *hsc);
AnnaBridge 145:64910690c574 596 void HAL_SMARTCARD_AbortTransmitCpltCallback(SMARTCARD_HandleTypeDef *hsc);
AnnaBridge 145:64910690c574 597 void HAL_SMARTCARD_AbortReceiveCpltCallback(SMARTCARD_HandleTypeDef *hsc);
Kojto 122:f9eeca106725 598 /**
Kojto 122:f9eeca106725 599 * @}
Kojto 122:f9eeca106725 600 */
Kojto 122:f9eeca106725 601
Kojto 122:f9eeca106725 602 /** @addtogroup SMARTCARD_Exported_Functions_Group3
Kojto 122:f9eeca106725 603 * @{
Kojto 122:f9eeca106725 604 */
Kojto 122:f9eeca106725 605 /* Peripheral State functions **************************************************/
Kojto 122:f9eeca106725 606 HAL_SMARTCARD_StateTypeDef HAL_SMARTCARD_GetState(SMARTCARD_HandleTypeDef *hsc);
Kojto 122:f9eeca106725 607 uint32_t HAL_SMARTCARD_GetError(SMARTCARD_HandleTypeDef *hsc);
Kojto 122:f9eeca106725 608
Kojto 122:f9eeca106725 609 /**
Kojto 122:f9eeca106725 610 * @}
Kojto 122:f9eeca106725 611 */
Kojto 122:f9eeca106725 612
Kojto 122:f9eeca106725 613 /**
Kojto 122:f9eeca106725 614 * @}
Kojto 122:f9eeca106725 615 */
Kojto 122:f9eeca106725 616 /* Private types -------------------------------------------------------------*/
Kojto 122:f9eeca106725 617 /* Private variables ---------------------------------------------------------*/
Kojto 122:f9eeca106725 618 /* Private constants ---------------------------------------------------------*/
Kojto 122:f9eeca106725 619 /** @defgroup SMARTCARD_Private_Constants SMARTCARD Private Constants
Kojto 122:f9eeca106725 620 * @{
Kojto 122:f9eeca106725 621 */
Kojto 122:f9eeca106725 622
Kojto 122:f9eeca106725 623 /** @brief SMARTCARD interruptions flag mask
Kojto 122:f9eeca106725 624 *
Kojto 122:f9eeca106725 625 */
Kojto 122:f9eeca106725 626 #define SMARTCARD_IT_MASK ((uint32_t) USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE | USART_CR1_RXNEIE | \
Kojto 122:f9eeca106725 627 USART_CR1_IDLEIE | USART_CR3_EIE )
Kojto 122:f9eeca106725 628
Kojto 122:f9eeca106725 629 #define SMARTCARD_DIV(_PCLK_, _BAUD_) (((_PCLK_)*25U)/(4U*(_BAUD_)))
Kojto 122:f9eeca106725 630 #define SMARTCARD_DIVMANT(_PCLK_, _BAUD_) (SMARTCARD_DIV((_PCLK_), (_BAUD_))/100U)
Kojto 122:f9eeca106725 631 #define SMARTCARD_DIVFRAQ(_PCLK_, _BAUD_) (((SMARTCARD_DIV((_PCLK_), (_BAUD_)) - (SMARTCARD_DIVMANT((_PCLK_), (_BAUD_)) * 100U)) * 16U + 50U) / 100U)
Kojto 122:f9eeca106725 632 /* SMARTCARD BRR = mantissa + overflow + fraction
Kojto 122:f9eeca106725 633 = (SMARTCARD DIVMANT << 4) + (SMARTCARD DIVFRAQ & 0xF0) + (SMARTCARD DIVFRAQ & 0x0FU) */
Kojto 122:f9eeca106725 634 #define SMARTCARD_BRR(_PCLK_, _BAUD_) (((SMARTCARD_DIVMANT((_PCLK_), (_BAUD_)) << 4U) + \
Kojto 122:f9eeca106725 635 (SMARTCARD_DIVFRAQ((_PCLK_), (_BAUD_)) & 0xF0U)) + \
Kojto 122:f9eeca106725 636 (SMARTCARD_DIVFRAQ((_PCLK_), (_BAUD_)) & 0x0FU))
Kojto 122:f9eeca106725 637
Kojto 122:f9eeca106725 638 #define SMARTCARD_CR1_REG_INDEX 1U
Kojto 122:f9eeca106725 639 #define SMARTCARD_CR3_REG_INDEX 3U
Kojto 122:f9eeca106725 640 /**
Kojto 122:f9eeca106725 641 * @}
Kojto 122:f9eeca106725 642 */
Kojto 122:f9eeca106725 643
Kojto 122:f9eeca106725 644 /* Private macros --------------------------------------------------------*/
Kojto 122:f9eeca106725 645 /** @defgroup SMARTCARD_Private_Macros SMARTCARD Private Macros
Kojto 122:f9eeca106725 646 * @{
Kojto 122:f9eeca106725 647 */
Kojto 122:f9eeca106725 648 #define IS_SMARTCARD_WORD_LENGTH(LENGTH) ((LENGTH) == SMARTCARD_WORDLENGTH_9B)
Kojto 122:f9eeca106725 649 #define IS_SMARTCARD_STOPBITS(STOPBITS) (((STOPBITS) == SMARTCARD_STOPBITS_0_5) || \
Kojto 122:f9eeca106725 650 ((STOPBITS) == SMARTCARD_STOPBITS_1_5))
Kojto 122:f9eeca106725 651 #define IS_SMARTCARD_PARITY(PARITY) (((PARITY) == SMARTCARD_PARITY_EVEN) || \
Kojto 122:f9eeca106725 652 ((PARITY) == SMARTCARD_PARITY_ODD))
AnnaBridge 145:64910690c574 653 #define IS_SMARTCARD_MODE(MODE) ((((MODE) & 0x0000FFF3U) == 0x00U) && ((MODE) != 0x000000U))
Kojto 122:f9eeca106725 654 #define IS_SMARTCARD_POLARITY(CPOL) (((CPOL) == SMARTCARD_POLARITY_LOW) || ((CPOL) == SMARTCARD_POLARITY_HIGH))
Kojto 122:f9eeca106725 655 #define IS_SMARTCARD_PHASE(CPHA) (((CPHA) == SMARTCARD_PHASE_1EDGE) || ((CPHA) == SMARTCARD_PHASE_2EDGE))
Kojto 122:f9eeca106725 656 #define IS_SMARTCARD_LASTBIT(LASTBIT) (((LASTBIT) == SMARTCARD_LASTBIT_DISABLE) || \
Kojto 122:f9eeca106725 657 ((LASTBIT) == SMARTCARD_LASTBIT_ENABLE))
Kojto 122:f9eeca106725 658 #define IS_SMARTCARD_NACK_STATE(NACK) (((NACK) == SMARTCARD_NACK_ENABLE) || \
Kojto 122:f9eeca106725 659 ((NACK) == SMARTCARD_NACK_DISABLE))
Kojto 122:f9eeca106725 660 #define IS_SMARTCARD_BAUDRATE(BAUDRATE) ((BAUDRATE) < 10500001U)
Kojto 122:f9eeca106725 661 /**
Kojto 122:f9eeca106725 662 * @}
Kojto 122:f9eeca106725 663 */
Kojto 122:f9eeca106725 664
Kojto 122:f9eeca106725 665 /* Private functions ---------------------------------------------------------*/
Kojto 122:f9eeca106725 666 /** @defgroup SMARTCARD_Private_Functions SMARTCARD Private Functions
Kojto 122:f9eeca106725 667 * @{
Kojto 122:f9eeca106725 668 */
Kojto 122:f9eeca106725 669
Kojto 122:f9eeca106725 670 /**
Kojto 122:f9eeca106725 671 * @}
Kojto 122:f9eeca106725 672 */
Kojto 122:f9eeca106725 673
Kojto 122:f9eeca106725 674 /**
Kojto 122:f9eeca106725 675 * @}
Kojto 122:f9eeca106725 676 */
Kojto 122:f9eeca106725 677
Kojto 122:f9eeca106725 678 /**
Kojto 122:f9eeca106725 679 * @}
Kojto 122:f9eeca106725 680 */
Kojto 122:f9eeca106725 681 #ifdef __cplusplus
Kojto 122:f9eeca106725 682 }
Kojto 122:f9eeca106725 683 #endif
Kojto 122:f9eeca106725 684
Kojto 122:f9eeca106725 685 #endif /* __STM32F4xx_HAL_SMARTCARD_H */
Kojto 122:f9eeca106725 686
Kojto 122:f9eeca106725 687 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/