2 ******************************************************************************
3 * @file stm32f3xx_hal_smartcard_ex.c
4 * @author MCD Application Team
7 * @brief SMARTCARD HAL module driver.
9 * This file provides extended firmware functions to manage the following
10 * functionalities of the SmartCard.
11 * + Initialization and de-initialization functions
12 * + Peripheral Control functions
16 ===============================================================================
17 ##### How to use this driver #####
18 ===============================================================================
20 The Extended SMARTCARD HAL driver can be used as follows:
23 (#) After having configured the SMARTCARD basic features with HAL_SMARTCARD_Init(),
24 then if required, program SMARTCARD advanced features (TX/RX pins swap, TimeOut,
25 auto-retry counter,...) in the hsmartcard AdvancedInit structure.
30 ******************************************************************************
33 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
35 * Redistribution and use in source and binary forms, with or without modification,
36 * are permitted provided that the following conditions are met:
37 * 1. Redistributions of source code must retain the above copyright notice,
38 * this list of conditions and the following disclaimer.
39 * 2. Redistributions in binary form must reproduce the above copyright notice,
40 * this list of conditions and the following disclaimer in the documentation
41 * and/or other materials provided with the distribution.
42 * 3. Neither the name of STMicroelectronics nor the names of its contributors
43 * may be used to endorse or promote products derived from this software
44 * without specific prior written permission.
46 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
47 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
49 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
50 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
52 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
53 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
54 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
55 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57 ******************************************************************************
60 /* Includes ------------------------------------------------------------------*/
61 #include "stm32f3xx_hal.h"
63 /** @addtogroup STM32F3xx_HAL_Driver
67 /** @defgroup SMARTCARDEx SMARTCARD Extended HAL module driver
68 * @brief SMARTCARD Extended HAL module driver
71 #ifdef HAL_SMARTCARD_MODULE_ENABLED
73 /* Private typedef -----------------------------------------------------------*/
74 /* Private define ------------------------------------------------------------*/
75 /* Private macro -------------------------------------------------------------*/
76 /* Private variables ---------------------------------------------------------*/
77 /* Private function prototypes -----------------------------------------------*/
79 /* Exported functions ---------------------------------------------------------*/
81 /** @defgroup SMARTCARDEx_Exported_Functions SMARTCARD Extended Exported Functions
85 /** @defgroup SMARTCARDEx_Exported_Functions_Group1 Extended Peripheral Control functions
86 * @brief Extended control functions
89 ===============================================================================
90 ##### Peripheral Control functions #####
91 ===============================================================================
93 This subsection provides a set of functions allowing to initialize the SMARTCARD.
94 (+) HAL_SMARTCARDEx_BlockLength_Config() API allows to configure the Block Length on the fly
95 (+) HAL_SMARTCARDEx_TimeOut_Config() API allows to configure the receiver timeout value on the fly
96 (+) HAL_SMARTCARDEx_EnableReceiverTimeOut() API enables the receiver timeout feature
97 (+) HAL_SMARTCARDEx_DisableReceiverTimeOut() API disables the receiver timeout feature
108 * @brief Update on the fly the SMARTCARD block length in RTOR register
109 * @param hsmartcard: SMARTCARD handle
110 * @param BlockLength: SMARTCARD block length (8-bit long at most)
113 void HAL_SMARTCARDEx_BlockLength_Config(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t BlockLength)
115 MODIFY_REG(hsmartcard->Instance->RTOR, USART_RTOR_BLEN, ((uint32_t)BlockLength << SMARTCARD_RTOR_BLEN_LSB_POS));
119 * @brief Update on the fly the receiver timeout value in RTOR register
120 * @param hsmartcard: SMARTCARD handle
121 * @param TimeOutValue: receiver timeout value in number of baud blocks. The timeout
122 * value must be less or equal to 0x0FFFFFFFF.
125 void HAL_SMARTCARDEx_TimeOut_Config(SMARTCARD_HandleTypeDef *hsmartcard, uint32_t TimeOutValue)
127 assert_param(IS_SMARTCARD_TIMEOUT_VALUE(hsmartcard->Init.TimeOutValue));
128 MODIFY_REG(hsmartcard->Instance->RTOR, USART_RTOR_RTO, TimeOutValue);
132 * @brief Enable the SMARTCARD receiver timeout feature
133 * @param hsmartcard: SMARTCARD handle
136 HAL_StatusTypeDef HAL_SMARTCARDEx_EnableReceiverTimeOut(SMARTCARD_HandleTypeDef *hsmartcard)
140 __HAL_LOCK(hsmartcard);
142 hsmartcard->State = HAL_SMARTCARD_STATE_BUSY;
144 /* Set the USART RTOEN bit */
145 hsmartcard->Instance->CR2 |= USART_CR2_RTOEN;
147 hsmartcard->State = HAL_SMARTCARD_STATE_READY;
149 /* Process Unlocked */
150 __HAL_UNLOCK(hsmartcard);
156 * @brief Disable the SMARTCARD receiver timeout feature
157 * @param hsmartcard: SMARTCARD handle
160 HAL_StatusTypeDef HAL_SMARTCARDEx_DisableReceiverTimeOut(SMARTCARD_HandleTypeDef *hsmartcard)
164 __HAL_LOCK(hsmartcard);
166 hsmartcard->State = HAL_SMARTCARD_STATE_BUSY;
168 /* Clear the USART RTOEN bit */
169 hsmartcard->Instance->CR2 &= ~(USART_CR2_RTOEN);
171 hsmartcard->State = HAL_SMARTCARD_STATE_READY;
173 /* Process Unlocked */
174 __HAL_UNLOCK(hsmartcard);
187 #endif /* HAL_SMARTCARD_MODULE_ENABLED */
196 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/