Subversion Repositories LedShow

Rev

Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 9
Line 1... Line 1...
1
/**
1
/**
2
  ******************************************************************************
2
  ******************************************************************************
3
  * @file    stm32f1xx_hal_hcd.c
3
  * @file    stm32f1xx_hal_hcd.c
4
  * @author  MCD Application Team
4
  * @author  MCD Application Team
5
  * @brief   HCD HAL module driver.
5
  * @brief   HCD HAL module driver.
6
  *          This file provides firmware functions to manage the following
6
  *          This file provides firmware functions to manage the following
7
  *          functionalities of the USB Peripheral Controller:
7
  *          functionalities of the USB Peripheral Controller:
8
  *           + Initialization and de-initialization functions
8
  *           + Initialization and de-initialization functions
9
  *           + IO operation functions
9
  *           + IO operation functions
10
  *           + Peripheral Control functions
10
  *           + Peripheral Control functions
11
  *           + Peripheral State functions
11
  *           + Peripheral State functions
12
  *
12
  *
13
  @verbatim
13
  @verbatim
14
  ==============================================================================
14
  ==============================================================================
15
                    ##### How to use this driver #####
15
                    ##### How to use this driver #####
16
  ==============================================================================
16
  ==============================================================================
17
  [..]
17
  [..]
18
    (#)Declare a HCD_HandleTypeDef handle structure, for example:
18
    (#)Declare a HCD_HandleTypeDef handle structure, for example:
19
       HCD_HandleTypeDef  hhcd;
19
       HCD_HandleTypeDef  hhcd;
20
       
20
 
21
    (#)Fill parameters of Init structure in HCD handle
21
    (#)Fill parameters of Init structure in HCD handle
22
 
22
 
23
    (#)Call HAL_HCD_Init() API to initialize the HCD peripheral (Core, Host core, ...)
23
    (#)Call HAL_HCD_Init() API to initialize the HCD peripheral (Core, Host core, ...)
24
 
24
 
25
    (#)Initialize the HCD low level resources through the HAL_HCD_MspInit() API:
25
    (#)Initialize the HCD low level resources through the HAL_HCD_MspInit() API:
26
        (##) Enable the HCD/USB Low Level interface clock using the following macro
26
        (##) Enable the HCD/USB Low Level interface clock using the following macros
27
             (+++) __HAL_RCC_USB_OTG_FS_CLK_ENABLE()
27
             (+++) __HAL_RCC_USB_OTG_FS_CLK_ENABLE();
28
 
-
 
29
        (##) Initialize the related GPIO clocks
28
        (##) Initialize the related GPIO clocks
30
        (##) Configure HCD pin-out
29
        (##) Configure HCD pin-out
31
        (##) Configure HCD NVIC interrupt
30
        (##) Configure HCD NVIC interrupt
32
 
31
 
33
    (#)Associate the Upper USB Host stack to the HAL HCD Driver:
32
    (#)Associate the Upper USB Host stack to the HAL HCD Driver:
Line 38... Line 37...
38
 
37
 
39
  @endverbatim
38
  @endverbatim
40
  ******************************************************************************
39
  ******************************************************************************
41
  * @attention
40
  * @attention
42
  *
41
  *
43
  * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
42
  * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
44
  *
-
 
45
  * Redistribution and use in source and binary forms, with or without modification,
-
 
46
  * are permitted provided that the following conditions are met:
-
 
47
  *   1. Redistributions of source code must retain the above copyright notice,
-
 
48
  *      this list of conditions and the following disclaimer.
-
 
49
  *   2. Redistributions in binary form must reproduce the above copyright notice,
-
 
50
  *      this list of conditions and the following disclaimer in the documentation
-
 
51
  *      and/or other materials provided with the distribution.
-
 
52
  *   3. Neither the name of STMicroelectronics nor the names of its contributors
-
 
53
  *      may be used to endorse or promote products derived from this software
-
 
54
  *      without specific prior written permission.
43
  * All rights reserved.</center></h2>
55
  *
44
  *
56
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
45
  * This software component is licensed by ST under BSD 3-Clause license,
57
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-
 
58
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-
 
59
  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-
 
60
  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-
 
61
  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
46
  * the "License"; You may not use this file except in compliance with the
62
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
47
  * License. You may obtain a copy of the License at:
63
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-
 
64
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-
 
65
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48
  *                        opensource.org/licenses/BSD-3-Clause
66
  *
49
  *
67
  ******************************************************************************
50
  ******************************************************************************
68
  */
51
  */
69
 
52
 
70
/* Includes ------------------------------------------------------------------*/
53
/* Includes ------------------------------------------------------------------*/
71
#include "stm32f1xx_hal.h"
54
#include "stm32f1xx_hal.h"
-
 
55
 
72
/** @addtogroup STM32F1xx_HAL_Driver
56
/** @addtogroup STM32F1xx_HAL_Driver
73
  * @{
57
  * @{
74
  */
58
  */
75
 
59
 
76
 
-
 
77
#ifdef HAL_HCD_MODULE_ENABLED
60
#ifdef HAL_HCD_MODULE_ENABLED
78
 
61
 
79
#if defined(STM32F105xC) || defined(STM32F107xC)
62
#if defined (USB_OTG_FS)
80
 
63
 
81
/** @defgroup HCD HCD
64
/** @defgroup HCD HCD
82
  * @brief HCD HAL module driver
65
  * @brief HCD HAL module driver
83
  * @{
66
  * @{
84
  */
67
  */
85
 
68
 
86
/* Private types -------------------------------------------------------------*/
69
/* Private typedef -----------------------------------------------------------*/
-
 
70
/* Private define ------------------------------------------------------------*/
-
 
71
/* Private macro -------------------------------------------------------------*/
87
/* Private variables ---------------------------------------------------------*/
72
/* Private variables ---------------------------------------------------------*/
88
/* Private constants ---------------------------------------------------------*/
-
 
89
/* Private macros ------------------------------------------------------------*/
-
 
90
/* Private function ----------------------------------------------------------*/
73
/* Private function prototypes -----------------------------------------------*/
91
/** @defgroup HCD_Private_Functions HCD Private Functions
74
/** @defgroup HCD_Private_Functions HCD Private Functions
92
  * @{
75
  * @{
93
  */
76
  */
94
static void HCD_HC_IN_IRQHandler(HCD_HandleTypeDef *hhcd, uint8_t chnum);
77
static void HCD_HC_IN_IRQHandler(HCD_HandleTypeDef *hhcd, uint8_t chnum);
95
static void HCD_HC_OUT_IRQHandler(HCD_HandleTypeDef *hhcd, uint8_t chnum);
78
static void HCD_HC_OUT_IRQHandler(HCD_HandleTypeDef *hhcd, uint8_t chnum);
Line 102... Line 85...
102
/* Exported functions --------------------------------------------------------*/
85
/* Exported functions --------------------------------------------------------*/
103
/** @defgroup HCD_Exported_Functions HCD Exported Functions
86
/** @defgroup HCD_Exported_Functions HCD Exported Functions
104
  * @{
87
  * @{
105
  */
88
  */
106
 
89
 
107
/** @defgroup HCD_Exported_Functions_Group1 Initialization and de-initialization functions
90
/** @defgroup HCD_Exported_Functions_Group1 Initialization and de-initialization functions
108
 *  @brief    Initialization and Configuration functions
91
  *  @brief    Initialization and Configuration functions
109
 *
92
  *
110
@verbatim
93
@verbatim
111
 ===============================================================================
94
 ===============================================================================
112
          ##### Initialization and de-initialization functions #####
95
          ##### Initialization and de-initialization functions #####
113
 ===============================================================================
96
 ===============================================================================
114
    [..]  This section provides functions allowing to:
97
    [..]  This section provides functions allowing to:
115
 
98
 
116
@endverbatim
99
@endverbatim
117
  * @{
100
  * @{
118
  */
101
  */
119
 
102
 
120
/**
103
/**
121
  * @brief  Initialize the host driver
104
  * @brief  Initialize the host driver.
122
  * @param  hhcd: HCD handle
105
  * @param  hhcd HCD handle
123
  * @retval HAL status
106
  * @retval HAL status
124
  */
107
  */
125
HAL_StatusTypeDef HAL_HCD_Init(HCD_HandleTypeDef *hhcd)
108
HAL_StatusTypeDef HAL_HCD_Init(HCD_HandleTypeDef *hhcd)
126
{
109
{
-
 
110
  USB_OTG_GlobalTypeDef *USBx;
-
 
111
 
127
  /* Check the HCD handle allocation */
112
  /* Check the HCD handle allocation */
128
  if(hhcd == NULL)
113
  if (hhcd == NULL)
129
  {
114
  {
130
    return HAL_ERROR;
115
    return HAL_ERROR;
131
  }
116
  }
132
 
117
 
133
  /* Check the parameters */
118
  /* Check the parameters */
134
  assert_param(IS_HCD_ALL_INSTANCE(hhcd->Instance));
119
  assert_param(IS_HCD_ALL_INSTANCE(hhcd->Instance));
-
 
120
 
-
 
121
  USBx = hhcd->Instance;
135
 
122
 
136
  if(hhcd->State == HAL_HCD_STATE_RESET)
123
  if (hhcd->State == HAL_HCD_STATE_RESET)
137
  {  
124
  {
138
    /* Allocate lock resource and initialize it */
125
    /* Allocate lock resource and initialize it */
139
    hhcd->Lock = HAL_UNLOCKED;
126
    hhcd->Lock = HAL_UNLOCKED;
140
 
127
 
-
 
128
#if (USE_HAL_HCD_REGISTER_CALLBACKS == 1U)
-
 
129
    hhcd->SOFCallback = HAL_HCD_SOF_Callback;
-
 
130
    hhcd->ConnectCallback = HAL_HCD_Connect_Callback;
-
 
131
    hhcd->DisconnectCallback = HAL_HCD_Disconnect_Callback;
-
 
132
    hhcd->PortEnabledCallback = HAL_HCD_PortEnabled_Callback;
-
 
133
    hhcd->PortDisabledCallback = HAL_HCD_PortDisabled_Callback;
-
 
134
    hhcd->HC_NotifyURBChangeCallback = HAL_HCD_HC_NotifyURBChange_Callback;
-
 
135
 
-
 
136
    if (hhcd->MspInitCallback == NULL)
-
 
137
    {
-
 
138
      hhcd->MspInitCallback = HAL_HCD_MspInit;
-
 
139
    }
-
 
140
 
-
 
141
    /* Init the low level hardware */
-
 
142
    hhcd->MspInitCallback(hhcd);
-
 
143
#else
141
    /* Init the low level hardware : GPIO, CLOCK, NVIC... */
144
    /* Init the low level hardware : GPIO, CLOCK, NVIC... */
142
    HAL_HCD_MspInit(hhcd);
145
    HAL_HCD_MspInit(hhcd);
-
 
146
#endif /* (USE_HAL_HCD_REGISTER_CALLBACKS) */
143
  }
147
  }
144
 
148
 
145
  hhcd->State = HAL_HCD_STATE_BUSY;
149
  hhcd->State = HAL_HCD_STATE_BUSY;
-
 
150
 
-
 
151
  /* Disable DMA mode for FS instance */
-
 
152
  if ((USBx->CID & (0x1U << 8)) == 0U)
146
 
153
  {
-
 
154
    hhcd->Init.dma_enable = 0U;
-
 
155
  }
-
 
156
 
147
  /* Disable the Interrupts */
157
  /* Disable the Interrupts */
148
  __HAL_HCD_DISABLE(hhcd);
158
  __HAL_HCD_DISABLE(hhcd);
149
 
159
 
150
  /* Init the Core (common init.) */
160
  /* Init the Core (common init.) */
151
  USB_CoreInit(hhcd->Instance, hhcd->Init);
161
  (void)USB_CoreInit(hhcd->Instance, hhcd->Init);
152
 
162
 
153
  /* Force Host Mode*/
163
  /* Force Host Mode*/
154
  USB_SetCurrentMode(hhcd->Instance , USB_HOST_MODE);
164
  (void)USB_SetCurrentMode(hhcd->Instance, USB_HOST_MODE);
155
 
165
 
156
  /* Init Host */
166
  /* Init Host */
157
  USB_HostInit(hhcd->Instance, hhcd->Init);
167
  (void)USB_HostInit(hhcd->Instance, hhcd->Init);
158
 
168
 
159
  hhcd->State= HAL_HCD_STATE_READY;
169
  hhcd->State = HAL_HCD_STATE_READY;
160
 
170
 
161
  return HAL_OK;
171
  return HAL_OK;
162
}
172
}
163
 
173
 
164
/**
174
/**
165
  * @brief  Initialize a host channel
175
  * @brief  Initialize a host channel.
166
  * @param  hhcd: HCD handle
176
  * @param  hhcd HCD handle
167
  * @param  ch_num: Channel number.
177
  * @param  ch_num Channel number.
168
  *         This parameter can be a value from 1 to 15
178
  *         This parameter can be a value from 1 to 15
169
  * @param  epnum: Endpoint number.
179
  * @param  epnum Endpoint number.
170
  *          This parameter can be a value from 1 to 15
180
  *          This parameter can be a value from 1 to 15
171
  * @param  dev_address : Current device address
181
  * @param  dev_address Current device address
172
  *          This parameter can be a value from 0 to 255
182
  *          This parameter can be a value from 0 to 255
173
  * @param  speed: Current device speed.
183
  * @param  speed Current device speed.
174
  *          This parameter can be one of these values:
184
  *          This parameter can be one of these values:
175
  *            HCD_SPEED_FULL: Full speed mode,
185
  *            HCD_SPEED_FULL: Full speed mode,
176
  *            HCD_SPEED_LOW: Low speed mode
186
  *            HCD_SPEED_LOW: Low speed mode
177
  * @param  ep_type: Endpoint Type.
187
  * @param  ep_type Endpoint Type.
178
  *          This parameter can be one of these values:
188
  *          This parameter can be one of these values:
179
  *            EP_TYPE_CTRL: Control type,
189
  *            EP_TYPE_CTRL: Control type,
180
  *            EP_TYPE_ISOC: Isochronous type,
190
  *            EP_TYPE_ISOC: Isochronous type,
181
  *            EP_TYPE_BULK: Bulk type,
191
  *            EP_TYPE_BULK: Bulk type,
182
  *            EP_TYPE_INTR: Interrupt type
192
  *            EP_TYPE_INTR: Interrupt type
183
  * @param  mps: Max Packet Size.
193
  * @param  mps Max Packet Size.
184
  *          This parameter can be a value from 0 to32K
194
  *          This parameter can be a value from 0 to32K
185
  * @retval HAL status
195
  * @retval HAL status
186
  */
196
  */
187
HAL_StatusTypeDef HAL_HCD_HC_Init(HCD_HandleTypeDef *hhcd,
197
HAL_StatusTypeDef HAL_HCD_HC_Init(HCD_HandleTypeDef *hhcd,
188
                                  uint8_t ch_num,
198
                                  uint8_t ch_num,
Line 190... Line 200...
190
                                  uint8_t dev_address,
200
                                  uint8_t dev_address,
191
                                  uint8_t speed,
201
                                  uint8_t speed,
192
                                  uint8_t ep_type,
202
                                  uint8_t ep_type,
193
                                  uint16_t mps)
203
                                  uint16_t mps)
194
{
204
{
195
  HAL_StatusTypeDef status = HAL_OK;
205
  HAL_StatusTypeDef status;
196
 
206
 
197
  __HAL_LOCK(hhcd);
207
  __HAL_LOCK(hhcd);
198
 
208
  hhcd->hc[ch_num].do_ping = 0U;
199
  hhcd->hc[ch_num].dev_addr = dev_address;
209
  hhcd->hc[ch_num].dev_addr = dev_address;
200
  hhcd->hc[ch_num].max_packet = mps;
210
  hhcd->hc[ch_num].max_packet = mps;
201
  hhcd->hc[ch_num].ch_num = ch_num;
211
  hhcd->hc[ch_num].ch_num = ch_num;
202
  hhcd->hc[ch_num].ep_type = ep_type;
212
  hhcd->hc[ch_num].ep_type = ep_type;
203
  hhcd->hc[ch_num].ep_num = epnum & 0x7FU;
213
  hhcd->hc[ch_num].ep_num = epnum & 0x7FU;
-
 
214
 
-
 
215
  if ((epnum & 0x80U) == 0x80U)
-
 
216
  {
-
 
217
    hhcd->hc[ch_num].ep_is_in = 1U;
-
 
218
  }
-
 
219
  else
-
 
220
  {
204
  hhcd->hc[ch_num].ep_is_in = ((epnum & 0x80U) == 0x80U);
221
    hhcd->hc[ch_num].ep_is_in = 0U;
-
 
222
  }
-
 
223
 
205
  hhcd->hc[ch_num].speed = speed;
224
  hhcd->hc[ch_num].speed = speed;
206
 
225
 
207
  status =  USB_HC_Init(hhcd->Instance,
226
  status =  USB_HC_Init(hhcd->Instance,
208
                        ch_num,
227
                        ch_num,
209
                        epnum,
228
                        epnum,
210
                        dev_address,
229
                        dev_address,
211
                        speed,
230
                        speed,
212
                        ep_type,
231
                        ep_type,
213
                        mps);
232
                        mps);
214
  __HAL_UNLOCK(hhcd);
233
  __HAL_UNLOCK(hhcd);
215
 
234
 
216
  return status;
235
  return status;
217
}
236
}
218
 
237
 
219
/**
238
/**
220
  * @brief  Halt a host channel
239
  * @brief  Halt a host channel.
221
  * @param  hhcd: HCD handle
240
  * @param  hhcd HCD handle
222
  * @param  ch_num: Channel number.
241
  * @param  ch_num Channel number.
223
  *         This parameter can be a value from 1 to 15
242
  *         This parameter can be a value from 1 to 15
224
  * @retval HAL status
243
  * @retval HAL status
225
  */
244
  */
226
HAL_StatusTypeDef HAL_HCD_HC_Halt(HCD_HandleTypeDef *hhcd,
245
HAL_StatusTypeDef HAL_HCD_HC_Halt(HCD_HandleTypeDef *hhcd, uint8_t ch_num)
227
                                  uint8_t ch_num)
-
 
228
{
246
{
-
 
247
  HAL_StatusTypeDef status = HAL_OK;
-
 
248
 
229
  __HAL_LOCK(hhcd);
249
  __HAL_LOCK(hhcd);
230
  USB_HC_Halt(hhcd->Instance, ch_num);
250
  (void)USB_HC_Halt(hhcd->Instance, (uint8_t)ch_num);
231
  __HAL_UNLOCK(hhcd);
251
  __HAL_UNLOCK(hhcd);
232
 
252
 
233
  return HAL_OK;
253
  return status;
234
}
254
}
235
 
255
 
236
/**
256
/**
237
  * @brief  DeInitialize the host driver
257
  * @brief  DeInitialize the host driver.
238
  * @param  hhcd: HCD handle
258
  * @param  hhcd HCD handle
239
  * @retval HAL status
259
  * @retval HAL status
240
  */
260
  */
241
HAL_StatusTypeDef HAL_HCD_DeInit(HCD_HandleTypeDef *hhcd)
261
HAL_StatusTypeDef HAL_HCD_DeInit(HCD_HandleTypeDef *hhcd)
242
{
262
{
243
  /* Check the HCD handle allocation */
263
  /* Check the HCD handle allocation */
244
  if(hhcd == NULL)
264
  if (hhcd == NULL)
245
  {
265
  {
246
    return HAL_ERROR;
266
    return HAL_ERROR;
247
  }
267
  }
248
 
268
 
249
  hhcd->State = HAL_HCD_STATE_BUSY;
269
  hhcd->State = HAL_HCD_STATE_BUSY;
-
 
270
 
-
 
271
#if (USE_HAL_HCD_REGISTER_CALLBACKS == 1U)
-
 
272
  if (hhcd->MspDeInitCallback == NULL)
250
 
273
  {
-
 
274
    hhcd->MspDeInitCallback = HAL_HCD_MspDeInit; /* Legacy weak MspDeInit  */
-
 
275
  }
-
 
276
 
251
  /* DeInit the low level hardware */
277
  /* DeInit the low level hardware */
-
 
278
  hhcd->MspDeInitCallback(hhcd);
-
 
279
#else
-
 
280
  /* DeInit the low level hardware: CLOCK, NVIC.*/
252
  HAL_HCD_MspDeInit(hhcd);
281
  HAL_HCD_MspDeInit(hhcd);
-
 
282
#endif /* USE_HAL_HCD_REGISTER_CALLBACKS */
253
 
283
 
254
  __HAL_HCD_DISABLE(hhcd);
284
  __HAL_HCD_DISABLE(hhcd);
255
 
285
 
256
  hhcd->State = HAL_HCD_STATE_RESET;
286
  hhcd->State = HAL_HCD_STATE_RESET;
257
 
287
 
258
  return HAL_OK;
288
  return HAL_OK;
259
}
289
}
260
 
290
 
261
/**
291
/**
262
  * @brief  Initializes the HCD MSP.
292
  * @brief  Initialize the HCD MSP.
263
  * @param  hhcd: HCD handle
293
  * @param  hhcd HCD handle
264
  * @retval None
294
  * @retval None
265
  */
295
  */
266
__weak void  HAL_HCD_MspInit(HCD_HandleTypeDef *hhcd)
296
__weak void  HAL_HCD_MspInit(HCD_HandleTypeDef *hhcd)
267
{
297
{
268
  /* Prevent unused argument(s) compilation warning */
298
  /* Prevent unused argument(s) compilation warning */
269
  UNUSED(hhcd);
299
  UNUSED(hhcd);
-
 
300
 
270
  /* NOTE : This function Should not be modified, when the callback is needed,
301
  /* NOTE : This function should not be modified, when the callback is needed,
271
            the HAL_HCD_MspInit could be implemented in the user file
302
            the HAL_HCD_MspInit could be implemented in the user file
272
   */
303
   */
273
}
304
}
274
 
305
 
275
/**
306
/**
276
  * @brief  DeInitializes HCD MSP.
307
  * @brief  DeInitialize the HCD MSP.
277
  * @param  hhcd: HCD handle
308
  * @param  hhcd HCD handle
278
  * @retval None
309
  * @retval None
279
  */
310
  */
280
__weak void  HAL_HCD_MspDeInit(HCD_HandleTypeDef *hhcd)
311
__weak void  HAL_HCD_MspDeInit(HCD_HandleTypeDef *hhcd)
281
{
312
{
282
  /* Prevent unused argument(s) compilation warning */
313
  /* Prevent unused argument(s) compilation warning */
283
  UNUSED(hhcd);
314
  UNUSED(hhcd);
-
 
315
 
284
  /* NOTE : This function Should not be modified, when the callback is needed,
316
  /* NOTE : This function should not be modified, when the callback is needed,
285
            the HAL_HCD_MspDeInit could be implemented in the user file
317
            the HAL_HCD_MspDeInit could be implemented in the user file
286
   */
318
   */
287
}
319
}
288
 
320
 
289
/**
321
/**
290
  * @}
322
  * @}
291
  */
323
  */
292
 
324
 
293
/** @defgroup HCD_Exported_Functions_Group2 IO operation functions
325
/** @defgroup HCD_Exported_Functions_Group2 Input and Output operation functions
294
  *  @brief   HCD IO operation functions
326
  *  @brief   HCD IO operation functions
295
  *
327
  *
296
@verbatim
328
@verbatim
297
 ===============================================================================
329
 ===============================================================================
298
                      ##### IO operation functions #####
330
                      ##### IO operation functions #####
299
 ===============================================================================
331
 ===============================================================================
300
    This subsection provides a set of functions allowing to manage the USB Host Data
332
 [..] This subsection provides a set of functions allowing to manage the USB Host Data
301
    Transfer
333
    Transfer
302
       
334
 
303
@endverbatim
335
@endverbatim
304
  * @{
336
  * @{
305
  */
337
  */
306
 
338
 
307
/**                                
339
/**
308
  * @brief  Submit a new URB for processing
340
  * @brief  Submit a new URB for processing.
309
  * @param  hhcd: HCD handle
341
  * @param  hhcd HCD handle
310
  * @param  ch_num: Channel number.
342
  * @param  ch_num Channel number.
311
  *         This parameter can be a value from 1 to 15
343
  *         This parameter can be a value from 1 to 15
312
  * @param  direction: Channel number.
344
  * @param  direction Channel number.
313
  *          This parameter can be one of these values:
345
  *          This parameter can be one of these values:
314
  *           0 : Output / 1 : Input
346
  *           0 : Output / 1 : Input
315
  * @param  ep_type: Endpoint Type.
347
  * @param  ep_type Endpoint Type.
316
  *          This parameter can be one of these values:
348
  *          This parameter can be one of these values:
317
  *            EP_TYPE_CTRL: Control type/
349
  *            EP_TYPE_CTRL: Control type/
318
  *            EP_TYPE_ISOC: Isochronous type/
350
  *            EP_TYPE_ISOC: Isochronous type/
319
  *            EP_TYPE_BULK: Bulk type/
351
  *            EP_TYPE_BULK: Bulk type/
320
  *            EP_TYPE_INTR: Interrupt type/
352
  *            EP_TYPE_INTR: Interrupt type/
321
  * @param  token: Endpoint Type.
353
  * @param  token Endpoint Type.
322
  *          This parameter can be one of these values:
354
  *          This parameter can be one of these values:
323
  *            0: HC_PID_SETUP / 1: HC_PID_DATA1
355
  *            0: HC_PID_SETUP / 1: HC_PID_DATA1
324
  * @param  pbuff: pointer to URB data
356
  * @param  pbuff pointer to URB data
325
  * @param  length: Length of URB data
357
  * @param  length Length of URB data
326
  * @param  do_ping: activate do ping protocol (for high speed only).
358
  * @param  do_ping activate do ping protocol (for high speed only).
327
  *          This parameter can be one of these values:
359
  *          This parameter can be one of these values:
328
  *           0 : do ping inactive / 1 : do ping active
360
  *           0 : do ping inactive / 1 : do ping active
329
  * @retval HAL status
361
  * @retval HAL status
330
  */
362
  */
331
HAL_StatusTypeDef HAL_HCD_HC_SubmitRequest(HCD_HandleTypeDef *hhcd,
363
HAL_StatusTypeDef HAL_HCD_HC_SubmitRequest(HCD_HandleTypeDef *hhcd,
332
                                           uint8_t ch_num,
364
                                           uint8_t ch_num,
333
                                           uint8_t direction,
365
                                           uint8_t direction,
334
                                           uint8_t ep_type,  
366
                                           uint8_t ep_type,
335
                                           uint8_t token,
367
                                           uint8_t token,
336
                                           uint8_t* pbuff,
368
                                           uint8_t *pbuff,
337
                                           uint16_t length,
369
                                           uint16_t length,
338
                                           uint8_t do_ping)
370
                                           uint8_t do_ping)
339
{
371
{
340
  hhcd->hc[ch_num].ep_is_in = direction;
372
  hhcd->hc[ch_num].ep_is_in = direction;
341
  hhcd->hc[ch_num].ep_type  = ep_type;
373
  hhcd->hc[ch_num].ep_type  = ep_type;
342
 
374
 
343
  if(token == 0U)
375
  if (token == 0U)
344
  {
376
  {
345
    hhcd->hc[ch_num].data_pid = HC_PID_SETUP;
377
    hhcd->hc[ch_num].data_pid = HC_PID_SETUP;
-
 
378
    hhcd->hc[ch_num].do_ping = do_ping;
346
  }
379
  }
347
  else
380
  else
348
  {
381
  {
349
    hhcd->hc[ch_num].data_pid = HC_PID_DATA1;
382
    hhcd->hc[ch_num].data_pid = HC_PID_DATA1;
350
  }
383
  }
351
 
384
 
352
  /* Manage Data Toggle */
385
  /* Manage Data Toggle */
353
  switch(ep_type)
386
  switch (ep_type)
354
  {
387
  {
355
  case EP_TYPE_CTRL:
388
    case EP_TYPE_CTRL:
356
    if((token == 1U) && (direction == 0U)) /*send data */
389
      if ((token == 1U) && (direction == 0U)) /*send data */
357
    {
-
 
358
      if (length == 0U)
-
 
359
      { /* For Status OUT stage, Length==0, Status Out PID = 1 */
-
 
360
        hhcd->hc[ch_num].toggle_out = 1U;
-
 
361
      }
-
 
362
     
-
 
363
      /* Set the Data Toggle bit as per the Flag */
-
 
364
      if ( hhcd->hc[ch_num].toggle_out == 0U)
-
 
365
      { /* Put the PID 0 */
-
 
366
        hhcd->hc[ch_num].data_pid = HC_PID_DATA0;
-
 
367
      }
-
 
368
      else
-
 
369
      { /* Put the PID 1 */
-
 
370
        hhcd->hc[ch_num].data_pid = HC_PID_DATA1;
-
 
371
      }
-
 
372
      if(hhcd->hc[ch_num].urb_state  != URB_NOTREADY)
-
 
373
      {
390
      {
374
        hhcd->hc[ch_num].do_ping = do_ping;
391
        if (length == 0U)
375
      }
392
        {
-
 
393
          /* For Status OUT stage, Length==0, Status Out PID = 1 */
376
    }
394
          hhcd->hc[ch_num].toggle_out = 1U;
377
    break;
395
        }
378
 
396
 
379
  case EP_TYPE_BULK:
-
 
380
    if(direction == 0U)
-
 
381
    {
-
 
382
      /* Set the Data Toggle bit as per the Flag */
397
        /* Set the Data Toggle bit as per the Flag */
383
      if ( hhcd->hc[ch_num].toggle_out == 0U)
398
        if (hhcd->hc[ch_num].toggle_out == 0U)
-
 
399
        {
384
      { /* Put the PID 0 */
400
          /* Put the PID 0 */
385
        hhcd->hc[ch_num].data_pid = HC_PID_DATA0;
401
          hhcd->hc[ch_num].data_pid = HC_PID_DATA0;
386
      }
402
        }
387
      else
403
        else
-
 
404
        {
388
      { /* Put the PID 1 */
405
          /* Put the PID 1 */
389
        hhcd->hc[ch_num].data_pid = HC_PID_DATA1;
406
          hhcd->hc[ch_num].data_pid = HC_PID_DATA1;
390
      }
407
        }
391
      if(hhcd->hc[ch_num].urb_state  != URB_NOTREADY)
-
 
392
      {
-
 
393
        hhcd->hc[ch_num].do_ping = do_ping;
-
 
394
      }
408
      }
395
    }
409
      break;
396
    else
410
 
397
    {
411
    case EP_TYPE_BULK:
398
      if( hhcd->hc[ch_num].toggle_in == 0U)
412
      if (direction == 0U)
399
      {
413
      {
-
 
414
        /* Set the Data Toggle bit as per the Flag */
-
 
415
        if (hhcd->hc[ch_num].toggle_out == 0U)
-
 
416
        {
-
 
417
          /* Put the PID 0 */
400
        hhcd->hc[ch_num].data_pid = HC_PID_DATA0;
418
          hhcd->hc[ch_num].data_pid = HC_PID_DATA0;
-
 
419
        }
-
 
420
        else
-
 
421
        {
-
 
422
          /* Put the PID 1 */
-
 
423
          hhcd->hc[ch_num].data_pid = HC_PID_DATA1;
-
 
424
        }
401
      }
425
      }
402
      else
426
      else
403
      {
427
      {
404
        hhcd->hc[ch_num].data_pid = HC_PID_DATA1;
428
        if (hhcd->hc[ch_num].toggle_in == 0U)
405
      }
429
        {
406
    }
-
 
407
    break;
-
 
408
 
-
 
409
  case EP_TYPE_INTR:
-
 
410
    if(direction == 0U)
-
 
411
    {
-
 
412
      /* Set the Data Toggle bit as per the Flag */
-
 
413
      if ( hhcd->hc[ch_num].toggle_out == 0U)
-
 
414
      { /* Put the PID 0 */
-
 
415
        hhcd->hc[ch_num].data_pid = HC_PID_DATA0;
430
          hhcd->hc[ch_num].data_pid = HC_PID_DATA0;
416
      }
431
        }
417
      else
432
        else
418
      { /* Put the PID 1 */
433
        {
419
        hhcd->hc[ch_num].data_pid = HC_PID_DATA1;
434
          hhcd->hc[ch_num].data_pid = HC_PID_DATA1;
-
 
435
        }
420
      }
436
      }
421
    }
437
 
422
    else
438
      break;
423
    {
439
    case EP_TYPE_INTR:
424
      if( hhcd->hc[ch_num].toggle_in == 0U)
440
      if (direction == 0U)
425
      {
441
      {
-
 
442
        /* Set the Data Toggle bit as per the Flag */
-
 
443
        if (hhcd->hc[ch_num].toggle_out == 0U)
-
 
444
        {
-
 
445
          /* Put the PID 0 */
426
        hhcd->hc[ch_num].data_pid = HC_PID_DATA0;
446
          hhcd->hc[ch_num].data_pid = HC_PID_DATA0;
-
 
447
        }
-
 
448
        else
-
 
449
        {
-
 
450
          /* Put the PID 1 */
-
 
451
          hhcd->hc[ch_num].data_pid = HC_PID_DATA1;
-
 
452
        }
427
      }
453
      }
428
      else
454
      else
429
      {
455
      {
-
 
456
        if (hhcd->hc[ch_num].toggle_in == 0U)
-
 
457
        {
-
 
458
          hhcd->hc[ch_num].data_pid = HC_PID_DATA0;
-
 
459
        }
-
 
460
        else
-
 
461
        {
430
        hhcd->hc[ch_num].data_pid = HC_PID_DATA1;
462
          hhcd->hc[ch_num].data_pid = HC_PID_DATA1;
-
 
463
        }
431
      }
464
      }
432
    }
-
 
433
    break;
465
      break;
434
 
466
 
435
  case EP_TYPE_ISOC:
467
    case EP_TYPE_ISOC:
436
    hhcd->hc[ch_num].data_pid = HC_PID_DATA0;
468
      hhcd->hc[ch_num].data_pid = HC_PID_DATA0;
-
 
469
      break;
-
 
470
 
-
 
471
    default:
437
    break;
472
      break;
438
  }
473
  }
439
 
474
 
440
  hhcd->hc[ch_num].xfer_buff = pbuff;
475
  hhcd->hc[ch_num].xfer_buff = pbuff;
441
  hhcd->hc[ch_num].xfer_len  = length;
476
  hhcd->hc[ch_num].xfer_len  = length;
442
  hhcd->hc[ch_num].urb_state = URB_IDLE;
477
  hhcd->hc[ch_num].urb_state = URB_IDLE;
443
  hhcd->hc[ch_num].xfer_count = 0U;
478
  hhcd->hc[ch_num].xfer_count = 0U;
444
  hhcd->hc[ch_num].ch_num = ch_num;
479
  hhcd->hc[ch_num].ch_num = ch_num;
445
  hhcd->hc[ch_num].state = HC_IDLE;
480
  hhcd->hc[ch_num].state = HC_IDLE;
446
 
481
 
447
  return USB_HC_StartXfer(hhcd->Instance, &(hhcd->hc[ch_num]));
482
  return USB_HC_StartXfer(hhcd->Instance, &hhcd->hc[ch_num]);
448
}
483
}
449
 
484
 
450
/**
485
/**
451
  * @brief  handle HCD interrupt request.
486
  * @brief  Handle HCD interrupt request.
452
  * @param  hhcd: HCD handle
487
  * @param  hhcd HCD handle
453
  * @retval None
488
  * @retval None
454
  */
489
  */
455
void HAL_HCD_IRQHandler(HCD_HandleTypeDef *hhcd)
490
void HAL_HCD_IRQHandler(HCD_HandleTypeDef *hhcd)
456
{
491
{
457
  USB_OTG_GlobalTypeDef *USBx = hhcd->Instance;
492
  USB_OTG_GlobalTypeDef *USBx = hhcd->Instance;
458
 
-
 
-
 
493
  uint32_t USBx_BASE = (uint32_t)USBx;
459
  uint32_t index = 0U, interrupt = 0U;
494
  uint32_t i, interrupt;
460
 
495
 
461
  /* ensure that we are in device mode */
496
  /* Ensure that we are in device mode */
462
  if (USB_GetMode(hhcd->Instance) == USB_OTG_MODE_HOST)
497
  if (USB_GetMode(hhcd->Instance) == USB_OTG_MODE_HOST)
463
  {
498
  {
464
    /* Avoid spurious interrupt */
499
    /* Avoid spurious interrupt */
465
    if(__HAL_HCD_IS_INVALID_INTERRUPT(hhcd))
500
    if (__HAL_HCD_IS_INVALID_INTERRUPT(hhcd))
466
    {
501
    {
467
      return;
502
      return;
468
    }
503
    }
469
   
504
 
470
    if(__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_PXFR_INCOMPISOOUT))
505
    if (__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_PXFR_INCOMPISOOUT))
471
    {
506
    {
472
     /* Incorrect mode, acknowledge the interrupt */
507
      /* Incorrect mode, acknowledge the interrupt */
473
      __HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_PXFR_INCOMPISOOUT);
508
      __HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_PXFR_INCOMPISOOUT);
474
    }
509
    }
475
   
510
 
476
    if(__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_IISOIXFR))
511
    if (__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_IISOIXFR))
477
    {
512
    {
478
     /* Incorrect mode, acknowledge the interrupt */
513
      /* Incorrect mode, acknowledge the interrupt */
479
      __HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_IISOIXFR);
514
      __HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_IISOIXFR);
480
    }
515
    }
481
   
516
 
482
    if(__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_PTXFE))
517
    if (__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_PTXFE))
483
    {
518
    {
484
     /* Incorrect mode, acknowledge the interrupt */
519
      /* Incorrect mode, acknowledge the interrupt */
485
      __HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_PTXFE);
520
      __HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_PTXFE);
486
    }
521
    }
487
   
522
 
488
    if(__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_MMIS))
523
    if (__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_MMIS))
489
    {
524
    {
490
     /* Incorrect mode, acknowledge the interrupt */
525
      /* Incorrect mode, acknowledge the interrupt */
491
      __HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_MMIS);
526
      __HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_MMIS);
492
    }
527
    }
493
   
528
 
494
    /* Handle Host Disconnect Interrupts */
529
    /* Handle Host Disconnect Interrupts */
495
    if(__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_DISCINT))
530
    if (__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_DISCINT))
496
    {
531
    {
497
   
-
 
498
      /* Cleanup HPRT */
-
 
499
      USBx_HPRT0 &= ~(USB_OTG_HPRT_PENA | USB_OTG_HPRT_PCDET |\
-
 
500
        USB_OTG_HPRT_PENCHNG | USB_OTG_HPRT_POCCHNG );
-
 
501
     
-
 
502
      /* Handle Host Port Interrupts */
-
 
503
      HAL_HCD_Disconnect_Callback(hhcd);
-
 
504
      USB_InitFSLSPClkSel(hhcd->Instance ,HCFG_48_MHZ);
-
 
505
      __HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_DISCINT);
532
      __HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_DISCINT);
-
 
533
 
-
 
534
      if ((USBx_HPRT0 & USB_OTG_HPRT_PCSTS) == 0U)
-
 
535
      {
-
 
536
        /* Handle Host Port Disconnect Interrupt */
-
 
537
#if (USE_HAL_HCD_REGISTER_CALLBACKS == 1U)
-
 
538
        hhcd->DisconnectCallback(hhcd);
-
 
539
#else
-
 
540
        HAL_HCD_Disconnect_Callback(hhcd);
-
 
541
#endif /* USE_HAL_HCD_REGISTER_CALLBACKS */
-
 
542
 
-
 
543
        (void)USB_InitFSLSPClkSel(hhcd->Instance, HCFG_48_MHZ);
-
 
544
      }
506
    }
545
    }
507
   
546
 
508
    /* Handle Host Port Interrupts */
547
    /* Handle Host Port Interrupts */
509
    if(__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_HPRTINT))
548
    if (__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_HPRTINT))
510
    {
549
    {
511
      HCD_Port_IRQHandler (hhcd);
550
      HCD_Port_IRQHandler(hhcd);
512
    }
551
    }
513
   
552
 
514
    /* Handle Host SOF Interrupts */
553
    /* Handle Host SOF Interrupt */
515
    if(__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_SOF))
554
    if (__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_SOF))
516
    {
555
    {
-
 
556
#if (USE_HAL_HCD_REGISTER_CALLBACKS == 1U)
-
 
557
      hhcd->SOFCallback(hhcd);
-
 
558
#else
517
      HAL_HCD_SOF_Callback(hhcd);
559
      HAL_HCD_SOF_Callback(hhcd);
-
 
560
#endif /* USE_HAL_HCD_REGISTER_CALLBACKS */
-
 
561
 
518
      __HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_SOF);
562
      __HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_SOF);
519
    }
563
    }
520
   
564
 
521
    /* Handle Host channel Interrupts */
565
    /* Handle Host channel Interrupt */
522
    if(__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_HCINT))
566
    if (__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_HCINT))
523
    {
567
    {
524
      interrupt = USB_HC_ReadInterrupt(hhcd->Instance);
568
      interrupt = USB_HC_ReadInterrupt(hhcd->Instance);
525
      for (index = 0U; index < hhcd->Init.Host_channels ; index++)
569
      for (i = 0U; i < hhcd->Init.Host_channels; i++)
526
      {
570
      {
527
        if (interrupt & (1 << index))
571
        if ((interrupt & (1UL << (i & 0xFU))) != 0U)
528
        {
572
        {
529
          if ((USBx_HC(index)->HCCHAR) &  USB_OTG_HCCHAR_EPDIR)
573
          if ((USBx_HC(i)->HCCHAR & USB_OTG_HCCHAR_EPDIR) == USB_OTG_HCCHAR_EPDIR)
530
          {
574
          {
531
            HCD_HC_IN_IRQHandler (hhcd, index);
575
            HCD_HC_IN_IRQHandler(hhcd, (uint8_t)i);
532
          }
576
          }
533
          else
577
          else
534
          {
578
          {
535
            HCD_HC_OUT_IRQHandler (hhcd, index);
579
            HCD_HC_OUT_IRQHandler(hhcd, (uint8_t)i);
536
          }
580
          }
537
        }
581
        }
538
      }
582
      }
539
      __HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_HCINT);
583
      __HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_HCINT);
540
    }
584
    }
541
   
585
 
542
    /* Handle Rx Queue Level Interrupts */
586
    /* Handle Rx Queue Level Interrupts */
543
    if(__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_RXFLVL))
587
    if ((__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_RXFLVL)) != 0U)
544
    {
588
    {
545
      USB_MASK_INTERRUPT(hhcd->Instance, USB_OTG_GINTSTS_RXFLVL);
589
      USB_MASK_INTERRUPT(hhcd->Instance, USB_OTG_GINTSTS_RXFLVL);
546
     
590
 
547
      HCD_RXQLVL_IRQHandler (hhcd);
591
      HCD_RXQLVL_IRQHandler(hhcd);
548
     
592
 
549
      USB_UNMASK_INTERRUPT(hhcd->Instance, USB_OTG_GINTSTS_RXFLVL);
593
      USB_UNMASK_INTERRUPT(hhcd->Instance, USB_OTG_GINTSTS_RXFLVL);
550
    }
594
    }
551
  }
595
  }
552
}
596
}
553
 
597
 
-
 
598
 
-
 
599
/**
-
 
600
  * @brief  Handles HCD Wakeup interrupt request.
-
 
601
  * @param  hhcd HCD handle
-
 
602
  * @retval HAL status
-
 
603
  */
-
 
604
void HAL_HCD_WKUP_IRQHandler(HCD_HandleTypeDef *hhcd)
-
 
605
{
-
 
606
  UNUSED(hhcd);
-
 
607
}
-
 
608
 
-
 
609
 
554
/**
610
/**
555
  * @brief  SOF callback.
611
  * @brief  SOF callback.
556
  * @param  hhcd: HCD handle
612
  * @param  hhcd HCD handle
557
  * @retval None
613
  * @retval None
558
  */
614
  */
559
__weak void HAL_HCD_SOF_Callback(HCD_HandleTypeDef *hhcd)
615
__weak void HAL_HCD_SOF_Callback(HCD_HandleTypeDef *hhcd)
560
{
616
{
561
  /* Prevent unused argument(s) compilation warning */
617
  /* Prevent unused argument(s) compilation warning */
562
  UNUSED(hhcd);
618
  UNUSED(hhcd);
-
 
619
 
563
  /* NOTE : This function Should not be modified, when the callback is needed,
620
  /* NOTE : This function should not be modified, when the callback is needed,
564
            the HAL_HCD_SOF_Callback could be implemented in the user file
621
            the HAL_HCD_SOF_Callback could be implemented in the user file
565
   */
622
   */
566
}
623
}
567
 
624
 
568
/**
625
/**
569
  * @brief Connexion Event callback.
626
  * @brief Connection Event callback.
570
  * @param  hhcd: HCD handle
627
  * @param  hhcd HCD handle
571
  * @retval None
628
  * @retval None
572
  */
629
  */
573
__weak void HAL_HCD_Connect_Callback(HCD_HandleTypeDef *hhcd)
630
__weak void HAL_HCD_Connect_Callback(HCD_HandleTypeDef *hhcd)
574
{
631
{
575
  /* Prevent unused argument(s) compilation warning */
632
  /* Prevent unused argument(s) compilation warning */
576
  UNUSED(hhcd);
633
  UNUSED(hhcd);
-
 
634
 
577
  /* NOTE : This function Should not be modified, when the callback is needed,
635
  /* NOTE : This function should not be modified, when the callback is needed,
578
            the HAL_HCD_Connect_Callback could be implemented in the user file
636
            the HAL_HCD_Connect_Callback could be implemented in the user file
579
   */
637
   */
580
}
638
}
581
 
639
 
582
/**
640
/**
583
  * @brief  Disonnection Event callback.
641
  * @brief  Disconnection Event callback.
584
  * @param  hhcd: HCD handle
642
  * @param  hhcd HCD handle
585
  * @retval None
643
  * @retval None
586
  */
644
  */
587
__weak void HAL_HCD_Disconnect_Callback(HCD_HandleTypeDef *hhcd)
645
__weak void HAL_HCD_Disconnect_Callback(HCD_HandleTypeDef *hhcd)
588
{
646
{
589
  /* Prevent unused argument(s) compilation warning */
647
  /* Prevent unused argument(s) compilation warning */
590
  UNUSED(hhcd);
648
  UNUSED(hhcd);
-
 
649
 
591
  /* NOTE : This function Should not be modified, when the callback is needed,
650
  /* NOTE : This function should not be modified, when the callback is needed,
592
            the HAL_HCD_Disconnect_Callback could be implemented in the user file
651
            the HAL_HCD_Disconnect_Callback could be implemented in the user file
593
   */
652
   */
594
}
653
}
-
 
654
 
-
 
655
/**
-
 
656
  * @brief  Port Enabled  Event callback.
-
 
657
  * @param  hhcd HCD handle
-
 
658
  * @retval None
-
 
659
  */
-
 
660
__weak void HAL_HCD_PortEnabled_Callback(HCD_HandleTypeDef *hhcd)
-
 
661
{
-
 
662
  /* Prevent unused argument(s) compilation warning */
-
 
663
  UNUSED(hhcd);
-
 
664
 
-
 
665
  /* NOTE : This function should not be modified, when the callback is needed,
-
 
666
            the HAL_HCD_Disconnect_Callback could be implemented in the user file
-
 
667
   */
-
 
668
}
-
 
669
 
-
 
670
/**
-
 
671
  * @brief  Port Disabled  Event callback.
-
 
672
  * @param  hhcd HCD handle
-
 
673
  * @retval None
-
 
674
  */
-
 
675
__weak void HAL_HCD_PortDisabled_Callback(HCD_HandleTypeDef *hhcd)
-
 
676
{
-
 
677
  /* Prevent unused argument(s) compilation warning */
-
 
678
  UNUSED(hhcd);
-
 
679
 
-
 
680
  /* NOTE : This function should not be modified, when the callback is needed,
-
 
681
            the HAL_HCD_Disconnect_Callback could be implemented in the user file
-
 
682
   */
-
 
683
}
595
 
684
 
596
/**
685
/**
597
  * @brief  Notify URB state change callback.
686
  * @brief  Notify URB state change callback.
598
  * @param  hhcd: HCD handle
687
  * @param  hhcd HCD handle
599
  * @param  chnum: Channel number.
688
  * @param  chnum Channel number.
600
  *         This parameter can be a value from 1 to 15
689
  *         This parameter can be a value from 1 to 15
601
  * @param  urb_state:
690
  * @param  urb_state:
602
  *          This parameter can be one of these values:
691
  *          This parameter can be one of these values:
603
  *            URB_IDLE/
692
  *            URB_IDLE/
604
  *            URB_DONE/
693
  *            URB_DONE/
605
  *            URB_NOTREADY/
694
  *            URB_NOTREADY/
606
  *            URB_NYET/
695
  *            URB_NYET/
607
  *            URB_ERROR/  
696
  *            URB_ERROR/
608
  *            URB_STALL/
697
  *            URB_STALL/
609
  * @retval None
698
  * @retval None
610
  */
699
  */
611
__weak void HAL_HCD_HC_NotifyURBChange_Callback(HCD_HandleTypeDef *hhcd, uint8_t chnum, HCD_URBStateTypeDef urb_state)
700
__weak void HAL_HCD_HC_NotifyURBChange_Callback(HCD_HandleTypeDef *hhcd, uint8_t chnum, HCD_URBStateTypeDef urb_state)
612
{
701
{
613
  /* Prevent unused argument(s) compilation warning */
702
  /* Prevent unused argument(s) compilation warning */
614
  UNUSED(hhcd);
703
  UNUSED(hhcd);
615
  UNUSED(chnum);
704
  UNUSED(chnum);
616
  UNUSED(urb_state);
705
  UNUSED(urb_state);
-
 
706
 
617
  /* NOTE : This function Should not be modified, when the callback is needed,
707
  /* NOTE : This function should not be modified, when the callback is needed,
618
            the HAL_HCD_HC_NotifyURBChange_Callback could be implemented in the user file
708
            the HAL_HCD_HC_NotifyURBChange_Callback could be implemented in the user file
619
   */
709
   */
620
}
710
}
621
 
711
 
-
 
712
#if (USE_HAL_HCD_REGISTER_CALLBACKS == 1U)
-
 
713
/**
-
 
714
  * @brief  Register a User USB HCD Callback
-
 
715
  *         To be used instead of the weak predefined callback
-
 
716
  * @param  hhcd USB HCD handle
-
 
717
  * @param  CallbackID ID of the callback to be registered
-
 
718
  *         This parameter can be one of the following values:
-
 
719
  *          @arg @ref HAL_HCD_SOF_CB_ID USB HCD SOF callback ID
-
 
720
  *          @arg @ref HAL_HCD_CONNECT_CB_ID USB HCD Connect callback ID
-
 
721
  *          @arg @ref HAL_HCD_DISCONNECT_CB_ID OTG HCD Disconnect callback ID
-
 
722
  *          @arg @ref HAL_HCD_PORT_ENABLED_CB_ID USB HCD Port Enable callback ID
-
 
723
  *          @arg @ref HAL_HCD_PORT_DISABLED_CB_ID USB HCD Port Disable callback ID
-
 
724
  *          @arg @ref HAL_HCD_MSPINIT_CB_ID MspDeInit callback ID
-
 
725
  *          @arg @ref HAL_HCD_MSPDEINIT_CB_ID MspDeInit callback ID
-
 
726
  * @param  pCallback pointer to the Callback function
-
 
727
  * @retval HAL status
-
 
728
  */
-
 
729
HAL_StatusTypeDef HAL_HCD_RegisterCallback(HCD_HandleTypeDef *hhcd,
-
 
730
                                           HAL_HCD_CallbackIDTypeDef CallbackID,
-
 
731
                                           pHCD_CallbackTypeDef pCallback)
-
 
732
{
-
 
733
  HAL_StatusTypeDef status = HAL_OK;
-
 
734
 
-
 
735
  if (pCallback == NULL)
-
 
736
  {
-
 
737
    /* Update the error code */
-
 
738
    hhcd->ErrorCode |= HAL_HCD_ERROR_INVALID_CALLBACK;
-
 
739
    return HAL_ERROR;
-
 
740
  }
-
 
741
  /* Process locked */
-
 
742
  __HAL_LOCK(hhcd);
-
 
743
 
-
 
744
  if (hhcd->State == HAL_HCD_STATE_READY)
-
 
745
  {
-
 
746
    switch (CallbackID)
-
 
747
    {
-
 
748
      case HAL_HCD_SOF_CB_ID :
-
 
749
        hhcd->SOFCallback = pCallback;
-
 
750
        break;
-
 
751
 
-
 
752
      case HAL_HCD_CONNECT_CB_ID :
-
 
753
        hhcd->ConnectCallback = pCallback;
-
 
754
        break;
-
 
755
 
-
 
756
      case HAL_HCD_DISCONNECT_CB_ID :
-
 
757
        hhcd->DisconnectCallback = pCallback;
-
 
758
        break;
-
 
759
 
-
 
760
      case HAL_HCD_PORT_ENABLED_CB_ID :
-
 
761
        hhcd->PortEnabledCallback = pCallback;
-
 
762
        break;
-
 
763
 
-
 
764
      case HAL_HCD_PORT_DISABLED_CB_ID :
-
 
765
        hhcd->PortDisabledCallback = pCallback;
-
 
766
        break;
-
 
767
 
-
 
768
      case HAL_HCD_MSPINIT_CB_ID :
-
 
769
        hhcd->MspInitCallback = pCallback;
-
 
770
        break;
-
 
771
 
-
 
772
      case HAL_HCD_MSPDEINIT_CB_ID :
-
 
773
        hhcd->MspDeInitCallback = pCallback;
-
 
774
        break;
-
 
775
 
-
 
776
      default :
-
 
777
        /* Update the error code */
-
 
778
        hhcd->ErrorCode |= HAL_HCD_ERROR_INVALID_CALLBACK;
-
 
779
        /* Return error status */
-
 
780
        status =  HAL_ERROR;
-
 
781
        break;
-
 
782
    }
-
 
783
  }
-
 
784
  else if (hhcd->State == HAL_HCD_STATE_RESET)
-
 
785
  {
-
 
786
    switch (CallbackID)
-
 
787
    {
-
 
788
      case HAL_HCD_MSPINIT_CB_ID :
-
 
789
        hhcd->MspInitCallback = pCallback;
-
 
790
        break;
-
 
791
 
-
 
792
      case HAL_HCD_MSPDEINIT_CB_ID :
-
 
793
        hhcd->MspDeInitCallback = pCallback;
-
 
794
        break;
-
 
795
 
-
 
796
      default :
-
 
797
        /* Update the error code */
-
 
798
        hhcd->ErrorCode |= HAL_HCD_ERROR_INVALID_CALLBACK;
-
 
799
        /* Return error status */
-
 
800
        status =  HAL_ERROR;
-
 
801
        break;
-
 
802
    }
-
 
803
  }
-
 
804
  else
-
 
805
  {
-
 
806
    /* Update the error code */
-
 
807
    hhcd->ErrorCode |= HAL_HCD_ERROR_INVALID_CALLBACK;
-
 
808
    /* Return error status */
-
 
809
    status =  HAL_ERROR;
-
 
810
  }
-
 
811
 
-
 
812
  /* Release Lock */
-
 
813
  __HAL_UNLOCK(hhcd);
-
 
814
  return status;
-
 
815
}
-
 
816
 
-
 
817
/**
-
 
818
  * @brief  Unregister an USB HCD Callback
-
 
819
  *         USB HCD callback is redirected to the weak predefined callback
-
 
820
  * @param  hhcd USB HCD handle
-
 
821
  * @param  CallbackID ID of the callback to be unregistered
-
 
822
  *         This parameter can be one of the following values:
-
 
823
  *          @arg @ref HAL_HCD_SOF_CB_ID USB HCD SOF callback ID
-
 
824
  *          @arg @ref HAL_HCD_CONNECT_CB_ID USB HCD Connect callback ID
-
 
825
  *          @arg @ref HAL_HCD_DISCONNECT_CB_ID OTG HCD Disconnect callback ID
-
 
826
  *          @arg @ref HAL_HCD_PORT_ENABLED_CB_ID USB HCD Port Enabled callback ID
-
 
827
  *          @arg @ref HAL_HCD_PORT_DISABLED_CB_ID USB HCD Port Disabled callback ID
-
 
828
  *          @arg @ref HAL_HCD_MSPINIT_CB_ID MspDeInit callback ID
-
 
829
  *          @arg @ref HAL_HCD_MSPDEINIT_CB_ID MspDeInit callback ID
-
 
830
  * @retval HAL status
-
 
831
  */
-
 
832
HAL_StatusTypeDef HAL_HCD_UnRegisterCallback(HCD_HandleTypeDef *hhcd, HAL_HCD_CallbackIDTypeDef CallbackID)
-
 
833
{
-
 
834
  HAL_StatusTypeDef status = HAL_OK;
-
 
835
 
-
 
836
  /* Process locked */
-
 
837
  __HAL_LOCK(hhcd);
-
 
838
 
-
 
839
  /* Setup Legacy weak Callbacks  */
-
 
840
  if (hhcd->State == HAL_HCD_STATE_READY)
-
 
841
  {
-
 
842
    switch (CallbackID)
-
 
843
    {
-
 
844
      case HAL_HCD_SOF_CB_ID :
-
 
845
        hhcd->SOFCallback = HAL_HCD_SOF_Callback;
-
 
846
        break;
-
 
847
 
-
 
848
      case HAL_HCD_CONNECT_CB_ID :
-
 
849
        hhcd->ConnectCallback = HAL_HCD_Connect_Callback;
-
 
850
        break;
-
 
851
 
-
 
852
      case HAL_HCD_DISCONNECT_CB_ID :
-
 
853
        hhcd->DisconnectCallback = HAL_HCD_Disconnect_Callback;
-
 
854
        break;
-
 
855
 
-
 
856
      case HAL_HCD_PORT_ENABLED_CB_ID :
-
 
857
        hhcd->PortEnabledCallback = HAL_HCD_PortEnabled_Callback;
-
 
858
        break;
-
 
859
 
-
 
860
      case HAL_HCD_PORT_DISABLED_CB_ID :
-
 
861
        hhcd->PortDisabledCallback = HAL_HCD_PortDisabled_Callback;
-
 
862
        break;
-
 
863
 
-
 
864
      case HAL_HCD_MSPINIT_CB_ID :
-
 
865
        hhcd->MspInitCallback = HAL_HCD_MspInit;
-
 
866
        break;
-
 
867
 
-
 
868
      case HAL_HCD_MSPDEINIT_CB_ID :
-
 
869
        hhcd->MspDeInitCallback = HAL_HCD_MspDeInit;
-
 
870
        break;
-
 
871
 
-
 
872
      default :
-
 
873
        /* Update the error code */
-
 
874
        hhcd->ErrorCode |= HAL_HCD_ERROR_INVALID_CALLBACK;
-
 
875
 
-
 
876
        /* Return error status */
-
 
877
        status =  HAL_ERROR;
-
 
878
        break;
-
 
879
    }
-
 
880
  }
-
 
881
  else if (hhcd->State == HAL_HCD_STATE_RESET)
-
 
882
  {
-
 
883
    switch (CallbackID)
-
 
884
    {
-
 
885
      case HAL_HCD_MSPINIT_CB_ID :
-
 
886
        hhcd->MspInitCallback = HAL_HCD_MspInit;
-
 
887
        break;
-
 
888
 
-
 
889
      case HAL_HCD_MSPDEINIT_CB_ID :
-
 
890
        hhcd->MspDeInitCallback = HAL_HCD_MspDeInit;
-
 
891
        break;
-
 
892
 
-
 
893
      default :
-
 
894
        /* Update the error code */
-
 
895
        hhcd->ErrorCode |= HAL_HCD_ERROR_INVALID_CALLBACK;
-
 
896
 
-
 
897
        /* Return error status */
-
 
898
        status =  HAL_ERROR;
-
 
899
        break;
-
 
900
    }
-
 
901
  }
-
 
902
  else
-
 
903
  {
-
 
904
    /* Update the error code */
-
 
905
    hhcd->ErrorCode |= HAL_HCD_ERROR_INVALID_CALLBACK;
-
 
906
 
-
 
907
    /* Return error status */
-
 
908
    status =  HAL_ERROR;
-
 
909
  }
-
 
910
 
-
 
911
  /* Release Lock */
-
 
912
  __HAL_UNLOCK(hhcd);
-
 
913
  return status;
-
 
914
}
-
 
915
 
-
 
916
/**
-
 
917
  * @brief  Register USB HCD Host Channel Notify URB Change Callback
-
 
918
  *         To be used instead of the weak HAL_HCD_HC_NotifyURBChange_Callback() predefined callback
-
 
919
  * @param  hhcd HCD handle
-
 
920
  * @param  pCallback pointer to the USB HCD Host Channel Notify URB Change Callback function
-
 
921
  * @retval HAL status
-
 
922
  */
-
 
923
HAL_StatusTypeDef HAL_HCD_RegisterHC_NotifyURBChangeCallback(HCD_HandleTypeDef *hhcd,
-
 
924
                                                             pHCD_HC_NotifyURBChangeCallbackTypeDef pCallback)
-
 
925
{
-
 
926
  HAL_StatusTypeDef status = HAL_OK;
-
 
927
 
-
 
928
  if (pCallback == NULL)
-
 
929
  {
-
 
930
    /* Update the error code */
-
 
931
    hhcd->ErrorCode |= HAL_HCD_ERROR_INVALID_CALLBACK;
-
 
932
 
-
 
933
    return HAL_ERROR;
-
 
934
  }
-
 
935
 
-
 
936
  /* Process locked */
-
 
937
  __HAL_LOCK(hhcd);
-
 
938
 
-
 
939
  if (hhcd->State == HAL_HCD_STATE_READY)
-
 
940
  {
-
 
941
    hhcd->HC_NotifyURBChangeCallback = pCallback;
-
 
942
  }
-
 
943
  else
-
 
944
  {
-
 
945
    /* Update the error code */
-
 
946
    hhcd->ErrorCode |= HAL_HCD_ERROR_INVALID_CALLBACK;
-
 
947
 
-
 
948
    /* Return error status */
-
 
949
    status =  HAL_ERROR;
-
 
950
  }
-
 
951
 
-
 
952
  /* Release Lock */
-
 
953
  __HAL_UNLOCK(hhcd);
-
 
954
 
-
 
955
  return status;
-
 
956
}
-
 
957
 
-
 
958
/**
-
 
959
  * @brief  Unregister the USB HCD Host Channel Notify URB Change Callback
-
 
960
  *         USB HCD Host Channel Notify URB Change Callback is redirected to the weak HAL_HCD_HC_NotifyURBChange_Callback() predefined callback
-
 
961
  * @param  hhcd HCD handle
-
 
962
  * @retval HAL status
-
 
963
  */
-
 
964
HAL_StatusTypeDef HAL_HCD_UnRegisterHC_NotifyURBChangeCallback(HCD_HandleTypeDef *hhcd)
-
 
965
{
-
 
966
  HAL_StatusTypeDef status = HAL_OK;
-
 
967
 
-
 
968
  /* Process locked */
-
 
969
  __HAL_LOCK(hhcd);
-
 
970
 
-
 
971
  if (hhcd->State == HAL_HCD_STATE_READY)
-
 
972
  {
-
 
973
    hhcd->HC_NotifyURBChangeCallback = HAL_HCD_HC_NotifyURBChange_Callback; /* Legacy weak DataOutStageCallback  */
-
 
974
  }
-
 
975
  else
-
 
976
  {
-
 
977
    /* Update the error code */
-
 
978
    hhcd->ErrorCode |= HAL_HCD_ERROR_INVALID_CALLBACK;
-
 
979
 
-
 
980
    /* Return error status */
-
 
981
    status =  HAL_ERROR;
-
 
982
  }
-
 
983
 
-
 
984
  /* Release Lock */
-
 
985
  __HAL_UNLOCK(hhcd);
-
 
986
 
-
 
987
  return status;
-
 
988
}
-
 
989
#endif /* USE_HAL_HCD_REGISTER_CALLBACKS */
-
 
990
 
622
/**
991
/**
623
  * @}
992
  * @}
624
  */
993
  */
625
 
994
 
626
/** @defgroup HCD_Exported_Functions_Group3 Peripheral Control functions
995
/** @defgroup HCD_Exported_Functions_Group3 Peripheral Control functions
627
 *  @brief   management functions
996
  *  @brief   Management functions
628
 *
997
  *
629
@verbatim
998
@verbatim
630
 ===============================================================================
999
 ===============================================================================
631
                      ##### Peripheral Control functions #####
1000
                      ##### Peripheral Control functions #####
632
 ===============================================================================
1001
 ===============================================================================
633
    [..]
1002
    [..]
Line 637... Line 1006...
637
@endverbatim
1006
@endverbatim
638
  * @{
1007
  * @{
639
  */
1008
  */
640
 
1009
 
641
/**
1010
/**
642
  * @brief  Start the host driver
1011
  * @brief  Start the host driver.
643
  * @param  hhcd: HCD handle
1012
  * @param  hhcd HCD handle
644
  * @retval HAL status
1013
  * @retval HAL status
645
  */
1014
  */
646
HAL_StatusTypeDef HAL_HCD_Start(HCD_HandleTypeDef *hhcd)
1015
HAL_StatusTypeDef HAL_HCD_Start(HCD_HandleTypeDef *hhcd)
647
{
1016
{
648
  __HAL_LOCK(hhcd);
1017
  __HAL_LOCK(hhcd);
649
  __HAL_HCD_ENABLE(hhcd);
1018
  __HAL_HCD_ENABLE(hhcd);
650
  USB_DriveVbus(hhcd->Instance, 1U);
1019
  (void)USB_DriveVbus(hhcd->Instance, 1U);
651
  __HAL_UNLOCK(hhcd);
1020
  __HAL_UNLOCK(hhcd);
-
 
1021
 
652
  return HAL_OK;
1022
  return HAL_OK;
653
}
1023
}
654
 
1024
 
655
/**
1025
/**
656
  * @brief  Stop the host driver
1026
  * @brief  Stop the host driver.
657
  * @param  hhcd: HCD handle
1027
  * @param  hhcd HCD handle
658
  * @retval HAL status
1028
  * @retval HAL status
659
  */
1029
  */
660
 
1030
 
661
HAL_StatusTypeDef HAL_HCD_Stop(HCD_HandleTypeDef *hhcd)
1031
HAL_StatusTypeDef HAL_HCD_Stop(HCD_HandleTypeDef *hhcd)
662
{
1032
{
663
  __HAL_LOCK(hhcd);
1033
  __HAL_LOCK(hhcd);
664
  USB_StopHost(hhcd->Instance);
1034
  (void)USB_StopHost(hhcd->Instance);
665
  __HAL_UNLOCK(hhcd);
1035
  __HAL_UNLOCK(hhcd);
-
 
1036
 
666
  return HAL_OK;
1037
  return HAL_OK;
667
}
1038
}
668
 
1039
 
669
/**
1040
/**
670
  * @brief  Reset the host port
1041
  * @brief  Reset the host port.
671
  * @param  hhcd: HCD handle
1042
  * @param  hhcd HCD handle
672
  * @retval HAL status
1043
  * @retval HAL status
673
  */
1044
  */
674
HAL_StatusTypeDef HAL_HCD_ResetPort(HCD_HandleTypeDef *hhcd)
1045
HAL_StatusTypeDef HAL_HCD_ResetPort(HCD_HandleTypeDef *hhcd)
675
{
1046
{
676
  return (USB_ResetPort(hhcd->Instance));
1047
  return (USB_ResetPort(hhcd->Instance));
Line 679... Line 1050...
679
/**
1050
/**
680
  * @}
1051
  * @}
681
  */
1052
  */
682
 
1053
 
683
/** @defgroup HCD_Exported_Functions_Group4 Peripheral State functions
1054
/** @defgroup HCD_Exported_Functions_Group4 Peripheral State functions
684
 *  @brief   Peripheral State functions
1055
  *  @brief   Peripheral State functions
685
 *
1056
  *
686
@verbatim
1057
@verbatim
687
 ===============================================================================
1058
 ===============================================================================
688
                      ##### Peripheral State functions #####
1059
                      ##### Peripheral State functions #####
689
 ===============================================================================
1060
 ===============================================================================
690
    [..]
1061
    [..]
691
    This subsection permits to get in run-time the status of the peripheral
1062
    This subsection permits to get in run-time the status of the peripheral
692
    and the data flow.
1063
    and the data flow.
693
 
1064
 
694
@endverbatim
1065
@endverbatim
695
  * @{
1066
  * @{
696
  */
1067
  */
697
 
1068
 
698
/**
1069
/**
699
  * @brief  Return the HCD handle state
1070
  * @brief  Return the HCD handle state.
700
  * @param  hhcd: HCD handle
1071
  * @param  hhcd HCD handle
701
  * @retval HAL state
1072
  * @retval HAL state
702
  */
1073
  */
703
HCD_StateTypeDef HAL_HCD_GetState(HCD_HandleTypeDef *hhcd)
1074
HCD_StateTypeDef HAL_HCD_GetState(HCD_HandleTypeDef *hhcd)
704
{
1075
{
705
  return hhcd->State;
1076
  return hhcd->State;
706
}
1077
}
707
 
1078
 
708
/**
1079
/**
709
  * @brief  Return  URB state for a channel
1080
  * @brief  Return  URB state for a channel.
710
  * @param  hhcd: HCD handle
1081
  * @param  hhcd HCD handle
711
  * @param  chnum: Channel number.
1082
  * @param  chnum Channel number.
712
  *         This parameter can be a value from 1 to 15
1083
  *         This parameter can be a value from 1 to 15
713
  * @retval URB state.
1084
  * @retval URB state.
714
  *          This parameter can be one of these values:
1085
  *          This parameter can be one of these values:
715
  *            URB_IDLE/
1086
  *            URB_IDLE/
716
  *            URB_DONE/
1087
  *            URB_DONE/
717
  *            URB_NOTREADY/
1088
  *            URB_NOTREADY/
718
  *            URB_NYET/
1089
  *            URB_NYET/
719
  *            URB_ERROR/
1090
  *            URB_ERROR/
720
  *            URB_STALL/
1091
  *            URB_STALL
721
  */
1092
  */
722
HCD_URBStateTypeDef HAL_HCD_HC_GetURBState(HCD_HandleTypeDef *hhcd, uint8_t chnum)
1093
HCD_URBStateTypeDef HAL_HCD_HC_GetURBState(HCD_HandleTypeDef *hhcd, uint8_t chnum)
723
{
1094
{
724
  return hhcd->hc[chnum].urb_state;
1095
  return hhcd->hc[chnum].urb_state;
725
}
1096
}
726
 
1097
 
727
 
1098
 
728
/**
1099
/**
729
  * @brief  Return the last host transfer size
1100
  * @brief  Return the last host transfer size.
730
  * @param  hhcd: HCD handle
1101
  * @param  hhcd HCD handle
731
  * @param  chnum: Channel number.
1102
  * @param  chnum Channel number.
732
  *         This parameter can be a value from 1 to 15
1103
  *         This parameter can be a value from 1 to 15
733
  * @retval last transfer size in byte
1104
  * @retval last transfer size in byte
734
  */
1105
  */
735
uint32_t HAL_HCD_HC_GetXferCount(HCD_HandleTypeDef *hhcd, uint8_t chnum)
1106
uint32_t HAL_HCD_HC_GetXferCount(HCD_HandleTypeDef *hhcd, uint8_t chnum)
736
{
1107
{
737
  return hhcd->hc[chnum].xfer_count;
1108
  return hhcd->hc[chnum].xfer_count;
738
}
1109
}
739
 
1110
 
740
/**
1111
/**
741
  * @brief  Return the Host Channel state
1112
  * @brief  Return the Host Channel state.
742
  * @param  hhcd: HCD handle
1113
  * @param  hhcd HCD handle
743
  * @param  chnum: Channel number.
1114
  * @param  chnum Channel number.
744
  *         This parameter can be a value from 1 to 15
1115
  *         This parameter can be a value from 1 to 15
745
  * @retval Host channel state
1116
  * @retval Host channel state
746
  *          This parameter can be one of the these values:
1117
  *          This parameter can be one of these values:
747
  *            HC_IDLE/
1118
  *            HC_IDLE/
748
  *            HC_XFRC/
1119
  *            HC_XFRC/
749
  *            HC_HALTED/
1120
  *            HC_HALTED/
750
  *            HC_NYET/
1121
  *            HC_NYET/
751
  *            HC_NAK/
1122
  *            HC_NAK/
752
  *            HC_STALL/
1123
  *            HC_STALL/
753
  *            HC_XACTERR/
1124
  *            HC_XACTERR/
754
  *            HC_BBLERR/
1125
  *            HC_BBLERR/
755
  *            HC_DATATGLERR/
1126
  *            HC_DATATGLERR
756
  */
1127
  */
757
HCD_HCStateTypeDef  HAL_HCD_HC_GetState(HCD_HandleTypeDef *hhcd, uint8_t chnum)
1128
HCD_HCStateTypeDef  HAL_HCD_HC_GetState(HCD_HandleTypeDef *hhcd, uint8_t chnum)
758
{
1129
{
759
  return hhcd->hc[chnum].state;
1130
  return hhcd->hc[chnum].state;
760
}
1131
}
761
 
1132
 
762
/**
1133
/**
763
  * @brief  Return the current Host frame number
1134
  * @brief  Return the current Host frame number.
764
  * @param  hhcd: HCD handle
1135
  * @param  hhcd HCD handle
765
  * @retval Current Host frame number
1136
  * @retval Current Host frame number
766
  */
1137
  */
767
uint32_t HAL_HCD_GetCurrentFrame(HCD_HandleTypeDef *hhcd)
1138
uint32_t HAL_HCD_GetCurrentFrame(HCD_HandleTypeDef *hhcd)
768
{
1139
{
769
  return (USB_GetCurrentFrame(hhcd->Instance));
1140
  return (USB_GetCurrentFrame(hhcd->Instance));
770
}
1141
}
771
 
1142
 
772
/**
1143
/**
773
  * @brief  Return the Host enumeration speed
1144
  * @brief  Return the Host enumeration speed.
774
  * @param  hhcd: HCD handle
1145
  * @param  hhcd HCD handle
775
  * @retval Enumeration speed
1146
  * @retval Enumeration speed
776
  */
1147
  */
777
uint32_t HAL_HCD_GetCurrentSpeed(HCD_HandleTypeDef *hhcd)
1148
uint32_t HAL_HCD_GetCurrentSpeed(HCD_HandleTypeDef *hhcd)
778
{
1149
{
779
  return (USB_GetHostSpeed(hhcd->Instance));
1150
  return (USB_GetHostSpeed(hhcd->Instance));
780
}
1151
}
781
 
1152
 
782
/**
1153
/**
783
  * @}
1154
  * @}
784
  */
1155
  */
-
 
1156
 
785
/**
1157
/**
786
  * @}
1158
  * @}
787
  */
1159
  */
788
 
1160
 
789
/** @addtogroup HCD_Private_Functions
1161
/** @addtogroup HCD_Private_Functions
790
  * @{
1162
  * @{
791
  */
1163
  */
792
/**
1164
/**
793
  * @brief  This function handles Host Channel IN interrupt requests.
1165
  * @brief  Handle Host Channel IN interrupt requests.
794
  * @param  hhcd: HCD handle
1166
  * @param  hhcd HCD handle
795
  * @param  chnum: Channel number.
1167
  * @param  chnum Channel number.
796
  *         This parameter can be a value from 1 to 15
1168
  *         This parameter can be a value from 1 to 15
797
  * @retval none
1169
  * @retval none
798
  */
1170
  */
799
static void HCD_HC_IN_IRQHandler (HCD_HandleTypeDef *hhcd, uint8_t chnum)
1171
static void HCD_HC_IN_IRQHandler(HCD_HandleTypeDef *hhcd, uint8_t chnum)
800
{
1172
{
801
  USB_OTG_GlobalTypeDef *USBx = hhcd->Instance;
1173
  USB_OTG_GlobalTypeDef *USBx = hhcd->Instance;
-
 
1174
  uint32_t USBx_BASE = (uint32_t)USBx;
-
 
1175
  uint32_t ch_num = (uint32_t)chnum;
-
 
1176
 
802
  uint32_t tmpreg = 0U;
1177
  uint32_t tmpreg;
803
 
1178
 
804
  if ((USBx_HC(chnum)->HCINT) &  USB_OTG_HCINT_AHBERR)
1179
  if ((USBx_HC(ch_num)->HCINT & USB_OTG_HCINT_AHBERR) == USB_OTG_HCINT_AHBERR)
805
  {
1180
  {
806
    __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_AHBERR);
1181
    __HAL_HCD_CLEAR_HC_INT(ch_num, USB_OTG_HCINT_AHBERR);
-
 
1182
    __HAL_HCD_UNMASK_HALT_HC_INT(ch_num);
-
 
1183
  }
-
 
1184
  else if ((USBx_HC(ch_num)->HCINT & USB_OTG_HCINT_BBERR) == USB_OTG_HCINT_BBERR)
-
 
1185
  {
-
 
1186
    __HAL_HCD_CLEAR_HC_INT(ch_num, USB_OTG_HCINT_BBERR);
-
 
1187
    hhcd->hc[ch_num].state = HC_BBLERR;
807
    __HAL_HCD_UNMASK_HALT_HC_INT(chnum);
1188
    __HAL_HCD_UNMASK_HALT_HC_INT(ch_num);
-
 
1189
    (void)USB_HC_Halt(hhcd->Instance, (uint8_t)ch_num);
808
  }  
1190
  }
809
  else if ((USBx_HC(chnum)->HCINT) &  USB_OTG_HCINT_ACK)
1191
  else if ((USBx_HC(ch_num)->HCINT & USB_OTG_HCINT_ACK) == USB_OTG_HCINT_ACK)
810
  {
1192
  {
811
    __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_ACK);
1193
    __HAL_HCD_CLEAR_HC_INT(ch_num, USB_OTG_HCINT_ACK);
812
  }
1194
  }
813
 
-
 
814
  else if ((USBx_HC(chnum)->HCINT) &  USB_OTG_HCINT_STALL)
1195
  else if ((USBx_HC(ch_num)->HCINT & USB_OTG_HCINT_STALL) == USB_OTG_HCINT_STALL)
815
  {
1196
  {
816
    __HAL_HCD_UNMASK_HALT_HC_INT(chnum);
1197
    __HAL_HCD_UNMASK_HALT_HC_INT(ch_num);
817
    hhcd->hc[chnum].state = HC_STALL;
1198
    hhcd->hc[ch_num].state = HC_STALL;
818
    __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_NAK);
1199
    __HAL_HCD_CLEAR_HC_INT(ch_num, USB_OTG_HCINT_NAK);
819
    __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_STALL);
1200
    __HAL_HCD_CLEAR_HC_INT(ch_num, USB_OTG_HCINT_STALL);
820
    USB_HC_Halt(hhcd->Instance, chnum);
1201
    (void)USB_HC_Halt(hhcd->Instance, (uint8_t)ch_num);
821
  }
1202
  }
822
  else if ((USBx_HC(chnum)->HCINT) &  USB_OTG_HCINT_DTERR)
1203
  else if ((USBx_HC(ch_num)->HCINT & USB_OTG_HCINT_DTERR) == USB_OTG_HCINT_DTERR)
823
  {
1204
  {
824
    __HAL_HCD_UNMASK_HALT_HC_INT(chnum);
1205
    __HAL_HCD_UNMASK_HALT_HC_INT(ch_num);
825
    USB_HC_Halt(hhcd->Instance, chnum);
1206
    (void)USB_HC_Halt(hhcd->Instance, (uint8_t)ch_num);
826
    __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_NAK);
1207
    __HAL_HCD_CLEAR_HC_INT(ch_num, USB_OTG_HCINT_NAK);
827
    hhcd->hc[chnum].state = HC_DATATGLERR;
1208
    hhcd->hc[ch_num].state = HC_DATATGLERR;
828
    __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_DTERR);
1209
    __HAL_HCD_CLEAR_HC_INT(ch_num, USB_OTG_HCINT_DTERR);
829
  }
1210
  }
830
 
1211
  else
831
  if ((USBx_HC(chnum)->HCINT) &  USB_OTG_HCINT_FRMOR)
-
 
832
  {
1212
  {
833
    __HAL_HCD_UNMASK_HALT_HC_INT(chnum);
-
 
834
    USB_HC_Halt(hhcd->Instance, chnum);
1213
    /* ... */
835
    __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_FRMOR);
-
 
836
  }
1214
  }
837
 
1215
 
838
  else if ((USBx_HC(chnum)->HCINT) &  USB_OTG_HCINT_XFRC)
1216
  if ((USBx_HC(ch_num)->HCINT & USB_OTG_HCINT_FRMOR) == USB_OTG_HCINT_FRMOR)
839
  {
1217
  {
-
 
1218
    __HAL_HCD_UNMASK_HALT_HC_INT(ch_num);
-
 
1219
    (void)USB_HC_Halt(hhcd->Instance, (uint8_t)ch_num);
-
 
1220
    __HAL_HCD_CLEAR_HC_INT(ch_num, USB_OTG_HCINT_FRMOR);
-
 
1221
  }
-
 
1222
  else if ((USBx_HC(ch_num)->HCINT & USB_OTG_HCINT_XFRC) == USB_OTG_HCINT_XFRC)
-
 
1223
  {
840
    hhcd->hc[chnum].state = HC_XFRC;
1224
    hhcd->hc[ch_num].state = HC_XFRC;
841
    hhcd->hc[chnum].ErrCnt = 0U;
1225
    hhcd->hc[ch_num].ErrCnt = 0U;
842
    __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_XFRC);
1226
    __HAL_HCD_CLEAR_HC_INT(ch_num, USB_OTG_HCINT_XFRC);
-
 
1227
 
-
 
1228
    if ((hhcd->hc[ch_num].ep_type == EP_TYPE_CTRL) ||
-
 
1229
        (hhcd->hc[ch_num].ep_type == EP_TYPE_BULK))
-
 
1230
    {
-
 
1231
      __HAL_HCD_UNMASK_HALT_HC_INT(ch_num);
-
 
1232
      (void)USB_HC_Halt(hhcd->Instance, (uint8_t)ch_num);
-
 
1233
      __HAL_HCD_CLEAR_HC_INT(ch_num, USB_OTG_HCINT_NAK);
843
   
1234
    }
844
    if ((hhcd->hc[chnum].ep_type == EP_TYPE_CTRL)||
1235
    else if (hhcd->hc[ch_num].ep_type == EP_TYPE_INTR)
-
 
1236
    {
-
 
1237
      USBx_HC(ch_num)->HCCHAR |= USB_OTG_HCCHAR_ODDFRM;
-
 
1238
      hhcd->hc[ch_num].urb_state = URB_DONE;
-
 
1239
 
-
 
1240
#if (USE_HAL_HCD_REGISTER_CALLBACKS == 1U)
-
 
1241
      hhcd->HC_NotifyURBChangeCallback(hhcd, (uint8_t)ch_num, hhcd->hc[ch_num].urb_state);
-
 
1242
#else
-
 
1243
      HAL_HCD_HC_NotifyURBChange_Callback(hhcd, (uint8_t)ch_num, hhcd->hc[ch_num].urb_state);
-
 
1244
#endif /* USE_HAL_HCD_REGISTER_CALLBACKS */
-
 
1245
    }
845
        (hhcd->hc[chnum].ep_type == EP_TYPE_BULK))
1246
    else if (hhcd->hc[ch_num].ep_type == EP_TYPE_ISOC)
846
    {
1247
    {
847
      __HAL_HCD_UNMASK_HALT_HC_INT(chnum);
1248
      hhcd->hc[ch_num].urb_state = URB_DONE;
848
      USB_HC_Halt(hhcd->Instance, chnum);
1249
      hhcd->hc[ch_num].toggle_in ^= 1U;
-
 
1250
 
849
      __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_NAK);
1251
#if (USE_HAL_HCD_REGISTER_CALLBACKS == 1U)
-
 
1252
      hhcd->HC_NotifyURBChangeCallback(hhcd, (uint8_t)ch_num, hhcd->hc[ch_num].urb_state);
850
     
1253
#else
-
 
1254
      HAL_HCD_HC_NotifyURBChange_Callback(hhcd, (uint8_t)ch_num, hhcd->hc[ch_num].urb_state);
-
 
1255
#endif /* USE_HAL_HCD_REGISTER_CALLBACKS */
851
    }
1256
    }
852
    else if(hhcd->hc[chnum].ep_type == EP_TYPE_INTR)
1257
    else
853
    {
1258
    {
854
      USBx_HC(chnum)->HCCHAR |= USB_OTG_HCCHAR_ODDFRM;
-
 
855
      hhcd->hc[chnum].urb_state = URB_DONE;
1259
      /* ... */
856
      HAL_HCD_HC_NotifyURBChange_Callback(hhcd, chnum, hhcd->hc[chnum].urb_state);
-
 
857
    }
1260
    }
858
    hhcd->hc[chnum].toggle_in ^= 1U;
1261
    hhcd->hc[ch_num].toggle_in ^= 1U;
859
   
1262
 
860
  }
1263
  }
861
  else if ((USBx_HC(chnum)->HCINT) &  USB_OTG_HCINT_CHH)
1264
  else if ((USBx_HC(ch_num)->HCINT & USB_OTG_HCINT_CHH) == USB_OTG_HCINT_CHH)
862
  {
1265
  {
863
    __HAL_HCD_MASK_HALT_HC_INT(chnum);
1266
    __HAL_HCD_MASK_HALT_HC_INT(ch_num);
864
   
1267
 
865
    if(hhcd->hc[chnum].state == HC_XFRC)
1268
    if (hhcd->hc[ch_num].state == HC_XFRC)
866
    {
1269
    {
867
      hhcd->hc[chnum].urb_state  = URB_DONE;
1270
      hhcd->hc[ch_num].urb_state  = URB_DONE;
868
    }
1271
    }
869
    else if (hhcd->hc[chnum].state == HC_STALL)
1272
    else if (hhcd->hc[ch_num].state == HC_STALL)
870
    {
1273
    {
871
      hhcd->hc[chnum].urb_state  = URB_STALL;
1274
      hhcd->hc[ch_num].urb_state  = URB_STALL;
872
    }
1275
    }
873
    else if((hhcd->hc[chnum].state == HC_XACTERR) ||
1276
    else if ((hhcd->hc[ch_num].state == HC_XACTERR) ||
874
            (hhcd->hc[chnum].state == HC_DATATGLERR))
1277
             (hhcd->hc[ch_num].state == HC_DATATGLERR))
875
    {
1278
    {
-
 
1279
      hhcd->hc[ch_num].ErrCnt++;
876
      if(hhcd->hc[chnum].ErrCnt++ > 3U)
1280
      if (hhcd->hc[ch_num].ErrCnt > 3U)
877
      {
1281
      {
878
        hhcd->hc[chnum].ErrCnt = 0U;
1282
        hhcd->hc[ch_num].ErrCnt = 0U;
879
        hhcd->hc[chnum].urb_state = URB_ERROR;
1283
        hhcd->hc[ch_num].urb_state = URB_ERROR;
880
      }
1284
      }
881
      else
1285
      else
882
      {
1286
      {
883
        hhcd->hc[chnum].urb_state = URB_NOTREADY;
1287
        hhcd->hc[ch_num].urb_state = URB_NOTREADY;
884
      }
1288
      }
-
 
1289
 
-
 
1290
      /* re-activate the channel  */
-
 
1291
      tmpreg = USBx_HC(ch_num)->HCCHAR;
-
 
1292
      tmpreg &= ~USB_OTG_HCCHAR_CHDIS;
-
 
1293
      tmpreg |= USB_OTG_HCCHAR_CHENA;
-
 
1294
      USBx_HC(ch_num)->HCCHAR = tmpreg;
885
     
1295
    }
-
 
1296
    else if (hhcd->hc[ch_num].state == HC_NAK)
-
 
1297
    {
-
 
1298
      hhcd->hc[ch_num].urb_state  = URB_NOTREADY;
886
      /* re-activate the channel  */
1299
      /* re-activate the channel  */
887
      tmpreg = USBx_HC(chnum)->HCCHAR;
1300
      tmpreg = USBx_HC(ch_num)->HCCHAR;
888
      tmpreg &= ~USB_OTG_HCCHAR_CHDIS;
1301
      tmpreg &= ~USB_OTG_HCCHAR_CHDIS;
889
      tmpreg |= USB_OTG_HCCHAR_CHENA;
1302
      tmpreg |= USB_OTG_HCCHAR_CHENA;
890
      USBx_HC(chnum)->HCCHAR = tmpreg;
1303
      USBx_HC(ch_num)->HCCHAR = tmpreg;
891
    }
1304
    }
-
 
1305
    else if (hhcd->hc[ch_num].state == HC_BBLERR)
-
 
1306
    {
-
 
1307
      hhcd->hc[ch_num].ErrCnt++;
-
 
1308
      hhcd->hc[ch_num].urb_state = URB_ERROR;
-
 
1309
    }
-
 
1310
    else
-
 
1311
    {
-
 
1312
      /* ... */
-
 
1313
    }
892
    __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_CHH);
1314
    __HAL_HCD_CLEAR_HC_INT(ch_num, USB_OTG_HCINT_CHH);
893
    HAL_HCD_HC_NotifyURBChange_Callback(hhcd, chnum, hhcd->hc[chnum].urb_state);
1315
    HAL_HCD_HC_NotifyURBChange_Callback(hhcd, (uint8_t)ch_num, hhcd->hc[ch_num].urb_state);
894
  }
1316
  }
895
 
-
 
896
  else if ((USBx_HC(chnum)->HCINT) &  USB_OTG_HCINT_TXERR)
1317
  else if ((USBx_HC(ch_num)->HCINT & USB_OTG_HCINT_TXERR) == USB_OTG_HCINT_TXERR)
897
  {
1318
  {
898
    __HAL_HCD_UNMASK_HALT_HC_INT(chnum);
1319
    __HAL_HCD_UNMASK_HALT_HC_INT(ch_num);
899
     hhcd->hc[chnum].ErrCnt++;
1320
    hhcd->hc[ch_num].ErrCnt++;
900
     hhcd->hc[chnum].state = HC_XACTERR;
1321
    hhcd->hc[ch_num].state = HC_XACTERR;
901
     USB_HC_Halt(hhcd->Instance, chnum);
1322
    (void)USB_HC_Halt(hhcd->Instance, (uint8_t)ch_num);
902
     __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_TXERR);
1323
    __HAL_HCD_CLEAR_HC_INT(ch_num, USB_OTG_HCINT_TXERR);
903
  }
1324
  }
904
  else if ((USBx_HC(chnum)->HCINT) &  USB_OTG_HCINT_NAK)
1325
  else if ((USBx_HC(ch_num)->HCINT & USB_OTG_HCINT_NAK) == USB_OTG_HCINT_NAK)
905
  {
1326
  {
906
    if(hhcd->hc[chnum].ep_type == EP_TYPE_INTR)
1327
    if (hhcd->hc[ch_num].ep_type == EP_TYPE_INTR)
907
    {
1328
    {
-
 
1329
      hhcd->hc[ch_num].ErrCnt = 0U;
908
      __HAL_HCD_UNMASK_HALT_HC_INT(chnum);
1330
      __HAL_HCD_UNMASK_HALT_HC_INT(ch_num);
909
      USB_HC_Halt(hhcd->Instance, chnum);
1331
      (void)USB_HC_Halt(hhcd->Instance, (uint8_t)ch_num);
910
    }
1332
    }
911
    else if  ((hhcd->hc[chnum].ep_type == EP_TYPE_CTRL)||
1333
    else if ((hhcd->hc[ch_num].ep_type == EP_TYPE_CTRL) ||
912
              (hhcd->hc[chnum].ep_type == EP_TYPE_BULK))
1334
             (hhcd->hc[ch_num].ep_type == EP_TYPE_BULK))
913
    {
1335
    {
914
      /* re-activate the channel  */
1336
      hhcd->hc[ch_num].ErrCnt = 0U;
915
      tmpreg = USBx_HC(chnum)->HCCHAR;
1337
      hhcd->hc[ch_num].state = HC_NAK;
916
      tmpreg &= ~USB_OTG_HCCHAR_CHDIS;
1338
      __HAL_HCD_UNMASK_HALT_HC_INT(ch_num);
917
      tmpreg |= USB_OTG_HCCHAR_CHENA;
1339
      (void)USB_HC_Halt(hhcd->Instance, (uint8_t)ch_num);
-
 
1340
    }
-
 
1341
    else
-
 
1342
    {
918
      USBx_HC(chnum)->HCCHAR = tmpreg;
1343
      /* ... */
919
    }
1344
    }
920
    hhcd->hc[chnum].state = HC_NAK;
-
 
921
     __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_NAK);
1345
    __HAL_HCD_CLEAR_HC_INT(ch_num, USB_OTG_HCINT_NAK);
-
 
1346
  }
-
 
1347
  else
-
 
1348
  {
-
 
1349
    /* ... */
922
  }
1350
  }
923
}
1351
}
924
 
1352
 
925
/**
1353
/**
926
  * @brief  This function handles Host Channel OUT interrupt requests.
1354
  * @brief  Handle Host Channel OUT interrupt requests.
927
  * @param  hhcd: HCD handle
1355
  * @param  hhcd HCD handle
928
  * @param  chnum: Channel number.
1356
  * @param  chnum Channel number.
929
  *         This parameter can be a value from 1 to 15
1357
  *         This parameter can be a value from 1 to 15
930
  * @retval none
1358
  * @retval none
931
  */
1359
  */
932
static void HCD_HC_OUT_IRQHandler (HCD_HandleTypeDef *hhcd, uint8_t chnum)
1360
static void HCD_HC_OUT_IRQHandler(HCD_HandleTypeDef *hhcd, uint8_t chnum)
933
{
1361
{
934
  USB_OTG_GlobalTypeDef *USBx = hhcd->Instance;
1362
  USB_OTG_GlobalTypeDef *USBx = hhcd->Instance;
-
 
1363
  uint32_t USBx_BASE = (uint32_t)USBx;
-
 
1364
  uint32_t ch_num = (uint32_t)chnum;
935
  uint32_t tmpreg = 0U;
1365
  uint32_t tmpreg;
936
 
1366
 
937
  if ((USBx_HC(chnum)->HCINT) &  USB_OTG_HCINT_AHBERR)
1367
  if ((USBx_HC(ch_num)->HCINT & USB_OTG_HCINT_AHBERR) == USB_OTG_HCINT_AHBERR)
938
  {
1368
  {
939
    __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_AHBERR);
1369
    __HAL_HCD_CLEAR_HC_INT(ch_num, USB_OTG_HCINT_AHBERR);
940
    __HAL_HCD_UNMASK_HALT_HC_INT(chnum);
1370
    __HAL_HCD_UNMASK_HALT_HC_INT(ch_num);
941
  }
1371
  }
942
  else if ((USBx_HC(chnum)->HCINT) &  USB_OTG_HCINT_ACK)
1372
  else if ((USBx_HC(ch_num)->HCINT & USB_OTG_HCINT_ACK) == USB_OTG_HCINT_ACK)
943
  {
1373
  {
944
    __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_ACK);
1374
    __HAL_HCD_CLEAR_HC_INT(ch_num, USB_OTG_HCINT_ACK);
945
   
1375
 
946
    if( hhcd->hc[chnum].do_ping == 1U)
1376
    if (hhcd->hc[ch_num].do_ping == 1U)
947
    {
1377
    {
-
 
1378
      hhcd->hc[ch_num].do_ping = 0U;
948
      hhcd->hc[chnum].state = HC_NYET;
1379
      hhcd->hc[ch_num].urb_state  = URB_NOTREADY;
949
      __HAL_HCD_UNMASK_HALT_HC_INT(chnum);
1380
      __HAL_HCD_UNMASK_HALT_HC_INT(ch_num);
950
      USB_HC_Halt(hhcd->Instance, chnum);
1381
      (void)USB_HC_Halt(hhcd->Instance, (uint8_t)ch_num);
951
      hhcd->hc[chnum].urb_state  = URB_NOTREADY;
-
 
952
    }
1382
    }
953
  }
1383
  }
954
 
-
 
955
  else if ((USBx_HC(chnum)->HCINT) &  USB_OTG_HCINT_NYET)
1384
  else if ((USBx_HC(ch_num)->HCINT & USB_OTG_HCINT_NYET) == USB_OTG_HCINT_NYET)
956
  {
1385
  {
957
    hhcd->hc[chnum].state = HC_NYET;
1386
    hhcd->hc[ch_num].state = HC_NYET;
-
 
1387
    hhcd->hc[ch_num].do_ping = 1U;
958
    hhcd->hc[chnum].ErrCnt= 0U;
1388
    hhcd->hc[ch_num].ErrCnt = 0U;
959
    __HAL_HCD_UNMASK_HALT_HC_INT(chnum);
1389
    __HAL_HCD_UNMASK_HALT_HC_INT(ch_num);
960
    USB_HC_Halt(hhcd->Instance, chnum);
1390
    (void)USB_HC_Halt(hhcd->Instance, (uint8_t)ch_num);
961
    __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_NYET);
1391
    __HAL_HCD_CLEAR_HC_INT(ch_num, USB_OTG_HCINT_NYET);
962
 
-
 
963
  }
1392
  }
964
 
-
 
965
  else if ((USBx_HC(chnum)->HCINT) &  USB_OTG_HCINT_FRMOR)
1393
  else if ((USBx_HC(ch_num)->HCINT & USB_OTG_HCINT_FRMOR) == USB_OTG_HCINT_FRMOR)
966
  {
1394
  {
967
    __HAL_HCD_UNMASK_HALT_HC_INT(chnum);
1395
    __HAL_HCD_UNMASK_HALT_HC_INT(ch_num);
968
    USB_HC_Halt(hhcd->Instance, chnum);
1396
    (void)USB_HC_Halt(hhcd->Instance, (uint8_t)ch_num);
969
    __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_FRMOR);
1397
    __HAL_HCD_CLEAR_HC_INT(ch_num, USB_OTG_HCINT_FRMOR);
970
  }
1398
  }
971
 
-
 
972
  else if ((USBx_HC(chnum)->HCINT) &  USB_OTG_HCINT_XFRC)
1399
  else if ((USBx_HC(ch_num)->HCINT & USB_OTG_HCINT_XFRC) == USB_OTG_HCINT_XFRC)
973
  {
1400
  {
974
    hhcd->hc[chnum].ErrCnt = 0U;
1401
    hhcd->hc[ch_num].ErrCnt = 0U;
975
    __HAL_HCD_UNMASK_HALT_HC_INT(chnum);
1402
    __HAL_HCD_UNMASK_HALT_HC_INT(ch_num);
976
    USB_HC_Halt(hhcd->Instance, chnum);
1403
    (void)USB_HC_Halt(hhcd->Instance, (uint8_t)ch_num);
977
    __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_XFRC);
1404
    __HAL_HCD_CLEAR_HC_INT(ch_num, USB_OTG_HCINT_XFRC);
978
    hhcd->hc[chnum].state = HC_XFRC;
1405
    hhcd->hc[ch_num].state = HC_XFRC;
979
  }
1406
  }
980
  else if ((USBx_HC(chnum)->HCINT) &  USB_OTG_HCINT_STALL)
1407
  else if ((USBx_HC(ch_num)->HCINT & USB_OTG_HCINT_STALL) == USB_OTG_HCINT_STALL)
981
  {
1408
  {
982
    __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_STALL);
1409
    __HAL_HCD_CLEAR_HC_INT(ch_num, USB_OTG_HCINT_STALL);
983
    __HAL_HCD_UNMASK_HALT_HC_INT(chnum);
1410
    __HAL_HCD_UNMASK_HALT_HC_INT(ch_num);
984
    USB_HC_Halt(hhcd->Instance, chnum);
1411
    (void)USB_HC_Halt(hhcd->Instance, (uint8_t)ch_num);
985
    hhcd->hc[chnum].state = HC_STALL;
1412
    hhcd->hc[ch_num].state = HC_STALL;
986
  }
1413
  }
987
  else if ((USBx_HC(chnum)->HCINT) &  USB_OTG_HCINT_NAK)
1414
  else if ((USBx_HC(ch_num)->HCINT & USB_OTG_HCINT_NAK) == USB_OTG_HCINT_NAK)
988
  {
1415
  {
989
    hhcd->hc[chnum].ErrCnt = 0U;
1416
    hhcd->hc[ch_num].ErrCnt = 0U;
-
 
1417
    hhcd->hc[ch_num].state = HC_NAK;
-
 
1418
 
990
    __HAL_HCD_UNMASK_HALT_HC_INT(chnum);
1419
    __HAL_HCD_UNMASK_HALT_HC_INT(ch_num);
991
    USB_HC_Halt(hhcd->Instance, chnum);
1420
    (void)USB_HC_Halt(hhcd->Instance, (uint8_t)ch_num);
992
    hhcd->hc[chnum].state = HC_NAK;
-
 
993
    __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_NAK);
1421
    __HAL_HCD_CLEAR_HC_INT(ch_num, USB_OTG_HCINT_NAK);
994
  }
1422
  }
995
  else if ((USBx_HC(chnum)->HCINT) &  USB_OTG_HCINT_TXERR)
1423
  else if ((USBx_HC(ch_num)->HCINT & USB_OTG_HCINT_TXERR) == USB_OTG_HCINT_TXERR)
996
  {
1424
  {
997
    __HAL_HCD_UNMASK_HALT_HC_INT(chnum);
1425
    __HAL_HCD_UNMASK_HALT_HC_INT(ch_num);
998
    USB_HC_Halt(hhcd->Instance, chnum);
1426
    (void)USB_HC_Halt(hhcd->Instance, (uint8_t)ch_num);
999
    hhcd->hc[chnum].state = HC_XACTERR;
1427
    hhcd->hc[ch_num].state = HC_XACTERR;
1000
     __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_TXERR);
1428
    __HAL_HCD_CLEAR_HC_INT(ch_num, USB_OTG_HCINT_TXERR);
1001
  }
1429
  }
1002
  else if ((USBx_HC(chnum)->HCINT) &  USB_OTG_HCINT_DTERR)
1430
  else if ((USBx_HC(ch_num)->HCINT & USB_OTG_HCINT_DTERR) == USB_OTG_HCINT_DTERR)
1003
  {
1431
  {
1004
    __HAL_HCD_UNMASK_HALT_HC_INT(chnum);
1432
    __HAL_HCD_UNMASK_HALT_HC_INT(ch_num);
1005
    USB_HC_Halt(hhcd->Instance, chnum);
1433
    (void)USB_HC_Halt(hhcd->Instance, (uint8_t)ch_num);
1006
    __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_NAK);
1434
    __HAL_HCD_CLEAR_HC_INT(ch_num, USB_OTG_HCINT_NAK);
1007
    __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_DTERR);
1435
    __HAL_HCD_CLEAR_HC_INT(ch_num, USB_OTG_HCINT_DTERR);
1008
    hhcd->hc[chnum].state = HC_DATATGLERR;
1436
    hhcd->hc[ch_num].state = HC_DATATGLERR;
1009
  }
1437
  }
1010
  else if ((USBx_HC(chnum)->HCINT) &  USB_OTG_HCINT_CHH)
1438
  else if ((USBx_HC(ch_num)->HCINT & USB_OTG_HCINT_CHH) == USB_OTG_HCINT_CHH)
1011
  {
1439
  {
1012
    __HAL_HCD_MASK_HALT_HC_INT(chnum);
1440
    __HAL_HCD_MASK_HALT_HC_INT(ch_num);
1013
   
1441
 
1014
    if(hhcd->hc[chnum].state == HC_XFRC)
1442
    if (hhcd->hc[ch_num].state == HC_XFRC)
1015
    {
1443
    {
1016
      hhcd->hc[chnum].urb_state  = URB_DONE;
1444
      hhcd->hc[ch_num].urb_state  = URB_DONE;
1017
      if (hhcd->hc[chnum].ep_type == EP_TYPE_BULK)
1445
      if ((hhcd->hc[ch_num].ep_type == EP_TYPE_BULK) ||
-
 
1446
          (hhcd->hc[ch_num].ep_type == EP_TYPE_INTR))
1018
      {
1447
      {
1019
        hhcd->hc[chnum].toggle_out ^= 1U;
1448
        hhcd->hc[ch_num].toggle_out ^= 1U;
1020
      }
1449
      }
1021
    }
1450
    }
1022
    else if (hhcd->hc[chnum].state == HC_NAK)
1451
    else if (hhcd->hc[ch_num].state == HC_NAK)
1023
    {
1452
    {
1024
      hhcd->hc[chnum].urb_state  = URB_NOTREADY;
1453
      hhcd->hc[ch_num].urb_state = URB_NOTREADY;
1025
    }
1454
    }
1026
    else if (hhcd->hc[chnum].state == HC_NYET)
1455
    else if (hhcd->hc[ch_num].state == HC_NYET)
1027
    {
1456
    {
1028
      hhcd->hc[chnum].urb_state  = URB_NOTREADY;
1457
      hhcd->hc[ch_num].urb_state  = URB_NOTREADY;
1029
      hhcd->hc[chnum].do_ping = 0U;
-
 
1030
    }
1458
    }
1031
    else if (hhcd->hc[chnum].state == HC_STALL)
1459
    else if (hhcd->hc[ch_num].state == HC_STALL)
1032
    {
1460
    {
1033
      hhcd->hc[chnum].urb_state  = URB_STALL;
1461
      hhcd->hc[ch_num].urb_state  = URB_STALL;
1034
    }
1462
    }
1035
    else if((hhcd->hc[chnum].state == HC_XACTERR) ||
1463
    else if ((hhcd->hc[ch_num].state == HC_XACTERR) ||
1036
            (hhcd->hc[chnum].state == HC_DATATGLERR))
1464
             (hhcd->hc[ch_num].state == HC_DATATGLERR))
1037
    {
1465
    {
-
 
1466
      hhcd->hc[ch_num].ErrCnt++;
1038
      if(hhcd->hc[chnum].ErrCnt++ > 3U)
1467
      if (hhcd->hc[ch_num].ErrCnt > 3U)
1039
      {
1468
      {
1040
        hhcd->hc[chnum].ErrCnt = 0U;
1469
        hhcd->hc[ch_num].ErrCnt = 0U;
1041
        hhcd->hc[chnum].urb_state = URB_ERROR;
1470
        hhcd->hc[ch_num].urb_state = URB_ERROR;
1042
      }
1471
      }
1043
      else
1472
      else
1044
      {
1473
      {
1045
        hhcd->hc[chnum].urb_state = URB_NOTREADY;
1474
        hhcd->hc[ch_num].urb_state = URB_NOTREADY;
1046
      }
1475
      }
1047
     
1476
 
1048
      /* re-activate the channel  */
1477
      /* re-activate the channel  */
1049
      tmpreg = USBx_HC(chnum)->HCCHAR;
1478
      tmpreg = USBx_HC(ch_num)->HCCHAR;
1050
      tmpreg &= ~USB_OTG_HCCHAR_CHDIS;
1479
      tmpreg &= ~USB_OTG_HCCHAR_CHDIS;
1051
      tmpreg |= USB_OTG_HCCHAR_CHENA;
1480
      tmpreg |= USB_OTG_HCCHAR_CHENA;
1052
      USBx_HC(chnum)->HCCHAR = tmpreg;
1481
      USBx_HC(ch_num)->HCCHAR = tmpreg;
-
 
1482
    }
-
 
1483
    else
-
 
1484
    {
-
 
1485
      /* ... */
1053
    }
1486
    }
1054
   
1487
 
1055
    __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_CHH);
1488
    __HAL_HCD_CLEAR_HC_INT(ch_num, USB_OTG_HCINT_CHH);
1056
    HAL_HCD_HC_NotifyURBChange_Callback(hhcd, chnum, hhcd->hc[chnum].urb_state);
1489
    HAL_HCD_HC_NotifyURBChange_Callback(hhcd, (uint8_t)ch_num, hhcd->hc[ch_num].urb_state);
-
 
1490
  }
-
 
1491
  else
-
 
1492
  {
-
 
1493
    /* ... */
1057
  }
1494
  }
1058
}
1495
}
1059
 
1496
 
1060
/**
1497
/**
1061
  * @brief  This function handles Rx Queue Level interrupt requests.
1498
  * @brief  Handle Rx Queue Level interrupt requests.
1062
  * @param  hhcd: HCD handle
1499
  * @param  hhcd HCD handle
1063
  * @retval none
1500
  * @retval none
1064
  */
1501
  */
1065
static void HCD_RXQLVL_IRQHandler  (HCD_HandleTypeDef *hhcd)
1502
static void HCD_RXQLVL_IRQHandler(HCD_HandleTypeDef *hhcd)
1066
{
1503
{
1067
  USB_OTG_GlobalTypeDef *USBx = hhcd->Instance;
1504
  USB_OTG_GlobalTypeDef *USBx = hhcd->Instance;
1068
  uint8_t                       channelnum =0U;
1505
  uint32_t USBx_BASE = (uint32_t)USBx;
1069
  uint32_t                      pktsts;
1506
  uint32_t pktsts;
1070
  uint32_t                      pktcnt;
1507
  uint32_t pktcnt;
1071
  uint32_t                      temp = 0U;
1508
  uint32_t temp;
1072
  uint32_t tmpreg = 0U;
1509
  uint32_t tmpreg;
-
 
1510
  uint32_t ch_num;
1073
 
1511
 
1074
  temp = hhcd->Instance->GRXSTSP;
1512
  temp = hhcd->Instance->GRXSTSP;
1075
  channelnum = temp &  USB_OTG_GRXSTSP_EPNUM;
1513
  ch_num = temp & USB_OTG_GRXSTSP_EPNUM;
1076
  pktsts = (temp &  USB_OTG_GRXSTSP_PKTSTS) >> 17U;
1514
  pktsts = (temp & USB_OTG_GRXSTSP_PKTSTS) >> 17;
1077
  pktcnt = (temp &  USB_OTG_GRXSTSP_BCNT) >> 4U;
1515
  pktcnt = (temp & USB_OTG_GRXSTSP_BCNT) >> 4;
1078
 
1516
 
1079
  switch (pktsts)
1517
  switch (pktsts)
1080
  {
1518
  {
1081
  case GRXSTS_PKTSTS_IN:
1519
    case GRXSTS_PKTSTS_IN:
1082
    /* Read the data into the host buffer. */
1520
      /* Read the data into the host buffer. */
1083
    if ((pktcnt > 0U) && (hhcd->hc[channelnum].xfer_buff != (void  *)0U))
1521
      if ((pktcnt > 0U) && (hhcd->hc[ch_num].xfer_buff != (void *)0))
1084
    {
-
 
1085
      USB_ReadPacket(hhcd->Instance, hhcd->hc[channelnum].xfer_buff, pktcnt);
-
 
1086
     
-
 
1087
      /*manage multiple Xfer */
-
 
1088
      hhcd->hc[channelnum].xfer_buff += pktcnt;
-
 
1089
      hhcd->hc[channelnum].xfer_count  += pktcnt;
-
 
1090
     
-
 
1091
      if((USBx_HC(channelnum)->HCTSIZ & USB_OTG_HCTSIZ_PKTCNT) > 0U)
-
 
1092
      {
1522
      {
-
 
1523
        (void)USB_ReadPacket(hhcd->Instance, hhcd->hc[ch_num].xfer_buff, (uint16_t)pktcnt);
-
 
1524
 
-
 
1525
        /*manage multiple Xfer */
-
 
1526
        hhcd->hc[ch_num].xfer_buff += pktcnt;
-
 
1527
        hhcd->hc[ch_num].xfer_count  += pktcnt;
-
 
1528
 
-
 
1529
        if ((USBx_HC(ch_num)->HCTSIZ & USB_OTG_HCTSIZ_PKTCNT) > 0U)
-
 
1530
        {
1093
        /* re-activate the channel when more packets are expected */
1531
          /* re-activate the channel when more packets are expected */
1094
        tmpreg = USBx_HC(channelnum)->HCCHAR;
1532
          tmpreg = USBx_HC(ch_num)->HCCHAR;
1095
        tmpreg &= ~USB_OTG_HCCHAR_CHDIS;
1533
          tmpreg &= ~USB_OTG_HCCHAR_CHDIS;
1096
        tmpreg |= USB_OTG_HCCHAR_CHENA;
1534
          tmpreg |= USB_OTG_HCCHAR_CHENA;
1097
        USBx_HC(channelnum)->HCCHAR = tmpreg;
1535
          USBx_HC(ch_num)->HCCHAR = tmpreg;
1098
        hhcd->hc[channelnum].toggle_in ^= 1U;
1536
          hhcd->hc[ch_num].toggle_in ^= 1U;
-
 
1537
        }
1099
      }
1538
      }
1100
    }
-
 
1101
    break;
1539
      break;
1102
 
1540
 
1103
  case GRXSTS_PKTSTS_DATA_TOGGLE_ERR:
1541
    case GRXSTS_PKTSTS_DATA_TOGGLE_ERR:
1104
    break;
1542
      break;
1105
 
1543
 
1106
  case GRXSTS_PKTSTS_IN_XFER_COMP:
1544
    case GRXSTS_PKTSTS_IN_XFER_COMP:
1107
  case GRXSTS_PKTSTS_CH_HALTED:
1545
    case GRXSTS_PKTSTS_CH_HALTED:
1108
  default:
1546
    default:
1109
    break;
1547
      break;
1110
  }
1548
  }
1111
}
1549
}
1112
 
1550
 
1113
/**
1551
/**
1114
  * @brief  This function handles Host Port interrupt requests.
1552
  * @brief  Handle Host Port interrupt requests.
1115
  * @param  hhcd: HCD handle
1553
  * @param  hhcd HCD handle
1116
  * @retval None
1554
  * @retval None
1117
  */
1555
  */
1118
static void HCD_Port_IRQHandler (HCD_HandleTypeDef *hhcd)
1556
static void HCD_Port_IRQHandler(HCD_HandleTypeDef *hhcd)
1119
{
1557
{
1120
  USB_OTG_GlobalTypeDef *USBx = hhcd->Instance;  
1558
  USB_OTG_GlobalTypeDef *USBx = hhcd->Instance;
-
 
1559
  uint32_t USBx_BASE = (uint32_t)USBx;
1121
  __IO uint32_t hprt0 = 0, hprt0_dup = 0U;
1560
  __IO uint32_t hprt0, hprt0_dup;
1122
 
1561
 
1123
  /* Handle Host Port Interrupts */
1562
  /* Handle Host Port Interrupts */
1124
  hprt0 = USBx_HPRT0;
1563
  hprt0 = USBx_HPRT0;
1125
  hprt0_dup = USBx_HPRT0;
1564
  hprt0_dup = USBx_HPRT0;
1126
 
1565
 
1127
  hprt0_dup &= ~(USB_OTG_HPRT_PENA | USB_OTG_HPRT_PCDET |\
1566
  hprt0_dup &= ~(USB_OTG_HPRT_PENA | USB_OTG_HPRT_PCDET | \
1128
                 USB_OTG_HPRT_PENCHNG | USB_OTG_HPRT_POCCHNG );
1567
                 USB_OTG_HPRT_PENCHNG | USB_OTG_HPRT_POCCHNG);
1129
 
1568
 
1130
  /* Check whether Port Connect Detected */
1569
  /* Check whether Port Connect detected */
1131
  if((hprt0 & USB_OTG_HPRT_PCDET) == USB_OTG_HPRT_PCDET)
1570
  if ((hprt0 & USB_OTG_HPRT_PCDET) == USB_OTG_HPRT_PCDET)
1132
  {
1571
  {
1133
    if((hprt0 & USB_OTG_HPRT_PCSTS) == USB_OTG_HPRT_PCSTS)
1572
    if ((hprt0 & USB_OTG_HPRT_PCSTS) == USB_OTG_HPRT_PCSTS)
1134
    {
1573
    {
-
 
1574
#if (USE_HAL_HCD_REGISTER_CALLBACKS == 1U)
1135
      USB_MASK_INTERRUPT(hhcd->Instance, USB_OTG_GINTSTS_DISCINT);
1575
      hhcd->ConnectCallback(hhcd);
-
 
1576
#else
1136
      HAL_HCD_Connect_Callback(hhcd);
1577
      HAL_HCD_Connect_Callback(hhcd);
-
 
1578
#endif /* USE_HAL_HCD_REGISTER_CALLBACKS */
1137
    }
1579
    }
1138
    hprt0_dup  |= USB_OTG_HPRT_PCDET;
1580
    hprt0_dup  |= USB_OTG_HPRT_PCDET;
1139
  }
1581
  }
1140
 
1582
 
1141
  /* Check whether Port Enable Changed */
1583
  /* Check whether Port Enable Changed */
1142
  if((hprt0 & USB_OTG_HPRT_PENCHNG) == USB_OTG_HPRT_PENCHNG)
1584
  if ((hprt0 & USB_OTG_HPRT_PENCHNG) == USB_OTG_HPRT_PENCHNG)
1143
  {
1585
  {
1144
    hprt0_dup |= USB_OTG_HPRT_PENCHNG;
1586
    hprt0_dup |= USB_OTG_HPRT_PENCHNG;
1145
   
1587
 
1146
    if((hprt0 & USB_OTG_HPRT_PENA) == USB_OTG_HPRT_PENA)
1588
    if ((hprt0 & USB_OTG_HPRT_PENA) == USB_OTG_HPRT_PENA)
1147
    {
1589
    {
1148
      if ((hprt0 & USB_OTG_HPRT_PSPD) == (HPRT0_PRTSPD_LOW_SPEED << 17U))
1590
      if (hhcd->Init.phy_itface  == USB_OTG_EMBEDDED_PHY)
1149
      {
1591
      {
-
 
1592
        if ((hprt0 & USB_OTG_HPRT_PSPD) == (HPRT0_PRTSPD_LOW_SPEED << 17))
-
 
1593
        {
1150
        USB_InitFSLSPClkSel(hhcd->Instance ,HCFG_6_MHZ );
1594
          (void)USB_InitFSLSPClkSel(hhcd->Instance, HCFG_6_MHZ);
-
 
1595
        }
-
 
1596
        else
-
 
1597
        {
-
 
1598
          (void)USB_InitFSLSPClkSel(hhcd->Instance, HCFG_48_MHZ);
-
 
1599
        }
1151
      }
1600
      }
1152
      else
1601
      else
1153
      {
1602
      {
1154
        USB_InitFSLSPClkSel(hhcd->Instance ,HCFG_48_MHZ );
1603
        if (hhcd->Init.speed == HCD_SPEED_FULL)
-
 
1604
        {
-
 
1605
          USBx_HOST->HFIR = 60000U;
-
 
1606
        }
1155
      }
1607
      }
-
 
1608
#if (USE_HAL_HCD_REGISTER_CALLBACKS == 1U)
-
 
1609
      hhcd->PortEnabledCallback(hhcd);
-
 
1610
#else
1156
      HAL_HCD_Connect_Callback(hhcd);
1611
      HAL_HCD_PortEnabled_Callback(hhcd);
-
 
1612
#endif /* USE_HAL_HCD_REGISTER_CALLBACKS */
-
 
1613
 
1157
    }
1614
    }
1158
    else
1615
    else
1159
    {
1616
    {
1160
      /* Cleanup HPRT */
-
 
1161
      USBx_HPRT0 &= ~(USB_OTG_HPRT_PENA | USB_OTG_HPRT_PCDET |\
1617
#if (USE_HAL_HCD_REGISTER_CALLBACKS == 1U)
1162
        USB_OTG_HPRT_PENCHNG | USB_OTG_HPRT_POCCHNG );
1618
      hhcd->PortDisabledCallback(hhcd);
1163
     
1619
#else
1164
      USB_UNMASK_INTERRUPT(hhcd->Instance, USB_OTG_GINTSTS_DISCINT);
1620
      HAL_HCD_PortDisabled_Callback(hhcd);
-
 
1621
#endif /* USE_HAL_HCD_REGISTER_CALLBACKS */
1165
    }
1622
    }
1166
  }
1623
  }
1167
 
1624
 
1168
  /* Check For an over current */
1625
  /* Check for an overcurrent */
1169
  if((hprt0 & USB_OTG_HPRT_POCCHNG) == USB_OTG_HPRT_POCCHNG)
1626
  if ((hprt0 & USB_OTG_HPRT_POCCHNG) == USB_OTG_HPRT_POCCHNG)
1170
  {
1627
  {
1171
    hprt0_dup |= USB_OTG_HPRT_POCCHNG;
1628
    hprt0_dup |= USB_OTG_HPRT_POCCHNG;
1172
  }
1629
  }
1173
 
1630
 
1174
  /* Clear Port Interrupts */
1631
  /* Clear Port Interrupts */
1175
  USBx_HPRT0 = hprt0_dup;
1632
  USBx_HPRT0 = hprt0_dup;
1176
}
1633
}
1177
 
1634
 
1178
/**
1635
/**
Line 1181... Line 1638...
1181
 
1638
 
1182
/**
1639
/**
1183
  * @}
1640
  * @}
1184
  */
1641
  */
1185
 
1642
 
1186
#endif /* STM32F105xC || STM32F107xC */
1643
#endif /* defined (USB_OTG_FS) */
1187
 
-
 
1188
#endif /* HAL_HCD_MODULE_ENABLED */
1644
#endif /* HAL_HCD_MODULE_ENABLED */
1189
 
1645
 
1190
/**
1646
/**
1191
  * @}
1647
  * @}
1192
  */
1648
  */
1193
 
1649
 
-
 
1650
/**
-
 
1651
  * @}
-
 
1652
  */
-
 
1653
 
1194
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
1654
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/