Subversion Repositories canSerial

Rev

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

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