cc y / mbed

Fork of mbed by mbed official

Committer:
Kojto
Date:
Thu Jul 07 14:34:11 2016 +0100
Revision:
122:f9eeca106725
Parent:
110:165afa46840b
Release 122 of the mbed library

Changes:
- new targets - Nucleo L432KC, Beetle, Nucleo F446ZE, Nucleo L011K4
- Thread safety addition - mbed API should contain a statement about thread safety
- critical section API addition
- CAS API (core_util_atomic_incr/decr)
- DEVICE_ are generated from targets.json file, device.h deprecated
- Callback replaces FunctionPointer to provide std like interface
- mbed HAL API docs improvements
- toolchain - prexif attributes with MBED_
- add new attributes - packed, weak, forcedinline, align
- target.json - contains targets definitions
- ST - L1XX - Cube update to 1.5
- SPI clock selection fix (clock from APB domain)
- F7 - Cube update v1.4.0
- L0 - baudrate init fix
- L1 - Cube update v1.5
- F3 - baudrate init fix, 3 targets CAN support
- F4 - Cube update v1.12.0, 3 targets CAN support
- L4XX - Cube update v1.5.1
- F0 - update Cube to v1.5.0
- L4 - 2 targets (L476RG/VG) CAN support
- NXP - pwm clock fix for KSDK2 MCU
- LPC2368 - remove ARM toolchain support - due to regression
- KSDK2 - fix SPI , I2C address and repeat start
- Silabs - some fixes backported from mbed 3
- Renesas - RZ_A1H - SystemCoreClockUpdate addition

Who changed what in which revision?

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