annotate Common/Drivers/STM32F4xx_HAL_DRIVER_v120/Src/stm32f4xx_hal_smartcard.c @ 56:bab006305b58

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