2 ******************************************************************************
3 * @file stm32l0xx_hal_smartcard_ex.c
4 * @author MCD Application Team
6 * @date 06-February-2015
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
14 ===============================================================================
15 ##### How to use this driver #####
16 ===============================================================================
18 The Extended SMARTCARD HAL driver can be used as follow:
20 (#) After having configured the SMARTCARD basic features with HAL_SMARTCARD_Init(),
21 then if required, program SMARTCARD advanced features (TX/RX pins swap, TimeOut,
22 auto-retry counter,...) in the hsc AdvancedInit structure.
25 ******************************************************************************
28 * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
30 * Redistribution and use in source and binary forms, with or without modification,
31 * are permitted provided that the following conditions are met:
32 * 1. Redistributions of source code must retain the above copyright notice,
33 * this list of conditions and the following disclaimer.
34 * 2. Redistributions in binary form must reproduce the above copyright notice,
35 * this list of conditions and the following disclaimer in the documentation
36 * and/or other materials provided with the distribution.
37 * 3. Neither the name of STMicroelectronics nor the names of its contributors
38 * may be used to endorse or promote products derived from this software
39 * without specific prior written permission.
41 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
42 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
44 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
47 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
48 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
49 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
50 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
52 ******************************************************************************
55 /* Includes ------------------------------------------------------------------*/
56 #include "stm32l0xx_hal.h"
58 /** @addtogroup STM32L0xx_HAL_Driver
62 /** @addtogroup SMARTCARDEx
63 * @brief SMARTCARD Extended HAL module driver
66 #ifdef HAL_SMARTCARD_MODULE_ENABLED
68 /* Private typedef -----------------------------------------------------------*/
69 /* Private define ------------------------------------------------------------*/
70 /* Private macro -------------------------------------------------------------*/
71 /* Private variables ---------------------------------------------------------*/
72 /* Private function prototypes -----------------------------------------------*/
73 /* Private functions ---------------------------------------------------------*/
75 /** @addtogroup SMARTCARDEx_Exported_Functions
79 /** @addtogroup SMARTCARDEx_Exported_Functions_Group1
80 * @brief Extended control functions
83 ===============================================================================
84 ##### Peripheral Control functions #####
85 ===============================================================================
87 This subsection provides a set of functions allowing to initialize the SMARTCARD.
88 (+) HAL_SMARTCARDEx_BlockLength_Config() API allows to configure the Block Length on the fly
89 (+) HAL_SMARTCARDEx_TimeOut_Config() API allows to configure the receiver timeout value on the fly
90 (+) HAL_SMARTCARDEx_EnableReceiverTimeOut() API enables the receiver timeout feature
91 (+) HAL_SMARTCARDEx_DisableReceiverTimeOut() API disables the receiver timeout feature
98 * @brief Update on the fly the SMARTCARD block length in RTOR register
99 * @param hsc: SMARTCARD handle
100 * @param BlockLength: SMARTCARD block length (8-bit long at most)
103 void HAL_SMARTCARDEx_BlockLength_Config(SMARTCARD_HandleTypeDef *hsc, uint8_t BlockLength)
105 MODIFY_REG(hsc->Instance->RTOR, USART_RTOR_BLEN, ((uint32_t)BlockLength << SMARTCARD_RTOR_BLEN_LSB_POS));
109 * @brief Update on the fly the receiver timeout value in RTOR register
110 * @param hsc: SMARTCARD handle
111 * @param TimeOutValue: receiver timeout value in number of baud blocks. The timeout
112 * value must be less or equal to 0x0FFFFFFFF.
115 void HAL_SMARTCARDEx_TimeOut_Config(SMARTCARD_HandleTypeDef *hsc, uint32_t TimeOutValue)
117 assert_param(IS_SMARTCARD_TIMEOUT_VALUE(hsc->Init.TimeOutValue));
118 MODIFY_REG(hsc->Instance->RTOR, USART_RTOR_RTO, TimeOutValue);
122 * @brief Enable the SMARTCARD receiver timeout feature
123 * @param hsc: SMARTCARD handle
126 HAL_StatusTypeDef HAL_SMARTCARDEx_EnableReceiverTimeOut(SMARTCARD_HandleTypeDef *hsc)
131 hsc->State = HAL_SMARTCARD_STATE_BUSY;
133 /* Set the USART RTOEN bit */
134 hsc->Instance->CR2 |= USART_CR2_RTOEN;
136 hsc->State = HAL_SMARTCARD_STATE_READY;
138 /* Process Unlocked */
145 * @brief Disable the SMARTCARD receiver timeout feature
146 * @param hsc: SMARTCARD handle
149 HAL_StatusTypeDef HAL_SMARTCARDEx_DisableReceiverTimeOut(SMARTCARD_HandleTypeDef *hsc)
154 hsc->State = HAL_SMARTCARD_STATE_BUSY;
156 /* Clear the USART RTOEN bit */
157 hsc->Instance->CR2 &= ~(USART_CR2_RTOEN);
159 hsc->State = HAL_SMARTCARD_STATE_READY;
161 /* Process Unlocked */
175 #endif /* HAL_SMARTCARD_MODULE_ENABLED */
184 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/