2 ******************************************************************************
3 * @file stm32f0xx_hal_smartcard_ex.c
4 * @author MCD Application Team
6 * @date 11-December-2014
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 function
12 * + Peripheral Control function
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 "stm32f0xx_hal.h"
63 #ifdef HAL_SMARTCARD_MODULE_ENABLED
65 #if !defined(STM32F030x6) && !defined(STM32F030x8)&& !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC)
67 /** @addtogroup STM32F0xx_HAL_Driver
71 /** @defgroup SMARTCARDEx SMARTCARD Extended HAL module driver
72 * @brief SMARTCARD Extended HAL module driver
76 /* Private typedef -----------------------------------------------------------*/
77 /* Private define ------------------------------------------------------------*/
78 /* Private macro -------------------------------------------------------------*/
79 /* Private variables ---------------------------------------------------------*/
80 /* Private function prototypes -----------------------------------------------*/
81 /* Exported functions ---------------------------------------------------------*/
83 /** @defgroup SMARTCARDEx_Exported_Functions SMARTCARDEx Exported Functions
87 /** @defgroup SMARTCARDEx_Exported_Functions_Group1 Extended Peripheral Control functions
88 * @brief Extended control functions
91 ===============================================================================
92 ##### Peripheral Control functions #####
93 ===============================================================================
95 This subsection provides a set of functions allowing to initialize the SMARTCARD.
96 (+) HAL_SMARTCARDEx_BlockLength_Config() API allows to configure the Block Length on the fly
97 (+) HAL_SMARTCARDEx_TimeOut_Config() API allows to configure the receiver timeout value on the fly
98 (+) HAL_SMARTCARDEx_EnableReceiverTimeOut() API enables the receiver timeout feature
99 (+) HAL_SMARTCARDEx_DisableReceiverTimeOut() API disables the receiver timeout feature
106 * @brief Update on the fly the SMARTCARD block length in RTOR register
107 * @param hsmartcard: SMARTCARD handle
108 * @param BlockLength: SMARTCARD block length (8-bit long at most)
111 void HAL_SMARTCARDEx_BlockLength_Config(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t BlockLength)
113 MODIFY_REG(hsmartcard->Instance->RTOR, USART_RTOR_BLEN, ((uint32_t)BlockLength << SMARTCARD_RTOR_BLEN_LSB_POS));
117 * @brief Update on the fly the receiver timeout value in RTOR register
118 * @param hsmartcard: SMARTCARD handle
119 * @param TimeOutValue: receiver timeout value in number of baud blocks. The timeout
120 * value must be less or equal to 0x0FFFFFFFF.
123 void HAL_SMARTCARDEx_TimeOut_Config(SMARTCARD_HandleTypeDef *hsmartcard, uint32_t TimeOutValue)
125 assert_param(IS_SMARTCARD_TIMEOUT_VALUE(hsmartcard->Init.TimeOutValue));
126 MODIFY_REG(hsmartcard->Instance->RTOR, USART_RTOR_RTO, TimeOutValue);
130 * @brief Enable the SMARTCARD receiver timeout feature
131 * @param hsmartcard: SMARTCARD handle
134 HAL_StatusTypeDef HAL_SMARTCARDEx_EnableReceiverTimeOut(SMARTCARD_HandleTypeDef *hsmartcard)
138 __HAL_LOCK(hsmartcard);
140 hsmartcard->State = HAL_SMARTCARD_STATE_BUSY;
142 /* Set the USART RTOEN bit */
143 hsmartcard->Instance->CR2 |= USART_CR2_RTOEN;
145 hsmartcard->State = HAL_SMARTCARD_STATE_READY;
147 /* Process Unlocked */
148 __HAL_UNLOCK(hsmartcard);
154 * @brief Disable the SMARTCARD receiver timeout feature
155 * @param hsmartcard: SMARTCARD handle
158 HAL_StatusTypeDef HAL_SMARTCARDEx_DisableReceiverTimeOut(SMARTCARD_HandleTypeDef *hsmartcard)
162 __HAL_LOCK(hsmartcard);
164 hsmartcard->State = HAL_SMARTCARD_STATE_BUSY;
166 /* Clear the USART RTOEN bit */
167 hsmartcard->Instance->CR2 &= ~(USART_CR2_RTOEN);
169 hsmartcard->State = HAL_SMARTCARD_STATE_READY;
171 /* Process Unlocked */
172 __HAL_UNLOCK(hsmartcard);
193 #endif /* !defined(STM32F030x6) && !defined(STM32F030x8)&& !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) */
195 #endif /* HAL_SMARTCARD_MODULE_ENABLED */
197 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/