Go to the documentation of this file.
21 #ifndef __STM32F4xx_HAL_SMARTCARD_H
22 #define __STM32F4xx_HAL_SMARTCARD_H
187 #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
207 #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
213 HAL_SMARTCARD_TX_COMPLETE_CB_ID = 0x00U,
214 HAL_SMARTCARD_RX_COMPLETE_CB_ID = 0x01U,
215 HAL_SMARTCARD_ERROR_CB_ID = 0x02U,
216 HAL_SMARTCARD_ABORT_COMPLETE_CB_ID = 0x03U,
217 HAL_SMARTCARD_ABORT_TRANSMIT_COMPLETE_CB_ID = 0x04U,
218 HAL_SMARTCARD_ABORT_RECEIVE_COMPLETE_CB_ID = 0x05U,
220 HAL_SMARTCARD_MSPINIT_CB_ID = 0x08U,
221 HAL_SMARTCARD_MSPDEINIT_CB_ID = 0x09U
223 } HAL_SMARTCARD_CallbackIDTypeDef;
244 #define HAL_SMARTCARD_ERROR_NONE 0x00000000U
245 #define HAL_SMARTCARD_ERROR_PE 0x00000001U
246 #define HAL_SMARTCARD_ERROR_NE 0x00000002U
247 #define HAL_SMARTCARD_ERROR_FE 0x00000004U
248 #define HAL_SMARTCARD_ERROR_ORE 0x00000008U
249 #define HAL_SMARTCARD_ERROR_DMA 0x00000010U
250 #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
251 #define HAL_SMARTCARD_ERROR_INVALID_CALLBACK 0x00000020U
260 #define SMARTCARD_WORDLENGTH_9B ((uint32_t)USART_CR1_M)
268 #define SMARTCARD_STOPBITS_0_5 ((uint32_t)USART_CR2_STOP_0)
269 #define SMARTCARD_STOPBITS_1_5 ((uint32_t)(USART_CR2_STOP_0 | USART_CR2_STOP_1))
277 #define SMARTCARD_PARITY_EVEN ((uint32_t)USART_CR1_PCE)
278 #define SMARTCARD_PARITY_ODD ((uint32_t)(USART_CR1_PCE | USART_CR1_PS))
286 #define SMARTCARD_MODE_RX ((uint32_t)USART_CR1_RE)
287 #define SMARTCARD_MODE_TX ((uint32_t)USART_CR1_TE)
288 #define SMARTCARD_MODE_TX_RX ((uint32_t)(USART_CR1_TE |USART_CR1_RE))
296 #define SMARTCARD_POLARITY_LOW 0x00000000U
297 #define SMARTCARD_POLARITY_HIGH ((uint32_t)USART_CR2_CPOL)
305 #define SMARTCARD_PHASE_1EDGE 0x00000000U
306 #define SMARTCARD_PHASE_2EDGE ((uint32_t)USART_CR2_CPHA)
314 #define SMARTCARD_LASTBIT_DISABLE 0x00000000U
315 #define SMARTCARD_LASTBIT_ENABLE ((uint32_t)USART_CR2_LBCL)
323 #define SMARTCARD_NACK_ENABLE ((uint32_t)USART_CR3_NACK)
324 #define SMARTCARD_NACK_DISABLE 0x00000000U
332 #define SMARTCARD_DMAREQ_TX ((uint32_t)USART_CR3_DMAT)
333 #define SMARTCARD_DMAREQ_RX ((uint32_t)USART_CR3_DMAR)
341 #define SMARTCARD_PRESCALER_SYSCLK_DIV2 0x00000001U
342 #define SMARTCARD_PRESCALER_SYSCLK_DIV4 0x00000002U
343 #define SMARTCARD_PRESCALER_SYSCLK_DIV6 0x00000003U
344 #define SMARTCARD_PRESCALER_SYSCLK_DIV8 0x00000004U
345 #define SMARTCARD_PRESCALER_SYSCLK_DIV10 0x00000005U
346 #define SMARTCARD_PRESCALER_SYSCLK_DIV12 0x00000006U
347 #define SMARTCARD_PRESCALER_SYSCLK_DIV14 0x00000007U
348 #define SMARTCARD_PRESCALER_SYSCLK_DIV16 0x00000008U
349 #define SMARTCARD_PRESCALER_SYSCLK_DIV18 0x00000009U
350 #define SMARTCARD_PRESCALER_SYSCLK_DIV20 0x0000000AU
351 #define SMARTCARD_PRESCALER_SYSCLK_DIV22 0x0000000BU
352 #define SMARTCARD_PRESCALER_SYSCLK_DIV24 0x0000000CU
353 #define SMARTCARD_PRESCALER_SYSCLK_DIV26 0x0000000DU
354 #define SMARTCARD_PRESCALER_SYSCLK_DIV28 0x0000000EU
355 #define SMARTCARD_PRESCALER_SYSCLK_DIV30 0x0000000FU
356 #define SMARTCARD_PRESCALER_SYSCLK_DIV32 0x00000010U
357 #define SMARTCARD_PRESCALER_SYSCLK_DIV34 0x00000011U
358 #define SMARTCARD_PRESCALER_SYSCLK_DIV36 0x00000012U
359 #define SMARTCARD_PRESCALER_SYSCLK_DIV38 0x00000013U
360 #define SMARTCARD_PRESCALER_SYSCLK_DIV40 0x00000014U
361 #define SMARTCARD_PRESCALER_SYSCLK_DIV42 0x00000015U
362 #define SMARTCARD_PRESCALER_SYSCLK_DIV44 0x00000016U
363 #define SMARTCARD_PRESCALER_SYSCLK_DIV46 0x00000017U
364 #define SMARTCARD_PRESCALER_SYSCLK_DIV48 0x00000018U
365 #define SMARTCARD_PRESCALER_SYSCLK_DIV50 0x00000019U
366 #define SMARTCARD_PRESCALER_SYSCLK_DIV52 0x0000001AU
367 #define SMARTCARD_PRESCALER_SYSCLK_DIV54 0x0000001BU
368 #define SMARTCARD_PRESCALER_SYSCLK_DIV56 0x0000001CU
369 #define SMARTCARD_PRESCALER_SYSCLK_DIV58 0x0000001DU
370 #define SMARTCARD_PRESCALER_SYSCLK_DIV60 0x0000001EU
371 #define SMARTCARD_PRESCALER_SYSCLK_DIV62 0x0000001FU
381 #define SMARTCARD_FLAG_TXE ((uint32_t)USART_SR_TXE)
382 #define SMARTCARD_FLAG_TC ((uint32_t)USART_SR_TC)
383 #define SMARTCARD_FLAG_RXNE ((uint32_t)USART_SR_RXNE)
384 #define SMARTCARD_FLAG_IDLE ((uint32_t)USART_SR_IDLE)
385 #define SMARTCARD_FLAG_ORE ((uint32_t)USART_SR_ORE)
386 #define SMARTCARD_FLAG_NE ((uint32_t)USART_SR_NE)
387 #define SMARTCARD_FLAG_FE ((uint32_t)USART_SR_FE)
388 #define SMARTCARD_FLAG_PE ((uint32_t)USART_SR_PE)
401 #define SMARTCARD_IT_PE ((uint32_t)(SMARTCARD_CR1_REG_INDEX << 28U | USART_CR1_PEIE))
402 #define SMARTCARD_IT_TXE ((uint32_t)(SMARTCARD_CR1_REG_INDEX << 28U | USART_CR1_TXEIE))
403 #define SMARTCARD_IT_TC ((uint32_t)(SMARTCARD_CR1_REG_INDEX << 28U | USART_CR1_TCIE))
404 #define SMARTCARD_IT_RXNE ((uint32_t)(SMARTCARD_CR1_REG_INDEX << 28U | USART_CR1_RXNEIE))
405 #define SMARTCARD_IT_IDLE ((uint32_t)(SMARTCARD_CR1_REG_INDEX << 28U | USART_CR1_IDLEIE))
406 #define SMARTCARD_IT_ERR ((uint32_t)(SMARTCARD_CR3_REG_INDEX << 28U | USART_CR3_EIE))
425 #if USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1
426 #define __HAL_SMARTCARD_RESET_HANDLE_STATE(__HANDLE__) do{ \
427 (__HANDLE__)->gState = HAL_SMARTCARD_STATE_RESET; \
428 (__HANDLE__)->RxState = HAL_SMARTCARD_STATE_RESET; \
429 (__HANDLE__)->MspInitCallback = NULL; \
430 (__HANDLE__)->MspDeInitCallback = NULL; \
433 #define __HAL_SMARTCARD_RESET_HANDLE_STATE(__HANDLE__) do{ \
434 (__HANDLE__)->gState = HAL_SMARTCARD_STATE_RESET; \
435 (__HANDLE__)->RxState = HAL_SMARTCARD_STATE_RESET; \
444 #define __HAL_SMARTCARD_FLUSH_DRREGISTER(__HANDLE__) ((__HANDLE__)->Instance->DR)
461 #define __HAL_SMARTCARD_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
480 #define __HAL_SMARTCARD_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR = ~(__FLAG__))
487 #define __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__) \
489 __IO uint32_t tmpreg = 0x00U; \
490 tmpreg = (__HANDLE__)->Instance->SR; \
491 tmpreg = (__HANDLE__)->Instance->DR; \
500 #define __HAL_SMARTCARD_CLEAR_FEFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__)
507 #define __HAL_SMARTCARD_CLEAR_NEFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__)
514 #define __HAL_SMARTCARD_CLEAR_OREFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__)
521 #define __HAL_SMARTCARD_CLEAR_IDLEFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__)
536 #define __HAL_SMARTCARD_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28U) == SMARTCARD_CR1_REG_INDEX)? ((__HANDLE__)->Instance->CR1 |= ((__INTERRUPT__) & SMARTCARD_IT_MASK)): \
537 ((__HANDLE__)->Instance->CR3 |= ((__INTERRUPT__) & SMARTCARD_IT_MASK)))
552 #define __HAL_SMARTCARD_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28U) == SMARTCARD_CR1_REG_INDEX)? ((__HANDLE__)->Instance->CR1 &= ~((__INTERRUPT__) & SMARTCARD_IT_MASK)): \
553 ((__HANDLE__)->Instance->CR3 &= ~ ((__INTERRUPT__) & SMARTCARD_IT_MASK)))
567 #define __HAL_SMARTCARD_GET_IT_SOURCE(__HANDLE__, __IT__) (((((__IT__) >> 28U) == SMARTCARD_CR1_REG_INDEX)? (__HANDLE__)->Instance->CR1: (__HANDLE__)->Instance->CR3) & (((uint32_t)(__IT__)) & SMARTCARD_IT_MASK))
573 #define __HAL_SMARTCARD_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT)
579 #define __HAL_SMARTCARD_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 &= (uint16_t)~((uint16_t)USART_CR3_ONEBIT))
586 #define __HAL_SMARTCARD_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= USART_CR1_UE)
593 #define __HAL_SMARTCARD_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~USART_CR1_UE)
603 #define __HAL_SMARTCARD_DMA_REQUEST_ENABLE(__HANDLE__, __REQUEST__) ((__HANDLE__)->Instance->CR3 |= (__REQUEST__))
613 #define __HAL_SMARTCARD_DMA_REQUEST_DISABLE(__HANDLE__, __REQUEST__) ((__HANDLE__)->Instance->CR3 &= ~(__REQUEST__))
633 #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
694 #define SMARTCARD_IT_MASK ((uint32_t) USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE | USART_CR1_RXNEIE | \
695 USART_CR1_IDLEIE | USART_CR3_EIE )
697 #define SMARTCARD_CR1_REG_INDEX 1U
698 #define SMARTCARD_CR3_REG_INDEX 3U
707 #define IS_SMARTCARD_WORD_LENGTH(LENGTH) ((LENGTH) == SMARTCARD_WORDLENGTH_9B)
708 #define IS_SMARTCARD_STOPBITS(STOPBITS) (((STOPBITS) == SMARTCARD_STOPBITS_0_5) || \
709 ((STOPBITS) == SMARTCARD_STOPBITS_1_5))
710 #define IS_SMARTCARD_PARITY(PARITY) (((PARITY) == SMARTCARD_PARITY_EVEN) || \
711 ((PARITY) == SMARTCARD_PARITY_ODD))
712 #define IS_SMARTCARD_MODE(MODE) ((((MODE) & 0x0000FFF3U) == 0x00U) && ((MODE) != 0x000000U))
713 #define IS_SMARTCARD_POLARITY(CPOL) (((CPOL) == SMARTCARD_POLARITY_LOW) || ((CPOL) == SMARTCARD_POLARITY_HIGH))
714 #define IS_SMARTCARD_PHASE(CPHA) (((CPHA) == SMARTCARD_PHASE_1EDGE) || ((CPHA) == SMARTCARD_PHASE_2EDGE))
715 #define IS_SMARTCARD_LASTBIT(LASTBIT) (((LASTBIT) == SMARTCARD_LASTBIT_DISABLE) || \
716 ((LASTBIT) == SMARTCARD_LASTBIT_ENABLE))
717 #define IS_SMARTCARD_NACK_STATE(NACK) (((NACK) == SMARTCARD_NACK_ENABLE) || \
718 ((NACK) == SMARTCARD_NACK_DISABLE))
719 #define IS_SMARTCARD_BAUDRATE(BAUDRATE) ((BAUDRATE) < 10500001U)
721 #define SMARTCARD_DIV(__PCLK__, __BAUD__) ((uint32_t)((((uint64_t)(__PCLK__))*25U)/(4U*((uint64_t)(__BAUD__)))))
722 #define SMARTCARD_DIVMANT(__PCLK__, __BAUD__) (SMARTCARD_DIV((__PCLK__), (__BAUD__))/100U)
723 #define SMARTCARD_DIVFRAQ(__PCLK__, __BAUD__) ((((SMARTCARD_DIV((__PCLK__), (__BAUD__)) - (SMARTCARD_DIVMANT((__PCLK__), (__BAUD__)) * 100U)) * 16U) + 50U) / 100U)
726 #define SMARTCARD_BRR(__PCLK__, __BAUD__) (((SMARTCARD_DIVMANT((__PCLK__), (__BAUD__)) << 4U) + \
727 (SMARTCARD_DIVFRAQ((__PCLK__), (__BAUD__)) & 0xF0U)) + \
728 (SMARTCARD_DIVFRAQ((__PCLK__), (__BAUD__)) & 0x0FU))
__IO uint16_t RxXferCount
__IO HAL_SMARTCARD_StateTypeDef gState
@ HAL_SMARTCARD_STATE_BUSY_TX_RX
HAL_StatusTypeDef
HAL Status structures definition
Universal Synchronous Asynchronous Receiver Transmitter.
HAL_StatusTypeDef HAL_SMARTCARD_Transmit(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size, uint32_t Timeout)
DMA handle Structure definition.
void HAL_SMARTCARD_AbortReceiveCpltCallback(SMARTCARD_HandleTypeDef *hsc)
void HAL_SMARTCARD_MspDeInit(SMARTCARD_HandleTypeDef *hsc)
void HAL_SMARTCARD_RxCpltCallback(SMARTCARD_HandleTypeDef *hsc)
void HAL_SMARTCARD_ErrorCallback(SMARTCARD_HandleTypeDef *hsc)
uint32_t HAL_SMARTCARD_GetError(SMARTCARD_HandleTypeDef *hsc)
HAL_StatusTypeDef HAL_SMARTCARD_Abort_IT(SMARTCARD_HandleTypeDef *hsc)
HAL_StatusTypeDef HAL_SMARTCARD_Transmit_DMA(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size)
HAL_LockTypeDef
HAL Lock structures definition
DMA_HandleTypeDef * hdmarx
HAL_SMARTCARD_StateTypeDef HAL_SMARTCARD_GetState(SMARTCARD_HandleTypeDef *hsc)
@ HAL_SMARTCARD_STATE_READY
HAL_StatusTypeDef HAL_SMARTCARD_AbortTransmit(SMARTCARD_HandleTypeDef *hsc)
@ HAL_SMARTCARD_STATE_BUSY_RX
HAL_StatusTypeDef HAL_SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size)
This file contains HAL common defines, enumeration, macros and structures definitions.
@ HAL_SMARTCARD_STATE_ERROR
HAL_StatusTypeDef HAL_SMARTCARD_Init(SMARTCARD_HandleTypeDef *hsc)
void HAL_SMARTCARD_AbortCpltCallback(SMARTCARD_HandleTypeDef *hsc)
SMARTCARD handle Structure definition.
@ HAL_SMARTCARD_STATE_BUSY_TX
HAL_StatusTypeDef HAL_SMARTCARD_Abort(SMARTCARD_HandleTypeDef *hsc)
void HAL_SMARTCARD_AbortTransmitCpltCallback(SMARTCARD_HandleTypeDef *hsc)
SMARTCARD Init Structure definition.
HAL_StatusTypeDef HAL_SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size)
__IO HAL_SMARTCARD_StateTypeDef RxState
@ HAL_SMARTCARD_STATE_RESET
HAL_StatusTypeDef HAL_SMARTCARD_AbortReceive(SMARTCARD_HandleTypeDef *hsc)
HAL_StatusTypeDef HAL_SMARTCARD_Receive_DMA(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size)
HAL_StatusTypeDef HAL_SMARTCARD_Receive(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size, uint32_t Timeout)
HAL_SMARTCARD_StateTypeDef
HAL SMARTCARD State structures definition.
void HAL_SMARTCARD_TxCpltCallback(SMARTCARD_HandleTypeDef *hsc)
HAL_StatusTypeDef HAL_SMARTCARD_ReInit(SMARTCARD_HandleTypeDef *hsc)
DMA_HandleTypeDef * hdmatx
void HAL_SMARTCARD_IRQHandler(SMARTCARD_HandleTypeDef *hsc)
HAL_StatusTypeDef HAL_SMARTCARD_AbortReceive_IT(SMARTCARD_HandleTypeDef *hsc)
@ HAL_SMARTCARD_STATE_TIMEOUT
HAL_StatusTypeDef HAL_SMARTCARD_AbortTransmit_IT(SMARTCARD_HandleTypeDef *hsc)
__IO uint16_t TxXferCount
SMARTCARD_InitTypeDef Init
HAL_StatusTypeDef HAL_SMARTCARD_DeInit(SMARTCARD_HandleTypeDef *hsc)
void HAL_SMARTCARD_MspInit(SMARTCARD_HandleTypeDef *hsc)
struct __SMARTCARD_HandleTypeDef SMARTCARD_HandleTypeDef
SMARTCARD handle Structure definition.
@ HAL_SMARTCARD_STATE_BUSY