annotate Common/Drivers/STM32F4xx_HAL_DRIVER_v120/Src/stm32f4xx_hal_pcd.c @ 98:01169b86f9c6 kittz

+2ms delay
author Dmitry Romanov <kitt@bk.ru>
date Mon, 26 Nov 2018 13:58:51 +0300
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_pcd.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 PCD 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 USB Peripheral Controller:
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 Control functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
13 * + Peripheral State functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
14 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
15 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
16 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
17 ##### How to use this driver #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
18 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
19 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
20 The PCD HAL driver can be used as follows:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
21
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
22 (#) Declare a PCD_HandleTypeDef handle structure, for example:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
23 PCD_HandleTypeDef hpcd;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
24
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
25 (#) Fill parameters of Init structure in HCD handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
26
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
27 (#) Call HAL_PCD_Init() API to initialize the HCD peripheral (Core, Device core, ...)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
28
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
29 (#) Initialize the PCD low level resources through the HAL_PCD_MspInit() API:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
30 (##) Enable the PCD/USB Low Level interface clock using
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
31 (+++) __OTGFS-OTG_CLK_ENABLE()/__OTGHS-OTG_CLK_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
32 (+++) __OTGHSULPI_CLK_ENABLE(); (For High Speed Mode)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
33
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
34 (##) Initialize the related GPIO clocks
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
35 (##) Configure PCD pin-out
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
36 (##) Configure PCD NVIC interrupt
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
37
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
38 (#)Associate the Upper USB device stack to the HAL PCD Driver:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
39 (##) hpcd.pData = pdev;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
40
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
41 (#)Enable HCD transmission and reception:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
42 (##) HAL_PCD_Start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
43
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
44 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
45 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
46 * @attention
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
47 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
48 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
49 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
50 * Redistribution and use in source and binary forms, with or without modification,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
51 * are permitted provided that the following conditions are met:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
52 * 1. Redistributions of source code must retain the above copyright notice,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
53 * this list of conditions and the following disclaimer.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
54 * 2. Redistributions in binary form must reproduce the above copyright notice,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
55 * this list of conditions and the following disclaimer in the documentation
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
56 * and/or other materials provided with the distribution.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
57 * 3. Neither the name of STMicroelectronics nor the names of its contributors
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
58 * may be used to endorse or promote products derived from this software
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
59 * without specific prior written permission.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
60 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
61 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
62 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
63 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
64 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
65 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
66 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
67 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
68 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
69 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
70 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
71 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
72 ******************************************************************************
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 /* Includes ------------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
76 #include "stm32f4xx_hal.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
77
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
78 /** @addtogroup STM32F4xx_HAL_Driver
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
79 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
80 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
81
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
82 /** @defgroup PCD PCD
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
83 * @brief PCD HAL module driver
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
84 * @{
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 #ifdef HAL_PCD_MODULE_ENABLED
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
88
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
89 /* Private types -------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
90 /* Private variables ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
91 /* Private constants ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
92 /* Private macros ------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
93 /** @defgroup PCD_Private_Macros PCD Private Macros
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
94 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
95 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
96 #define PCD_MIN(a, b) (((a) < (b)) ? (a) : (b))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
97 #define PCD_MAX(a, b) (((a) > (b)) ? (a) : (b))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
98 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
99 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
100 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
101
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
102 /* Private functions prototypes ----------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
103 /** @defgroup PCD_Private_Functions PCD Private Functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
104 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
105 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
106 static HAL_StatusTypeDef PCD_WriteEmptyTxFifo(PCD_HandleTypeDef *hpcd, uint32_t epnum);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
107 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
108 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
109 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
110
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
111 /* Exported functions --------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
112 /** @defgroup PCD_Exported_Functions PCD Exported Functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
113 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
114 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
115
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
116 /** @defgroup PCD_Exported_Functions_Group1 Initialization and de-initialization functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
117 * @brief Initialization and Configuration functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
118 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
119 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
120 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
121 ##### Initialization and de-initialization functions #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
122 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
123 [..] This section provides functions allowing to:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
124
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
125 @endverbatim
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 * @brief Initializes the PCD according to the specified
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
131 * parameters in the PCD_InitTypeDef and create the associated handle.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
132 * @param hpcd: PCD handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
133 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
134 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
135 HAL_StatusTypeDef HAL_PCD_Init(PCD_HandleTypeDef *hpcd)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
136 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
137 uint32_t i = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
138
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
139 /* Check the PCD handle allocation */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
140 if(hpcd == NULL)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
141 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
142 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
143 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
144
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
145 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
146 assert_param(IS_PCD_ALL_INSTANCE(hpcd->Instance));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
147
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
148 hpcd->State = HAL_PCD_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
149
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
150 /* Init the low level hardware : GPIO, CLOCK, NVIC... */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
151 HAL_PCD_MspInit(hpcd);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
152
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
153 /* Disable the Interrupts */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
154 __HAL_PCD_DISABLE(hpcd);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
155
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
156 /*Init the Core (common init.) */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
157 USB_CoreInit(hpcd->Instance, hpcd->Init);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
158
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
159 /* Force Device Mode*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
160 USB_SetCurrentMode(hpcd->Instance , USB_OTG_DEVICE_MODE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
161
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
162 /* Init endpoints structures */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
163 for (i = 0; i < 15 ; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
164 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
165 /* Init ep structure */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
166 hpcd->IN_ep[i].is_in = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
167 hpcd->IN_ep[i].num = i;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
168 hpcd->IN_ep[i].tx_fifo_num = i;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
169 /* Control until ep is activated */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
170 hpcd->IN_ep[i].type = EP_TYPE_CTRL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
171 hpcd->IN_ep[i].maxpacket = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
172 hpcd->IN_ep[i].xfer_buff = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
173 hpcd->IN_ep[i].xfer_len = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
174 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
175
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
176 for (i = 0; i < 15 ; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
177 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
178 hpcd->OUT_ep[i].is_in = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
179 hpcd->OUT_ep[i].num = i;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
180 hpcd->IN_ep[i].tx_fifo_num = i;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
181 /* Control until ep is activated */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
182 hpcd->OUT_ep[i].type = EP_TYPE_CTRL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
183 hpcd->OUT_ep[i].maxpacket = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
184 hpcd->OUT_ep[i].xfer_buff = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
185 hpcd->OUT_ep[i].xfer_len = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
186
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
187 hpcd->Instance->DIEPTXF[i] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
188 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
189
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
190 /* Init Device */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
191 USB_DevInit(hpcd->Instance, hpcd->Init);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
192
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
193 hpcd->State= HAL_PCD_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
194
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
195 USB_DevDisconnect (hpcd->Instance);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
196 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
197 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
198
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
199 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
200 * @brief DeInitializes the PCD peripheral
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
201 * @param hpcd: PCD handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
202 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
203 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
204 HAL_StatusTypeDef HAL_PCD_DeInit(PCD_HandleTypeDef *hpcd)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
205 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
206 /* Check the PCD handle allocation */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
207 if(hpcd == NULL)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
208 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
209 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
210 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
211
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
212 hpcd->State = HAL_PCD_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
213
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
214 /* Stop Device */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
215 HAL_PCD_Stop(hpcd);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
216
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
217 /* DeInit the low level hardware */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
218 HAL_PCD_MspDeInit(hpcd);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
219
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
220 hpcd->State = HAL_PCD_STATE_RESET;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
221
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
222 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
223 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
224
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
225 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
226 * @brief Initializes the PCD MSP.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
227 * @param hpcd: PCD handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
228 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
229 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
230 __weak void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
231 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
232 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
233 the HAL_PCD_MspInit could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
234 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
235 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
236
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
237 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
238 * @brief DeInitializes PCD MSP.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
239 * @param hpcd: PCD handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
240 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
241 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
242 __weak void HAL_PCD_MspDeInit(PCD_HandleTypeDef *hpcd)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
243 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
244 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
245 the HAL_PCD_MspDeInit could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
246 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
247 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
248
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
249 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
250 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
251 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
252
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
253 /** @defgroup PCD_Exported_Functions_Group2 IO operation functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
254 * @brief Data transfers functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
255 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
256 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
257 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
258 ##### IO operation functions #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
259 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
260 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
261 This subsection provides a set of functions allowing to manage the PCD data
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
262 transfers.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
263
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
264 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
265 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
266 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
267
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
268 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
269 * @brief Start The USB OTG Device.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
270 * @param hpcd: PCD handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
271 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
272 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
273 HAL_StatusTypeDef HAL_PCD_Start(PCD_HandleTypeDef *hpcd)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
274 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
275 __HAL_LOCK(hpcd);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
276 USB_DevConnect (hpcd->Instance);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
277 __HAL_PCD_ENABLE(hpcd);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
278 __HAL_UNLOCK(hpcd);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
279 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
280 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
281
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
282 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
283 * @brief Stop The USB OTG Device.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
284 * @param hpcd: PCD handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
285 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
286 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
287 HAL_StatusTypeDef HAL_PCD_Stop(PCD_HandleTypeDef *hpcd)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
288 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
289 __HAL_LOCK(hpcd);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
290 __HAL_PCD_DISABLE(hpcd);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
291 USB_StopDevice(hpcd->Instance);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
292 USB_DevDisconnect(hpcd->Instance);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
293 __HAL_UNLOCK(hpcd);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
294 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
295 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
296
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
297 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
298 * @brief This function handles PCD interrupt request.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
299 * @param hpcd: PCD handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
300 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
301 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
302 void HAL_PCD_IRQHandler(PCD_HandleTypeDef *hpcd)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
303 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
304 USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
305 uint32_t i = 0, ep_intr = 0, epint = 0, epnum = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
306 uint32_t fifoemptymsk = 0, temp = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
307 USB_OTG_EPTypeDef *ep;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
308
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
309 /* ensure that we are in device mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
310 if (USB_GetMode(hpcd->Instance) == USB_OTG_MODE_DEVICE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
311 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
312 /* avoid spurious interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
313 if(__HAL_PCD_IS_INVALID_INTERRUPT(hpcd))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
314 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
315 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
316 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
317
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
318 if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_MMIS))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
319 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
320 /* incorrect mode, acknowledge the interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
321 __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_MMIS);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
322 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
323
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
324 if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_OEPINT))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
325 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
326 epnum = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
327
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
328 /* Read in the device interrupt bits */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
329 ep_intr = USB_ReadDevAllOutEpInterrupt(hpcd->Instance);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
330
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
331 while ( ep_intr )
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
332 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
333 if (ep_intr & 0x1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
334 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
335 epint = USB_ReadDevOutEPInterrupt(hpcd->Instance, epnum);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
336
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
337 if(( epint & USB_OTG_DOEPINT_XFRC) == USB_OTG_DOEPINT_XFRC)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
338 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
339 CLEAR_OUT_EP_INTR(epnum, USB_OTG_DOEPINT_XFRC);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
340
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
341 if(hpcd->Init.dma_enable == 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
342 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
343 hpcd->OUT_ep[epnum].xfer_count = hpcd->OUT_ep[epnum].maxpacket- (USBx_OUTEP(epnum)->DOEPTSIZ & USB_OTG_DOEPTSIZ_XFRSIZ);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
344 hpcd->OUT_ep[epnum].xfer_buff += hpcd->OUT_ep[epnum].maxpacket;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
345 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
346
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
347 HAL_PCD_DataOutStageCallback(hpcd, epnum);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
348 if(hpcd->Init.dma_enable == 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
349 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
350 if((epnum == 0) && (hpcd->OUT_ep[epnum].xfer_len == 0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
351 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
352 /* this is ZLP, so prepare EP0 for next setup */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
353 USB_EP0_OutStart(hpcd->Instance, 1, (uint8_t *)hpcd->Setup);
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
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
358 if(( epint & USB_OTG_DOEPINT_STUP) == USB_OTG_DOEPINT_STUP)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
359 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
360 /* Inform the upper layer that a setup packet is available */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
361 HAL_PCD_SetupStageCallback(hpcd);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
362 CLEAR_OUT_EP_INTR(epnum, USB_OTG_DOEPINT_STUP);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
363 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
364
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
365 if(( epint & USB_OTG_DOEPINT_OTEPDIS) == USB_OTG_DOEPINT_OTEPDIS)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
366 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
367 CLEAR_OUT_EP_INTR(epnum, USB_OTG_DOEPINT_OTEPDIS);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
368 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
369 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
370 epnum++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
371 ep_intr >>= 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
372 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
373 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
374
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
375 if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_IEPINT))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
376 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
377 /* Read in the device interrupt bits */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
378 ep_intr = USB_ReadDevAllInEpInterrupt(hpcd->Instance);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
379
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
380 epnum = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
381
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
382 while ( ep_intr )
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
383 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
384 if (ep_intr & 0x1) /* In ITR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
385 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
386 epint = USB_ReadDevInEPInterrupt(hpcd->Instance, epnum);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
387
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
388 if(( epint & USB_OTG_DIEPINT_XFRC) == USB_OTG_DIEPINT_XFRC)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
389 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
390 fifoemptymsk = 0x1 << epnum;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
391 USBx_DEVICE->DIEPEMPMSK &= ~fifoemptymsk;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
392
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
393 CLEAR_IN_EP_INTR(epnum, USB_OTG_DIEPINT_XFRC);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
394
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
395 if (hpcd->Init.dma_enable == 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
396 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
397 hpcd->IN_ep[epnum].xfer_buff += hpcd->IN_ep[epnum].maxpacket;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
398 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
399
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
400 HAL_PCD_DataInStageCallback(hpcd, epnum);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
401
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
402 if (hpcd->Init.dma_enable == 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
403 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
404 /* this is ZLP, so prepare EP0 for next setup */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
405 if((epnum == 0) && (hpcd->IN_ep[epnum].xfer_len == 0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
406 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
407 /* prepare to rx more setup packets */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
408 USB_EP0_OutStart(hpcd->Instance, 1, (uint8_t *)hpcd->Setup);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
409 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
410 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
411 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
412 if(( epint & USB_OTG_DIEPINT_TOC) == USB_OTG_DIEPINT_TOC)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
413 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
414 CLEAR_IN_EP_INTR(epnum, USB_OTG_DIEPINT_TOC);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
415 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
416 if(( epint & USB_OTG_DIEPINT_ITTXFE) == USB_OTG_DIEPINT_ITTXFE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
417 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
418 CLEAR_IN_EP_INTR(epnum, USB_OTG_DIEPINT_ITTXFE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
419 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
420 if(( epint & USB_OTG_DIEPINT_INEPNE) == USB_OTG_DIEPINT_INEPNE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
421 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
422 CLEAR_IN_EP_INTR(epnum, USB_OTG_DIEPINT_INEPNE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
423 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
424 if(( epint & USB_OTG_DIEPINT_EPDISD) == USB_OTG_DIEPINT_EPDISD)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
425 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
426 CLEAR_IN_EP_INTR(epnum, USB_OTG_DIEPINT_EPDISD);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
427 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
428 if(( epint & USB_OTG_DIEPINT_TXFE) == USB_OTG_DIEPINT_TXFE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
429 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
430 PCD_WriteEmptyTxFifo(hpcd , epnum);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
431 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
432 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
433 epnum++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
434 ep_intr >>= 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
435 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
436 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
437
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
438 /* Handle Resume Interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
439 if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_WKUINT))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
440 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
441 /* Clear the Remote Wake-up Signaling */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
442 USBx_DEVICE->DCTL &= ~USB_OTG_DCTL_RWUSIG;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
443
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
444 HAL_PCD_ResumeCallback(hpcd);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
445
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
446 __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_WKUINT);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
447 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
448
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
449 /* Handle Suspend Interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
450 if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_USBSUSP))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
451 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
452
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
453 if((USBx_DEVICE->DSTS & USB_OTG_DSTS_SUSPSTS) == USB_OTG_DSTS_SUSPSTS)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
454 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
455
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
456 HAL_PCD_SuspendCallback(hpcd);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
457 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
458 __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_USBSUSP);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
459 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
460
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
461 /* Handle Reset Interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
462 if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_USBRST))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
463 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
464 USBx_DEVICE->DCTL &= ~USB_OTG_DCTL_RWUSIG;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
465 USB_FlushTxFifo(hpcd->Instance , 0 );
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
466
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
467 for (i = 0; i < hpcd->Init.dev_endpoints ; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
468 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
469 USBx_INEP(i)->DIEPINT = 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
470 USBx_OUTEP(i)->DOEPINT = 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
471 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
472 USBx_DEVICE->DAINT = 0xFFFFFFFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
473 USBx_DEVICE->DAINTMSK |= 0x10001;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
474
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
475 if(hpcd->Init.use_dedicated_ep1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
476 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
477 USBx_DEVICE->DOUTEP1MSK |= (USB_OTG_DOEPMSK_STUPM | USB_OTG_DOEPMSK_XFRCM | USB_OTG_DOEPMSK_EPDM);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
478 USBx_DEVICE->DINEP1MSK |= (USB_OTG_DIEPMSK_TOM | USB_OTG_DIEPMSK_XFRCM | USB_OTG_DIEPMSK_EPDM);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
479 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
480 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
481 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
482 USBx_DEVICE->DOEPMSK |= (USB_OTG_DOEPMSK_STUPM | USB_OTG_DOEPMSK_XFRCM | USB_OTG_DOEPMSK_EPDM);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
483 USBx_DEVICE->DIEPMSK |= (USB_OTG_DIEPMSK_TOM | USB_OTG_DIEPMSK_XFRCM | USB_OTG_DIEPMSK_EPDM);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
484 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
485
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
486 /* Set Default Address to 0 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
487 USBx_DEVICE->DCFG &= ~USB_OTG_DCFG_DAD;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
488
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
489 /* setup EP0 to receive SETUP packets */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
490 USB_EP0_OutStart(hpcd->Instance, hpcd->Init.dma_enable, (uint8_t *)hpcd->Setup);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
491
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
492 __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_USBRST);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
493 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
494
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
495 /* Handle Enumeration done Interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
496 if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_ENUMDNE))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
497 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
498 USB_ActivateSetup(hpcd->Instance);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
499 hpcd->Instance->GUSBCFG &= ~USB_OTG_GUSBCFG_TRDT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
500
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
501 if ( USB_GetDevSpeed(hpcd->Instance) == USB_OTG_SPEED_HIGH)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
502 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
503 hpcd->Init.speed = USB_OTG_SPEED_HIGH;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
504 hpcd->Init.ep0_mps = USB_OTG_HS_MAX_PACKET_SIZE ;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
505 hpcd->Instance->GUSBCFG |= (USB_OTG_GUSBCFG_TRDT_0 | USB_OTG_GUSBCFG_TRDT_3);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
506 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
507 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
508 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
509 hpcd->Init.speed = USB_OTG_SPEED_FULL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
510 hpcd->Init.ep0_mps = USB_OTG_FS_MAX_PACKET_SIZE ;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
511 hpcd->Instance->GUSBCFG |= (USB_OTG_GUSBCFG_TRDT_0 | USB_OTG_GUSBCFG_TRDT_2);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
512 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
513
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
514 HAL_PCD_ResetCallback(hpcd);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
515
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
516 __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_ENUMDNE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
517 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
518
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
519 /* Handle RxQLevel Interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
520 if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_RXFLVL))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
521 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
522 USB_MASK_INTERRUPT(hpcd->Instance, USB_OTG_GINTSTS_RXFLVL);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
523 temp = USBx->GRXSTSP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
524 ep = &hpcd->OUT_ep[temp & USB_OTG_GRXSTSP_EPNUM];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
525
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
526 if(((temp & USB_OTG_GRXSTSP_PKTSTS) >> 17) == STS_DATA_UPDT)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
527 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
528 if((temp & USB_OTG_GRXSTSP_BCNT) != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
529 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
530 USB_ReadPacket(USBx, ep->xfer_buff, (temp & USB_OTG_GRXSTSP_BCNT) >> 4);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
531 ep->xfer_buff += (temp & USB_OTG_GRXSTSP_BCNT) >> 4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
532 ep->xfer_count += (temp & USB_OTG_GRXSTSP_BCNT) >> 4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
533 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
534 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
535 else if (((temp & USB_OTG_GRXSTSP_PKTSTS) >> 17) == STS_SETUP_UPDT)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
536 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
537 USB_ReadPacket(USBx, (uint8_t *)hpcd->Setup, 8);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
538 ep->xfer_count += (temp & USB_OTG_GRXSTSP_BCNT) >> 4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
539 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
540 USB_UNMASK_INTERRUPT(hpcd->Instance, USB_OTG_GINTSTS_RXFLVL);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
541 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
542
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
543 /* Handle SOF Interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
544 if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_SOF))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
545 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
546 HAL_PCD_SOFCallback(hpcd);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
547 __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_SOF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
548 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
549
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
550 /* Handle Incomplete ISO IN Interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
551 if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_IISOIXFR))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
552 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
553 HAL_PCD_ISOINIncompleteCallback(hpcd, epnum);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
554 __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_IISOIXFR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
555 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
556
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
557 /* Handle Incomplete ISO OUT Interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
558 if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_PXFR_INCOMPISOOUT))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
559 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
560 HAL_PCD_ISOOUTIncompleteCallback(hpcd, epnum);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
561 __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_PXFR_INCOMPISOOUT);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
562 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
563
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
564 /* Handle Connection event Interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
565 if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_SRQINT))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
566 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
567 HAL_PCD_ConnectCallback(hpcd);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
568 __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_SRQINT);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
569 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
570
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
571 /* Handle Disconnection event Interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
572 if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_OTGINT))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
573 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
574 temp = hpcd->Instance->GOTGINT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
575
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
576 if((temp & USB_OTG_GOTGINT_SEDET) == USB_OTG_GOTGINT_SEDET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
577 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
578 HAL_PCD_DisconnectCallback(hpcd);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
579 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
580 hpcd->Instance->GOTGINT |= temp;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
581 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
582 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
583 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
584
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
585 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
586 * @brief Data OUT stage callbacks
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
587 * @param hpcd: PCD handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
588 * @param epnum: endpoint number
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
589 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
590 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
591 __weak void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
592 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
593 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
594 the HAL_PCD_DataOutStageCallback could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
595 */
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 * @brief Data IN stage callbacks
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
600 * @param hpcd: PCD handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
601 * @param epnum: endpoint number
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
602 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
603 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
604 __weak void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
605 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
606 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
607 the HAL_PCD_DataOutStageCallback could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
608 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
609 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
610 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
611 * @brief Setup stage callback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
612 * @param hpcd: PCD handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
613 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
614 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
615 __weak void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
616 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
617 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
618 the HAL_PCD_DataOutStageCallback could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
619 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
620 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
621
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
622 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
623 * @brief USB Start Of Frame callbacks
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
624 * @param hpcd: PCD handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
625 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
626 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
627 __weak void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
628 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
629 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
630 the HAL_PCD_DataOutStageCallback could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
631 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
632 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
633
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
634 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
635 * @brief USB Reset callbacks
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
636 * @param hpcd: PCD handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
637 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
638 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
639 __weak void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
640 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
641 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
642 the HAL_PCD_DataOutStageCallback could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
643 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
644 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
645
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
646
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
647 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
648 * @brief Suspend event callbacks
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
649 * @param hpcd: PCD handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
650 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
651 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
652 __weak void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
653 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
654 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
655 the HAL_PCD_DataOutStageCallback could be implemented in the user file
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
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
659 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
660 * @brief Resume event callbacks
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
661 * @param hpcd: PCD handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
662 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
663 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
664 __weak void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
665 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
666 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
667 the HAL_PCD_DataOutStageCallback could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
668 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
669 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
670
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
671 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
672 * @brief Incomplete ISO OUT callbacks
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
673 * @param hpcd: PCD handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
674 * @param epnum: endpoint number
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
675 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
676 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
677 __weak void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
678 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
679 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
680 the HAL_PCD_DataOutStageCallback could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
681 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
682 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
683
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
684 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
685 * @brief Incomplete ISO IN callbacks
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
686 * @param hpcd: PCD handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
687 * @param epnum: endpoint number
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
688 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
689 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
690 __weak void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
691 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
692 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
693 the HAL_PCD_DataOutStageCallback could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
694 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
695 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
696
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
697 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
698 * @brief Connection event callbacks
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
699 * @param hpcd: PCD handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
700 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
701 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
702 __weak void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
703 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
704 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
705 the HAL_PCD_DataOutStageCallback could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
706 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
707 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
708
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
709 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
710 * @brief Disconnection event callbacks
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
711 * @param hpcd: PCD handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
712 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
713 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
714 __weak void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
715 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
716 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
717 the HAL_PCD_DataOutStageCallback could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
718 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
719 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
720
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
721 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
722 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
723 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
724
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
725 /** @defgroup PCD_Exported_Functions_Group3 Peripheral Control functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
726 * @brief management functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
727 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
728 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
729 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
730 ##### Peripheral Control functions #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
731 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
732 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
733 This subsection provides a set of functions allowing to control the PCD data
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
734 transfers.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
735
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
736 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
737 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
738 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
739
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
740 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
741 * @brief Connect the USB device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
742 * @param hpcd: PCD handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
743 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
744 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
745 HAL_StatusTypeDef HAL_PCD_DevConnect(PCD_HandleTypeDef *hpcd)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
746 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
747 __HAL_LOCK(hpcd);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
748 USB_DevConnect(hpcd->Instance);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
749 __HAL_UNLOCK(hpcd);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
750 return HAL_OK;
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 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
754 * @brief Disconnect the USB device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
755 * @param hpcd: PCD handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
756 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
757 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
758 HAL_StatusTypeDef HAL_PCD_DevDisconnect(PCD_HandleTypeDef *hpcd)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
759 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
760 __HAL_LOCK(hpcd);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
761 USB_DevDisconnect(hpcd->Instance);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
762 __HAL_UNLOCK(hpcd);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
763 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
764 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
765
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
766 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
767 * @brief Set the USB Device address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
768 * @param hpcd: PCD handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
769 * @param address: new device address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
770 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
771 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
772 HAL_StatusTypeDef HAL_PCD_SetAddress(PCD_HandleTypeDef *hpcd, uint8_t address)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
773 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
774 __HAL_LOCK(hpcd);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
775 USB_SetDevAddress(hpcd->Instance, address);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
776 __HAL_UNLOCK(hpcd);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
777 return HAL_OK;
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 * @brief Open and configure an endpoint
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
781 * @param hpcd: PCD handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
782 * @param ep_addr: endpoint address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
783 * @param ep_mps: endpoint max packet size
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
784 * @param ep_type: endpoint type
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
785 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
786 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
787 HAL_StatusTypeDef HAL_PCD_EP_Open(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint16_t ep_mps, uint8_t ep_type)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
788 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
789 HAL_StatusTypeDef ret = HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
790 USB_OTG_EPTypeDef *ep;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
791
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
792 if ((ep_addr & 0x80) == 0x80)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
793 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
794 ep = &hpcd->IN_ep[ep_addr & 0x7F];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
795 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
796 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
797 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
798 ep = &hpcd->OUT_ep[ep_addr & 0x7F];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
799 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
800 ep->num = ep_addr & 0x7F;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
801
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
802 ep->is_in = (0x80 & ep_addr) != 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
803 ep->maxpacket = ep_mps;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
804 ep->type = ep_type;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
805 if (ep->is_in)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
806 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
807 /* Assign a Tx FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
808 ep->tx_fifo_num = ep->num;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
809 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
810 /* Set initial data PID. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
811 if (ep_type == EP_TYPE_BULK )
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
812 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
813 ep->data_pid_start = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
814 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
815
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
816 __HAL_LOCK(hpcd);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
817 USB_ActivateEndpoint(hpcd->Instance , ep);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
818 __HAL_UNLOCK(hpcd);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
819 return ret;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
820 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
821
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
822
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
823 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
824 * @brief Deactivate an endpoint
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
825 * @param hpcd: PCD handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
826 * @param ep_addr: endpoint address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
827 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
828 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
829 HAL_StatusTypeDef HAL_PCD_EP_Close(PCD_HandleTypeDef *hpcd, uint8_t ep_addr)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
830 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
831 USB_OTG_EPTypeDef *ep;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
832
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
833 if ((ep_addr & 0x80) == 0x80)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
834 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
835 ep = &hpcd->IN_ep[ep_addr & 0x7F];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
836 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
837 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
838 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
839 ep = &hpcd->OUT_ep[ep_addr & 0x7F];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
840 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
841 ep->num = ep_addr & 0x7F;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
842
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
843 ep->is_in = (0x80 & ep_addr) != 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
844
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
845 __HAL_LOCK(hpcd);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
846 USB_DeactivateEndpoint(hpcd->Instance , ep);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
847 __HAL_UNLOCK(hpcd);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
848 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
849 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
850
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
851
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
852 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
853 * @brief Receive an amount of data
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
854 * @param hpcd: PCD handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
855 * @param ep_addr: endpoint address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
856 * @param pBuf: pointer to the reception buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
857 * @param len: amount of data to be received
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
858 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
859 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
860 HAL_StatusTypeDef HAL_PCD_EP_Receive(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
861 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
862 USB_OTG_EPTypeDef *ep;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
863
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
864 ep = &hpcd->OUT_ep[ep_addr & 0x7F];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
865
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
866 /*setup and start the Xfer */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
867 ep->xfer_buff = pBuf;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
868 ep->xfer_len = len;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
869 ep->xfer_count = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
870 ep->is_in = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
871 ep->num = ep_addr & 0x7F;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
872
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
873 if (hpcd->Init.dma_enable == 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
874 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
875 ep->dma_addr = (uint32_t)pBuf;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
876 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
877
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
878 __HAL_LOCK(hpcd);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
879
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
880 if ((ep_addr & 0x7F) == 0 )
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
881 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
882 USB_EP0StartXfer(hpcd->Instance , ep, hpcd->Init.dma_enable);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
883 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
884 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
885 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
886 USB_EPStartXfer(hpcd->Instance , ep, hpcd->Init.dma_enable);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
887 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
888 __HAL_UNLOCK(hpcd);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
889
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
890 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
891 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
892
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
893 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
894 * @brief Get Received Data Size
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
895 * @param hpcd: PCD handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
896 * @param ep_addr: endpoint address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
897 * @retval Data Size
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
898 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
899 uint16_t HAL_PCD_EP_GetRxCount(PCD_HandleTypeDef *hpcd, uint8_t ep_addr)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
900 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
901 return hpcd->OUT_ep[ep_addr & 0x7F].xfer_count;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
902 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
903 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
904 * @brief Send an amount of data
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
905 * @param hpcd: PCD handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
906 * @param ep_addr: endpoint address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
907 * @param pBuf: pointer to the transmission buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
908 * @param len: amount of data to be sent
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
909 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
910 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
911 HAL_StatusTypeDef HAL_PCD_EP_Transmit(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
912 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
913 USB_OTG_EPTypeDef *ep;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
914
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
915 ep = &hpcd->IN_ep[ep_addr & 0x7F];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
916
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
917 /*setup and start the Xfer */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
918 ep->xfer_buff = pBuf;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
919 ep->xfer_len = len;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
920 ep->xfer_count = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
921 ep->is_in = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
922 ep->num = ep_addr & 0x7F;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
923
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
924 if (hpcd->Init.dma_enable == 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
925 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
926 ep->dma_addr = (uint32_t)pBuf;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
927 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
928
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
929 __HAL_LOCK(hpcd);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
930
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
931 if ((ep_addr & 0x7F) == 0 )
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
932 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
933 USB_EP0StartXfer(hpcd->Instance , ep, hpcd->Init.dma_enable);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
934 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
935 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
936 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
937 USB_EPStartXfer(hpcd->Instance , ep, hpcd->Init.dma_enable);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
938 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
939
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
940 __HAL_UNLOCK(hpcd);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
941
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
942 return HAL_OK;
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 Set a STALL condition over an endpoint
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
947 * @param hpcd: PCD handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
948 * @param ep_addr: endpoint address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
949 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
950 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
951 HAL_StatusTypeDef HAL_PCD_EP_SetStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
952 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
953 USB_OTG_EPTypeDef *ep;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
954
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
955 if ((0x80 & ep_addr) == 0x80)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
956 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
957 ep = &hpcd->IN_ep[ep_addr & 0x7F];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
958 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
959 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
960 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
961 ep = &hpcd->OUT_ep[ep_addr];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
962 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
963
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
964 ep->is_stall = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
965 ep->num = ep_addr & 0x7F;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
966 ep->is_in = ((ep_addr & 0x80) == 0x80);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
967
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
968
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
969 __HAL_LOCK(hpcd);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
970 USB_EPSetStall(hpcd->Instance , ep);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
971 if((ep_addr & 0x7F) == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
972 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
973 USB_EP0_OutStart(hpcd->Instance, hpcd->Init.dma_enable, (uint8_t *)hpcd->Setup);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
974 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
975 __HAL_UNLOCK(hpcd);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
976
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
977 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
978 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
979
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
980 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
981 * @brief Clear a STALL condition over in an endpoint
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
982 * @param hpcd: PCD handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
983 * @param ep_addr: endpoint address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
984 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
985 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
986 HAL_StatusTypeDef HAL_PCD_EP_ClrStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
987 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
988 USB_OTG_EPTypeDef *ep;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
989
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
990 if ((0x80 & ep_addr) == 0x80)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
991 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
992 ep = &hpcd->IN_ep[ep_addr & 0x7F];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
993 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
994 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
995 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
996 ep = &hpcd->OUT_ep[ep_addr];
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 ep->is_stall = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1000 ep->num = ep_addr & 0x7F;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1001 ep->is_in = ((ep_addr & 0x80) == 0x80);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1002
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1003 __HAL_LOCK(hpcd);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1004 USB_EPClearStall(hpcd->Instance , ep);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1005 __HAL_UNLOCK(hpcd);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1006
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1007 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1008 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1009
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1010 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1011 * @brief Flush an endpoint
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1012 * @param hpcd: PCD handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1013 * @param ep_addr: endpoint address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1014 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1015 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1016 HAL_StatusTypeDef HAL_PCD_EP_Flush(PCD_HandleTypeDef *hpcd, uint8_t ep_addr)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1017 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1018 __HAL_LOCK(hpcd);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1019
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1020 if ((ep_addr & 0x80) == 0x80)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1021 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1022 USB_FlushTxFifo(hpcd->Instance, ep_addr & 0x7F);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1023 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1024 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1025 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1026 USB_FlushRxFifo(hpcd->Instance);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1027 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1028
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1029 __HAL_UNLOCK(hpcd);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1030
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1031 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1032 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1033
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1034 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1035 * @brief HAL_PCD_ActivateRemoteWakeup : active remote wake-up signalling
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1036 * @param hpcd: PCD handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1037 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1038 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1039 HAL_StatusTypeDef HAL_PCD_ActivateRemoteWakeup(PCD_HandleTypeDef *hpcd)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1040 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1041 USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1042
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1043 if((USBx_DEVICE->DSTS & USB_OTG_DSTS_SUSPSTS) == USB_OTG_DSTS_SUSPSTS)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1044 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1045 /* active Remote wake-up signaling */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1046 USBx_DEVICE->DCTL |= USB_OTG_DCTL_RWUSIG;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1047 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1048 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1049 }
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 * @brief HAL_PCD_DeActivateRemoteWakeup : de-active remote wake-up signalling
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1053 * @param hpcd: PCD handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1054 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1055 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1056 HAL_StatusTypeDef HAL_PCD_DeActivateRemoteWakeup(PCD_HandleTypeDef *hpcd)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1057 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1058 USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1059
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1060 /* Active Remote wake-up signaling */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1061 USBx_DEVICE->DCTL &= ~(USB_OTG_DCTL_RWUSIG);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1062 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1063 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1064 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1065 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1066 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1067
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1068 /** @defgroup PCD_Exported_Functions_Group4 Peripheral State functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1069 * @brief Peripheral State functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1070 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1071 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1072 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1073 ##### Peripheral State functions #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1074 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1075 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1076 This subsection permits to get in run-time the status of the peripheral
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1077 and the data flow.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1078
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1079 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1080 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1081 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1082
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1083 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1084 * @brief Return the PCD state
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1085 * @param hpcd: PCD handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1086 * @retval HAL state
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1087 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1088 PCD_StateTypeDef HAL_PCD_GetState(PCD_HandleTypeDef *hpcd)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1089 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1090 return hpcd->State;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1091 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1092 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1093 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1094 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1095
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1096 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1097 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1098 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1099
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1100 /* Private functions ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1101 /** @addtogroup PCD_Private_Functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1102 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1103 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1104
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1105 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1106 * @brief DCD_WriteEmptyTxFifo
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1107 * check FIFO for the next packet to be loaded
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1108 * @param hpcd: PCD handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1109 * @param epnum : endpoint number
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1110 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1111 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1112 static HAL_StatusTypeDef PCD_WriteEmptyTxFifo(PCD_HandleTypeDef *hpcd, uint32_t epnum)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1113 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1114 USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1115 USB_OTG_EPTypeDef *ep;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1116 int32_t len = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1117 uint32_t len32b;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1118 uint32_t fifoemptymsk = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1119
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1120 ep = &hpcd->IN_ep[epnum];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1121 len = ep->xfer_len - ep->xfer_count;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1122
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1123 if (len > ep->maxpacket)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1124 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1125 len = ep->maxpacket;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1126 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1127
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1128
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1129 len32b = (len + 3) / 4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1130
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1131 while ( (USBx_INEP(epnum)->DTXFSTS & USB_OTG_DTXFSTS_INEPTFSAV) > len32b &&
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1132 ep->xfer_count < ep->xfer_len &&
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1133 ep->xfer_len != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1134 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1135 /* Write the FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1136 len = ep->xfer_len - ep->xfer_count;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1137
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1138 if (len > ep->maxpacket)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1139 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1140 len = ep->maxpacket;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1141 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1142 len32b = (len + 3) / 4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1143
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1144 USB_WritePacket(USBx, ep->xfer_buff, epnum, len, hpcd->Init.dma_enable);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1145
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1146 ep->xfer_buff += len;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1147 ep->xfer_count += len;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1148 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1149
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1150 if(len <= 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1151 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1152 fifoemptymsk = 0x1 << epnum;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1153 USBx_DEVICE->DIEPEMPMSK &= ~fifoemptymsk;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1154
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1155 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1156
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1157 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1158 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1159
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 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1163
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1164 #endif /* HAL_PCD_MODULE_ENABLED */
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 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1168
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1169 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1170 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1171 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1172
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1173 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/