mbed library sources modified for open wear
Dependents: openwear-lifelogger-example
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_NUCLEO_L053R8/stm32l0xx_hal_smartcard.c@181:a4cbdfbbd2f4, 2014-05-07 (annotated)
- Committer:
- mbed_official
- Date:
- Wed May 07 13:15:08 2014 +0100
- Revision:
- 181:a4cbdfbbd2f4
Synchronized with git revision 7751e759576c6fd68deccb81ea82bac19ed41745
Full URL: https://github.com/mbedmicro/mbed/commit/7751e759576c6fd68deccb81ea82bac19ed41745/
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 181:a4cbdfbbd2f4 | 1 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 2 | ****************************************************************************** |
mbed_official | 181:a4cbdfbbd2f4 | 3 | * @file stm32l0xx_hal_smartcard.c |
mbed_official | 181:a4cbdfbbd2f4 | 4 | * @author MCD Application Team |
mbed_official | 181:a4cbdfbbd2f4 | 5 | * @version V1.0.0 |
mbed_official | 181:a4cbdfbbd2f4 | 6 | * @date 22-April-2014 |
mbed_official | 181:a4cbdfbbd2f4 | 7 | * @brief SMARTCARD HAL module driver. |
mbed_official | 181:a4cbdfbbd2f4 | 8 | * |
mbed_official | 181:a4cbdfbbd2f4 | 9 | * This file provides firmware functions to manage the following |
mbed_official | 181:a4cbdfbbd2f4 | 10 | * functionalities of the SmartCard. |
mbed_official | 181:a4cbdfbbd2f4 | 11 | * + Initialization and de-initialization methods |
mbed_official | 181:a4cbdfbbd2f4 | 12 | * + IO operation methods |
mbed_official | 181:a4cbdfbbd2f4 | 13 | * + Peripheral Control methods |
mbed_official | 181:a4cbdfbbd2f4 | 14 | * |
mbed_official | 181:a4cbdfbbd2f4 | 15 | * |
mbed_official | 181:a4cbdfbbd2f4 | 16 | @verbatim |
mbed_official | 181:a4cbdfbbd2f4 | 17 | =============================================================================== |
mbed_official | 181:a4cbdfbbd2f4 | 18 | ##### How to use this driver ##### |
mbed_official | 181:a4cbdfbbd2f4 | 19 | =============================================================================== |
mbed_official | 181:a4cbdfbbd2f4 | 20 | [..] |
mbed_official | 181:a4cbdfbbd2f4 | 21 | The SMARTCARD HAL driver can be used as follow: |
mbed_official | 181:a4cbdfbbd2f4 | 22 | |
mbed_official | 181:a4cbdfbbd2f4 | 23 | (#) Declare a SMARTCARD_HandleTypeDef handle structure. |
mbed_official | 181:a4cbdfbbd2f4 | 24 | (#) Associate a USART to the SMARTCARD handle hsc. |
mbed_official | 181:a4cbdfbbd2f4 | 25 | (#) Initialize the SMARTCARD low level resources by implementing the HAL_SMARTCARD_MspInit ()API: |
mbed_official | 181:a4cbdfbbd2f4 | 26 | (##) Enable the USARTx interface clock. |
mbed_official | 181:a4cbdfbbd2f4 | 27 | (##) USART pins configuration: |
mbed_official | 181:a4cbdfbbd2f4 | 28 | (+) Enable the clock for the USART GPIOs. |
mbed_official | 181:a4cbdfbbd2f4 | 29 | (+) Configure these USART pins as alternate function pull-up. |
mbed_official | 181:a4cbdfbbd2f4 | 30 | (##) NVIC configuration if you need to use interrupt process (HAL_SMARTCARD_Transmit_IT() |
mbed_official | 181:a4cbdfbbd2f4 | 31 | and HAL_SMARTCARD_Receive_IT() APIs): |
mbed_official | 181:a4cbdfbbd2f4 | 32 | (+) Configure the USARTx interrupt priority. |
mbed_official | 181:a4cbdfbbd2f4 | 33 | (+) Enable the NVIC USART IRQ handle. |
mbed_official | 181:a4cbdfbbd2f4 | 34 | (@) The specific USART interrupts (Transmission complete interrupt, |
mbed_official | 181:a4cbdfbbd2f4 | 35 | RXNE interrupt and Error Interrupts) will be managed using the macros |
mbed_official | 181:a4cbdfbbd2f4 | 36 | __HAL_SMARTCARD_ENABLE_IT() and __HAL_SMARTCARD_DISABLE_IT() inside the transmit and receive process. |
mbed_official | 181:a4cbdfbbd2f4 | 37 | (##) DMA Configuration if you need to use DMA process (HAL_SMARTCARD_Transmit_DMA() |
mbed_official | 181:a4cbdfbbd2f4 | 38 | and HAL_SMARTCARD_Receive_DMA() APIs): |
mbed_official | 181:a4cbdfbbd2f4 | 39 | (+) Declare a DMA handle structure for the Tx/Rx stream. |
mbed_official | 181:a4cbdfbbd2f4 | 40 | (+) Enable the DMAx interface clock. |
mbed_official | 181:a4cbdfbbd2f4 | 41 | (+) Configure the declared DMA handle structure with the required Tx/Rx parameters. |
mbed_official | 181:a4cbdfbbd2f4 | 42 | (+) Configure the DMA Tx/Rx Stream. |
mbed_official | 181:a4cbdfbbd2f4 | 43 | (+) Associate the initialized DMA handle to the SMARTCARD DMA Tx/Rx handle. |
mbed_official | 181:a4cbdfbbd2f4 | 44 | (+) Configure the priority and enable the NVIC for the transfer complete interrupt on the DMA Tx/Rx Stream. |
mbed_official | 181:a4cbdfbbd2f4 | 45 | |
mbed_official | 181:a4cbdfbbd2f4 | 46 | (#) Program the Baud Rate, Parity, Mode(Receiver/Transmitter), clock enabling/disabling and accordingly, |
mbed_official | 181:a4cbdfbbd2f4 | 47 | the clock parameters (parity, phase, last bit), prescaler value, guard time and NACK on transmission |
mbed_official | 181:a4cbdfbbd2f4 | 48 | error enabling or disabling in the hsc Init structure. |
mbed_official | 181:a4cbdfbbd2f4 | 49 | |
mbed_official | 181:a4cbdfbbd2f4 | 50 | (#) If required, program SMARTCARD advanced features (TX/RX pins swap, TimeOut, auto-retry counter,...) |
mbed_official | 181:a4cbdfbbd2f4 | 51 | in the hsc AdvancedInit structure. |
mbed_official | 181:a4cbdfbbd2f4 | 52 | |
mbed_official | 181:a4cbdfbbd2f4 | 53 | (#) Initialize the SMARTCARD associated USART registers by calling |
mbed_official | 181:a4cbdfbbd2f4 | 54 | the HAL_SMARTCARD_Init() API. |
mbed_official | 181:a4cbdfbbd2f4 | 55 | |
mbed_official | 181:a4cbdfbbd2f4 | 56 | (@) HAL_SMARTCARD_Init() API also configure also the low level Hardware GPIO, CLOCK, CORTEX...etc) by |
mbed_official | 181:a4cbdfbbd2f4 | 57 | calling the customized HAL_SMARTCARD_MspInit() API. |
mbed_official | 181:a4cbdfbbd2f4 | 58 | |
mbed_official | 181:a4cbdfbbd2f4 | 59 | @endverbatim |
mbed_official | 181:a4cbdfbbd2f4 | 60 | ****************************************************************************** |
mbed_official | 181:a4cbdfbbd2f4 | 61 | * @attention |
mbed_official | 181:a4cbdfbbd2f4 | 62 | * |
mbed_official | 181:a4cbdfbbd2f4 | 63 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
mbed_official | 181:a4cbdfbbd2f4 | 64 | * |
mbed_official | 181:a4cbdfbbd2f4 | 65 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 181:a4cbdfbbd2f4 | 66 | * are permitted provided that the following conditions are met: |
mbed_official | 181:a4cbdfbbd2f4 | 67 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 181:a4cbdfbbd2f4 | 68 | * this list of conditions and the following disclaimer. |
mbed_official | 181:a4cbdfbbd2f4 | 69 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 181:a4cbdfbbd2f4 | 70 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 181:a4cbdfbbd2f4 | 71 | * and/or other materials provided with the distribution. |
mbed_official | 181:a4cbdfbbd2f4 | 72 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 181:a4cbdfbbd2f4 | 73 | * may be used to endorse or promote products derived from this software |
mbed_official | 181:a4cbdfbbd2f4 | 74 | * without specific prior written permission. |
mbed_official | 181:a4cbdfbbd2f4 | 75 | * |
mbed_official | 181:a4cbdfbbd2f4 | 76 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 181:a4cbdfbbd2f4 | 77 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 181:a4cbdfbbd2f4 | 78 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 181:a4cbdfbbd2f4 | 79 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 181:a4cbdfbbd2f4 | 80 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 181:a4cbdfbbd2f4 | 81 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 181:a4cbdfbbd2f4 | 82 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 181:a4cbdfbbd2f4 | 83 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 181:a4cbdfbbd2f4 | 84 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 181:a4cbdfbbd2f4 | 85 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 181:a4cbdfbbd2f4 | 86 | * |
mbed_official | 181:a4cbdfbbd2f4 | 87 | ****************************************************************************** |
mbed_official | 181:a4cbdfbbd2f4 | 88 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 89 | |
mbed_official | 181:a4cbdfbbd2f4 | 90 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 91 | #include "stm32l0xx_hal.h" |
mbed_official | 181:a4cbdfbbd2f4 | 92 | |
mbed_official | 181:a4cbdfbbd2f4 | 93 | /** @addtogroup STM32L0xx_HAL_Driver |
mbed_official | 181:a4cbdfbbd2f4 | 94 | * @{ |
mbed_official | 181:a4cbdfbbd2f4 | 95 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 96 | |
mbed_official | 181:a4cbdfbbd2f4 | 97 | /** @defgroup SMARTCARD |
mbed_official | 181:a4cbdfbbd2f4 | 98 | * @brief HAL SMARTCARD module driver |
mbed_official | 181:a4cbdfbbd2f4 | 99 | * @{ |
mbed_official | 181:a4cbdfbbd2f4 | 100 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 101 | #ifdef HAL_SMARTCARD_MODULE_ENABLED |
mbed_official | 181:a4cbdfbbd2f4 | 102 | |
mbed_official | 181:a4cbdfbbd2f4 | 103 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 104 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 105 | #define TEACK_REACK_TIMEOUT 1000 |
mbed_official | 181:a4cbdfbbd2f4 | 106 | #define HAL_SMARTCARD_TXDMA_TIMEOUTVALUE 22000 |
mbed_official | 181:a4cbdfbbd2f4 | 107 | #define USART_CR1_FIELDS ((uint32_t)(USART_CR1_M | USART_CR1_PCE | USART_CR1_PS | \ |
mbed_official | 181:a4cbdfbbd2f4 | 108 | USART_CR1_TE | USART_CR1_RE | USART_CR1_OVER8)) |
mbed_official | 181:a4cbdfbbd2f4 | 109 | #define USART_CR2_CLK_FIELDS ((uint32_t)(USART_CR2_CLKEN|USART_CR2_CPOL|USART_CR2_CPHA|USART_CR2_LBCL)) |
mbed_official | 181:a4cbdfbbd2f4 | 110 | #define USART_CR2_FIELDS ((uint32_t)(USART_CR2_RTOEN|USART_CR2_CLK_FIELDS|USART_CR2_STOP)) |
mbed_official | 181:a4cbdfbbd2f4 | 111 | #define USART_CR3_FIELDS ((uint32_t)(USART_CR3_ONEBIT|USART_CR3_NACK|USART_CR3_SCARCNT)) |
mbed_official | 181:a4cbdfbbd2f4 | 112 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 113 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 114 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 115 | static void SMARTCARD_DMATransmitCplt(DMA_HandleTypeDef *hdma); |
mbed_official | 181:a4cbdfbbd2f4 | 116 | static void SMARTCARD_DMAReceiveCplt(DMA_HandleTypeDef *hdma); |
mbed_official | 181:a4cbdfbbd2f4 | 117 | static void SMARTCARD_DMAError(DMA_HandleTypeDef *hdma); |
mbed_official | 181:a4cbdfbbd2f4 | 118 | static void SMARTCARD_SetConfig(SMARTCARD_HandleTypeDef *hsc); |
mbed_official | 181:a4cbdfbbd2f4 | 119 | static HAL_StatusTypeDef SMARTCARD_WaitOnFlagUntilTimeout(SMARTCARD_HandleTypeDef *hsc, uint32_t Flag, FlagStatus Status, uint32_t Timeout); |
mbed_official | 181:a4cbdfbbd2f4 | 120 | static HAL_StatusTypeDef SMARTCARD_CheckIdleState(SMARTCARD_HandleTypeDef *hsc); |
mbed_official | 181:a4cbdfbbd2f4 | 121 | static HAL_StatusTypeDef SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsc); |
mbed_official | 181:a4cbdfbbd2f4 | 122 | static HAL_StatusTypeDef SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsc); |
mbed_official | 181:a4cbdfbbd2f4 | 123 | static void SMARTCARD_AdvFeatureConfig(SMARTCARD_HandleTypeDef *hsc); |
mbed_official | 181:a4cbdfbbd2f4 | 124 | /* Private functions ---------------------------------------------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 125 | |
mbed_official | 181:a4cbdfbbd2f4 | 126 | /** @defgroup SMARTCARD_Private_Functions |
mbed_official | 181:a4cbdfbbd2f4 | 127 | * @{ |
mbed_official | 181:a4cbdfbbd2f4 | 128 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 129 | |
mbed_official | 181:a4cbdfbbd2f4 | 130 | /** @defgroup HAL_SMARTCARD_Group1 Initialization/de-initialization methods |
mbed_official | 181:a4cbdfbbd2f4 | 131 | * @brief Initialization and Configuration functions |
mbed_official | 181:a4cbdfbbd2f4 | 132 | * |
mbed_official | 181:a4cbdfbbd2f4 | 133 | @verbatim |
mbed_official | 181:a4cbdfbbd2f4 | 134 | =============================================================================== |
mbed_official | 181:a4cbdfbbd2f4 | 135 | ##### Initialization and Configuration functions ##### |
mbed_official | 181:a4cbdfbbd2f4 | 136 | =============================================================================== |
mbed_official | 181:a4cbdfbbd2f4 | 137 | [..] |
mbed_official | 181:a4cbdfbbd2f4 | 138 | This subsection provides a set of functions allowing to initialize the USARTx |
mbed_official | 181:a4cbdfbbd2f4 | 139 | associated to the SmartCard. |
mbed_official | 181:a4cbdfbbd2f4 | 140 | (+) These parameters can be configured: |
mbed_official | 181:a4cbdfbbd2f4 | 141 | (++) Baud Rate |
mbed_official | 181:a4cbdfbbd2f4 | 142 | (++) Parity: parity should be enabled, |
mbed_official | 181:a4cbdfbbd2f4 | 143 | Frame Length is fixed to 8 bits plus parity: |
mbed_official | 181:a4cbdfbbd2f4 | 144 | the USART frame format is given in the following table: |
mbed_official | 181:a4cbdfbbd2f4 | 145 | +---------------------------------------------------------------+ |
mbed_official | 181:a4cbdfbbd2f4 | 146 | | M1M0 bits | PCE bit | USART frame | |
mbed_official | 181:a4cbdfbbd2f4 | 147 | |-----------------------|---------------------------------------| |
mbed_official | 181:a4cbdfbbd2f4 | 148 | | 01 | 1 | | SB | 8 bit data | PB | STB | | |
mbed_official | 181:a4cbdfbbd2f4 | 149 | +---------------------------------------------------------------+ |
mbed_official | 181:a4cbdfbbd2f4 | 150 | (++) Receiver/transmitter modes |
mbed_official | 181:a4cbdfbbd2f4 | 151 | (++) Synchronous mode (and if enabled, phase, polarity and last bit parameters) |
mbed_official | 181:a4cbdfbbd2f4 | 152 | (++) Prescaler value |
mbed_official | 181:a4cbdfbbd2f4 | 153 | (++) Guard bit time |
mbed_official | 181:a4cbdfbbd2f4 | 154 | (++) NACK enabling or disabling on transmission error |
mbed_official | 181:a4cbdfbbd2f4 | 155 | |
mbed_official | 181:a4cbdfbbd2f4 | 156 | (+) The following advanced features can be configured as well: |
mbed_official | 181:a4cbdfbbd2f4 | 157 | (++) TX and/or RX pin level inversion |
mbed_official | 181:a4cbdfbbd2f4 | 158 | (++) data logical level inversion |
mbed_official | 181:a4cbdfbbd2f4 | 159 | (++) RX and TX pins swap |
mbed_official | 181:a4cbdfbbd2f4 | 160 | (++) RX overrun detection disabling |
mbed_official | 181:a4cbdfbbd2f4 | 161 | (++) DMA disabling on RX error |
mbed_official | 181:a4cbdfbbd2f4 | 162 | (++) MSB first on communication line |
mbed_official | 181:a4cbdfbbd2f4 | 163 | (++) Time out enabling (and if activated, timeout value) |
mbed_official | 181:a4cbdfbbd2f4 | 164 | (++) Block length |
mbed_official | 181:a4cbdfbbd2f4 | 165 | (++) Auto-retry counter |
mbed_official | 181:a4cbdfbbd2f4 | 166 | |
mbed_official | 181:a4cbdfbbd2f4 | 167 | [..] |
mbed_official | 181:a4cbdfbbd2f4 | 168 | The HAL_SMARTCARD_Init() API follow respectively the USART (a)synchronous configuration procedures |
mbed_official | 181:a4cbdfbbd2f4 | 169 | (details for the procedures are available in reference manual). |
mbed_official | 181:a4cbdfbbd2f4 | 170 | |
mbed_official | 181:a4cbdfbbd2f4 | 171 | @endverbatim |
mbed_official | 181:a4cbdfbbd2f4 | 172 | * @{ |
mbed_official | 181:a4cbdfbbd2f4 | 173 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 174 | |
mbed_official | 181:a4cbdfbbd2f4 | 175 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 176 | * @brief Initializes the SMARTCARD mode according to the specified |
mbed_official | 181:a4cbdfbbd2f4 | 177 | * parameters in the SMARTCARD_InitTypeDef and creates the associated handle . |
mbed_official | 181:a4cbdfbbd2f4 | 178 | * @param hsc: SMARTCARD handle |
mbed_official | 181:a4cbdfbbd2f4 | 179 | * @retval HAL status |
mbed_official | 181:a4cbdfbbd2f4 | 180 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 181 | HAL_StatusTypeDef HAL_SMARTCARD_Init(SMARTCARD_HandleTypeDef *hsc) |
mbed_official | 181:a4cbdfbbd2f4 | 182 | { |
mbed_official | 181:a4cbdfbbd2f4 | 183 | /* Check the SMARTCARD handle allocation */ |
mbed_official | 181:a4cbdfbbd2f4 | 184 | if(hsc == NULL) |
mbed_official | 181:a4cbdfbbd2f4 | 185 | { |
mbed_official | 181:a4cbdfbbd2f4 | 186 | return HAL_ERROR; |
mbed_official | 181:a4cbdfbbd2f4 | 187 | } |
mbed_official | 181:a4cbdfbbd2f4 | 188 | |
mbed_official | 181:a4cbdfbbd2f4 | 189 | /* Check the USART associated to the SmartCard */ |
mbed_official | 181:a4cbdfbbd2f4 | 190 | assert_param(IS_SMARTCARD_INSTANCE(hsc->Instance)); |
mbed_official | 181:a4cbdfbbd2f4 | 191 | |
mbed_official | 181:a4cbdfbbd2f4 | 192 | if(hsc->State == HAL_SMARTCARD_STATE_RESET) |
mbed_official | 181:a4cbdfbbd2f4 | 193 | { |
mbed_official | 181:a4cbdfbbd2f4 | 194 | /* Init the low level hardware : GPIO, CLOCK, CORTEX */ |
mbed_official | 181:a4cbdfbbd2f4 | 195 | HAL_SMARTCARD_MspInit(hsc); |
mbed_official | 181:a4cbdfbbd2f4 | 196 | } |
mbed_official | 181:a4cbdfbbd2f4 | 197 | |
mbed_official | 181:a4cbdfbbd2f4 | 198 | hsc->State = HAL_SMARTCARD_STATE_BUSY; |
mbed_official | 181:a4cbdfbbd2f4 | 199 | |
mbed_official | 181:a4cbdfbbd2f4 | 200 | /* Disable the Peripheral */ |
mbed_official | 181:a4cbdfbbd2f4 | 201 | __HAL_SMARTCARD_DISABLE(hsc); |
mbed_official | 181:a4cbdfbbd2f4 | 202 | |
mbed_official | 181:a4cbdfbbd2f4 | 203 | /* Set the SMARTCARD Communication parameters */ |
mbed_official | 181:a4cbdfbbd2f4 | 204 | SMARTCARD_SetConfig(hsc); |
mbed_official | 181:a4cbdfbbd2f4 | 205 | |
mbed_official | 181:a4cbdfbbd2f4 | 206 | if(hsc->AdvancedInit.AdvFeatureInit != SMARTCARD_ADVFEATURE_NO_INIT) |
mbed_official | 181:a4cbdfbbd2f4 | 207 | { |
mbed_official | 181:a4cbdfbbd2f4 | 208 | SMARTCARD_AdvFeatureConfig(hsc); |
mbed_official | 181:a4cbdfbbd2f4 | 209 | } |
mbed_official | 181:a4cbdfbbd2f4 | 210 | |
mbed_official | 181:a4cbdfbbd2f4 | 211 | /* In SmartCard mode, the following bits must be kept cleared: |
mbed_official | 181:a4cbdfbbd2f4 | 212 | - LINEN in the USART_CR2 register, |
mbed_official | 181:a4cbdfbbd2f4 | 213 | - HDSEL and IREN bits in the USART_CR3 register.*/ |
mbed_official | 181:a4cbdfbbd2f4 | 214 | hsc->Instance->CR2 &= ~(USART_CR2_LINEN); |
mbed_official | 181:a4cbdfbbd2f4 | 215 | hsc->Instance->CR3 &= ~(USART_CR3_HDSEL | USART_CR3_IREN); |
mbed_official | 181:a4cbdfbbd2f4 | 216 | |
mbed_official | 181:a4cbdfbbd2f4 | 217 | /* set the USART in SMARTCARD mode */ |
mbed_official | 181:a4cbdfbbd2f4 | 218 | hsc->Instance->CR3 |= USART_CR3_SCEN; |
mbed_official | 181:a4cbdfbbd2f4 | 219 | |
mbed_official | 181:a4cbdfbbd2f4 | 220 | /* Enable the Peripheral */ |
mbed_official | 181:a4cbdfbbd2f4 | 221 | __HAL_SMARTCARD_ENABLE(hsc); |
mbed_official | 181:a4cbdfbbd2f4 | 222 | |
mbed_official | 181:a4cbdfbbd2f4 | 223 | /* TEACK and/or REACK to check before moving hsc->State to Ready */ |
mbed_official | 181:a4cbdfbbd2f4 | 224 | return (SMARTCARD_CheckIdleState(hsc)); |
mbed_official | 181:a4cbdfbbd2f4 | 225 | } |
mbed_official | 181:a4cbdfbbd2f4 | 226 | |
mbed_official | 181:a4cbdfbbd2f4 | 227 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 228 | * @brief DeInitializes the SMARTCARD peripheral |
mbed_official | 181:a4cbdfbbd2f4 | 229 | * @param hsc: SMARTCARD handle |
mbed_official | 181:a4cbdfbbd2f4 | 230 | * @retval HAL status |
mbed_official | 181:a4cbdfbbd2f4 | 231 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 232 | HAL_StatusTypeDef HAL_SMARTCARD_DeInit(SMARTCARD_HandleTypeDef *hsc) |
mbed_official | 181:a4cbdfbbd2f4 | 233 | { |
mbed_official | 181:a4cbdfbbd2f4 | 234 | /* Check the SMARTCARD handle allocation */ |
mbed_official | 181:a4cbdfbbd2f4 | 235 | if(hsc == NULL) |
mbed_official | 181:a4cbdfbbd2f4 | 236 | { |
mbed_official | 181:a4cbdfbbd2f4 | 237 | return HAL_ERROR; |
mbed_official | 181:a4cbdfbbd2f4 | 238 | } |
mbed_official | 181:a4cbdfbbd2f4 | 239 | |
mbed_official | 181:a4cbdfbbd2f4 | 240 | /* Check the parameters */ |
mbed_official | 181:a4cbdfbbd2f4 | 241 | assert_param(IS_SMARTCARD_INSTANCE(hsc->Instance)); |
mbed_official | 181:a4cbdfbbd2f4 | 242 | |
mbed_official | 181:a4cbdfbbd2f4 | 243 | hsc->State = HAL_SMARTCARD_STATE_BUSY; |
mbed_official | 181:a4cbdfbbd2f4 | 244 | |
mbed_official | 181:a4cbdfbbd2f4 | 245 | /* DeInit the low level hardware */ |
mbed_official | 181:a4cbdfbbd2f4 | 246 | HAL_SMARTCARD_MspDeInit(hsc); |
mbed_official | 181:a4cbdfbbd2f4 | 247 | |
mbed_official | 181:a4cbdfbbd2f4 | 248 | hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE; |
mbed_official | 181:a4cbdfbbd2f4 | 249 | hsc->State = HAL_SMARTCARD_STATE_RESET; |
mbed_official | 181:a4cbdfbbd2f4 | 250 | |
mbed_official | 181:a4cbdfbbd2f4 | 251 | /* Release Lock */ |
mbed_official | 181:a4cbdfbbd2f4 | 252 | __HAL_UNLOCK(hsc); |
mbed_official | 181:a4cbdfbbd2f4 | 253 | |
mbed_official | 181:a4cbdfbbd2f4 | 254 | return HAL_OK; |
mbed_official | 181:a4cbdfbbd2f4 | 255 | } |
mbed_official | 181:a4cbdfbbd2f4 | 256 | |
mbed_official | 181:a4cbdfbbd2f4 | 257 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 258 | * @brief SMARTCARD MSP Init |
mbed_official | 181:a4cbdfbbd2f4 | 259 | * @param hsc: SMARTCARD handle |
mbed_official | 181:a4cbdfbbd2f4 | 260 | * @retval None |
mbed_official | 181:a4cbdfbbd2f4 | 261 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 262 | __weak void HAL_SMARTCARD_MspInit(SMARTCARD_HandleTypeDef *hsc) |
mbed_official | 181:a4cbdfbbd2f4 | 263 | { |
mbed_official | 181:a4cbdfbbd2f4 | 264 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 181:a4cbdfbbd2f4 | 265 | the HAL_SMARTCARD_MspInit could be implenetd in the user file |
mbed_official | 181:a4cbdfbbd2f4 | 266 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 267 | } |
mbed_official | 181:a4cbdfbbd2f4 | 268 | |
mbed_official | 181:a4cbdfbbd2f4 | 269 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 270 | * @brief SMARTCARD MSP DeInit |
mbed_official | 181:a4cbdfbbd2f4 | 271 | * @param hsc: SMARTCARD handle |
mbed_official | 181:a4cbdfbbd2f4 | 272 | * @retval None |
mbed_official | 181:a4cbdfbbd2f4 | 273 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 274 | __weak void HAL_SMARTCARD_MspDeInit(SMARTCARD_HandleTypeDef *hsc) |
mbed_official | 181:a4cbdfbbd2f4 | 275 | { |
mbed_official | 181:a4cbdfbbd2f4 | 276 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 181:a4cbdfbbd2f4 | 277 | the HAL_SMARTCARD_MspDeInit could be implenetd in the user file |
mbed_official | 181:a4cbdfbbd2f4 | 278 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 279 | } |
mbed_official | 181:a4cbdfbbd2f4 | 280 | |
mbed_official | 181:a4cbdfbbd2f4 | 281 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 282 | * @} |
mbed_official | 181:a4cbdfbbd2f4 | 283 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 284 | |
mbed_official | 181:a4cbdfbbd2f4 | 285 | /** @defgroup HAL_SMARTCARD_Group2 IO operation methods |
mbed_official | 181:a4cbdfbbd2f4 | 286 | * @brief SMARTCARD Transmit/Receive functions |
mbed_official | 181:a4cbdfbbd2f4 | 287 | * |
mbed_official | 181:a4cbdfbbd2f4 | 288 | @verbatim |
mbed_official | 181:a4cbdfbbd2f4 | 289 | =============================================================================== |
mbed_official | 181:a4cbdfbbd2f4 | 290 | ##### I/O operation methods ##### |
mbed_official | 181:a4cbdfbbd2f4 | 291 | =============================================================================== |
mbed_official | 181:a4cbdfbbd2f4 | 292 | This subsection provides a set of functions allowing to manage the SMARTCARD data transfers. |
mbed_official | 181:a4cbdfbbd2f4 | 293 | |
mbed_official | 181:a4cbdfbbd2f4 | 294 | (#) There are two mode of transfer: |
mbed_official | 181:a4cbdfbbd2f4 | 295 | (+) Blocking mode: The communication is performed in polling mode. |
mbed_official | 181:a4cbdfbbd2f4 | 296 | The HAL status of all data processing is returned by the same function |
mbed_official | 181:a4cbdfbbd2f4 | 297 | after finishing transfer. |
mbed_official | 181:a4cbdfbbd2f4 | 298 | (+) No-Blocking mode: The communication is performed using Interrupts |
mbed_official | 181:a4cbdfbbd2f4 | 299 | or DMA, These API's return the HAL status. |
mbed_official | 181:a4cbdfbbd2f4 | 300 | The end of the data processing will be indicated through the |
mbed_official | 181:a4cbdfbbd2f4 | 301 | dedicated SMARTCARD IRQ when using Interrupt mode or the DMA IRQ when |
mbed_official | 181:a4cbdfbbd2f4 | 302 | using DMA mode. |
mbed_official | 181:a4cbdfbbd2f4 | 303 | The HAL_SMARTCARD_TxCpltCallback(), HAL_SMARTCARD_RxCpltCallback() user callbacks |
mbed_official | 181:a4cbdfbbd2f4 | 304 | will be executed respectivelly at the end of the transmit or Receive process |
mbed_official | 181:a4cbdfbbd2f4 | 305 | The HAL_SMARTCARD_ErrorCallback()user callback will be executed when a communication error is detected |
mbed_official | 181:a4cbdfbbd2f4 | 306 | |
mbed_official | 181:a4cbdfbbd2f4 | 307 | (#) Blocking mode API's are : |
mbed_official | 181:a4cbdfbbd2f4 | 308 | (+) HAL_SMARTCARD_Transmit() |
mbed_official | 181:a4cbdfbbd2f4 | 309 | (+) HAL_SMARTCARD_Receive() |
mbed_official | 181:a4cbdfbbd2f4 | 310 | |
mbed_official | 181:a4cbdfbbd2f4 | 311 | (#) Non-Blocking mode API's with Interrupt are : |
mbed_official | 181:a4cbdfbbd2f4 | 312 | (+) HAL_SMARTCARD_Transmit_IT() |
mbed_official | 181:a4cbdfbbd2f4 | 313 | (+) HAL_SMARTCARD_Receive_IT() |
mbed_official | 181:a4cbdfbbd2f4 | 314 | (+) HAL_SMARTCARD_IRQHandler() |
mbed_official | 181:a4cbdfbbd2f4 | 315 | (+) SMARTCARD_Transmit_IT() |
mbed_official | 181:a4cbdfbbd2f4 | 316 | (+) SMARTCARD_Receive_IT() |
mbed_official | 181:a4cbdfbbd2f4 | 317 | |
mbed_official | 181:a4cbdfbbd2f4 | 318 | (#) No-Blocking mode functions with DMA are : |
mbed_official | 181:a4cbdfbbd2f4 | 319 | (+) HAL_SMARTCARD_Transmit_DMA() |
mbed_official | 181:a4cbdfbbd2f4 | 320 | (+) HAL_SMARTCARD_Receive_DMA() |
mbed_official | 181:a4cbdfbbd2f4 | 321 | |
mbed_official | 181:a4cbdfbbd2f4 | 322 | (#) A set of Transfer Complete Callbacks are provided in No_Blocking mode: |
mbed_official | 181:a4cbdfbbd2f4 | 323 | (+) HAL_SMARTCARD_TxCpltCallback() |
mbed_official | 181:a4cbdfbbd2f4 | 324 | (+) HAL_SMARTCARD_RxCpltCallback() |
mbed_official | 181:a4cbdfbbd2f4 | 325 | (+) HAL_SMARTCARD_ErrorCallback() |
mbed_official | 181:a4cbdfbbd2f4 | 326 | |
mbed_official | 181:a4cbdfbbd2f4 | 327 | @endverbatim |
mbed_official | 181:a4cbdfbbd2f4 | 328 | * @{ |
mbed_official | 181:a4cbdfbbd2f4 | 329 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 330 | |
mbed_official | 181:a4cbdfbbd2f4 | 331 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 332 | * @brief Send an amount of data in blocking mode |
mbed_official | 181:a4cbdfbbd2f4 | 333 | * @param hsc: SMARTCARD handle |
mbed_official | 181:a4cbdfbbd2f4 | 334 | * @param pData: pointer to data buffer |
mbed_official | 181:a4cbdfbbd2f4 | 335 | * @param Size: amount of data to be sent |
mbed_official | 181:a4cbdfbbd2f4 | 336 | * @param Timeout : Timeout duration |
mbed_official | 181:a4cbdfbbd2f4 | 337 | * @retval HAL status |
mbed_official | 181:a4cbdfbbd2f4 | 338 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 339 | HAL_StatusTypeDef HAL_SMARTCARD_Transmit(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size, uint32_t Timeout) |
mbed_official | 181:a4cbdfbbd2f4 | 340 | { |
mbed_official | 181:a4cbdfbbd2f4 | 341 | if((hsc->State == HAL_SMARTCARD_STATE_READY) || (hsc->State == HAL_SMARTCARD_STATE_BUSY_RX)) |
mbed_official | 181:a4cbdfbbd2f4 | 342 | { |
mbed_official | 181:a4cbdfbbd2f4 | 343 | if((pData == NULL) || (Size == 0)) |
mbed_official | 181:a4cbdfbbd2f4 | 344 | { |
mbed_official | 181:a4cbdfbbd2f4 | 345 | return HAL_ERROR; |
mbed_official | 181:a4cbdfbbd2f4 | 346 | } |
mbed_official | 181:a4cbdfbbd2f4 | 347 | |
mbed_official | 181:a4cbdfbbd2f4 | 348 | /* Process Locked */ |
mbed_official | 181:a4cbdfbbd2f4 | 349 | __HAL_LOCK(hsc); |
mbed_official | 181:a4cbdfbbd2f4 | 350 | hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE; |
mbed_official | 181:a4cbdfbbd2f4 | 351 | /* Check if a non-blocking receive process is ongoing or not */ |
mbed_official | 181:a4cbdfbbd2f4 | 352 | if(hsc->State == HAL_SMARTCARD_STATE_BUSY_RX) |
mbed_official | 181:a4cbdfbbd2f4 | 353 | { |
mbed_official | 181:a4cbdfbbd2f4 | 354 | hsc->State = HAL_SMARTCARD_STATE_BUSY_TX_RX; |
mbed_official | 181:a4cbdfbbd2f4 | 355 | } |
mbed_official | 181:a4cbdfbbd2f4 | 356 | else |
mbed_official | 181:a4cbdfbbd2f4 | 357 | { |
mbed_official | 181:a4cbdfbbd2f4 | 358 | hsc->State = HAL_SMARTCARD_STATE_BUSY_TX; |
mbed_official | 181:a4cbdfbbd2f4 | 359 | } |
mbed_official | 181:a4cbdfbbd2f4 | 360 | |
mbed_official | 181:a4cbdfbbd2f4 | 361 | hsc->TxXferSize = Size; |
mbed_official | 181:a4cbdfbbd2f4 | 362 | hsc->TxXferCount = Size; |
mbed_official | 181:a4cbdfbbd2f4 | 363 | while(hsc->TxXferCount > 0) |
mbed_official | 181:a4cbdfbbd2f4 | 364 | { |
mbed_official | 181:a4cbdfbbd2f4 | 365 | hsc->TxXferCount--; |
mbed_official | 181:a4cbdfbbd2f4 | 366 | if(SMARTCARD_WaitOnFlagUntilTimeout(hsc, SMARTCARD_FLAG_TXE, RESET, Timeout) != HAL_OK) |
mbed_official | 181:a4cbdfbbd2f4 | 367 | { |
mbed_official | 181:a4cbdfbbd2f4 | 368 | return HAL_TIMEOUT; |
mbed_official | 181:a4cbdfbbd2f4 | 369 | } |
mbed_official | 181:a4cbdfbbd2f4 | 370 | hsc->Instance->TDR = (*pData++ & (uint8_t)0xFF); |
mbed_official | 181:a4cbdfbbd2f4 | 371 | } |
mbed_official | 181:a4cbdfbbd2f4 | 372 | if(SMARTCARD_WaitOnFlagUntilTimeout(hsc, SMARTCARD_FLAG_TC, RESET, Timeout) != HAL_OK) |
mbed_official | 181:a4cbdfbbd2f4 | 373 | { |
mbed_official | 181:a4cbdfbbd2f4 | 374 | return HAL_TIMEOUT; |
mbed_official | 181:a4cbdfbbd2f4 | 375 | } |
mbed_official | 181:a4cbdfbbd2f4 | 376 | /* Check if a non-blocking receive Process is ongoing or not */ |
mbed_official | 181:a4cbdfbbd2f4 | 377 | if(hsc->State == HAL_SMARTCARD_STATE_BUSY_TX_RX) |
mbed_official | 181:a4cbdfbbd2f4 | 378 | { |
mbed_official | 181:a4cbdfbbd2f4 | 379 | hsc->State = HAL_SMARTCARD_STATE_BUSY_RX; |
mbed_official | 181:a4cbdfbbd2f4 | 380 | } |
mbed_official | 181:a4cbdfbbd2f4 | 381 | else |
mbed_official | 181:a4cbdfbbd2f4 | 382 | { |
mbed_official | 181:a4cbdfbbd2f4 | 383 | hsc->State = HAL_SMARTCARD_STATE_READY; |
mbed_official | 181:a4cbdfbbd2f4 | 384 | } |
mbed_official | 181:a4cbdfbbd2f4 | 385 | |
mbed_official | 181:a4cbdfbbd2f4 | 386 | /* Process Unlocked */ |
mbed_official | 181:a4cbdfbbd2f4 | 387 | __HAL_UNLOCK(hsc); |
mbed_official | 181:a4cbdfbbd2f4 | 388 | |
mbed_official | 181:a4cbdfbbd2f4 | 389 | return HAL_OK; |
mbed_official | 181:a4cbdfbbd2f4 | 390 | } |
mbed_official | 181:a4cbdfbbd2f4 | 391 | else |
mbed_official | 181:a4cbdfbbd2f4 | 392 | { |
mbed_official | 181:a4cbdfbbd2f4 | 393 | return HAL_BUSY; |
mbed_official | 181:a4cbdfbbd2f4 | 394 | } |
mbed_official | 181:a4cbdfbbd2f4 | 395 | } |
mbed_official | 181:a4cbdfbbd2f4 | 396 | |
mbed_official | 181:a4cbdfbbd2f4 | 397 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 398 | * @brief Receive an amount of data in blocking mode |
mbed_official | 181:a4cbdfbbd2f4 | 399 | * @param hsc: SMARTCARD handle |
mbed_official | 181:a4cbdfbbd2f4 | 400 | * @param pData: pointer to data buffer |
mbed_official | 181:a4cbdfbbd2f4 | 401 | * @param Size: amount of data to be received |
mbed_official | 181:a4cbdfbbd2f4 | 402 | * @param Timeout : Timeout duration |
mbed_official | 181:a4cbdfbbd2f4 | 403 | * @retval HAL status |
mbed_official | 181:a4cbdfbbd2f4 | 404 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 405 | HAL_StatusTypeDef HAL_SMARTCARD_Receive(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size, uint32_t Timeout) |
mbed_official | 181:a4cbdfbbd2f4 | 406 | { |
mbed_official | 181:a4cbdfbbd2f4 | 407 | if((hsc->State == HAL_SMARTCARD_STATE_READY) || (hsc->State == HAL_SMARTCARD_STATE_BUSY_TX)) |
mbed_official | 181:a4cbdfbbd2f4 | 408 | { |
mbed_official | 181:a4cbdfbbd2f4 | 409 | if((pData == NULL) || (Size == 0)) |
mbed_official | 181:a4cbdfbbd2f4 | 410 | { |
mbed_official | 181:a4cbdfbbd2f4 | 411 | return HAL_ERROR; |
mbed_official | 181:a4cbdfbbd2f4 | 412 | } |
mbed_official | 181:a4cbdfbbd2f4 | 413 | |
mbed_official | 181:a4cbdfbbd2f4 | 414 | /* Process Locked */ |
mbed_official | 181:a4cbdfbbd2f4 | 415 | __HAL_LOCK(hsc); |
mbed_official | 181:a4cbdfbbd2f4 | 416 | |
mbed_official | 181:a4cbdfbbd2f4 | 417 | hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE; |
mbed_official | 181:a4cbdfbbd2f4 | 418 | /* Check if a non-blocking transmit process is ongoing or not */ |
mbed_official | 181:a4cbdfbbd2f4 | 419 | if(hsc->State == HAL_SMARTCARD_STATE_BUSY_TX) |
mbed_official | 181:a4cbdfbbd2f4 | 420 | { |
mbed_official | 181:a4cbdfbbd2f4 | 421 | hsc->State = HAL_SMARTCARD_STATE_BUSY_TX_RX; |
mbed_official | 181:a4cbdfbbd2f4 | 422 | } |
mbed_official | 181:a4cbdfbbd2f4 | 423 | else |
mbed_official | 181:a4cbdfbbd2f4 | 424 | { |
mbed_official | 181:a4cbdfbbd2f4 | 425 | hsc->State = HAL_SMARTCARD_STATE_BUSY_RX; |
mbed_official | 181:a4cbdfbbd2f4 | 426 | } |
mbed_official | 181:a4cbdfbbd2f4 | 427 | |
mbed_official | 181:a4cbdfbbd2f4 | 428 | hsc->RxXferSize = Size; |
mbed_official | 181:a4cbdfbbd2f4 | 429 | hsc->RxXferCount = Size; |
mbed_official | 181:a4cbdfbbd2f4 | 430 | /* Check the remain data to be received */ |
mbed_official | 181:a4cbdfbbd2f4 | 431 | while(hsc->RxXferCount > 0) |
mbed_official | 181:a4cbdfbbd2f4 | 432 | { |
mbed_official | 181:a4cbdfbbd2f4 | 433 | hsc->RxXferCount--; |
mbed_official | 181:a4cbdfbbd2f4 | 434 | if(SMARTCARD_WaitOnFlagUntilTimeout(hsc, SMARTCARD_FLAG_RXNE, RESET, Timeout) != HAL_OK) |
mbed_official | 181:a4cbdfbbd2f4 | 435 | { |
mbed_official | 181:a4cbdfbbd2f4 | 436 | return HAL_TIMEOUT; |
mbed_official | 181:a4cbdfbbd2f4 | 437 | } |
mbed_official | 181:a4cbdfbbd2f4 | 438 | *pData++ = (uint8_t)(hsc->Instance->RDR & (uint8_t)0x00FF); |
mbed_official | 181:a4cbdfbbd2f4 | 439 | } |
mbed_official | 181:a4cbdfbbd2f4 | 440 | |
mbed_official | 181:a4cbdfbbd2f4 | 441 | /* Check if a non-blocking transmit Process is ongoing or not */ |
mbed_official | 181:a4cbdfbbd2f4 | 442 | if(hsc->State == HAL_SMARTCARD_STATE_BUSY_TX_RX) |
mbed_official | 181:a4cbdfbbd2f4 | 443 | { |
mbed_official | 181:a4cbdfbbd2f4 | 444 | hsc->State = HAL_SMARTCARD_STATE_BUSY_TX; |
mbed_official | 181:a4cbdfbbd2f4 | 445 | } |
mbed_official | 181:a4cbdfbbd2f4 | 446 | else |
mbed_official | 181:a4cbdfbbd2f4 | 447 | { |
mbed_official | 181:a4cbdfbbd2f4 | 448 | hsc->State = HAL_SMARTCARD_STATE_READY; |
mbed_official | 181:a4cbdfbbd2f4 | 449 | } |
mbed_official | 181:a4cbdfbbd2f4 | 450 | |
mbed_official | 181:a4cbdfbbd2f4 | 451 | /* Process Unlocked */ |
mbed_official | 181:a4cbdfbbd2f4 | 452 | __HAL_UNLOCK(hsc); |
mbed_official | 181:a4cbdfbbd2f4 | 453 | |
mbed_official | 181:a4cbdfbbd2f4 | 454 | return HAL_OK; |
mbed_official | 181:a4cbdfbbd2f4 | 455 | } |
mbed_official | 181:a4cbdfbbd2f4 | 456 | else |
mbed_official | 181:a4cbdfbbd2f4 | 457 | { |
mbed_official | 181:a4cbdfbbd2f4 | 458 | return HAL_BUSY; |
mbed_official | 181:a4cbdfbbd2f4 | 459 | } |
mbed_official | 181:a4cbdfbbd2f4 | 460 | } |
mbed_official | 181:a4cbdfbbd2f4 | 461 | |
mbed_official | 181:a4cbdfbbd2f4 | 462 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 463 | * @brief Send an amount of data in interrupt mode |
mbed_official | 181:a4cbdfbbd2f4 | 464 | * @param hsc: SMARTCARD handle |
mbed_official | 181:a4cbdfbbd2f4 | 465 | * @param pData: pointer to data buffer |
mbed_official | 181:a4cbdfbbd2f4 | 466 | * @param Size: amount of data to be sent |
mbed_official | 181:a4cbdfbbd2f4 | 467 | * @retval HAL status |
mbed_official | 181:a4cbdfbbd2f4 | 468 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 469 | HAL_StatusTypeDef HAL_SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size) |
mbed_official | 181:a4cbdfbbd2f4 | 470 | { |
mbed_official | 181:a4cbdfbbd2f4 | 471 | if((hsc->State == HAL_SMARTCARD_STATE_READY) || (hsc->State == HAL_SMARTCARD_STATE_BUSY_RX)) |
mbed_official | 181:a4cbdfbbd2f4 | 472 | { |
mbed_official | 181:a4cbdfbbd2f4 | 473 | if((pData == NULL) || (Size == 0)) |
mbed_official | 181:a4cbdfbbd2f4 | 474 | { |
mbed_official | 181:a4cbdfbbd2f4 | 475 | return HAL_ERROR; |
mbed_official | 181:a4cbdfbbd2f4 | 476 | } |
mbed_official | 181:a4cbdfbbd2f4 | 477 | |
mbed_official | 181:a4cbdfbbd2f4 | 478 | /* Process Locked */ |
mbed_official | 181:a4cbdfbbd2f4 | 479 | __HAL_LOCK(hsc); |
mbed_official | 181:a4cbdfbbd2f4 | 480 | |
mbed_official | 181:a4cbdfbbd2f4 | 481 | hsc->pTxBuffPtr = pData; |
mbed_official | 181:a4cbdfbbd2f4 | 482 | hsc->TxXferSize = Size; |
mbed_official | 181:a4cbdfbbd2f4 | 483 | hsc->TxXferCount = Size; |
mbed_official | 181:a4cbdfbbd2f4 | 484 | |
mbed_official | 181:a4cbdfbbd2f4 | 485 | hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE; |
mbed_official | 181:a4cbdfbbd2f4 | 486 | /* Check if a receive process is ongoing or not */ |
mbed_official | 181:a4cbdfbbd2f4 | 487 | if(hsc->State == HAL_SMARTCARD_STATE_BUSY_RX) |
mbed_official | 181:a4cbdfbbd2f4 | 488 | { |
mbed_official | 181:a4cbdfbbd2f4 | 489 | hsc->State = HAL_SMARTCARD_STATE_BUSY_TX_RX; |
mbed_official | 181:a4cbdfbbd2f4 | 490 | } |
mbed_official | 181:a4cbdfbbd2f4 | 491 | else |
mbed_official | 181:a4cbdfbbd2f4 | 492 | { |
mbed_official | 181:a4cbdfbbd2f4 | 493 | hsc->State = HAL_SMARTCARD_STATE_BUSY_TX; |
mbed_official | 181:a4cbdfbbd2f4 | 494 | } |
mbed_official | 181:a4cbdfbbd2f4 | 495 | |
mbed_official | 181:a4cbdfbbd2f4 | 496 | /* Enable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */ |
mbed_official | 181:a4cbdfbbd2f4 | 497 | __HAL_SMARTCARD_ENABLE_IT(hsc, SMARTCARD_IT_ERR); |
mbed_official | 181:a4cbdfbbd2f4 | 498 | |
mbed_official | 181:a4cbdfbbd2f4 | 499 | /* Process Unlocked */ |
mbed_official | 181:a4cbdfbbd2f4 | 500 | __HAL_UNLOCK(hsc); |
mbed_official | 181:a4cbdfbbd2f4 | 501 | |
mbed_official | 181:a4cbdfbbd2f4 | 502 | /* Enable the SMARTCARD Transmit Complete Interrupt */ |
mbed_official | 181:a4cbdfbbd2f4 | 503 | __HAL_SMARTCARD_ENABLE_IT(hsc, SMARTCARD_IT_TC); |
mbed_official | 181:a4cbdfbbd2f4 | 504 | |
mbed_official | 181:a4cbdfbbd2f4 | 505 | return HAL_OK; |
mbed_official | 181:a4cbdfbbd2f4 | 506 | } |
mbed_official | 181:a4cbdfbbd2f4 | 507 | else |
mbed_official | 181:a4cbdfbbd2f4 | 508 | { |
mbed_official | 181:a4cbdfbbd2f4 | 509 | return HAL_BUSY; |
mbed_official | 181:a4cbdfbbd2f4 | 510 | } |
mbed_official | 181:a4cbdfbbd2f4 | 511 | } |
mbed_official | 181:a4cbdfbbd2f4 | 512 | |
mbed_official | 181:a4cbdfbbd2f4 | 513 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 514 | * @brief Receive an amount of data in interrupt mode |
mbed_official | 181:a4cbdfbbd2f4 | 515 | * @param hsc: SMARTCARD handle |
mbed_official | 181:a4cbdfbbd2f4 | 516 | * @param pData: pointer to data buffer |
mbed_official | 181:a4cbdfbbd2f4 | 517 | * @param Size: amount of data to be received |
mbed_official | 181:a4cbdfbbd2f4 | 518 | * @retval HAL status |
mbed_official | 181:a4cbdfbbd2f4 | 519 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 520 | HAL_StatusTypeDef HAL_SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size) |
mbed_official | 181:a4cbdfbbd2f4 | 521 | { |
mbed_official | 181:a4cbdfbbd2f4 | 522 | if((hsc->State == HAL_SMARTCARD_STATE_READY) || (hsc->State == HAL_SMARTCARD_STATE_BUSY_TX)) |
mbed_official | 181:a4cbdfbbd2f4 | 523 | { |
mbed_official | 181:a4cbdfbbd2f4 | 524 | if((pData == NULL) || (Size == 0)) |
mbed_official | 181:a4cbdfbbd2f4 | 525 | { |
mbed_official | 181:a4cbdfbbd2f4 | 526 | return HAL_ERROR; |
mbed_official | 181:a4cbdfbbd2f4 | 527 | } |
mbed_official | 181:a4cbdfbbd2f4 | 528 | |
mbed_official | 181:a4cbdfbbd2f4 | 529 | /* Process Locked */ |
mbed_official | 181:a4cbdfbbd2f4 | 530 | __HAL_LOCK(hsc); |
mbed_official | 181:a4cbdfbbd2f4 | 531 | |
mbed_official | 181:a4cbdfbbd2f4 | 532 | hsc->pRxBuffPtr = pData; |
mbed_official | 181:a4cbdfbbd2f4 | 533 | hsc->RxXferSize = Size; |
mbed_official | 181:a4cbdfbbd2f4 | 534 | hsc->RxXferCount = Size; |
mbed_official | 181:a4cbdfbbd2f4 | 535 | |
mbed_official | 181:a4cbdfbbd2f4 | 536 | hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE; |
mbed_official | 181:a4cbdfbbd2f4 | 537 | /* Check if a transmit process is ongoing or not */ |
mbed_official | 181:a4cbdfbbd2f4 | 538 | if(hsc->State == HAL_SMARTCARD_STATE_BUSY_TX) |
mbed_official | 181:a4cbdfbbd2f4 | 539 | { |
mbed_official | 181:a4cbdfbbd2f4 | 540 | hsc->State = HAL_SMARTCARD_STATE_BUSY_TX_RX; |
mbed_official | 181:a4cbdfbbd2f4 | 541 | } |
mbed_official | 181:a4cbdfbbd2f4 | 542 | else |
mbed_official | 181:a4cbdfbbd2f4 | 543 | { |
mbed_official | 181:a4cbdfbbd2f4 | 544 | hsc->State = HAL_SMARTCARD_STATE_BUSY_RX; |
mbed_official | 181:a4cbdfbbd2f4 | 545 | } |
mbed_official | 181:a4cbdfbbd2f4 | 546 | |
mbed_official | 181:a4cbdfbbd2f4 | 547 | /* Enable the SMARTCARD Parity Error Interrupt */ |
mbed_official | 181:a4cbdfbbd2f4 | 548 | __HAL_SMARTCARD_ENABLE_IT(hsc, SMARTCARD_IT_PE); |
mbed_official | 181:a4cbdfbbd2f4 | 549 | |
mbed_official | 181:a4cbdfbbd2f4 | 550 | /* Enable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */ |
mbed_official | 181:a4cbdfbbd2f4 | 551 | __HAL_SMARTCARD_ENABLE_IT(hsc, SMARTCARD_IT_ERR); |
mbed_official | 181:a4cbdfbbd2f4 | 552 | |
mbed_official | 181:a4cbdfbbd2f4 | 553 | /* Process Unlocked */ |
mbed_official | 181:a4cbdfbbd2f4 | 554 | __HAL_UNLOCK(hsc); |
mbed_official | 181:a4cbdfbbd2f4 | 555 | |
mbed_official | 181:a4cbdfbbd2f4 | 556 | /* Enable the SMARTCARD Data Register not empty Interrupt */ |
mbed_official | 181:a4cbdfbbd2f4 | 557 | __HAL_SMARTCARD_ENABLE_IT(hsc, SMARTCARD_IT_RXNE); |
mbed_official | 181:a4cbdfbbd2f4 | 558 | |
mbed_official | 181:a4cbdfbbd2f4 | 559 | return HAL_OK; |
mbed_official | 181:a4cbdfbbd2f4 | 560 | } |
mbed_official | 181:a4cbdfbbd2f4 | 561 | else |
mbed_official | 181:a4cbdfbbd2f4 | 562 | { |
mbed_official | 181:a4cbdfbbd2f4 | 563 | return HAL_BUSY; |
mbed_official | 181:a4cbdfbbd2f4 | 564 | } |
mbed_official | 181:a4cbdfbbd2f4 | 565 | } |
mbed_official | 181:a4cbdfbbd2f4 | 566 | |
mbed_official | 181:a4cbdfbbd2f4 | 567 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 568 | * @brief Send an amount of data in DMA mode |
mbed_official | 181:a4cbdfbbd2f4 | 569 | * @param hsc: SMARTCARD handle |
mbed_official | 181:a4cbdfbbd2f4 | 570 | * @param pData: pointer to data buffer |
mbed_official | 181:a4cbdfbbd2f4 | 571 | * @param Size: amount of data to be sent |
mbed_official | 181:a4cbdfbbd2f4 | 572 | * @retval HAL status |
mbed_official | 181:a4cbdfbbd2f4 | 573 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 574 | HAL_StatusTypeDef HAL_SMARTCARD_Transmit_DMA(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size) |
mbed_official | 181:a4cbdfbbd2f4 | 575 | { |
mbed_official | 181:a4cbdfbbd2f4 | 576 | uint32_t *tmp; |
mbed_official | 181:a4cbdfbbd2f4 | 577 | |
mbed_official | 181:a4cbdfbbd2f4 | 578 | if((hsc->State == HAL_SMARTCARD_STATE_READY) || (hsc->State == HAL_SMARTCARD_STATE_BUSY_RX)) |
mbed_official | 181:a4cbdfbbd2f4 | 579 | { |
mbed_official | 181:a4cbdfbbd2f4 | 580 | if((pData == NULL) || (Size == 0)) |
mbed_official | 181:a4cbdfbbd2f4 | 581 | { |
mbed_official | 181:a4cbdfbbd2f4 | 582 | return HAL_ERROR; |
mbed_official | 181:a4cbdfbbd2f4 | 583 | } |
mbed_official | 181:a4cbdfbbd2f4 | 584 | |
mbed_official | 181:a4cbdfbbd2f4 | 585 | /* Process Locked */ |
mbed_official | 181:a4cbdfbbd2f4 | 586 | __HAL_LOCK(hsc); |
mbed_official | 181:a4cbdfbbd2f4 | 587 | |
mbed_official | 181:a4cbdfbbd2f4 | 588 | hsc->pTxBuffPtr = pData; |
mbed_official | 181:a4cbdfbbd2f4 | 589 | hsc->TxXferSize = Size; |
mbed_official | 181:a4cbdfbbd2f4 | 590 | hsc->TxXferCount = Size; |
mbed_official | 181:a4cbdfbbd2f4 | 591 | |
mbed_official | 181:a4cbdfbbd2f4 | 592 | hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE; |
mbed_official | 181:a4cbdfbbd2f4 | 593 | /* Check if a receive process is ongoing or not */ |
mbed_official | 181:a4cbdfbbd2f4 | 594 | if(hsc->State == HAL_SMARTCARD_STATE_BUSY_RX) |
mbed_official | 181:a4cbdfbbd2f4 | 595 | { |
mbed_official | 181:a4cbdfbbd2f4 | 596 | hsc->State = HAL_SMARTCARD_STATE_BUSY_TX_RX; |
mbed_official | 181:a4cbdfbbd2f4 | 597 | } |
mbed_official | 181:a4cbdfbbd2f4 | 598 | else |
mbed_official | 181:a4cbdfbbd2f4 | 599 | { |
mbed_official | 181:a4cbdfbbd2f4 | 600 | hsc->State = HAL_SMARTCARD_STATE_BUSY_TX; |
mbed_official | 181:a4cbdfbbd2f4 | 601 | } |
mbed_official | 181:a4cbdfbbd2f4 | 602 | |
mbed_official | 181:a4cbdfbbd2f4 | 603 | /* Set the SMARTCARD DMA transfert complete callback */ |
mbed_official | 181:a4cbdfbbd2f4 | 604 | hsc->hdmatx->XferCpltCallback = SMARTCARD_DMATransmitCplt; |
mbed_official | 181:a4cbdfbbd2f4 | 605 | |
mbed_official | 181:a4cbdfbbd2f4 | 606 | /* Set the SMARTCARD error callback */ |
mbed_official | 181:a4cbdfbbd2f4 | 607 | hsc->hdmatx->XferErrorCallback = SMARTCARD_DMAError; |
mbed_official | 181:a4cbdfbbd2f4 | 608 | |
mbed_official | 181:a4cbdfbbd2f4 | 609 | /* Enable the SMARTCARD transmit DMA Stream */ |
mbed_official | 181:a4cbdfbbd2f4 | 610 | tmp = (uint32_t*)&pData; |
mbed_official | 181:a4cbdfbbd2f4 | 611 | HAL_DMA_Start_IT(hsc->hdmatx, *(uint32_t*)tmp, (uint32_t)&hsc->Instance->TDR, Size); |
mbed_official | 181:a4cbdfbbd2f4 | 612 | |
mbed_official | 181:a4cbdfbbd2f4 | 613 | /* Enable the DMA transfer for transmit request by setting the DMAT bit |
mbed_official | 181:a4cbdfbbd2f4 | 614 | in the SMARTCARD associated USART CR3 register */ |
mbed_official | 181:a4cbdfbbd2f4 | 615 | hsc->Instance->CR3 |= USART_CR3_DMAT; |
mbed_official | 181:a4cbdfbbd2f4 | 616 | |
mbed_official | 181:a4cbdfbbd2f4 | 617 | /* Process Unlocked */ |
mbed_official | 181:a4cbdfbbd2f4 | 618 | __HAL_UNLOCK(hsc); |
mbed_official | 181:a4cbdfbbd2f4 | 619 | |
mbed_official | 181:a4cbdfbbd2f4 | 620 | return HAL_OK; |
mbed_official | 181:a4cbdfbbd2f4 | 621 | } |
mbed_official | 181:a4cbdfbbd2f4 | 622 | else |
mbed_official | 181:a4cbdfbbd2f4 | 623 | { |
mbed_official | 181:a4cbdfbbd2f4 | 624 | return HAL_BUSY; |
mbed_official | 181:a4cbdfbbd2f4 | 625 | } |
mbed_official | 181:a4cbdfbbd2f4 | 626 | } |
mbed_official | 181:a4cbdfbbd2f4 | 627 | |
mbed_official | 181:a4cbdfbbd2f4 | 628 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 629 | * @brief Receive an amount of data in DMA mode |
mbed_official | 181:a4cbdfbbd2f4 | 630 | * @param hsc: SMARTCARD handle |
mbed_official | 181:a4cbdfbbd2f4 | 631 | * @param pData: pointer to data buffer |
mbed_official | 181:a4cbdfbbd2f4 | 632 | * @param Size: amount of data to be received |
mbed_official | 181:a4cbdfbbd2f4 | 633 | * @note The SMARTCARD-associated USART parity is enabled (PCE = 1), |
mbed_official | 181:a4cbdfbbd2f4 | 634 | * the received data contain the parity bit (MSB position) |
mbed_official | 181:a4cbdfbbd2f4 | 635 | * @retval HAL status |
mbed_official | 181:a4cbdfbbd2f4 | 636 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 637 | HAL_StatusTypeDef HAL_SMARTCARD_Receive_DMA(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size) |
mbed_official | 181:a4cbdfbbd2f4 | 638 | { |
mbed_official | 181:a4cbdfbbd2f4 | 639 | uint32_t *tmp; |
mbed_official | 181:a4cbdfbbd2f4 | 640 | |
mbed_official | 181:a4cbdfbbd2f4 | 641 | if((hsc->State == HAL_SMARTCARD_STATE_READY) || (hsc->State == HAL_SMARTCARD_STATE_BUSY_TX)) |
mbed_official | 181:a4cbdfbbd2f4 | 642 | { |
mbed_official | 181:a4cbdfbbd2f4 | 643 | if((pData == NULL) || (Size == 0)) |
mbed_official | 181:a4cbdfbbd2f4 | 644 | { |
mbed_official | 181:a4cbdfbbd2f4 | 645 | return HAL_ERROR; |
mbed_official | 181:a4cbdfbbd2f4 | 646 | } |
mbed_official | 181:a4cbdfbbd2f4 | 647 | |
mbed_official | 181:a4cbdfbbd2f4 | 648 | /* Process Locked */ |
mbed_official | 181:a4cbdfbbd2f4 | 649 | __HAL_LOCK(hsc); |
mbed_official | 181:a4cbdfbbd2f4 | 650 | |
mbed_official | 181:a4cbdfbbd2f4 | 651 | hsc->pRxBuffPtr = pData; |
mbed_official | 181:a4cbdfbbd2f4 | 652 | hsc->RxXferSize = Size; |
mbed_official | 181:a4cbdfbbd2f4 | 653 | |
mbed_official | 181:a4cbdfbbd2f4 | 654 | hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE; |
mbed_official | 181:a4cbdfbbd2f4 | 655 | /* Check if a transmit rocess is ongoing or not */ |
mbed_official | 181:a4cbdfbbd2f4 | 656 | if(hsc->State == HAL_SMARTCARD_STATE_BUSY_TX) |
mbed_official | 181:a4cbdfbbd2f4 | 657 | { |
mbed_official | 181:a4cbdfbbd2f4 | 658 | hsc->State = HAL_SMARTCARD_STATE_BUSY_TX_RX; |
mbed_official | 181:a4cbdfbbd2f4 | 659 | } |
mbed_official | 181:a4cbdfbbd2f4 | 660 | else |
mbed_official | 181:a4cbdfbbd2f4 | 661 | { |
mbed_official | 181:a4cbdfbbd2f4 | 662 | hsc->State = HAL_SMARTCARD_STATE_BUSY_RX; |
mbed_official | 181:a4cbdfbbd2f4 | 663 | } |
mbed_official | 181:a4cbdfbbd2f4 | 664 | |
mbed_official | 181:a4cbdfbbd2f4 | 665 | /* Set the SMARTCARD DMA transfert complete callback */ |
mbed_official | 181:a4cbdfbbd2f4 | 666 | hsc->hdmarx->XferCpltCallback = SMARTCARD_DMAReceiveCplt; |
mbed_official | 181:a4cbdfbbd2f4 | 667 | |
mbed_official | 181:a4cbdfbbd2f4 | 668 | /* Set the SMARTCARD DMA error callback */ |
mbed_official | 181:a4cbdfbbd2f4 | 669 | hsc->hdmarx->XferErrorCallback = SMARTCARD_DMAError; |
mbed_official | 181:a4cbdfbbd2f4 | 670 | |
mbed_official | 181:a4cbdfbbd2f4 | 671 | /* Enable the DMA Stream */ |
mbed_official | 181:a4cbdfbbd2f4 | 672 | tmp = (uint32_t*)&pData; |
mbed_official | 181:a4cbdfbbd2f4 | 673 | HAL_DMA_Start_IT(hsc->hdmarx, (uint32_t)&hsc->Instance->RDR, *(uint32_t*)tmp, Size); |
mbed_official | 181:a4cbdfbbd2f4 | 674 | |
mbed_official | 181:a4cbdfbbd2f4 | 675 | /* Enable the DMA transfer for the receiver request by setting the DMAR bit |
mbed_official | 181:a4cbdfbbd2f4 | 676 | in the SMARTCARD associated USART CR3 register */ |
mbed_official | 181:a4cbdfbbd2f4 | 677 | hsc->Instance->CR3 |= USART_CR3_DMAR; |
mbed_official | 181:a4cbdfbbd2f4 | 678 | |
mbed_official | 181:a4cbdfbbd2f4 | 679 | /* Process Unlocked */ |
mbed_official | 181:a4cbdfbbd2f4 | 680 | __HAL_UNLOCK(hsc); |
mbed_official | 181:a4cbdfbbd2f4 | 681 | |
mbed_official | 181:a4cbdfbbd2f4 | 682 | return HAL_OK; |
mbed_official | 181:a4cbdfbbd2f4 | 683 | } |
mbed_official | 181:a4cbdfbbd2f4 | 684 | else |
mbed_official | 181:a4cbdfbbd2f4 | 685 | { |
mbed_official | 181:a4cbdfbbd2f4 | 686 | return HAL_BUSY; |
mbed_official | 181:a4cbdfbbd2f4 | 687 | } |
mbed_official | 181:a4cbdfbbd2f4 | 688 | } |
mbed_official | 181:a4cbdfbbd2f4 | 689 | |
mbed_official | 181:a4cbdfbbd2f4 | 690 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 691 | * @brief SMARTCARD interrupt requests handling. |
mbed_official | 181:a4cbdfbbd2f4 | 692 | * @param hsc: SMARTCARD handle |
mbed_official | 181:a4cbdfbbd2f4 | 693 | * @retval None |
mbed_official | 181:a4cbdfbbd2f4 | 694 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 695 | void HAL_SMARTCARD_IRQHandler(SMARTCARD_HandleTypeDef *hsc) |
mbed_official | 181:a4cbdfbbd2f4 | 696 | { |
mbed_official | 181:a4cbdfbbd2f4 | 697 | /* SMARTCARD parity error interrupt occurred -------------------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 698 | if((__HAL_SMARTCARD_GET_IT(hsc, SMARTCARD_IT_PE) != RESET) && (__HAL_SMARTCARD_GET_IT_SOURCE(hsc, SMARTCARD_IT_PE) != RESET)) |
mbed_official | 181:a4cbdfbbd2f4 | 699 | { |
mbed_official | 181:a4cbdfbbd2f4 | 700 | __HAL_SMARTCARD_CLEAR_IT(hsc, SMARTCARD_CLEAR_PEF); |
mbed_official | 181:a4cbdfbbd2f4 | 701 | hsc->ErrorCode |= HAL_SMARTCARD_ERROR_PE; |
mbed_official | 181:a4cbdfbbd2f4 | 702 | /* Set the SMARTCARD state ready to be able to start again the process */ |
mbed_official | 181:a4cbdfbbd2f4 | 703 | hsc->State = HAL_SMARTCARD_STATE_READY; |
mbed_official | 181:a4cbdfbbd2f4 | 704 | } |
mbed_official | 181:a4cbdfbbd2f4 | 705 | |
mbed_official | 181:a4cbdfbbd2f4 | 706 | /* SMARTCARD frame error interrupt occured ---------------------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 707 | if((__HAL_SMARTCARD_GET_IT(hsc, SMARTCARD_IT_FE) != RESET) && (__HAL_SMARTCARD_GET_IT_SOURCE(hsc, SMARTCARD_IT_ERR) != RESET)) |
mbed_official | 181:a4cbdfbbd2f4 | 708 | { |
mbed_official | 181:a4cbdfbbd2f4 | 709 | __HAL_SMARTCARD_CLEAR_IT(hsc, SMARTCARD_CLEAR_FEF); |
mbed_official | 181:a4cbdfbbd2f4 | 710 | hsc->ErrorCode |= HAL_SMARTCARD_ERROR_FE; |
mbed_official | 181:a4cbdfbbd2f4 | 711 | /* Set the SMARTCARD state ready to be able to start again the process */ |
mbed_official | 181:a4cbdfbbd2f4 | 712 | hsc->State = HAL_SMARTCARD_STATE_READY; |
mbed_official | 181:a4cbdfbbd2f4 | 713 | } |
mbed_official | 181:a4cbdfbbd2f4 | 714 | |
mbed_official | 181:a4cbdfbbd2f4 | 715 | /* SMARTCARD noise error interrupt occured ---------------------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 716 | if((__HAL_SMARTCARD_GET_IT(hsc, SMARTCARD_IT_NE) != RESET) && (__HAL_SMARTCARD_GET_IT_SOURCE(hsc, SMARTCARD_IT_ERR) != RESET)) |
mbed_official | 181:a4cbdfbbd2f4 | 717 | { |
mbed_official | 181:a4cbdfbbd2f4 | 718 | __HAL_SMARTCARD_CLEAR_IT(hsc, SMARTCARD_CLEAR_NEF); |
mbed_official | 181:a4cbdfbbd2f4 | 719 | hsc->ErrorCode |= HAL_SMARTCARD_ERROR_NE; |
mbed_official | 181:a4cbdfbbd2f4 | 720 | /* Set the SMARTCARD state ready to be able to start again the process */ |
mbed_official | 181:a4cbdfbbd2f4 | 721 | hsc->State = HAL_SMARTCARD_STATE_READY; |
mbed_official | 181:a4cbdfbbd2f4 | 722 | } |
mbed_official | 181:a4cbdfbbd2f4 | 723 | |
mbed_official | 181:a4cbdfbbd2f4 | 724 | /* SMARTCARD Over-Run interrupt occured ------------------------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 725 | if((__HAL_SMARTCARD_GET_IT(hsc, SMARTCARD_IT_ORE) != RESET) && (__HAL_SMARTCARD_GET_IT_SOURCE(hsc, SMARTCARD_IT_ERR) != RESET)) |
mbed_official | 181:a4cbdfbbd2f4 | 726 | { |
mbed_official | 181:a4cbdfbbd2f4 | 727 | __HAL_SMARTCARD_CLEAR_IT(hsc, SMARTCARD_CLEAR_OREF); |
mbed_official | 181:a4cbdfbbd2f4 | 728 | hsc->ErrorCode |= HAL_SMARTCARD_ERROR_ORE; |
mbed_official | 181:a4cbdfbbd2f4 | 729 | /* Set the SMARTCARD state ready to be able to start again the process */ |
mbed_official | 181:a4cbdfbbd2f4 | 730 | hsc->State = HAL_SMARTCARD_STATE_READY; |
mbed_official | 181:a4cbdfbbd2f4 | 731 | } |
mbed_official | 181:a4cbdfbbd2f4 | 732 | |
mbed_official | 181:a4cbdfbbd2f4 | 733 | /* SMARTCARD receiver timeout interrupt occured ----------------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 734 | if((__HAL_SMARTCARD_GET_IT(hsc, SMARTCARD_IT_RTO) != RESET) && (__HAL_SMARTCARD_GET_IT_SOURCE(hsc, SMARTCARD_IT_RTO) != RESET)) |
mbed_official | 181:a4cbdfbbd2f4 | 735 | { |
mbed_official | 181:a4cbdfbbd2f4 | 736 | __HAL_SMARTCARD_CLEAR_IT(hsc, SMARTCARD_CLEAR_RTOF); |
mbed_official | 181:a4cbdfbbd2f4 | 737 | hsc->ErrorCode |= HAL_SMARTCARD_ERROR_RTO; |
mbed_official | 181:a4cbdfbbd2f4 | 738 | /* Set the SMARTCARD state ready to be able to start again the process */ |
mbed_official | 181:a4cbdfbbd2f4 | 739 | hsc->State = HAL_SMARTCARD_STATE_READY; |
mbed_official | 181:a4cbdfbbd2f4 | 740 | } |
mbed_official | 181:a4cbdfbbd2f4 | 741 | |
mbed_official | 181:a4cbdfbbd2f4 | 742 | /* Call SMARTCARD Error Call back function if need be ----------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 743 | if(hsc->ErrorCode != HAL_SMARTCARD_ERROR_NONE) |
mbed_official | 181:a4cbdfbbd2f4 | 744 | { |
mbed_official | 181:a4cbdfbbd2f4 | 745 | HAL_SMARTCARD_ErrorCallback(hsc); |
mbed_official | 181:a4cbdfbbd2f4 | 746 | } |
mbed_official | 181:a4cbdfbbd2f4 | 747 | |
mbed_official | 181:a4cbdfbbd2f4 | 748 | /* SMARTCARD in mode Receiver ----------------------------------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 749 | if((__HAL_SMARTCARD_GET_IT(hsc, SMARTCARD_IT_RXNE) != RESET) && (__HAL_SMARTCARD_GET_IT_SOURCE(hsc, SMARTCARD_IT_RXNE) != RESET)) |
mbed_official | 181:a4cbdfbbd2f4 | 750 | { |
mbed_official | 181:a4cbdfbbd2f4 | 751 | SMARTCARD_Receive_IT(hsc); |
mbed_official | 181:a4cbdfbbd2f4 | 752 | /* Clear RXNE interrupt flag */ |
mbed_official | 181:a4cbdfbbd2f4 | 753 | __HAL_SMARTCARD_SEND_REQ(hsc, SMARTCARD_RXDATA_FLUSH_REQUEST); |
mbed_official | 181:a4cbdfbbd2f4 | 754 | } |
mbed_official | 181:a4cbdfbbd2f4 | 755 | |
mbed_official | 181:a4cbdfbbd2f4 | 756 | /* SMARTCARD in mode Receiver, end of block interruption -------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 757 | if((__HAL_SMARTCARD_GET_IT(hsc, SMARTCARD_IT_EOB) != RESET) && (__HAL_SMARTCARD_GET_IT_SOURCE(hsc, SMARTCARD_IT_EOB) != RESET)) |
mbed_official | 181:a4cbdfbbd2f4 | 758 | { |
mbed_official | 181:a4cbdfbbd2f4 | 759 | hsc->State = HAL_SMARTCARD_STATE_READY; |
mbed_official | 181:a4cbdfbbd2f4 | 760 | HAL_SMARTCARD_RxCpltCallback(hsc); |
mbed_official | 181:a4cbdfbbd2f4 | 761 | /* Clear EOBF interrupt after HAL_SMARTCARD_RxCpltCallback() call for the End of Block information |
mbed_official | 181:a4cbdfbbd2f4 | 762 | * to be available during HAL_SMARTCARD_RxCpltCallback() processing */ |
mbed_official | 181:a4cbdfbbd2f4 | 763 | __HAL_SMARTCARD_CLEAR_IT(hsc, SMARTCARD_CLEAR_EOBF); |
mbed_official | 181:a4cbdfbbd2f4 | 764 | } |
mbed_official | 181:a4cbdfbbd2f4 | 765 | |
mbed_official | 181:a4cbdfbbd2f4 | 766 | /* SMARTCARD in mode Transmitter -------------------------------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 767 | if((__HAL_SMARTCARD_GET_IT(hsc, SMARTCARD_IT_TC) != RESET) && (__HAL_SMARTCARD_GET_IT_SOURCE(hsc, SMARTCARD_IT_TC) != RESET)) |
mbed_official | 181:a4cbdfbbd2f4 | 768 | { |
mbed_official | 181:a4cbdfbbd2f4 | 769 | SMARTCARD_Transmit_IT(hsc); |
mbed_official | 181:a4cbdfbbd2f4 | 770 | } |
mbed_official | 181:a4cbdfbbd2f4 | 771 | } |
mbed_official | 181:a4cbdfbbd2f4 | 772 | |
mbed_official | 181:a4cbdfbbd2f4 | 773 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 774 | * @brief This function handles SMARTCARD Communication Timeout. |
mbed_official | 181:a4cbdfbbd2f4 | 775 | * @param hsc: SMARTCARD handle |
mbed_official | 181:a4cbdfbbd2f4 | 776 | * @param Flag: specifies the SMARTCARD flag to check. |
mbed_official | 181:a4cbdfbbd2f4 | 777 | * @param Status: The new Flag status (SET or RESET). |
mbed_official | 181:a4cbdfbbd2f4 | 778 | * @param Timeout: Timeout duration |
mbed_official | 181:a4cbdfbbd2f4 | 779 | * @retval HAL status |
mbed_official | 181:a4cbdfbbd2f4 | 780 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 781 | static HAL_StatusTypeDef SMARTCARD_WaitOnFlagUntilTimeout(SMARTCARD_HandleTypeDef *hsc, uint32_t Flag, FlagStatus Status, uint32_t Timeout) |
mbed_official | 181:a4cbdfbbd2f4 | 782 | { |
mbed_official | 181:a4cbdfbbd2f4 | 783 | uint32_t tickstart = 0x00; |
mbed_official | 181:a4cbdfbbd2f4 | 784 | tickstart = HAL_GetTick(); |
mbed_official | 181:a4cbdfbbd2f4 | 785 | |
mbed_official | 181:a4cbdfbbd2f4 | 786 | /* Wait until flag is set */ |
mbed_official | 181:a4cbdfbbd2f4 | 787 | if(Status == RESET) |
mbed_official | 181:a4cbdfbbd2f4 | 788 | { |
mbed_official | 181:a4cbdfbbd2f4 | 789 | while(__HAL_SMARTCARD_GET_FLAG(hsc, Flag) == RESET) |
mbed_official | 181:a4cbdfbbd2f4 | 790 | { |
mbed_official | 181:a4cbdfbbd2f4 | 791 | /* Check for the Timeout */ |
mbed_official | 181:a4cbdfbbd2f4 | 792 | if(Timeout != HAL_MAX_DELAY) |
mbed_official | 181:a4cbdfbbd2f4 | 793 | { |
mbed_official | 181:a4cbdfbbd2f4 | 794 | if((HAL_GetTick() - tickstart ) > Timeout) |
mbed_official | 181:a4cbdfbbd2f4 | 795 | { |
mbed_official | 181:a4cbdfbbd2f4 | 796 | /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */ |
mbed_official | 181:a4cbdfbbd2f4 | 797 | __HAL_SMARTCARD_DISABLE_IT(hsc, SMARTCARD_IT_TXE); |
mbed_official | 181:a4cbdfbbd2f4 | 798 | __HAL_SMARTCARD_DISABLE_IT(hsc, SMARTCARD_IT_RXNE); |
mbed_official | 181:a4cbdfbbd2f4 | 799 | __HAL_SMARTCARD_DISABLE_IT(hsc, SMARTCARD_IT_PE); |
mbed_official | 181:a4cbdfbbd2f4 | 800 | __HAL_SMARTCARD_DISABLE_IT(hsc, SMARTCARD_IT_ERR); |
mbed_official | 181:a4cbdfbbd2f4 | 801 | |
mbed_official | 181:a4cbdfbbd2f4 | 802 | hsc->State= HAL_SMARTCARD_STATE_READY; |
mbed_official | 181:a4cbdfbbd2f4 | 803 | |
mbed_official | 181:a4cbdfbbd2f4 | 804 | /* Process Unlocked */ |
mbed_official | 181:a4cbdfbbd2f4 | 805 | __HAL_UNLOCK(hsc); |
mbed_official | 181:a4cbdfbbd2f4 | 806 | |
mbed_official | 181:a4cbdfbbd2f4 | 807 | return HAL_TIMEOUT; |
mbed_official | 181:a4cbdfbbd2f4 | 808 | } |
mbed_official | 181:a4cbdfbbd2f4 | 809 | } |
mbed_official | 181:a4cbdfbbd2f4 | 810 | } |
mbed_official | 181:a4cbdfbbd2f4 | 811 | } |
mbed_official | 181:a4cbdfbbd2f4 | 812 | else |
mbed_official | 181:a4cbdfbbd2f4 | 813 | { |
mbed_official | 181:a4cbdfbbd2f4 | 814 | while(__HAL_SMARTCARD_GET_FLAG(hsc, Flag) != RESET) |
mbed_official | 181:a4cbdfbbd2f4 | 815 | { |
mbed_official | 181:a4cbdfbbd2f4 | 816 | /* Check for the Timeout */ |
mbed_official | 181:a4cbdfbbd2f4 | 817 | if(Timeout != HAL_MAX_DELAY) |
mbed_official | 181:a4cbdfbbd2f4 | 818 | { |
mbed_official | 181:a4cbdfbbd2f4 | 819 | if((HAL_GetTick() - tickstart ) > Timeout) |
mbed_official | 181:a4cbdfbbd2f4 | 820 | { |
mbed_official | 181:a4cbdfbbd2f4 | 821 | /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */ |
mbed_official | 181:a4cbdfbbd2f4 | 822 | __HAL_SMARTCARD_DISABLE_IT(hsc, SMARTCARD_IT_TXE); |
mbed_official | 181:a4cbdfbbd2f4 | 823 | __HAL_SMARTCARD_DISABLE_IT(hsc, SMARTCARD_IT_RXNE); |
mbed_official | 181:a4cbdfbbd2f4 | 824 | __HAL_SMARTCARD_DISABLE_IT(hsc, SMARTCARD_IT_PE); |
mbed_official | 181:a4cbdfbbd2f4 | 825 | __HAL_SMARTCARD_DISABLE_IT(hsc, SMARTCARD_IT_ERR); |
mbed_official | 181:a4cbdfbbd2f4 | 826 | |
mbed_official | 181:a4cbdfbbd2f4 | 827 | hsc->State= HAL_SMARTCARD_STATE_READY; |
mbed_official | 181:a4cbdfbbd2f4 | 828 | |
mbed_official | 181:a4cbdfbbd2f4 | 829 | /* Process Unlocked */ |
mbed_official | 181:a4cbdfbbd2f4 | 830 | __HAL_UNLOCK(hsc); |
mbed_official | 181:a4cbdfbbd2f4 | 831 | |
mbed_official | 181:a4cbdfbbd2f4 | 832 | return HAL_TIMEOUT; |
mbed_official | 181:a4cbdfbbd2f4 | 833 | } |
mbed_official | 181:a4cbdfbbd2f4 | 834 | } |
mbed_official | 181:a4cbdfbbd2f4 | 835 | } |
mbed_official | 181:a4cbdfbbd2f4 | 836 | } |
mbed_official | 181:a4cbdfbbd2f4 | 837 | return HAL_OK; |
mbed_official | 181:a4cbdfbbd2f4 | 838 | } |
mbed_official | 181:a4cbdfbbd2f4 | 839 | |
mbed_official | 181:a4cbdfbbd2f4 | 840 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 841 | * @brief DMA SMARTCARD transmit process complete callback |
mbed_official | 181:a4cbdfbbd2f4 | 842 | * @param hdma: DMA handle |
mbed_official | 181:a4cbdfbbd2f4 | 843 | * @retval None |
mbed_official | 181:a4cbdfbbd2f4 | 844 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 845 | static void SMARTCARD_DMATransmitCplt(DMA_HandleTypeDef *hdma) |
mbed_official | 181:a4cbdfbbd2f4 | 846 | { |
mbed_official | 181:a4cbdfbbd2f4 | 847 | SMARTCARD_HandleTypeDef* hsc = ( SMARTCARD_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
mbed_official | 181:a4cbdfbbd2f4 | 848 | hsc->TxXferCount = 0; |
mbed_official | 181:a4cbdfbbd2f4 | 849 | |
mbed_official | 181:a4cbdfbbd2f4 | 850 | /* Disable the DMA transfer for transmit request by setting the DMAT bit |
mbed_official | 181:a4cbdfbbd2f4 | 851 | in the SMARTCARD associated USART CR3 register */ |
mbed_official | 181:a4cbdfbbd2f4 | 852 | hsc->Instance->CR3 &= (uint16_t)~((uint16_t)USART_CR3_DMAT); |
mbed_official | 181:a4cbdfbbd2f4 | 853 | |
mbed_official | 181:a4cbdfbbd2f4 | 854 | /* Wait for SMARTCARD TC Flag */ |
mbed_official | 181:a4cbdfbbd2f4 | 855 | if(SMARTCARD_WaitOnFlagUntilTimeout(hsc, SMARTCARD_FLAG_TC, RESET, HAL_SMARTCARD_TXDMA_TIMEOUTVALUE) != HAL_OK) |
mbed_official | 181:a4cbdfbbd2f4 | 856 | { |
mbed_official | 181:a4cbdfbbd2f4 | 857 | /* Timeout Occured */ |
mbed_official | 181:a4cbdfbbd2f4 | 858 | hsc->State = HAL_SMARTCARD_STATE_TIMEOUT; |
mbed_official | 181:a4cbdfbbd2f4 | 859 | HAL_SMARTCARD_ErrorCallback(hsc); |
mbed_official | 181:a4cbdfbbd2f4 | 860 | } |
mbed_official | 181:a4cbdfbbd2f4 | 861 | else |
mbed_official | 181:a4cbdfbbd2f4 | 862 | { |
mbed_official | 181:a4cbdfbbd2f4 | 863 | /* No Timeout */ |
mbed_official | 181:a4cbdfbbd2f4 | 864 | /* Check if a receive Process is ongoing or not */ |
mbed_official | 181:a4cbdfbbd2f4 | 865 | if(hsc->State == HAL_SMARTCARD_STATE_BUSY_TX_RX) |
mbed_official | 181:a4cbdfbbd2f4 | 866 | { |
mbed_official | 181:a4cbdfbbd2f4 | 867 | hsc->State = HAL_SMARTCARD_STATE_BUSY_RX; |
mbed_official | 181:a4cbdfbbd2f4 | 868 | } |
mbed_official | 181:a4cbdfbbd2f4 | 869 | else |
mbed_official | 181:a4cbdfbbd2f4 | 870 | { |
mbed_official | 181:a4cbdfbbd2f4 | 871 | hsc->State = HAL_SMARTCARD_STATE_READY; |
mbed_official | 181:a4cbdfbbd2f4 | 872 | } |
mbed_official | 181:a4cbdfbbd2f4 | 873 | HAL_SMARTCARD_TxCpltCallback(hsc); |
mbed_official | 181:a4cbdfbbd2f4 | 874 | } |
mbed_official | 181:a4cbdfbbd2f4 | 875 | } |
mbed_official | 181:a4cbdfbbd2f4 | 876 | |
mbed_official | 181:a4cbdfbbd2f4 | 877 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 878 | * @brief DMA SMARTCARD receive process complete callback |
mbed_official | 181:a4cbdfbbd2f4 | 879 | * @param hdma: DMA handle |
mbed_official | 181:a4cbdfbbd2f4 | 880 | * @retval None |
mbed_official | 181:a4cbdfbbd2f4 | 881 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 882 | static void SMARTCARD_DMAReceiveCplt(DMA_HandleTypeDef *hdma) |
mbed_official | 181:a4cbdfbbd2f4 | 883 | { |
mbed_official | 181:a4cbdfbbd2f4 | 884 | SMARTCARD_HandleTypeDef* hsc = ( SMARTCARD_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
mbed_official | 181:a4cbdfbbd2f4 | 885 | hsc->RxXferCount = 0; |
mbed_official | 181:a4cbdfbbd2f4 | 886 | |
mbed_official | 181:a4cbdfbbd2f4 | 887 | /* Disable the DMA transfer for the receiver request by setting the DMAR bit |
mbed_official | 181:a4cbdfbbd2f4 | 888 | in the SMARTCARD associated USART CR3 register */ |
mbed_official | 181:a4cbdfbbd2f4 | 889 | hsc->Instance->CR3 &= (uint16_t)~((uint16_t)USART_CR3_DMAR); |
mbed_official | 181:a4cbdfbbd2f4 | 890 | |
mbed_official | 181:a4cbdfbbd2f4 | 891 | /* Check if a transmit Process is ongoing or not */ |
mbed_official | 181:a4cbdfbbd2f4 | 892 | if(hsc->State == HAL_SMARTCARD_STATE_BUSY_TX_RX) |
mbed_official | 181:a4cbdfbbd2f4 | 893 | { |
mbed_official | 181:a4cbdfbbd2f4 | 894 | hsc->State = HAL_SMARTCARD_STATE_BUSY_TX; |
mbed_official | 181:a4cbdfbbd2f4 | 895 | } |
mbed_official | 181:a4cbdfbbd2f4 | 896 | else |
mbed_official | 181:a4cbdfbbd2f4 | 897 | { |
mbed_official | 181:a4cbdfbbd2f4 | 898 | hsc->State = HAL_SMARTCARD_STATE_READY; |
mbed_official | 181:a4cbdfbbd2f4 | 899 | } |
mbed_official | 181:a4cbdfbbd2f4 | 900 | |
mbed_official | 181:a4cbdfbbd2f4 | 901 | HAL_SMARTCARD_RxCpltCallback(hsc); |
mbed_official | 181:a4cbdfbbd2f4 | 902 | } |
mbed_official | 181:a4cbdfbbd2f4 | 903 | |
mbed_official | 181:a4cbdfbbd2f4 | 904 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 905 | * @brief DMA SMARTCARD communication error callback |
mbed_official | 181:a4cbdfbbd2f4 | 906 | * @param hdma: DMA handle |
mbed_official | 181:a4cbdfbbd2f4 | 907 | * @retval None |
mbed_official | 181:a4cbdfbbd2f4 | 908 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 909 | static void SMARTCARD_DMAError(DMA_HandleTypeDef *hdma) |
mbed_official | 181:a4cbdfbbd2f4 | 910 | { |
mbed_official | 181:a4cbdfbbd2f4 | 911 | SMARTCARD_HandleTypeDef* hsc = ( SMARTCARD_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
mbed_official | 181:a4cbdfbbd2f4 | 912 | hsc->RxXferCount = 0; |
mbed_official | 181:a4cbdfbbd2f4 | 913 | hsc->TxXferCount = 0; |
mbed_official | 181:a4cbdfbbd2f4 | 914 | hsc->State= HAL_SMARTCARD_STATE_READY; |
mbed_official | 181:a4cbdfbbd2f4 | 915 | hsc->ErrorCode |= HAL_SMARTCARD_ERROR_DMA; |
mbed_official | 181:a4cbdfbbd2f4 | 916 | HAL_SMARTCARD_ErrorCallback(hsc); |
mbed_official | 181:a4cbdfbbd2f4 | 917 | } |
mbed_official | 181:a4cbdfbbd2f4 | 918 | |
mbed_official | 181:a4cbdfbbd2f4 | 919 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 920 | * @brief Tx Transfer completed callbacks |
mbed_official | 181:a4cbdfbbd2f4 | 921 | * @param hsc: SMARTCARD handle |
mbed_official | 181:a4cbdfbbd2f4 | 922 | * @retval None |
mbed_official | 181:a4cbdfbbd2f4 | 923 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 924 | __weak void HAL_SMARTCARD_TxCpltCallback(SMARTCARD_HandleTypeDef *hsc) |
mbed_official | 181:a4cbdfbbd2f4 | 925 | { |
mbed_official | 181:a4cbdfbbd2f4 | 926 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 181:a4cbdfbbd2f4 | 927 | the HAL_SMARTCARD_TxCpltCallback could be implemented in the user file |
mbed_official | 181:a4cbdfbbd2f4 | 928 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 929 | } |
mbed_official | 181:a4cbdfbbd2f4 | 930 | |
mbed_official | 181:a4cbdfbbd2f4 | 931 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 932 | * @brief Rx Transfer completed callbacks |
mbed_official | 181:a4cbdfbbd2f4 | 933 | * @param hsc: SMARTCARD handle |
mbed_official | 181:a4cbdfbbd2f4 | 934 | * @retval None |
mbed_official | 181:a4cbdfbbd2f4 | 935 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 936 | __weak void HAL_SMARTCARD_RxCpltCallback(SMARTCARD_HandleTypeDef *hsc) |
mbed_official | 181:a4cbdfbbd2f4 | 937 | { |
mbed_official | 181:a4cbdfbbd2f4 | 938 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 181:a4cbdfbbd2f4 | 939 | the HAL_SMARTCARD_TxCpltCallback could be implemented in the user file |
mbed_official | 181:a4cbdfbbd2f4 | 940 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 941 | } |
mbed_official | 181:a4cbdfbbd2f4 | 942 | |
mbed_official | 181:a4cbdfbbd2f4 | 943 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 944 | * @brief SMARTCARD error callbacks |
mbed_official | 181:a4cbdfbbd2f4 | 945 | * @param hsc: SMARTCARD handle |
mbed_official | 181:a4cbdfbbd2f4 | 946 | * @retval None |
mbed_official | 181:a4cbdfbbd2f4 | 947 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 948 | __weak void HAL_SMARTCARD_ErrorCallback(SMARTCARD_HandleTypeDef *hsc) |
mbed_official | 181:a4cbdfbbd2f4 | 949 | { |
mbed_official | 181:a4cbdfbbd2f4 | 950 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 181:a4cbdfbbd2f4 | 951 | the HAL_SMARTCARD_ErrorCallback could be implemented in the user file |
mbed_official | 181:a4cbdfbbd2f4 | 952 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 953 | } |
mbed_official | 181:a4cbdfbbd2f4 | 954 | |
mbed_official | 181:a4cbdfbbd2f4 | 955 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 956 | * @brief Send an amount of data in non blocking mode |
mbed_official | 181:a4cbdfbbd2f4 | 957 | * @param hsc: SMARTCARD handle. |
mbed_official | 181:a4cbdfbbd2f4 | 958 | * Function called under interruption only, once |
mbed_official | 181:a4cbdfbbd2f4 | 959 | * interruptions have been enabled by HAL_SMARTCARD_Transmit_IT() |
mbed_official | 181:a4cbdfbbd2f4 | 960 | * @retval HAL status |
mbed_official | 181:a4cbdfbbd2f4 | 961 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 962 | static HAL_StatusTypeDef SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsc) |
mbed_official | 181:a4cbdfbbd2f4 | 963 | { |
mbed_official | 181:a4cbdfbbd2f4 | 964 | if((hsc->State == HAL_SMARTCARD_STATE_BUSY_TX) || (hsc->State == HAL_SMARTCARD_STATE_BUSY_TX_RX)) |
mbed_official | 181:a4cbdfbbd2f4 | 965 | { |
mbed_official | 181:a4cbdfbbd2f4 | 966 | if(hsc->TxXferCount == 0) |
mbed_official | 181:a4cbdfbbd2f4 | 967 | { |
mbed_official | 181:a4cbdfbbd2f4 | 968 | /* Disable the SMARTCARD Transmit Complete Interrupt */ |
mbed_official | 181:a4cbdfbbd2f4 | 969 | __HAL_SMARTCARD_DISABLE_IT(hsc, SMARTCARD_IT_TC); |
mbed_official | 181:a4cbdfbbd2f4 | 970 | |
mbed_official | 181:a4cbdfbbd2f4 | 971 | /* Check if a receive Process is ongoing or not */ |
mbed_official | 181:a4cbdfbbd2f4 | 972 | if(hsc->State == HAL_SMARTCARD_STATE_BUSY_TX_RX) |
mbed_official | 181:a4cbdfbbd2f4 | 973 | { |
mbed_official | 181:a4cbdfbbd2f4 | 974 | hsc->State = HAL_SMARTCARD_STATE_BUSY_RX; |
mbed_official | 181:a4cbdfbbd2f4 | 975 | } |
mbed_official | 181:a4cbdfbbd2f4 | 976 | else |
mbed_official | 181:a4cbdfbbd2f4 | 977 | { |
mbed_official | 181:a4cbdfbbd2f4 | 978 | /* Disable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */ |
mbed_official | 181:a4cbdfbbd2f4 | 979 | __HAL_SMARTCARD_DISABLE_IT(hsc, SMARTCARD_IT_ERR); |
mbed_official | 181:a4cbdfbbd2f4 | 980 | |
mbed_official | 181:a4cbdfbbd2f4 | 981 | hsc->State = HAL_SMARTCARD_STATE_READY; |
mbed_official | 181:a4cbdfbbd2f4 | 982 | } |
mbed_official | 181:a4cbdfbbd2f4 | 983 | |
mbed_official | 181:a4cbdfbbd2f4 | 984 | HAL_SMARTCARD_TxCpltCallback(hsc); |
mbed_official | 181:a4cbdfbbd2f4 | 985 | |
mbed_official | 181:a4cbdfbbd2f4 | 986 | return HAL_OK; |
mbed_official | 181:a4cbdfbbd2f4 | 987 | } |
mbed_official | 181:a4cbdfbbd2f4 | 988 | else |
mbed_official | 181:a4cbdfbbd2f4 | 989 | { |
mbed_official | 181:a4cbdfbbd2f4 | 990 | hsc->Instance->TDR = (*hsc->pTxBuffPtr++ & (uint8_t)0xFF); |
mbed_official | 181:a4cbdfbbd2f4 | 991 | hsc->TxXferCount--; |
mbed_official | 181:a4cbdfbbd2f4 | 992 | |
mbed_official | 181:a4cbdfbbd2f4 | 993 | return HAL_OK; |
mbed_official | 181:a4cbdfbbd2f4 | 994 | } |
mbed_official | 181:a4cbdfbbd2f4 | 995 | } |
mbed_official | 181:a4cbdfbbd2f4 | 996 | else |
mbed_official | 181:a4cbdfbbd2f4 | 997 | { |
mbed_official | 181:a4cbdfbbd2f4 | 998 | return HAL_BUSY; |
mbed_official | 181:a4cbdfbbd2f4 | 999 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1000 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1001 | |
mbed_official | 181:a4cbdfbbd2f4 | 1002 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 1003 | * @brief Receive an amount of data in non blocking mode |
mbed_official | 181:a4cbdfbbd2f4 | 1004 | * @param hsc: SMARTCARD handle. |
mbed_official | 181:a4cbdfbbd2f4 | 1005 | * Function called under interruption only, once |
mbed_official | 181:a4cbdfbbd2f4 | 1006 | * interruptions have been enabled by HAL_SMARTCARD_Receive_IT() |
mbed_official | 181:a4cbdfbbd2f4 | 1007 | * @retval HAL status |
mbed_official | 181:a4cbdfbbd2f4 | 1008 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 1009 | static HAL_StatusTypeDef SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsc) |
mbed_official | 181:a4cbdfbbd2f4 | 1010 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1011 | if((hsc->State == HAL_SMARTCARD_STATE_BUSY_RX) || (hsc->State == HAL_SMARTCARD_STATE_BUSY_TX_RX)) |
mbed_official | 181:a4cbdfbbd2f4 | 1012 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1013 | *hsc->pRxBuffPtr++ = (uint8_t)(hsc->Instance->RDR & (uint8_t)0xFF); |
mbed_official | 181:a4cbdfbbd2f4 | 1014 | |
mbed_official | 181:a4cbdfbbd2f4 | 1015 | if(--hsc->RxXferCount == 0) |
mbed_official | 181:a4cbdfbbd2f4 | 1016 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1017 | while(HAL_IS_BIT_SET(hsc->Instance->ISR, SMARTCARD_FLAG_RXNE)) |
mbed_official | 181:a4cbdfbbd2f4 | 1018 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1019 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1020 | __HAL_SMARTCARD_DISABLE_IT(hsc, SMARTCARD_IT_RXNE); |
mbed_official | 181:a4cbdfbbd2f4 | 1021 | |
mbed_official | 181:a4cbdfbbd2f4 | 1022 | /* Check if a transmit Process is ongoing or not */ |
mbed_official | 181:a4cbdfbbd2f4 | 1023 | if(hsc->State == HAL_SMARTCARD_STATE_BUSY_TX_RX) |
mbed_official | 181:a4cbdfbbd2f4 | 1024 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1025 | hsc->State = HAL_SMARTCARD_STATE_BUSY_TX; |
mbed_official | 181:a4cbdfbbd2f4 | 1026 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1027 | else |
mbed_official | 181:a4cbdfbbd2f4 | 1028 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1029 | /* Disable the SMARTCARD Parity Error Interrupt */ |
mbed_official | 181:a4cbdfbbd2f4 | 1030 | __HAL_SMARTCARD_DISABLE_IT(hsc, SMARTCARD_IT_PE); |
mbed_official | 181:a4cbdfbbd2f4 | 1031 | |
mbed_official | 181:a4cbdfbbd2f4 | 1032 | /* Disable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */ |
mbed_official | 181:a4cbdfbbd2f4 | 1033 | __HAL_SMARTCARD_DISABLE_IT(hsc, SMARTCARD_IT_ERR); |
mbed_official | 181:a4cbdfbbd2f4 | 1034 | |
mbed_official | 181:a4cbdfbbd2f4 | 1035 | hsc->State = HAL_SMARTCARD_STATE_READY; |
mbed_official | 181:a4cbdfbbd2f4 | 1036 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1037 | |
mbed_official | 181:a4cbdfbbd2f4 | 1038 | HAL_SMARTCARD_RxCpltCallback(hsc); |
mbed_official | 181:a4cbdfbbd2f4 | 1039 | |
mbed_official | 181:a4cbdfbbd2f4 | 1040 | return HAL_OK; |
mbed_official | 181:a4cbdfbbd2f4 | 1041 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1042 | return HAL_OK; |
mbed_official | 181:a4cbdfbbd2f4 | 1043 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1044 | else |
mbed_official | 181:a4cbdfbbd2f4 | 1045 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1046 | return HAL_BUSY; |
mbed_official | 181:a4cbdfbbd2f4 | 1047 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1048 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1049 | |
mbed_official | 181:a4cbdfbbd2f4 | 1050 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 1051 | * @brief Configure the SMARTCARD associated USART peripheral |
mbed_official | 181:a4cbdfbbd2f4 | 1052 | * @param hsc: SMARTCARD handle |
mbed_official | 181:a4cbdfbbd2f4 | 1053 | * @retval None |
mbed_official | 181:a4cbdfbbd2f4 | 1054 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 1055 | static void SMARTCARD_SetConfig(SMARTCARD_HandleTypeDef *hsc) |
mbed_official | 181:a4cbdfbbd2f4 | 1056 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1057 | uint32_t tmpreg = 0x00000000; |
mbed_official | 181:a4cbdfbbd2f4 | 1058 | uint32_t clocksource = 0x00000000; |
mbed_official | 181:a4cbdfbbd2f4 | 1059 | |
mbed_official | 181:a4cbdfbbd2f4 | 1060 | /* Check the parameters */ |
mbed_official | 181:a4cbdfbbd2f4 | 1061 | assert_param(IS_SMARTCARD_INSTANCE(hsc->Instance)); |
mbed_official | 181:a4cbdfbbd2f4 | 1062 | assert_param(IS_SMARTCARD_BAUDRATE(hsc->Init.BaudRate)); |
mbed_official | 181:a4cbdfbbd2f4 | 1063 | assert_param(IS_SMARTCARD_WORD_LENGTH(hsc->Init.WordLength)); |
mbed_official | 181:a4cbdfbbd2f4 | 1064 | assert_param(IS_SMARTCARD_STOPBITS(hsc->Init.StopBits)); |
mbed_official | 181:a4cbdfbbd2f4 | 1065 | assert_param(IS_SMARTCARD_PARITY(hsc->Init.Parity)); |
mbed_official | 181:a4cbdfbbd2f4 | 1066 | assert_param(IS_SMARTCARD_MODE(hsc->Init.Mode)); |
mbed_official | 181:a4cbdfbbd2f4 | 1067 | assert_param(IS_SMARTCARD_POLARITY(hsc->Init.CLKPolarity)); |
mbed_official | 181:a4cbdfbbd2f4 | 1068 | assert_param(IS_SMARTCARD_PHASE(hsc->Init.CLKPhase)); |
mbed_official | 181:a4cbdfbbd2f4 | 1069 | assert_param(IS_SMARTCARD_LASTBIT(hsc->Init.CLKLastBit)); |
mbed_official | 181:a4cbdfbbd2f4 | 1070 | assert_param(IS_SMARTCARD_ONEBIT_SAMPLING(hsc->Init.OneBitSampling)); |
mbed_official | 181:a4cbdfbbd2f4 | 1071 | assert_param(IS_SMARTCARD_NACK(hsc->Init.NACKState)); |
mbed_official | 181:a4cbdfbbd2f4 | 1072 | assert_param(IS_SMARTCARD_TIMEOUT(hsc->Init.TimeOutEnable)); |
mbed_official | 181:a4cbdfbbd2f4 | 1073 | assert_param(IS_SMARTCARD_AUTORETRY_COUNT(hsc->Init.AutoRetryCount)); |
mbed_official | 181:a4cbdfbbd2f4 | 1074 | |
mbed_official | 181:a4cbdfbbd2f4 | 1075 | /*-------------------------- USART CR1 Configuration -----------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 1076 | /* In SmartCard mode, M and PCE are forced to 1 (8 bits + parity). |
mbed_official | 181:a4cbdfbbd2f4 | 1077 | * Oversampling is forced to 16 (OVER8 = 0). |
mbed_official | 181:a4cbdfbbd2f4 | 1078 | * Configure the Parity and Mode: |
mbed_official | 181:a4cbdfbbd2f4 | 1079 | * set PS bit according to hsc->Init.Parity value |
mbed_official | 181:a4cbdfbbd2f4 | 1080 | * set TE and RE bits according to hsc->Init.Mode value */ |
mbed_official | 181:a4cbdfbbd2f4 | 1081 | tmpreg = (uint32_t) hsc->Init.Parity | hsc->Init.Mode; |
mbed_official | 181:a4cbdfbbd2f4 | 1082 | /* in case of TX-only mode, if NACK is enabled, the USART must be able to monitor |
mbed_official | 181:a4cbdfbbd2f4 | 1083 | the bidirectional line to detect a NACK signal in case of parity error. |
mbed_official | 181:a4cbdfbbd2f4 | 1084 | Therefore, the receiver block must be enabled as well (RE bit must be set). */ |
mbed_official | 181:a4cbdfbbd2f4 | 1085 | if((hsc->Init.Mode == SMARTCARD_MODE_TX) && (hsc->Init.NACKState == SMARTCARD_NACK_ENABLED)) |
mbed_official | 181:a4cbdfbbd2f4 | 1086 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1087 | tmpreg |= USART_CR1_RE; |
mbed_official | 181:a4cbdfbbd2f4 | 1088 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1089 | tmpreg |= (uint32_t) hsc->Init.WordLength; |
mbed_official | 181:a4cbdfbbd2f4 | 1090 | MODIFY_REG(hsc->Instance->CR1, USART_CR1_FIELDS, tmpreg); |
mbed_official | 181:a4cbdfbbd2f4 | 1091 | |
mbed_official | 181:a4cbdfbbd2f4 | 1092 | /*-------------------------- USART CR2 Configuration -----------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 1093 | /* Stop bits are forced to 1.5 (STOP = 11) */ |
mbed_official | 181:a4cbdfbbd2f4 | 1094 | tmpreg = hsc->Init.StopBits; |
mbed_official | 181:a4cbdfbbd2f4 | 1095 | /* Synchronous mode is activated by default */ |
mbed_official | 181:a4cbdfbbd2f4 | 1096 | tmpreg |= (uint32_t) USART_CR2_CLKEN | hsc->Init.CLKPolarity; |
mbed_official | 181:a4cbdfbbd2f4 | 1097 | tmpreg |= (uint32_t) hsc->Init.CLKPhase | hsc->Init.CLKLastBit; |
mbed_official | 181:a4cbdfbbd2f4 | 1098 | tmpreg |= (uint32_t) hsc->Init.TimeOutEnable; |
mbed_official | 181:a4cbdfbbd2f4 | 1099 | MODIFY_REG(hsc->Instance->CR2, USART_CR2_FIELDS, tmpreg); |
mbed_official | 181:a4cbdfbbd2f4 | 1100 | |
mbed_official | 181:a4cbdfbbd2f4 | 1101 | /*-------------------------- USART CR3 Configuration -----------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 1102 | /* Configure |
mbed_official | 181:a4cbdfbbd2f4 | 1103 | * - one-bit sampling method versus three samples' majority rule |
mbed_official | 181:a4cbdfbbd2f4 | 1104 | * according to hsc->Init.OneBitSampling |
mbed_official | 181:a4cbdfbbd2f4 | 1105 | * - NACK transmission in case of parity error according |
mbed_official | 181:a4cbdfbbd2f4 | 1106 | * to hsc->Init.NACKEnable |
mbed_official | 181:a4cbdfbbd2f4 | 1107 | * - autoretry counter according to hsc->Init.AutoRetryCount */ |
mbed_official | 181:a4cbdfbbd2f4 | 1108 | tmpreg = (uint32_t) hsc->Init.OneBitSampling | hsc->Init.NACKState; |
mbed_official | 181:a4cbdfbbd2f4 | 1109 | tmpreg |= (uint32_t) (hsc->Init.AutoRetryCount << SMARTCARD_CR3_SCARCNT_LSB_POS); |
mbed_official | 181:a4cbdfbbd2f4 | 1110 | MODIFY_REG(hsc->Instance-> CR3,USART_CR3_FIELDS, tmpreg); |
mbed_official | 181:a4cbdfbbd2f4 | 1111 | |
mbed_official | 181:a4cbdfbbd2f4 | 1112 | /*-------------------------- USART GTPR Configuration ----------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 1113 | tmpreg = (uint32_t) (hsc->Init.Prescaler | (hsc->Init.GuardTime << SMARTCARD_GTPR_GT_LSB_POS)); |
mbed_official | 181:a4cbdfbbd2f4 | 1114 | MODIFY_REG(hsc->Instance->GTPR, (uint32_t)(USART_GTPR_GT|USART_GTPR_PSC), tmpreg); |
mbed_official | 181:a4cbdfbbd2f4 | 1115 | |
mbed_official | 181:a4cbdfbbd2f4 | 1116 | /*-------------------------- USART RTOR Configuration ----------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 1117 | tmpreg = (uint32_t) (hsc->Init.BlockLength << SMARTCARD_RTOR_BLEN_LSB_POS); |
mbed_official | 181:a4cbdfbbd2f4 | 1118 | if(hsc->Init.TimeOutEnable == SMARTCARD_TIMEOUT_ENABLED) |
mbed_official | 181:a4cbdfbbd2f4 | 1119 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1120 | assert_param(IS_SMARTCARD_TIMEOUT_VALUE(hsc->Init.TimeOutValue)); |
mbed_official | 181:a4cbdfbbd2f4 | 1121 | tmpreg |= (uint32_t) hsc->Init.TimeOutValue; |
mbed_official | 181:a4cbdfbbd2f4 | 1122 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1123 | MODIFY_REG(hsc->Instance->RTOR, (USART_RTOR_RTO|USART_RTOR_BLEN), tmpreg); |
mbed_official | 181:a4cbdfbbd2f4 | 1124 | |
mbed_official | 181:a4cbdfbbd2f4 | 1125 | /*-------------------------- USART BRR Configuration -----------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 1126 | __HAL_SMARTCARD_GETCLOCKSOURCE(hsc, clocksource); |
mbed_official | 181:a4cbdfbbd2f4 | 1127 | switch (clocksource) |
mbed_official | 181:a4cbdfbbd2f4 | 1128 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1129 | case SMARTCARD_CLOCKSOURCE_PCLK1: |
mbed_official | 181:a4cbdfbbd2f4 | 1130 | hsc->Instance->BRR = (uint16_t)(HAL_RCC_GetPCLK1Freq() / hsc->Init.BaudRate); |
mbed_official | 181:a4cbdfbbd2f4 | 1131 | break; |
mbed_official | 181:a4cbdfbbd2f4 | 1132 | case SMARTCARD_CLOCKSOURCE_PCLK2: |
mbed_official | 181:a4cbdfbbd2f4 | 1133 | hsc->Instance->BRR = (uint16_t)(HAL_RCC_GetPCLK2Freq() / hsc->Init.BaudRate); |
mbed_official | 181:a4cbdfbbd2f4 | 1134 | break; |
mbed_official | 181:a4cbdfbbd2f4 | 1135 | case SMARTCARD_CLOCKSOURCE_HSI: |
mbed_official | 181:a4cbdfbbd2f4 | 1136 | hsc->Instance->BRR = (uint16_t)(HSI_VALUE / hsc->Init.BaudRate); |
mbed_official | 181:a4cbdfbbd2f4 | 1137 | break; |
mbed_official | 181:a4cbdfbbd2f4 | 1138 | case SMARTCARD_CLOCKSOURCE_SYSCLK: |
mbed_official | 181:a4cbdfbbd2f4 | 1139 | hsc->Instance->BRR = (uint16_t)(HAL_RCC_GetSysClockFreq() / hsc->Init.BaudRate); |
mbed_official | 181:a4cbdfbbd2f4 | 1140 | break; |
mbed_official | 181:a4cbdfbbd2f4 | 1141 | case SMARTCARD_CLOCKSOURCE_LSE: |
mbed_official | 181:a4cbdfbbd2f4 | 1142 | hsc->Instance->BRR = (uint16_t)(LSE_VALUE / hsc->Init.BaudRate); |
mbed_official | 181:a4cbdfbbd2f4 | 1143 | break; |
mbed_official | 181:a4cbdfbbd2f4 | 1144 | default: |
mbed_official | 181:a4cbdfbbd2f4 | 1145 | break; |
mbed_official | 181:a4cbdfbbd2f4 | 1146 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1147 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1148 | |
mbed_official | 181:a4cbdfbbd2f4 | 1149 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 1150 | * @brief Check the SMARTCARD Idle State |
mbed_official | 181:a4cbdfbbd2f4 | 1151 | * @param hsc: SMARTCARD handle |
mbed_official | 181:a4cbdfbbd2f4 | 1152 | * @retval HAL status |
mbed_official | 181:a4cbdfbbd2f4 | 1153 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 1154 | static HAL_StatusTypeDef SMARTCARD_CheckIdleState(SMARTCARD_HandleTypeDef *hsc) |
mbed_official | 181:a4cbdfbbd2f4 | 1155 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1156 | |
mbed_official | 181:a4cbdfbbd2f4 | 1157 | /* Initialize the SMARTCARD ErrorCode */ |
mbed_official | 181:a4cbdfbbd2f4 | 1158 | hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE; |
mbed_official | 181:a4cbdfbbd2f4 | 1159 | |
mbed_official | 181:a4cbdfbbd2f4 | 1160 | /* Check if the Transmitter is enabled */ |
mbed_official | 181:a4cbdfbbd2f4 | 1161 | if((hsc->Instance->CR1 & USART_CR1_TE) == USART_CR1_TE) |
mbed_official | 181:a4cbdfbbd2f4 | 1162 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1163 | /* Wait until TEACK flag is set */ |
mbed_official | 181:a4cbdfbbd2f4 | 1164 | if(SMARTCARD_WaitOnFlagUntilTimeout(hsc, USART_ISR_TEACK, RESET, TEACK_REACK_TIMEOUT) != HAL_OK) |
mbed_official | 181:a4cbdfbbd2f4 | 1165 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1166 | return HAL_TIMEOUT; |
mbed_official | 181:a4cbdfbbd2f4 | 1167 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1168 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1169 | /* Check if the Receiver is enabled */ |
mbed_official | 181:a4cbdfbbd2f4 | 1170 | if((hsc->Instance->CR1 & USART_CR1_RE) == USART_CR1_RE) |
mbed_official | 181:a4cbdfbbd2f4 | 1171 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1172 | /* Wait until REACK flag is set */ |
mbed_official | 181:a4cbdfbbd2f4 | 1173 | if(SMARTCARD_WaitOnFlagUntilTimeout(hsc, USART_ISR_REACK, RESET, TEACK_REACK_TIMEOUT) != HAL_OK) |
mbed_official | 181:a4cbdfbbd2f4 | 1174 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1175 | return HAL_TIMEOUT; |
mbed_official | 181:a4cbdfbbd2f4 | 1176 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1177 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1178 | |
mbed_official | 181:a4cbdfbbd2f4 | 1179 | /* Process Unlocked */ |
mbed_official | 181:a4cbdfbbd2f4 | 1180 | __HAL_UNLOCK(hsc); |
mbed_official | 181:a4cbdfbbd2f4 | 1181 | |
mbed_official | 181:a4cbdfbbd2f4 | 1182 | /* Initialize the SMARTCARD state*/ |
mbed_official | 181:a4cbdfbbd2f4 | 1183 | hsc->State= HAL_SMARTCARD_STATE_READY; |
mbed_official | 181:a4cbdfbbd2f4 | 1184 | |
mbed_official | 181:a4cbdfbbd2f4 | 1185 | return HAL_OK; |
mbed_official | 181:a4cbdfbbd2f4 | 1186 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1187 | |
mbed_official | 181:a4cbdfbbd2f4 | 1188 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 1189 | * @brief Configure the SMARTCARD associated USART peripheral advanced feautures |
mbed_official | 181:a4cbdfbbd2f4 | 1190 | * @param hsc: SMARTCARD handle |
mbed_official | 181:a4cbdfbbd2f4 | 1191 | * @retval None |
mbed_official | 181:a4cbdfbbd2f4 | 1192 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 1193 | static void SMARTCARD_AdvFeatureConfig(SMARTCARD_HandleTypeDef *hsc) |
mbed_official | 181:a4cbdfbbd2f4 | 1194 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1195 | /* Check whether the set of advanced features to configure is properly set */ |
mbed_official | 181:a4cbdfbbd2f4 | 1196 | assert_param(IS_SMARTCARD_ADVFEATURE_INIT(hsc->AdvancedInit.AdvFeatureInit)); |
mbed_official | 181:a4cbdfbbd2f4 | 1197 | |
mbed_official | 181:a4cbdfbbd2f4 | 1198 | /* if required, configure TX pin active level inversion */ |
mbed_official | 181:a4cbdfbbd2f4 | 1199 | if(HAL_IS_BIT_SET(hsc->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_TXINVERT_INIT)) |
mbed_official | 181:a4cbdfbbd2f4 | 1200 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1201 | assert_param(IS_SMARTCARD_ADVFEATURE_TXINV(hsc->AdvancedInit.TxPinLevelInvert)); |
mbed_official | 181:a4cbdfbbd2f4 | 1202 | MODIFY_REG(hsc->Instance->CR2, USART_CR2_TXINV, hsc->AdvancedInit.TxPinLevelInvert); |
mbed_official | 181:a4cbdfbbd2f4 | 1203 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1204 | |
mbed_official | 181:a4cbdfbbd2f4 | 1205 | /* if required, configure RX pin active level inversion */ |
mbed_official | 181:a4cbdfbbd2f4 | 1206 | if(HAL_IS_BIT_SET(hsc->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_RXINVERT_INIT)) |
mbed_official | 181:a4cbdfbbd2f4 | 1207 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1208 | assert_param(IS_SMARTCARD_ADVFEATURE_RXINV(hsc->AdvancedInit.RxPinLevelInvert)); |
mbed_official | 181:a4cbdfbbd2f4 | 1209 | MODIFY_REG(hsc->Instance->CR2, USART_CR2_RXINV, hsc->AdvancedInit.RxPinLevelInvert); |
mbed_official | 181:a4cbdfbbd2f4 | 1210 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1211 | |
mbed_official | 181:a4cbdfbbd2f4 | 1212 | /* if required, configure data inversion */ |
mbed_official | 181:a4cbdfbbd2f4 | 1213 | if(HAL_IS_BIT_SET(hsc->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_DATAINVERT_INIT)) |
mbed_official | 181:a4cbdfbbd2f4 | 1214 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1215 | assert_param(IS_SMARTCARD_ADVFEATURE_DATAINV(hsc->AdvancedInit.DataInvert)); |
mbed_official | 181:a4cbdfbbd2f4 | 1216 | MODIFY_REG(hsc->Instance->CR2, USART_CR2_DATAINV, hsc->AdvancedInit.DataInvert); |
mbed_official | 181:a4cbdfbbd2f4 | 1217 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1218 | |
mbed_official | 181:a4cbdfbbd2f4 | 1219 | /* if required, configure RX/TX pins swap */ |
mbed_official | 181:a4cbdfbbd2f4 | 1220 | if(HAL_IS_BIT_SET(hsc->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_SWAP_INIT)) |
mbed_official | 181:a4cbdfbbd2f4 | 1221 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1222 | assert_param(IS_SMARTCARD_ADVFEATURE_SWAP(hsc->AdvancedInit.Swap)); |
mbed_official | 181:a4cbdfbbd2f4 | 1223 | MODIFY_REG(hsc->Instance->CR2, USART_CR2_SWAP, hsc->AdvancedInit.Swap); |
mbed_official | 181:a4cbdfbbd2f4 | 1224 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1225 | |
mbed_official | 181:a4cbdfbbd2f4 | 1226 | /* if required, configure RX overrun detection disabling */ |
mbed_official | 181:a4cbdfbbd2f4 | 1227 | if(HAL_IS_BIT_SET(hsc->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_RXOVERRUNDISABLE_INIT)) |
mbed_official | 181:a4cbdfbbd2f4 | 1228 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1229 | assert_param(IS_SMARTCARD_OVERRUN(hsc->AdvancedInit.OverrunDisable)); |
mbed_official | 181:a4cbdfbbd2f4 | 1230 | MODIFY_REG(hsc->Instance->CR3, USART_CR3_OVRDIS, hsc->AdvancedInit.OverrunDisable); |
mbed_official | 181:a4cbdfbbd2f4 | 1231 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1232 | |
mbed_official | 181:a4cbdfbbd2f4 | 1233 | /* if required, configure DMA disabling on reception error */ |
mbed_official | 181:a4cbdfbbd2f4 | 1234 | if(HAL_IS_BIT_SET(hsc->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_DMADISABLEONERROR_INIT)) |
mbed_official | 181:a4cbdfbbd2f4 | 1235 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1236 | assert_param(IS_SMARTCARD_ADVFEATURE_DMAONRXERROR(hsc->AdvancedInit.DMADisableonRxError)); |
mbed_official | 181:a4cbdfbbd2f4 | 1237 | MODIFY_REG(hsc->Instance->CR3, USART_CR3_DDRE, hsc->AdvancedInit.DMADisableonRxError); |
mbed_official | 181:a4cbdfbbd2f4 | 1238 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1239 | |
mbed_official | 181:a4cbdfbbd2f4 | 1240 | /* if required, configure MSB first on communication line */ |
mbed_official | 181:a4cbdfbbd2f4 | 1241 | if(HAL_IS_BIT_SET(hsc->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_MSBFIRST_INIT)) |
mbed_official | 181:a4cbdfbbd2f4 | 1242 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1243 | assert_param(IS_SMARTCARD_ADVFEATURE_MSBFIRST(hsc->AdvancedInit.MSBFirst)); |
mbed_official | 181:a4cbdfbbd2f4 | 1244 | MODIFY_REG(hsc->Instance->CR2, USART_CR2_MSBFIRST, hsc->AdvancedInit.MSBFirst); |
mbed_official | 181:a4cbdfbbd2f4 | 1245 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1246 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1247 | |
mbed_official | 181:a4cbdfbbd2f4 | 1248 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 1249 | * @} |
mbed_official | 181:a4cbdfbbd2f4 | 1250 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 1251 | |
mbed_official | 181:a4cbdfbbd2f4 | 1252 | /** @defgroup HAL_SMARTCARD_Group3 Peripheral Control methods |
mbed_official | 181:a4cbdfbbd2f4 | 1253 | * @brief SMARTCARD control functions |
mbed_official | 181:a4cbdfbbd2f4 | 1254 | * |
mbed_official | 181:a4cbdfbbd2f4 | 1255 | @verbatim |
mbed_official | 181:a4cbdfbbd2f4 | 1256 | =============================================================================== |
mbed_official | 181:a4cbdfbbd2f4 | 1257 | ##### Peripheral Control methods ##### |
mbed_official | 181:a4cbdfbbd2f4 | 1258 | =============================================================================== |
mbed_official | 181:a4cbdfbbd2f4 | 1259 | [..] |
mbed_official | 181:a4cbdfbbd2f4 | 1260 | This subsection provides a set of functions allowing to initialize the SMARTCARD. |
mbed_official | 181:a4cbdfbbd2f4 | 1261 | (+) HAL_SMARTCARD_GetState() API is helpful to check in run-time the state of the SMARTCARD peripheral |
mbed_official | 181:a4cbdfbbd2f4 | 1262 | (+) SMARTCARD_SetConfig() API configures the SMARTCARD peripheral |
mbed_official | 181:a4cbdfbbd2f4 | 1263 | (+) SMARTCARD_CheckIdleState() API ensures that TEACK and/or REACK are set after initialization |
mbed_official | 181:a4cbdfbbd2f4 | 1264 | |
mbed_official | 181:a4cbdfbbd2f4 | 1265 | @endverbatim |
mbed_official | 181:a4cbdfbbd2f4 | 1266 | * @{ |
mbed_official | 181:a4cbdfbbd2f4 | 1267 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 1268 | |
mbed_official | 181:a4cbdfbbd2f4 | 1269 | |
mbed_official | 181:a4cbdfbbd2f4 | 1270 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 1271 | * @brief return the SMARTCARD state |
mbed_official | 181:a4cbdfbbd2f4 | 1272 | * @param hsc: SMARTCARD handle |
mbed_official | 181:a4cbdfbbd2f4 | 1273 | * @retval HAL state |
mbed_official | 181:a4cbdfbbd2f4 | 1274 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 1275 | HAL_SMARTCARD_StateTypeDef HAL_SMARTCARD_GetState(SMARTCARD_HandleTypeDef *hsc) |
mbed_official | 181:a4cbdfbbd2f4 | 1276 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1277 | return hsc->State; |
mbed_official | 181:a4cbdfbbd2f4 | 1278 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1279 | |
mbed_official | 181:a4cbdfbbd2f4 | 1280 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 1281 | * @brief Return the SMARTCARD error code |
mbed_official | 181:a4cbdfbbd2f4 | 1282 | * @param hsc : pointer to a SMARTCARD_HandleTypeDef structure that contains |
mbed_official | 181:a4cbdfbbd2f4 | 1283 | * the configuration information for the specified SMARTCARD. |
mbed_official | 181:a4cbdfbbd2f4 | 1284 | * @retval SMARTCARD Error Code |
mbed_official | 181:a4cbdfbbd2f4 | 1285 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 1286 | uint32_t HAL_SMARTCARD_GetError(SMARTCARD_HandleTypeDef *hsc) |
mbed_official | 181:a4cbdfbbd2f4 | 1287 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1288 | return hsc->ErrorCode; |
mbed_official | 181:a4cbdfbbd2f4 | 1289 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1290 | |
mbed_official | 181:a4cbdfbbd2f4 | 1291 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 1292 | * @} |
mbed_official | 181:a4cbdfbbd2f4 | 1293 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 1294 | |
mbed_official | 181:a4cbdfbbd2f4 | 1295 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 1296 | * @} |
mbed_official | 181:a4cbdfbbd2f4 | 1297 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 1298 | |
mbed_official | 181:a4cbdfbbd2f4 | 1299 | #endif /* HAL_SMARTCARD_MODULE_ENABLED */ |
mbed_official | 181:a4cbdfbbd2f4 | 1300 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 1301 | * @} |
mbed_official | 181:a4cbdfbbd2f4 | 1302 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 1303 | |
mbed_official | 181:a4cbdfbbd2f4 | 1304 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 1305 | * @} |
mbed_official | 181:a4cbdfbbd2f4 | 1306 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 1307 | |
mbed_official | 181:a4cbdfbbd2f4 | 1308 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |