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