Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
HAL_L476/stm32l4xx_hal_smartcard_ex.c@1:d0dfbce63a89, 2017-02-24 (annotated)
- Committer:
- elmot
- Date:
- Fri Feb 24 21:13:56 2017 +0000
- Revision:
- 1:d0dfbce63a89
Ready-to-copy
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| elmot | 1:d0dfbce63a89 | 1 | /** |
| elmot | 1:d0dfbce63a89 | 2 | ****************************************************************************** |
| elmot | 1:d0dfbce63a89 | 3 | * @file stm32l4xx_hal_smartcard_ex.c |
| elmot | 1:d0dfbce63a89 | 4 | * @author MCD Application Team |
| elmot | 1:d0dfbce63a89 | 5 | * @version V1.5.1 |
| elmot | 1:d0dfbce63a89 | 6 | * @date 31-May-2016 |
| elmot | 1:d0dfbce63a89 | 7 | * @brief SMARTCARD HAL module driver. |
| elmot | 1:d0dfbce63a89 | 8 | * This file provides extended firmware functions to manage the following |
| elmot | 1:d0dfbce63a89 | 9 | * functionalities of the SmartCard. |
| elmot | 1:d0dfbce63a89 | 10 | * + Initialization and de-initialization functions |
| elmot | 1:d0dfbce63a89 | 11 | * + Peripheral Control functions |
| elmot | 1:d0dfbce63a89 | 12 | * |
| elmot | 1:d0dfbce63a89 | 13 | * |
| elmot | 1:d0dfbce63a89 | 14 | @verbatim |
| elmot | 1:d0dfbce63a89 | 15 | ============================================================================= |
| elmot | 1:d0dfbce63a89 | 16 | ##### SMARTCARD peripheral extended features ##### |
| elmot | 1:d0dfbce63a89 | 17 | ============================================================================= |
| elmot | 1:d0dfbce63a89 | 18 | [..] |
| elmot | 1:d0dfbce63a89 | 19 | The Extended SMARTCARD HAL driver can be used as follows: |
| elmot | 1:d0dfbce63a89 | 20 | |
| elmot | 1:d0dfbce63a89 | 21 | (#) After having configured the SMARTCARD basic features with HAL_SMARTCARD_Init(), |
| elmot | 1:d0dfbce63a89 | 22 | then program SMARTCARD advanced features if required (TX/RX pins swap, TimeOut, |
| elmot | 1:d0dfbce63a89 | 23 | auto-retry counter,...) in the hsmartcard AdvancedInit structure. |
| elmot | 1:d0dfbce63a89 | 24 | |
| elmot | 1:d0dfbce63a89 | 25 | |
| elmot | 1:d0dfbce63a89 | 26 | |
| elmot | 1:d0dfbce63a89 | 27 | @endverbatim |
| elmot | 1:d0dfbce63a89 | 28 | ****************************************************************************** |
| elmot | 1:d0dfbce63a89 | 29 | * @attention |
| elmot | 1:d0dfbce63a89 | 30 | * |
| elmot | 1:d0dfbce63a89 | 31 | * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
| elmot | 1:d0dfbce63a89 | 32 | * |
| elmot | 1:d0dfbce63a89 | 33 | * Redistribution and use in source and binary forms, with or without modification, |
| elmot | 1:d0dfbce63a89 | 34 | * are permitted provided that the following conditions are met: |
| elmot | 1:d0dfbce63a89 | 35 | * 1. Redistributions of source code must retain the above copyright notice, |
| elmot | 1:d0dfbce63a89 | 36 | * this list of conditions and the following disclaimer. |
| elmot | 1:d0dfbce63a89 | 37 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| elmot | 1:d0dfbce63a89 | 38 | * this list of conditions and the following disclaimer in the documentation |
| elmot | 1:d0dfbce63a89 | 39 | * and/or other materials provided with the distribution. |
| elmot | 1:d0dfbce63a89 | 40 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
| elmot | 1:d0dfbce63a89 | 41 | * may be used to endorse or promote products derived from this software |
| elmot | 1:d0dfbce63a89 | 42 | * without specific prior written permission. |
| elmot | 1:d0dfbce63a89 | 43 | * |
| elmot | 1:d0dfbce63a89 | 44 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| elmot | 1:d0dfbce63a89 | 45 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| elmot | 1:d0dfbce63a89 | 46 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| elmot | 1:d0dfbce63a89 | 47 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| elmot | 1:d0dfbce63a89 | 48 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| elmot | 1:d0dfbce63a89 | 49 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| elmot | 1:d0dfbce63a89 | 50 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| elmot | 1:d0dfbce63a89 | 51 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| elmot | 1:d0dfbce63a89 | 52 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| elmot | 1:d0dfbce63a89 | 53 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| elmot | 1:d0dfbce63a89 | 54 | * |
| elmot | 1:d0dfbce63a89 | 55 | ****************************************************************************** |
| elmot | 1:d0dfbce63a89 | 56 | */ |
| elmot | 1:d0dfbce63a89 | 57 | |
| elmot | 1:d0dfbce63a89 | 58 | /* Includes ------------------------------------------------------------------*/ |
| elmot | 1:d0dfbce63a89 | 59 | #include "stm32l4xx_hal.h" |
| elmot | 1:d0dfbce63a89 | 60 | |
| elmot | 1:d0dfbce63a89 | 61 | /** @addtogroup STM32L4xx_HAL_Driver |
| elmot | 1:d0dfbce63a89 | 62 | * @{ |
| elmot | 1:d0dfbce63a89 | 63 | */ |
| elmot | 1:d0dfbce63a89 | 64 | |
| elmot | 1:d0dfbce63a89 | 65 | /** @defgroup SMARTCARDEx SMARTCARDEx |
| elmot | 1:d0dfbce63a89 | 66 | * @brief SMARTCARD Extended HAL module driver |
| elmot | 1:d0dfbce63a89 | 67 | * @{ |
| elmot | 1:d0dfbce63a89 | 68 | */ |
| elmot | 1:d0dfbce63a89 | 69 | #ifdef HAL_SMARTCARD_MODULE_ENABLED |
| elmot | 1:d0dfbce63a89 | 70 | |
| elmot | 1:d0dfbce63a89 | 71 | /* Private typedef -----------------------------------------------------------*/ |
| elmot | 1:d0dfbce63a89 | 72 | /* Private define ------------------------------------------------------------*/ |
| elmot | 1:d0dfbce63a89 | 73 | /* Private macros ------------------------------------------------------------*/ |
| elmot | 1:d0dfbce63a89 | 74 | /* Private variables ---------------------------------------------------------*/ |
| elmot | 1:d0dfbce63a89 | 75 | /* Private function prototypes -----------------------------------------------*/ |
| elmot | 1:d0dfbce63a89 | 76 | |
| elmot | 1:d0dfbce63a89 | 77 | /* Exported functions --------------------------------------------------------*/ |
| elmot | 1:d0dfbce63a89 | 78 | /** @defgroup SMARTCARDEx_Exported_Functions SMARTCARD Extended Exported Functions |
| elmot | 1:d0dfbce63a89 | 79 | * @{ |
| elmot | 1:d0dfbce63a89 | 80 | */ |
| elmot | 1:d0dfbce63a89 | 81 | |
| elmot | 1:d0dfbce63a89 | 82 | /** @defgroup SMARTCARDEx_Exported_Functions_Group1 Extended Peripheral Control functions |
| elmot | 1:d0dfbce63a89 | 83 | * @brief Extended control functions |
| elmot | 1:d0dfbce63a89 | 84 | * |
| elmot | 1:d0dfbce63a89 | 85 | @verbatim |
| elmot | 1:d0dfbce63a89 | 86 | =============================================================================== |
| elmot | 1:d0dfbce63a89 | 87 | ##### Peripheral Control functions ##### |
| elmot | 1:d0dfbce63a89 | 88 | =============================================================================== |
| elmot | 1:d0dfbce63a89 | 89 | [..] |
| elmot | 1:d0dfbce63a89 | 90 | This subsection provides a set of functions allowing to initialize the SMARTCARD. |
| elmot | 1:d0dfbce63a89 | 91 | (+) HAL_SMARTCARDEx_BlockLength_Config() API allows to configure the Block Length on the fly |
| elmot | 1:d0dfbce63a89 | 92 | (+) HAL_SMARTCARDEx_TimeOut_Config() API allows to configure the receiver timeout value on the fly |
| elmot | 1:d0dfbce63a89 | 93 | (+) HAL_SMARTCARDEx_EnableReceiverTimeOut() API enables the receiver timeout feature |
| elmot | 1:d0dfbce63a89 | 94 | (+) HAL_SMARTCARDEx_DisableReceiverTimeOut() API disables the receiver timeout feature |
| elmot | 1:d0dfbce63a89 | 95 | |
| elmot | 1:d0dfbce63a89 | 96 | @endverbatim |
| elmot | 1:d0dfbce63a89 | 97 | * @{ |
| elmot | 1:d0dfbce63a89 | 98 | */ |
| elmot | 1:d0dfbce63a89 | 99 | |
| elmot | 1:d0dfbce63a89 | 100 | /** |
| elmot | 1:d0dfbce63a89 | 101 | * @brief Update on the fly the SMARTCARD block length in RTOR register. |
| elmot | 1:d0dfbce63a89 | 102 | * @param hsmartcard: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
| elmot | 1:d0dfbce63a89 | 103 | * the configuration information for the specified SMARTCARD module. |
| elmot | 1:d0dfbce63a89 | 104 | * @param BlockLength: SMARTCARD block length (8-bit long at most) |
| elmot | 1:d0dfbce63a89 | 105 | * @retval None |
| elmot | 1:d0dfbce63a89 | 106 | */ |
| elmot | 1:d0dfbce63a89 | 107 | void HAL_SMARTCARDEx_BlockLength_Config(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t BlockLength) |
| elmot | 1:d0dfbce63a89 | 108 | { |
| elmot | 1:d0dfbce63a89 | 109 | MODIFY_REG(hsmartcard->Instance->RTOR, USART_RTOR_BLEN, ((uint32_t)BlockLength << SMARTCARD_RTOR_BLEN_LSB_POS)); |
| elmot | 1:d0dfbce63a89 | 110 | } |
| elmot | 1:d0dfbce63a89 | 111 | |
| elmot | 1:d0dfbce63a89 | 112 | /** |
| elmot | 1:d0dfbce63a89 | 113 | * @brief Update on the fly the receiver timeout value in RTOR register. |
| elmot | 1:d0dfbce63a89 | 114 | * @param hsmartcard: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
| elmot | 1:d0dfbce63a89 | 115 | * the configuration information for the specified SMARTCARD module. |
| elmot | 1:d0dfbce63a89 | 116 | * @param TimeOutValue: receiver timeout value in number of baud blocks. The timeout |
| elmot | 1:d0dfbce63a89 | 117 | * value must be less or equal to 0x0FFFFFFFF. |
| elmot | 1:d0dfbce63a89 | 118 | * @retval None |
| elmot | 1:d0dfbce63a89 | 119 | */ |
| elmot | 1:d0dfbce63a89 | 120 | void HAL_SMARTCARDEx_TimeOut_Config(SMARTCARD_HandleTypeDef *hsmartcard, uint32_t TimeOutValue) |
| elmot | 1:d0dfbce63a89 | 121 | { |
| elmot | 1:d0dfbce63a89 | 122 | assert_param(IS_SMARTCARD_TIMEOUT_VALUE(hsmartcard->Init.TimeOutValue)); |
| elmot | 1:d0dfbce63a89 | 123 | MODIFY_REG(hsmartcard->Instance->RTOR, USART_RTOR_RTO, TimeOutValue); |
| elmot | 1:d0dfbce63a89 | 124 | } |
| elmot | 1:d0dfbce63a89 | 125 | |
| elmot | 1:d0dfbce63a89 | 126 | /** |
| elmot | 1:d0dfbce63a89 | 127 | * @brief Enable the SMARTCARD receiver timeout feature. |
| elmot | 1:d0dfbce63a89 | 128 | * @param hsmartcard: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
| elmot | 1:d0dfbce63a89 | 129 | * the configuration information for the specified SMARTCARD module. |
| elmot | 1:d0dfbce63a89 | 130 | * @retval HAL status |
| elmot | 1:d0dfbce63a89 | 131 | */ |
| elmot | 1:d0dfbce63a89 | 132 | HAL_StatusTypeDef HAL_SMARTCARDEx_EnableReceiverTimeOut(SMARTCARD_HandleTypeDef *hsmartcard) |
| elmot | 1:d0dfbce63a89 | 133 | { |
| elmot | 1:d0dfbce63a89 | 134 | |
| elmot | 1:d0dfbce63a89 | 135 | if(hsmartcard->gState == HAL_SMARTCARD_STATE_READY) |
| elmot | 1:d0dfbce63a89 | 136 | { |
| elmot | 1:d0dfbce63a89 | 137 | /* Process Locked */ |
| elmot | 1:d0dfbce63a89 | 138 | __HAL_LOCK(hsmartcard); |
| elmot | 1:d0dfbce63a89 | 139 | |
| elmot | 1:d0dfbce63a89 | 140 | hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY; |
| elmot | 1:d0dfbce63a89 | 141 | |
| elmot | 1:d0dfbce63a89 | 142 | /* Set the USART RTOEN bit */ |
| elmot | 1:d0dfbce63a89 | 143 | SET_BIT(hsmartcard->Instance->CR2, USART_CR2_RTOEN); |
| elmot | 1:d0dfbce63a89 | 144 | |
| elmot | 1:d0dfbce63a89 | 145 | hsmartcard->gState = HAL_SMARTCARD_STATE_READY; |
| elmot | 1:d0dfbce63a89 | 146 | |
| elmot | 1:d0dfbce63a89 | 147 | /* Process Unlocked */ |
| elmot | 1:d0dfbce63a89 | 148 | __HAL_UNLOCK(hsmartcard); |
| elmot | 1:d0dfbce63a89 | 149 | |
| elmot | 1:d0dfbce63a89 | 150 | return HAL_OK; |
| elmot | 1:d0dfbce63a89 | 151 | } |
| elmot | 1:d0dfbce63a89 | 152 | else |
| elmot | 1:d0dfbce63a89 | 153 | { |
| elmot | 1:d0dfbce63a89 | 154 | return HAL_BUSY; |
| elmot | 1:d0dfbce63a89 | 155 | } |
| elmot | 1:d0dfbce63a89 | 156 | } |
| elmot | 1:d0dfbce63a89 | 157 | |
| elmot | 1:d0dfbce63a89 | 158 | /** |
| elmot | 1:d0dfbce63a89 | 159 | * @brief Disable the SMARTCARD receiver timeout feature. |
| elmot | 1:d0dfbce63a89 | 160 | * @param hsmartcard: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
| elmot | 1:d0dfbce63a89 | 161 | * the configuration information for the specified SMARTCARD module. |
| elmot | 1:d0dfbce63a89 | 162 | * @retval HAL status |
| elmot | 1:d0dfbce63a89 | 163 | */ |
| elmot | 1:d0dfbce63a89 | 164 | HAL_StatusTypeDef HAL_SMARTCARDEx_DisableReceiverTimeOut(SMARTCARD_HandleTypeDef *hsmartcard) |
| elmot | 1:d0dfbce63a89 | 165 | { |
| elmot | 1:d0dfbce63a89 | 166 | |
| elmot | 1:d0dfbce63a89 | 167 | if(hsmartcard->gState == HAL_SMARTCARD_STATE_READY) |
| elmot | 1:d0dfbce63a89 | 168 | { |
| elmot | 1:d0dfbce63a89 | 169 | /* Process Locked */ |
| elmot | 1:d0dfbce63a89 | 170 | __HAL_LOCK(hsmartcard); |
| elmot | 1:d0dfbce63a89 | 171 | |
| elmot | 1:d0dfbce63a89 | 172 | hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY; |
| elmot | 1:d0dfbce63a89 | 173 | |
| elmot | 1:d0dfbce63a89 | 174 | /* Clear the USART RTOEN bit */ |
| elmot | 1:d0dfbce63a89 | 175 | CLEAR_BIT(hsmartcard->Instance->CR2, USART_CR2_RTOEN); |
| elmot | 1:d0dfbce63a89 | 176 | |
| elmot | 1:d0dfbce63a89 | 177 | hsmartcard->gState = HAL_SMARTCARD_STATE_READY; |
| elmot | 1:d0dfbce63a89 | 178 | |
| elmot | 1:d0dfbce63a89 | 179 | /* Process Unlocked */ |
| elmot | 1:d0dfbce63a89 | 180 | __HAL_UNLOCK(hsmartcard); |
| elmot | 1:d0dfbce63a89 | 181 | |
| elmot | 1:d0dfbce63a89 | 182 | return HAL_OK; |
| elmot | 1:d0dfbce63a89 | 183 | } |
| elmot | 1:d0dfbce63a89 | 184 | else |
| elmot | 1:d0dfbce63a89 | 185 | { |
| elmot | 1:d0dfbce63a89 | 186 | return HAL_BUSY; |
| elmot | 1:d0dfbce63a89 | 187 | } |
| elmot | 1:d0dfbce63a89 | 188 | } |
| elmot | 1:d0dfbce63a89 | 189 | |
| elmot | 1:d0dfbce63a89 | 190 | /** |
| elmot | 1:d0dfbce63a89 | 191 | * @} |
| elmot | 1:d0dfbce63a89 | 192 | */ |
| elmot | 1:d0dfbce63a89 | 193 | |
| elmot | 1:d0dfbce63a89 | 194 | /** |
| elmot | 1:d0dfbce63a89 | 195 | * @} |
| elmot | 1:d0dfbce63a89 | 196 | */ |
| elmot | 1:d0dfbce63a89 | 197 | |
| elmot | 1:d0dfbce63a89 | 198 | #endif /* HAL_SMARTCARD_MODULE_ENABLED */ |
| elmot | 1:d0dfbce63a89 | 199 | |
| elmot | 1:d0dfbce63a89 | 200 | /** |
| elmot | 1:d0dfbce63a89 | 201 | * @} |
| elmot | 1:d0dfbce63a89 | 202 | */ |
| elmot | 1:d0dfbce63a89 | 203 | |
| elmot | 1:d0dfbce63a89 | 204 | /** |
| elmot | 1:d0dfbce63a89 | 205 | * @} |
| elmot | 1:d0dfbce63a89 | 206 | */ |
| elmot | 1:d0dfbce63a89 | 207 | |
| elmot | 1:d0dfbce63a89 | 208 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |