Subversion Repositories DashDisplay

Rev

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

Rev 61 Rev 77
Line 1... Line 1...
1
/**
1
/**
2
  ******************************************************************************
2
  ******************************************************************************
3
  * @file    stm32l1xx_hal_pcd.c
3
  * @file    stm32l1xx_hal_pcd.c
4
  * @author  MCD Application Team
4
  * @author  MCD Application Team
5
  * @brief   PCD HAL module driver.
5
  * @brief   PCD 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
      The PCD HAL driver can be used as follows:
18
  *
19
 
19
  * This software is licensed under terms that can be found in the LICENSE file
20
     (#) Declare a PCD_HandleTypeDef handle structure, for example:
20
  * in the root directory of this software component.
21
         PCD_HandleTypeDef  hpcd;
21
  * If no LICENSE file comes with this software, it is provided AS-IS.
22
 
22
  *
23
     (#) Fill parameters of Init structure in HCD handle
23
  ******************************************************************************
24
 
24
  @verbatim
25
     (#) Call HAL_PCD_Init() API to initialize the PCD peripheral (Core, Device core, ...)
25
  ==============================================================================
26
 
26
                    ##### How to use this driver #####
27
     (#) Initialize the PCD low level resources through the HAL_PCD_MspInit() API:
27
  ==============================================================================
28
         (##) Enable the PCD/USB Low Level interface clock using
28
    [..]
29
              (+++) __HAL_RCC_USB_CLK_ENABLE(); For USB Device only FS peripheral
29
      The PCD HAL driver can be used as follows:
30
 
30
 
31
         (##) Initialize the related GPIO clocks
31
     (#) Declare a PCD_HandleTypeDef handle structure, for example:
32
         (##) Configure PCD pin-out
32
         PCD_HandleTypeDef  hpcd;
33
         (##) Configure PCD NVIC interrupt
33
 
34
 
34
     (#) Fill parameters of Init structure in HCD handle
35
     (#)Associate the Upper USB device stack to the HAL PCD Driver:
35
 
36
         (##) hpcd.pData = pdev;
36
     (#) Call HAL_PCD_Init() API to initialize the PCD peripheral (Core, Device core, ...)
37
 
37
 
38
     (#)Enable PCD transmission and reception:
38
     (#) Initialize the PCD low level resources through the HAL_PCD_MspInit() API:
39
         (##) HAL_PCD_Start();
39
         (##) Enable the PCD/USB Low Level interface clock using
40
 
40
              (+++) __HAL_RCC_USB_CLK_ENABLE(); For USB Device FS peripheral
41
  @endverbatim
41
 
42
  ******************************************************************************
42
         (##) Initialize the related GPIO clocks
43
  * @attention
43
         (##) Configure PCD pin-out
44
  *
44
         (##) Configure PCD NVIC interrupt
45
  * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
45
 
46
  * All rights reserved.</center></h2>
46
     (#)Associate the Upper USB device stack to the HAL PCD Driver:
47
  *
47
         (##) hpcd.pData = pdev;
48
  * This software component is licensed by ST under BSD 3-Clause license,
48
 
49
  * the "License"; You may not use this file except in compliance with the
49
     (#)Enable PCD transmission and reception:
50
  * License. You may obtain a copy of the License at:
50
         (##) HAL_PCD_Start();
51
  *                        opensource.org/licenses/BSD-3-Clause
51
 
52
  *
52
  @endverbatim
53
  ******************************************************************************
53
  ******************************************************************************
54
  */
54
  */
55
 
55
 
56
/* Includes ------------------------------------------------------------------*/
56
/* Includes ------------------------------------------------------------------*/
57
#include "stm32l1xx_hal.h"
57
#include "stm32l1xx_hal.h"
58
 
58
 
59
/** @addtogroup STM32L1xx_HAL_Driver
59
/** @addtogroup STM32L1xx_HAL_Driver
60
  * @{
60
  * @{
61
  */
61
  */
62
 
62
 
63
/** @defgroup PCD PCD
63
/** @defgroup PCD PCD
64
  * @brief PCD HAL module driver
64
  * @brief PCD HAL module driver
65
  * @{
65
  * @{
66
  */
66
  */
67
 
67
 
68
#ifdef HAL_PCD_MODULE_ENABLED
68
#ifdef HAL_PCD_MODULE_ENABLED
69
 
69
 
70
#if defined (USB)
70
#if defined (USB)
71
 
71
 
72
/* Private types -------------------------------------------------------------*/
72
/* Private types -------------------------------------------------------------*/
73
/* Private variables ---------------------------------------------------------*/
73
/* Private variables ---------------------------------------------------------*/
74
/* Private constants ---------------------------------------------------------*/
74
/* Private constants ---------------------------------------------------------*/
75
/* Private macros ------------------------------------------------------------*/
75
/* Private macros ------------------------------------------------------------*/
76
/** @defgroup PCD_Private_Macros PCD Private Macros
76
/** @defgroup PCD_Private_Macros PCD Private Macros
77
  * @{
77
  * @{
78
  */
78
  */
79
#define PCD_MIN(a, b)  (((a) < (b)) ? (a) : (b))
79
#define PCD_MIN(a, b)  (((a) < (b)) ? (a) : (b))
80
#define PCD_MAX(a, b)  (((a) > (b)) ? (a) : (b))
80
#define PCD_MAX(a, b)  (((a) > (b)) ? (a) : (b))
81
/**
81
/**
82
  * @}
82
  * @}
83
  */
83
  */
84
 
84
 
85
/* Private functions prototypes ----------------------------------------------*/
85
/* Private functions prototypes ----------------------------------------------*/
86
/** @defgroup PCD_Private_Functions PCD Private Functions
86
/** @defgroup PCD_Private_Functions PCD Private Functions
87
  * @{
87
  * @{
88
  */
88
  */
89
 
89
 
90
static HAL_StatusTypeDef PCD_EP_ISR_Handler(PCD_HandleTypeDef *hpcd);
90
static HAL_StatusTypeDef PCD_EP_ISR_Handler(PCD_HandleTypeDef *hpcd);
91
static HAL_StatusTypeDef HAL_PCD_EP_DB_Transmit(PCD_HandleTypeDef *hpcd, PCD_EPTypeDef *ep, uint16_t wEPVal);
91
#if (USE_USB_DOUBLE_BUFFER == 1U)
92
static uint16_t HAL_PCD_EP_DB_Receive(PCD_HandleTypeDef *hpcd, PCD_EPTypeDef *ep, uint16_t wEPVal);
92
static HAL_StatusTypeDef HAL_PCD_EP_DB_Transmit(PCD_HandleTypeDef *hpcd, PCD_EPTypeDef *ep, uint16_t wEPVal);
93
 
93
static uint16_t HAL_PCD_EP_DB_Receive(PCD_HandleTypeDef *hpcd, PCD_EPTypeDef *ep, uint16_t wEPVal);
94
/**
94
#endif /* (USE_USB_DOUBLE_BUFFER == 1U) */
95
  * @}
95
 
96
  */
96
/**
97
 
97
  * @}
98
/* Exported functions --------------------------------------------------------*/
98
  */
99
/** @defgroup PCD_Exported_Functions PCD Exported Functions
99
 
100
  * @{
100
/* Exported functions --------------------------------------------------------*/
101
  */
101
/** @defgroup PCD_Exported_Functions PCD Exported Functions
102
 
102
  * @{
103
/** @defgroup PCD_Exported_Functions_Group1 Initialization and de-initialization functions
103
  */
104
  *  @brief    Initialization and Configuration functions
104
 
105
  *
105
/** @defgroup PCD_Exported_Functions_Group1 Initialization and de-initialization functions
106
@verbatim
106
  *  @brief    Initialization and Configuration functions
107
 ===============================================================================
107
  *
108
            ##### Initialization and de-initialization functions #####
108
@verbatim
109
 ===============================================================================
109
 ===============================================================================
110
    [..]  This section provides functions allowing to:
110
            ##### Initialization and de-initialization functions #####
111
 
111
 ===============================================================================
112
@endverbatim
112
    [..]  This section provides functions allowing to:
113
  * @{
113
 
114
  */
114
@endverbatim
115
 
115
  * @{
116
/**
116
  */
117
  * @brief  Initializes the PCD according to the specified
117
 
118
  *         parameters in the PCD_InitTypeDef and initialize the associated handle.
118
/**
119
  * @param  hpcd PCD handle
119
  * @brief  Initializes the PCD according to the specified
120
  * @retval HAL status
120
  *         parameters in the PCD_InitTypeDef and initialize the associated handle.
121
  */
121
  * @param  hpcd PCD handle
122
HAL_StatusTypeDef HAL_PCD_Init(PCD_HandleTypeDef *hpcd)
122
  * @retval HAL status
123
{
123
  */
124
  uint8_t i;
124
HAL_StatusTypeDef HAL_PCD_Init(PCD_HandleTypeDef *hpcd)
125
 
125
{
126
  /* Check the PCD handle allocation */
126
  uint8_t i;
127
  if (hpcd == NULL)
127
 
128
  {
128
  /* Check the PCD handle allocation */
129
    return HAL_ERROR;
129
  if (hpcd == NULL)
130
  }
130
  {
131
 
131
    return HAL_ERROR;
132
  /* Check the parameters */
132
  }
133
  assert_param(IS_PCD_ALL_INSTANCE(hpcd->Instance));
133
 
134
 
134
  /* Check the parameters */
135
  if (hpcd->State == HAL_PCD_STATE_RESET)
135
  assert_param(IS_PCD_ALL_INSTANCE(hpcd->Instance));
136
  {
136
 
137
    /* Allocate lock resource and initialize it */
137
  if (hpcd->State == HAL_PCD_STATE_RESET)
138
    hpcd->Lock = HAL_UNLOCKED;
138
  {
139
 
139
    /* Allocate lock resource and initialize it */
140
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
140
    hpcd->Lock = HAL_UNLOCKED;
141
    hpcd->SOFCallback = HAL_PCD_SOFCallback;
141
 
142
    hpcd->SetupStageCallback = HAL_PCD_SetupStageCallback;
142
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
143
    hpcd->ResetCallback = HAL_PCD_ResetCallback;
143
    hpcd->SOFCallback = HAL_PCD_SOFCallback;
144
    hpcd->SuspendCallback = HAL_PCD_SuspendCallback;
144
    hpcd->SetupStageCallback = HAL_PCD_SetupStageCallback;
145
    hpcd->ResumeCallback = HAL_PCD_ResumeCallback;
145
    hpcd->ResetCallback = HAL_PCD_ResetCallback;
146
    hpcd->ConnectCallback = HAL_PCD_ConnectCallback;
146
    hpcd->SuspendCallback = HAL_PCD_SuspendCallback;
147
    hpcd->DisconnectCallback = HAL_PCD_DisconnectCallback;
147
    hpcd->ResumeCallback = HAL_PCD_ResumeCallback;
148
    hpcd->DataOutStageCallback = HAL_PCD_DataOutStageCallback;
148
    hpcd->ConnectCallback = HAL_PCD_ConnectCallback;
149
    hpcd->DataInStageCallback = HAL_PCD_DataInStageCallback;
149
    hpcd->DisconnectCallback = HAL_PCD_DisconnectCallback;
150
    hpcd->ISOOUTIncompleteCallback = HAL_PCD_ISOOUTIncompleteCallback;
150
    hpcd->DataOutStageCallback = HAL_PCD_DataOutStageCallback;
151
    hpcd->ISOINIncompleteCallback = HAL_PCD_ISOINIncompleteCallback;
151
    hpcd->DataInStageCallback = HAL_PCD_DataInStageCallback;
152
 
152
    hpcd->ISOOUTIncompleteCallback = HAL_PCD_ISOOUTIncompleteCallback;
153
    if (hpcd->MspInitCallback == NULL)
153
    hpcd->ISOINIncompleteCallback = HAL_PCD_ISOINIncompleteCallback;
154
    {
154
 
155
      hpcd->MspInitCallback = HAL_PCD_MspInit;
155
    if (hpcd->MspInitCallback == NULL)
156
    }
156
    {
157
 
157
      hpcd->MspInitCallback = HAL_PCD_MspInit;
158
    /* Init the low level hardware */
158
    }
159
    hpcd->MspInitCallback(hpcd);
159
 
160
#else
160
    /* Init the low level hardware */
161
    /* Init the low level hardware : GPIO, CLOCK, NVIC... */
161
    hpcd->MspInitCallback(hpcd);
162
    HAL_PCD_MspInit(hpcd);
162
#else
163
#endif /* (USE_HAL_PCD_REGISTER_CALLBACKS) */
163
    /* Init the low level hardware : GPIO, CLOCK, NVIC... */
164
  }
164
    HAL_PCD_MspInit(hpcd);
165
 
165
#endif /* (USE_HAL_PCD_REGISTER_CALLBACKS) */
166
  hpcd->State = HAL_PCD_STATE_BUSY;
166
  }
167
 
167
 
168
  /* Disable the Interrupts */
168
  hpcd->State = HAL_PCD_STATE_BUSY;
169
  __HAL_PCD_DISABLE(hpcd);
169
 
170
 
170
  /* Disable the Interrupts */
171
  /* Init endpoints structures */
171
  __HAL_PCD_DISABLE(hpcd);
172
  for (i = 0U; i < hpcd->Init.dev_endpoints; i++)
172
 
173
  {
173
  /* Init endpoints structures */
174
    /* Init ep structure */
174
  for (i = 0U; i < hpcd->Init.dev_endpoints; i++)
175
    hpcd->IN_ep[i].is_in = 1U;
175
  {
176
    hpcd->IN_ep[i].num = i;
176
    /* Init ep structure */
177
    hpcd->IN_ep[i].tx_fifo_num = i;
177
    hpcd->IN_ep[i].is_in = 1U;
178
    /* Control until ep is activated */
178
    hpcd->IN_ep[i].num = i;
179
    hpcd->IN_ep[i].type = EP_TYPE_CTRL;
179
    /* Control until ep is activated */
180
    hpcd->IN_ep[i].maxpacket = 0U;
180
    hpcd->IN_ep[i].type = EP_TYPE_CTRL;
181
    hpcd->IN_ep[i].xfer_buff = 0U;
181
    hpcd->IN_ep[i].maxpacket = 0U;
182
    hpcd->IN_ep[i].xfer_len = 0U;
182
    hpcd->IN_ep[i].xfer_buff = 0U;
183
  }
183
    hpcd->IN_ep[i].xfer_len = 0U;
184
 
184
  }
185
  for (i = 0U; i < hpcd->Init.dev_endpoints; i++)
185
 
186
  {
186
  for (i = 0U; i < hpcd->Init.dev_endpoints; i++)
187
    hpcd->OUT_ep[i].is_in = 0U;
187
  {
188
    hpcd->OUT_ep[i].num = i;
188
    hpcd->OUT_ep[i].is_in = 0U;
189
    /* Control until ep is activated */
189
    hpcd->OUT_ep[i].num = i;
190
    hpcd->OUT_ep[i].type = EP_TYPE_CTRL;
190
    /* Control until ep is activated */
191
    hpcd->OUT_ep[i].maxpacket = 0U;
191
    hpcd->OUT_ep[i].type = EP_TYPE_CTRL;
192
    hpcd->OUT_ep[i].xfer_buff = 0U;
192
    hpcd->OUT_ep[i].maxpacket = 0U;
193
    hpcd->OUT_ep[i].xfer_len = 0U;
193
    hpcd->OUT_ep[i].xfer_buff = 0U;
194
  }
194
    hpcd->OUT_ep[i].xfer_len = 0U;
195
 
195
  }
196
  /* Init Device */
196
 
197
  (void)USB_DevInit(hpcd->Instance, hpcd->Init);
197
  /* Init Device */
198
 
198
  (void)USB_DevInit(hpcd->Instance, hpcd->Init);
199
  hpcd->USB_Address = 0U;
199
 
200
  hpcd->State = HAL_PCD_STATE_READY;
200
  hpcd->USB_Address = 0U;
201
  return HAL_OK;
201
  hpcd->State = HAL_PCD_STATE_READY;
202
}
202
  return HAL_OK;
203
 
203
}
204
/**
204
 
205
  * @brief  DeInitializes the PCD peripheral.
205
/**
206
  * @param  hpcd PCD handle
206
  * @brief  DeInitializes the PCD peripheral.
207
  * @retval HAL status
207
  * @param  hpcd PCD handle
208
  */
208
  * @retval HAL status
209
HAL_StatusTypeDef HAL_PCD_DeInit(PCD_HandleTypeDef *hpcd)
209
  */
210
{
210
HAL_StatusTypeDef HAL_PCD_DeInit(PCD_HandleTypeDef *hpcd)
211
  /* Check the PCD handle allocation */
211
{
212
  if (hpcd == NULL)
212
  /* Check the PCD handle allocation */
213
  {
213
  if (hpcd == NULL)
214
    return HAL_ERROR;
214
  {
215
  }
215
    return HAL_ERROR;
216
 
216
  }
217
  hpcd->State = HAL_PCD_STATE_BUSY;
217
 
218
 
218
  hpcd->State = HAL_PCD_STATE_BUSY;
219
  /* Stop Device */
219
 
220
  if (USB_StopDevice(hpcd->Instance) != HAL_OK)
220
  /* Stop Device */
221
  {
221
  if (USB_StopDevice(hpcd->Instance) != HAL_OK)
222
    return HAL_ERROR;
222
  {
223
  }
223
    return HAL_ERROR;
224
 
224
  }
225
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
225
 
226
  if (hpcd->MspDeInitCallback == NULL)
226
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
227
  {
227
  if (hpcd->MspDeInitCallback == NULL)
228
    hpcd->MspDeInitCallback = HAL_PCD_MspDeInit; /* Legacy weak MspDeInit  */
228
  {
229
  }
229
    hpcd->MspDeInitCallback = HAL_PCD_MspDeInit; /* Legacy weak MspDeInit  */
230
 
230
  }
231
  /* DeInit the low level hardware */
231
 
232
  hpcd->MspDeInitCallback(hpcd);
232
  /* DeInit the low level hardware */
233
#else
233
  hpcd->MspDeInitCallback(hpcd);
234
  /* DeInit the low level hardware: CLOCK, NVIC.*/
234
#else
235
  HAL_PCD_MspDeInit(hpcd);
235
  /* DeInit the low level hardware: CLOCK, NVIC.*/
236
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
236
  HAL_PCD_MspDeInit(hpcd);
237
 
237
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
238
  hpcd->State = HAL_PCD_STATE_RESET;
238
 
239
 
239
  hpcd->State = HAL_PCD_STATE_RESET;
240
  return HAL_OK;
240
 
241
}
241
  return HAL_OK;
242
 
242
}
243
/**
243
 
244
  * @brief  Initializes the PCD MSP.
244
/**
245
  * @param  hpcd PCD handle
245
  * @brief  Initializes the PCD MSP.
246
  * @retval None
246
  * @param  hpcd PCD handle
247
  */
247
  * @retval None
248
__weak void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd)
248
  */
249
{
249
__weak void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd)
250
  /* Prevent unused argument(s) compilation warning */
250
{
251
  UNUSED(hpcd);
251
  /* Prevent unused argument(s) compilation warning */
252
 
252
  UNUSED(hpcd);
253
  /* NOTE : This function should not be modified, when the callback is needed,
253
 
254
            the HAL_PCD_MspInit could be implemented in the user file
254
  /* NOTE : This function should not be modified, when the callback is needed,
255
   */
255
            the HAL_PCD_MspInit could be implemented in the user file
256
}
256
   */
257
 
257
}
258
/**
258
 
259
  * @brief  DeInitializes PCD MSP.
259
/**
260
  * @param  hpcd PCD handle
260
  * @brief  DeInitializes PCD MSP.
261
  * @retval None
261
  * @param  hpcd PCD handle
262
  */
262
  * @retval None
263
__weak void HAL_PCD_MspDeInit(PCD_HandleTypeDef *hpcd)
263
  */
264
{
264
__weak void HAL_PCD_MspDeInit(PCD_HandleTypeDef *hpcd)
265
  /* Prevent unused argument(s) compilation warning */
265
{
266
  UNUSED(hpcd);
266
  /* Prevent unused argument(s) compilation warning */
267
 
267
  UNUSED(hpcd);
268
  /* NOTE : This function should not be modified, when the callback is needed,
268
 
269
            the HAL_PCD_MspDeInit could be implemented in the user file
269
  /* NOTE : This function should not be modified, when the callback is needed,
270
   */
270
            the HAL_PCD_MspDeInit could be implemented in the user file
271
}
271
   */
272
 
272
}
273
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
273
 
274
/**
274
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
275
  * @brief  Register a User USB PCD Callback
275
/**
276
  *         To be used instead of the weak predefined callback
276
  * @brief  Register a User USB PCD Callback
277
  * @param  hpcd USB PCD handle
277
  *         To be used instead of the weak predefined callback
278
  * @param  CallbackID ID of the callback to be registered
278
  * @param  hpcd USB PCD handle
279
  *         This parameter can be one of the following values:
279
  * @param  CallbackID ID of the callback to be registered
280
  *          @arg @ref HAL_PCD_SOF_CB_ID USB PCD SOF callback ID
280
  *         This parameter can be one of the following values:
281
  *          @arg @ref HAL_PCD_SETUPSTAGE_CB_ID USB PCD Setup callback ID
281
  *          @arg @ref HAL_PCD_SOF_CB_ID USB PCD SOF callback ID
282
  *          @arg @ref HAL_PCD_RESET_CB_ID USB PCD Reset callback ID
282
  *          @arg @ref HAL_PCD_SETUPSTAGE_CB_ID USB PCD Setup callback ID
283
  *          @arg @ref HAL_PCD_SUSPEND_CB_ID USB PCD Suspend callback ID
283
  *          @arg @ref HAL_PCD_RESET_CB_ID USB PCD Reset callback ID
284
  *          @arg @ref HAL_PCD_RESUME_CB_ID USB PCD Resume callback ID
284
  *          @arg @ref HAL_PCD_SUSPEND_CB_ID USB PCD Suspend callback ID
285
  *          @arg @ref HAL_PCD_CONNECT_CB_ID USB PCD Connect callback ID
285
  *          @arg @ref HAL_PCD_RESUME_CB_ID USB PCD Resume callback ID
286
  *          @arg @ref HAL_PCD_DISCONNECT_CB_ID OTG PCD Disconnect callback ID
286
  *          @arg @ref HAL_PCD_CONNECT_CB_ID USB PCD Connect callback ID
287
  *          @arg @ref HAL_PCD_MSPINIT_CB_ID MspDeInit callback ID
287
  *          @arg @ref HAL_PCD_DISCONNECT_CB_ID USB PCD Disconnect callback ID
288
  *          @arg @ref HAL_PCD_MSPDEINIT_CB_ID MspDeInit callback ID
288
  *          @arg @ref HAL_PCD_MSPINIT_CB_ID MspDeInit callback ID
289
  * @param  pCallback pointer to the Callback function
289
  *          @arg @ref HAL_PCD_MSPDEINIT_CB_ID MspDeInit callback ID
290
  * @retval HAL status
290
  * @param  pCallback pointer to the Callback function
291
  */
291
  * @retval HAL status
292
HAL_StatusTypeDef HAL_PCD_RegisterCallback(PCD_HandleTypeDef *hpcd,
292
  */
293
                                           HAL_PCD_CallbackIDTypeDef CallbackID,
293
HAL_StatusTypeDef HAL_PCD_RegisterCallback(PCD_HandleTypeDef *hpcd,
294
                                           pPCD_CallbackTypeDef pCallback)
294
                                           HAL_PCD_CallbackIDTypeDef CallbackID,
295
{
295
                                           pPCD_CallbackTypeDef pCallback)
296
  HAL_StatusTypeDef status = HAL_OK;
296
{
297
 
297
  HAL_StatusTypeDef status = HAL_OK;
298
  if (pCallback == NULL)
298
 
299
  {
299
  if (pCallback == NULL)
300
    /* Update the error code */
300
  {
301
    hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK;
301
    /* Update the error code */
302
    return HAL_ERROR;
302
    hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK;
303
  }
303
    return HAL_ERROR;
304
  /* Process locked */
304
  }
305
  __HAL_LOCK(hpcd);
305
  /* Process locked */
306
 
306
  __HAL_LOCK(hpcd);
307
  if (hpcd->State == HAL_PCD_STATE_READY)
307
 
308
  {
308
  if (hpcd->State == HAL_PCD_STATE_READY)
309
    switch (CallbackID)
309
  {
310
    {
310
    switch (CallbackID)
311
      case HAL_PCD_SOF_CB_ID :
311
    {
312
        hpcd->SOFCallback = pCallback;
312
      case HAL_PCD_SOF_CB_ID :
313
        break;
313
        hpcd->SOFCallback = pCallback;
314
 
314
        break;
315
      case HAL_PCD_SETUPSTAGE_CB_ID :
315
 
316
        hpcd->SetupStageCallback = pCallback;
316
      case HAL_PCD_SETUPSTAGE_CB_ID :
317
        break;
317
        hpcd->SetupStageCallback = pCallback;
318
 
318
        break;
319
      case HAL_PCD_RESET_CB_ID :
319
 
320
        hpcd->ResetCallback = pCallback;
320
      case HAL_PCD_RESET_CB_ID :
321
        break;
321
        hpcd->ResetCallback = pCallback;
322
 
322
        break;
323
      case HAL_PCD_SUSPEND_CB_ID :
323
 
324
        hpcd->SuspendCallback = pCallback;
324
      case HAL_PCD_SUSPEND_CB_ID :
325
        break;
325
        hpcd->SuspendCallback = pCallback;
326
 
326
        break;
327
      case HAL_PCD_RESUME_CB_ID :
327
 
328
        hpcd->ResumeCallback = pCallback;
328
      case HAL_PCD_RESUME_CB_ID :
329
        break;
329
        hpcd->ResumeCallback = pCallback;
330
 
330
        break;
331
      case HAL_PCD_CONNECT_CB_ID :
331
 
332
        hpcd->ConnectCallback = pCallback;
332
      case HAL_PCD_CONNECT_CB_ID :
333
        break;
333
        hpcd->ConnectCallback = pCallback;
334
 
334
        break;
335
      case HAL_PCD_DISCONNECT_CB_ID :
335
 
336
        hpcd->DisconnectCallback = pCallback;
336
      case HAL_PCD_DISCONNECT_CB_ID :
337
        break;
337
        hpcd->DisconnectCallback = pCallback;
338
 
338
        break;
339
      case HAL_PCD_MSPINIT_CB_ID :
339
 
340
        hpcd->MspInitCallback = pCallback;
340
      case HAL_PCD_MSPINIT_CB_ID :
341
        break;
341
        hpcd->MspInitCallback = pCallback;
342
 
342
        break;
343
      case HAL_PCD_MSPDEINIT_CB_ID :
343
 
344
        hpcd->MspDeInitCallback = pCallback;
344
      case HAL_PCD_MSPDEINIT_CB_ID :
345
        break;
345
        hpcd->MspDeInitCallback = pCallback;
346
 
346
        break;
347
      default :
347
 
348
        /* Update the error code */
348
      default :
349
        hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK;
349
        /* Update the error code */
350
        /* Return error status */
350
        hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK;
351
        status =  HAL_ERROR;
351
        /* Return error status */
352
        break;
352
        status =  HAL_ERROR;
353
    }
353
        break;
354
  }
354
    }
355
  else if (hpcd->State == HAL_PCD_STATE_RESET)
355
  }
356
  {
356
  else if (hpcd->State == HAL_PCD_STATE_RESET)
357
    switch (CallbackID)
357
  {
358
    {
358
    switch (CallbackID)
359
      case HAL_PCD_MSPINIT_CB_ID :
359
    {
360
        hpcd->MspInitCallback = pCallback;
360
      case HAL_PCD_MSPINIT_CB_ID :
361
        break;
361
        hpcd->MspInitCallback = pCallback;
362
 
362
        break;
363
      case HAL_PCD_MSPDEINIT_CB_ID :
363
 
364
        hpcd->MspDeInitCallback = pCallback;
364
      case HAL_PCD_MSPDEINIT_CB_ID :
365
        break;
365
        hpcd->MspDeInitCallback = pCallback;
366
 
366
        break;
367
      default :
367
 
368
        /* Update the error code */
368
      default :
369
        hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK;
369
        /* Update the error code */
370
        /* Return error status */
370
        hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK;
371
        status =  HAL_ERROR;
371
        /* Return error status */
372
        break;
372
        status =  HAL_ERROR;
373
    }
373
        break;
374
  }
374
    }
375
  else
375
  }
376
  {
376
  else
377
    /* Update the error code */
377
  {
378
    hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK;
378
    /* Update the error code */
379
    /* Return error status */
379
    hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK;
380
    status =  HAL_ERROR;
380
    /* Return error status */
381
  }
381
    status =  HAL_ERROR;
382
 
382
  }
383
  /* Release Lock */
383
 
384
  __HAL_UNLOCK(hpcd);
384
  /* Release Lock */
385
  return status;
385
  __HAL_UNLOCK(hpcd);
386
}
386
  return status;
387
 
387
}
388
/**
388
 
389
  * @brief  Unregister an USB PCD Callback
389
/**
390
  *         USB PCD callabck is redirected to the weak predefined callback
390
  * @brief  Unregister an USB PCD Callback
391
  * @param  hpcd USB PCD handle
391
  *         USB PCD callback is redirected to the weak predefined callback
392
  * @param  CallbackID ID of the callback to be unregistered
392
  * @param  hpcd USB PCD handle
393
  *         This parameter can be one of the following values:
393
  * @param  CallbackID ID of the callback to be unregistered
394
  *          @arg @ref HAL_PCD_SOF_CB_ID USB PCD SOF callback ID
394
  *         This parameter can be one of the following values:
395
  *          @arg @ref HAL_PCD_SETUPSTAGE_CB_ID USB PCD Setup callback ID
395
  *          @arg @ref HAL_PCD_SOF_CB_ID USB PCD SOF callback ID
396
  *          @arg @ref HAL_PCD_RESET_CB_ID USB PCD Reset callback ID
396
  *          @arg @ref HAL_PCD_SETUPSTAGE_CB_ID USB PCD Setup callback ID
397
  *          @arg @ref HAL_PCD_SUSPEND_CB_ID USB PCD Suspend callback ID
397
  *          @arg @ref HAL_PCD_RESET_CB_ID USB PCD Reset callback ID
398
  *          @arg @ref HAL_PCD_RESUME_CB_ID USB PCD Resume callback ID
398
  *          @arg @ref HAL_PCD_SUSPEND_CB_ID USB PCD Suspend callback ID
399
  *          @arg @ref HAL_PCD_CONNECT_CB_ID USB PCD Connect callback ID
399
  *          @arg @ref HAL_PCD_RESUME_CB_ID USB PCD Resume callback ID
400
  *          @arg @ref HAL_PCD_DISCONNECT_CB_ID OTG PCD Disconnect callback ID
400
  *          @arg @ref HAL_PCD_CONNECT_CB_ID USB PCD Connect callback ID
401
  *          @arg @ref HAL_PCD_MSPINIT_CB_ID MspDeInit callback ID
401
  *          @arg @ref HAL_PCD_DISCONNECT_CB_ID USB PCD Disconnect callback ID
402
  *          @arg @ref HAL_PCD_MSPDEINIT_CB_ID MspDeInit callback ID
402
  *          @arg @ref HAL_PCD_MSPINIT_CB_ID MspDeInit callback ID
403
  * @retval HAL status
403
  *          @arg @ref HAL_PCD_MSPDEINIT_CB_ID MspDeInit callback ID
404
  */
404
  * @retval HAL status
405
HAL_StatusTypeDef HAL_PCD_UnRegisterCallback(PCD_HandleTypeDef *hpcd, HAL_PCD_CallbackIDTypeDef CallbackID)
405
  */
406
{
406
HAL_StatusTypeDef HAL_PCD_UnRegisterCallback(PCD_HandleTypeDef *hpcd, HAL_PCD_CallbackIDTypeDef CallbackID)
407
  HAL_StatusTypeDef status = HAL_OK;
407
{
408
 
408
  HAL_StatusTypeDef status = HAL_OK;
409
  /* Process locked */
409
 
410
  __HAL_LOCK(hpcd);
410
  /* Process locked */
411
 
411
  __HAL_LOCK(hpcd);
412
  /* Setup Legacy weak Callbacks  */
412
 
413
  if (hpcd->State == HAL_PCD_STATE_READY)
413
  /* Setup Legacy weak Callbacks  */
414
  {
414
  if (hpcd->State == HAL_PCD_STATE_READY)
415
    switch (CallbackID)
415
  {
416
    {
416
    switch (CallbackID)
417
      case HAL_PCD_SOF_CB_ID :
417
    {
418
        hpcd->SOFCallback = HAL_PCD_SOFCallback;
418
      case HAL_PCD_SOF_CB_ID :
419
        break;
419
        hpcd->SOFCallback = HAL_PCD_SOFCallback;
420
 
420
        break;
421
      case HAL_PCD_SETUPSTAGE_CB_ID :
421
 
422
        hpcd->SetupStageCallback = HAL_PCD_SetupStageCallback;
422
      case HAL_PCD_SETUPSTAGE_CB_ID :
423
        break;
423
        hpcd->SetupStageCallback = HAL_PCD_SetupStageCallback;
424
 
424
        break;
425
      case HAL_PCD_RESET_CB_ID :
425
 
426
        hpcd->ResetCallback = HAL_PCD_ResetCallback;
426
      case HAL_PCD_RESET_CB_ID :
427
        break;
427
        hpcd->ResetCallback = HAL_PCD_ResetCallback;
428
 
428
        break;
429
      case HAL_PCD_SUSPEND_CB_ID :
429
 
430
        hpcd->SuspendCallback = HAL_PCD_SuspendCallback;
430
      case HAL_PCD_SUSPEND_CB_ID :
431
        break;
431
        hpcd->SuspendCallback = HAL_PCD_SuspendCallback;
432
 
432
        break;
433
      case HAL_PCD_RESUME_CB_ID :
433
 
434
        hpcd->ResumeCallback = HAL_PCD_ResumeCallback;
434
      case HAL_PCD_RESUME_CB_ID :
435
        break;
435
        hpcd->ResumeCallback = HAL_PCD_ResumeCallback;
436
 
436
        break;
437
      case HAL_PCD_CONNECT_CB_ID :
437
 
438
        hpcd->ConnectCallback = HAL_PCD_ConnectCallback;
438
      case HAL_PCD_CONNECT_CB_ID :
439
        break;
439
        hpcd->ConnectCallback = HAL_PCD_ConnectCallback;
440
 
440
        break;
441
      case HAL_PCD_DISCONNECT_CB_ID :
441
 
442
        hpcd->DisconnectCallback = HAL_PCD_DisconnectCallback;
442
      case HAL_PCD_DISCONNECT_CB_ID :
443
        break;
443
        hpcd->DisconnectCallback = HAL_PCD_DisconnectCallback;
444
 
444
        break;
445
      case HAL_PCD_MSPINIT_CB_ID :
445
 
446
        hpcd->MspInitCallback = HAL_PCD_MspInit;
446
      case HAL_PCD_MSPINIT_CB_ID :
447
        break;
447
        hpcd->MspInitCallback = HAL_PCD_MspInit;
448
 
448
        break;
449
      case HAL_PCD_MSPDEINIT_CB_ID :
449
 
450
        hpcd->MspDeInitCallback = HAL_PCD_MspDeInit;
450
      case HAL_PCD_MSPDEINIT_CB_ID :
451
        break;
451
        hpcd->MspDeInitCallback = HAL_PCD_MspDeInit;
452
 
452
        break;
453
      default :
453
 
454
        /* Update the error code */
454
      default :
455
        hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK;
455
        /* Update the error code */
456
 
456
        hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK;
457
        /* Return error status */
457
 
458
        status =  HAL_ERROR;
458
        /* Return error status */
459
        break;
459
        status =  HAL_ERROR;
460
    }
460
        break;
461
  }
461
    }
462
  else if (hpcd->State == HAL_PCD_STATE_RESET)
462
  }
463
  {
463
  else if (hpcd->State == HAL_PCD_STATE_RESET)
464
    switch (CallbackID)
464
  {
465
    {
465
    switch (CallbackID)
466
      case HAL_PCD_MSPINIT_CB_ID :
466
    {
467
        hpcd->MspInitCallback = HAL_PCD_MspInit;
467
      case HAL_PCD_MSPINIT_CB_ID :
468
        break;
468
        hpcd->MspInitCallback = HAL_PCD_MspInit;
469
 
469
        break;
470
      case HAL_PCD_MSPDEINIT_CB_ID :
470
 
471
        hpcd->MspDeInitCallback = HAL_PCD_MspDeInit;
471
      case HAL_PCD_MSPDEINIT_CB_ID :
472
        break;
472
        hpcd->MspDeInitCallback = HAL_PCD_MspDeInit;
473
 
473
        break;
474
      default :
474
 
475
        /* Update the error code */
475
      default :
476
        hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK;
476
        /* Update the error code */
477
 
477
        hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK;
478
        /* Return error status */
478
 
479
        status =  HAL_ERROR;
479
        /* Return error status */
480
        break;
480
        status =  HAL_ERROR;
481
    }
481
        break;
482
  }
482
    }
483
  else
483
  }
484
  {
484
  else
485
    /* Update the error code */
485
  {
486
    hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK;
486
    /* Update the error code */
487
 
487
    hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK;
488
    /* Return error status */
488
 
489
    status =  HAL_ERROR;
489
    /* Return error status */
490
  }
490
    status =  HAL_ERROR;
491
 
491
  }
492
  /* Release Lock */
492
 
493
  __HAL_UNLOCK(hpcd);
493
  /* Release Lock */
494
  return status;
494
  __HAL_UNLOCK(hpcd);
495
}
495
  return status;
496
 
496
}
497
/**
497
 
498
  * @brief  Register USB PCD Data OUT Stage Callback
498
/**
499
  *         To be used instead of the weak HAL_PCD_DataOutStageCallback() predefined callback
499
  * @brief  Register USB PCD Data OUT Stage Callback
500
  * @param  hpcd PCD handle
500
  *         To be used instead of the weak HAL_PCD_DataOutStageCallback() predefined callback
501
  * @param  pCallback pointer to the USB PCD Data OUT Stage Callback function
501
  * @param  hpcd PCD handle
502
  * @retval HAL status
502
  * @param  pCallback pointer to the USB PCD Data OUT Stage Callback function
503
  */
503
  * @retval HAL status
504
HAL_StatusTypeDef HAL_PCD_RegisterDataOutStageCallback(PCD_HandleTypeDef *hpcd,
504
  */
505
                                                       pPCD_DataOutStageCallbackTypeDef pCallback)
505
HAL_StatusTypeDef HAL_PCD_RegisterDataOutStageCallback(PCD_HandleTypeDef *hpcd,
506
{
506
                                                       pPCD_DataOutStageCallbackTypeDef pCallback)
507
  HAL_StatusTypeDef status = HAL_OK;
507
{
508
 
508
  HAL_StatusTypeDef status = HAL_OK;
509
  if (pCallback == NULL)
509
 
510
  {
510
  if (pCallback == NULL)
511
    /* Update the error code */
511
  {
512
    hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK;
512
    /* Update the error code */
513
 
513
    hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK;
514
    return HAL_ERROR;
514
 
515
  }
515
    return HAL_ERROR;
516
 
516
  }
517
  /* Process locked */
517
 
518
  __HAL_LOCK(hpcd);
518
  /* Process locked */
519
 
519
  __HAL_LOCK(hpcd);
520
  if (hpcd->State == HAL_PCD_STATE_READY)
520
 
521
  {
521
  if (hpcd->State == HAL_PCD_STATE_READY)
522
    hpcd->DataOutStageCallback = pCallback;
522
  {
523
  }
523
    hpcd->DataOutStageCallback = pCallback;
524
  else
524
  }
525
  {
525
  else
526
    /* Update the error code */
526
  {
527
    hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK;
527
    /* Update the error code */
528
 
528
    hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK;
529
    /* Return error status */
529
 
530
    status =  HAL_ERROR;
530
    /* Return error status */
531
  }
531
    status =  HAL_ERROR;
532
 
532
  }
533
  /* Release Lock */
533
 
534
  __HAL_UNLOCK(hpcd);
534
  /* Release Lock */
535
 
535
  __HAL_UNLOCK(hpcd);
536
  return status;
536
 
537
}
537
  return status;
538
 
538
}
539
/**
539
 
540
  * @brief  Unregister the USB PCD Data OUT Stage Callback
540
/**
541
  *         USB PCD Data OUT Stage Callback is redirected to the weak HAL_PCD_DataOutStageCallback() predefined callback
541
  * @brief  Unregister the USB PCD Data OUT Stage Callback
542
  * @param  hpcd PCD handle
542
  *         USB PCD Data OUT Stage Callback is redirected to the weak HAL_PCD_DataOutStageCallback() predefined callback
543
  * @retval HAL status
543
  * @param  hpcd PCD handle
544
  */
544
  * @retval HAL status
545
HAL_StatusTypeDef HAL_PCD_UnRegisterDataOutStageCallback(PCD_HandleTypeDef *hpcd)
545
  */
546
{
546
HAL_StatusTypeDef HAL_PCD_UnRegisterDataOutStageCallback(PCD_HandleTypeDef *hpcd)
547
  HAL_StatusTypeDef status = HAL_OK;
547
{
548
 
548
  HAL_StatusTypeDef status = HAL_OK;
549
  /* Process locked */
549
 
550
  __HAL_LOCK(hpcd);
550
  /* Process locked */
551
 
551
  __HAL_LOCK(hpcd);
552
  if (hpcd->State == HAL_PCD_STATE_READY)
552
 
553
  {
553
  if (hpcd->State == HAL_PCD_STATE_READY)
554
    hpcd->DataOutStageCallback = HAL_PCD_DataOutStageCallback; /* Legacy weak DataOutStageCallback  */
554
  {
555
  }
555
    hpcd->DataOutStageCallback = HAL_PCD_DataOutStageCallback; /* Legacy weak DataOutStageCallback  */
556
  else
556
  }
557
  {
557
  else
558
    /* Update the error code */
558
  {
559
    hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK;
559
    /* Update the error code */
560
 
560
    hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK;
561
    /* Return error status */
561
 
562
    status =  HAL_ERROR;
562
    /* Return error status */
563
  }
563
    status =  HAL_ERROR;
564
 
564
  }
565
  /* Release Lock */
565
 
566
  __HAL_UNLOCK(hpcd);
566
  /* Release Lock */
567
 
567
  __HAL_UNLOCK(hpcd);
568
  return status;
568
 
569
}
569
  return status;
570
 
570
}
571
/**
571
 
572
  * @brief  Register USB PCD Data IN Stage Callback
572
/**
573
  *         To be used instead of the weak HAL_PCD_DataInStageCallback() predefined callback
573
  * @brief  Register USB PCD Data IN Stage Callback
574
  * @param  hpcd PCD handle
574
  *         To be used instead of the weak HAL_PCD_DataInStageCallback() predefined callback
575
  * @param  pCallback pointer to the USB PCD Data IN Stage Callback function
575
  * @param  hpcd PCD handle
576
  * @retval HAL status
576
  * @param  pCallback pointer to the USB PCD Data IN Stage Callback function
577
  */
577
  * @retval HAL status
578
HAL_StatusTypeDef HAL_PCD_RegisterDataInStageCallback(PCD_HandleTypeDef *hpcd,
578
  */
579
                                                      pPCD_DataInStageCallbackTypeDef pCallback)
579
HAL_StatusTypeDef HAL_PCD_RegisterDataInStageCallback(PCD_HandleTypeDef *hpcd,
580
{
580
                                                      pPCD_DataInStageCallbackTypeDef pCallback)
581
  HAL_StatusTypeDef status = HAL_OK;
581
{
582
 
582
  HAL_StatusTypeDef status = HAL_OK;
583
  if (pCallback == NULL)
583
 
584
  {
584
  if (pCallback == NULL)
585
    /* Update the error code */
585
  {
586
    hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK;
586
    /* Update the error code */
587
 
587
    hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK;
588
    return HAL_ERROR;
588
 
589
  }
589
    return HAL_ERROR;
590
 
590
  }
591
  /* Process locked */
591
 
592
  __HAL_LOCK(hpcd);
592
  /* Process locked */
593
 
593
  __HAL_LOCK(hpcd);
594
  if (hpcd->State == HAL_PCD_STATE_READY)
594
 
595
  {
595
  if (hpcd->State == HAL_PCD_STATE_READY)
596
    hpcd->DataInStageCallback = pCallback;
596
  {
597
  }
597
    hpcd->DataInStageCallback = pCallback;
598
  else
598
  }
599
  {
599
  else
600
    /* Update the error code */
600
  {
601
    hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK;
601
    /* Update the error code */
602
 
602
    hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK;
603
    /* Return error status */
603
 
604
    status =  HAL_ERROR;
604
    /* Return error status */
605
  }
605
    status =  HAL_ERROR;
606
 
606
  }
607
  /* Release Lock */
607
 
608
  __HAL_UNLOCK(hpcd);
608
  /* Release Lock */
609
 
609
  __HAL_UNLOCK(hpcd);
610
  return status;
610
 
611
}
611
  return status;
612
 
612
}
613
/**
613
 
614
  * @brief  Unregister the USB PCD Data IN Stage Callback
614
/**
615
  *         USB PCD Data OUT Stage Callback is redirected to the weak HAL_PCD_DataInStageCallback() predefined callback
615
  * @brief  Unregister the USB PCD Data IN Stage Callback
616
  * @param  hpcd PCD handle
616
  *         USB PCD Data OUT Stage Callback is redirected to the weak HAL_PCD_DataInStageCallback() predefined callback
617
  * @retval HAL status
617
  * @param  hpcd PCD handle
618
  */
618
  * @retval HAL status
619
HAL_StatusTypeDef HAL_PCD_UnRegisterDataInStageCallback(PCD_HandleTypeDef *hpcd)
619
  */
620
{
620
HAL_StatusTypeDef HAL_PCD_UnRegisterDataInStageCallback(PCD_HandleTypeDef *hpcd)
621
  HAL_StatusTypeDef status = HAL_OK;
621
{
622
 
622
  HAL_StatusTypeDef status = HAL_OK;
623
  /* Process locked */
623
 
624
  __HAL_LOCK(hpcd);
624
  /* Process locked */
625
 
625
  __HAL_LOCK(hpcd);
626
  if (hpcd->State == HAL_PCD_STATE_READY)
626
 
627
  {
627
  if (hpcd->State == HAL_PCD_STATE_READY)
628
    hpcd->DataInStageCallback = HAL_PCD_DataInStageCallback; /* Legacy weak DataInStageCallback  */
628
  {
629
  }
629
    hpcd->DataInStageCallback = HAL_PCD_DataInStageCallback; /* Legacy weak DataInStageCallback  */
630
  else
630
  }
631
  {
631
  else
632
    /* Update the error code */
632
  {
633
    hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK;
633
    /* Update the error code */
634
 
634
    hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK;
635
    /* Return error status */
635
 
636
    status =  HAL_ERROR;
636
    /* Return error status */
637
  }
637
    status =  HAL_ERROR;
638
 
638
  }
639
  /* Release Lock */
639
 
640
  __HAL_UNLOCK(hpcd);
640
  /* Release Lock */
641
 
641
  __HAL_UNLOCK(hpcd);
642
  return status;
642
 
643
}
643
  return status;
644
 
644
}
645
/**
645
 
646
  * @brief  Register USB PCD Iso OUT incomplete Callback
646
/**
647
  *         To be used instead of the weak HAL_PCD_ISOOUTIncompleteCallback() predefined callback
647
  * @brief  Register USB PCD Iso OUT incomplete Callback
648
  * @param  hpcd PCD handle
648
  *         To be used instead of the weak HAL_PCD_ISOOUTIncompleteCallback() predefined callback
649
  * @param  pCallback pointer to the USB PCD Iso OUT incomplete Callback function
649
  * @param  hpcd PCD handle
650
  * @retval HAL status
650
  * @param  pCallback pointer to the USB PCD Iso OUT incomplete Callback function
651
  */
651
  * @retval HAL status
652
HAL_StatusTypeDef HAL_PCD_RegisterIsoOutIncpltCallback(PCD_HandleTypeDef *hpcd,
652
  */
653
                                                       pPCD_IsoOutIncpltCallbackTypeDef pCallback)
653
HAL_StatusTypeDef HAL_PCD_RegisterIsoOutIncpltCallback(PCD_HandleTypeDef *hpcd,
654
{
654
                                                       pPCD_IsoOutIncpltCallbackTypeDef pCallback)
655
  HAL_StatusTypeDef status = HAL_OK;
655
{
656
 
656
  HAL_StatusTypeDef status = HAL_OK;
657
  if (pCallback == NULL)
657
 
658
  {
658
  if (pCallback == NULL)
659
    /* Update the error code */
659
  {
660
    hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK;
660
    /* Update the error code */
661
 
661
    hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK;
662
    return HAL_ERROR;
662
 
663
  }
663
    return HAL_ERROR;
664
 
664
  }
665
  /* Process locked */
665
 
666
  __HAL_LOCK(hpcd);
666
  /* Process locked */
667
 
667
  __HAL_LOCK(hpcd);
668
  if (hpcd->State == HAL_PCD_STATE_READY)
668
 
669
  {
669
  if (hpcd->State == HAL_PCD_STATE_READY)
670
    hpcd->ISOOUTIncompleteCallback = pCallback;
670
  {
671
  }
671
    hpcd->ISOOUTIncompleteCallback = pCallback;
672
  else
672
  }
673
  {
673
  else
674
    /* Update the error code */
674
  {
675
    hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK;
675
    /* Update the error code */
676
 
676
    hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK;
677
    /* Return error status */
677
 
678
    status =  HAL_ERROR;
678
    /* Return error status */
679
  }
679
    status =  HAL_ERROR;
680
 
680
  }
681
  /* Release Lock */
681
 
682
  __HAL_UNLOCK(hpcd);
682
  /* Release Lock */
683
 
683
  __HAL_UNLOCK(hpcd);
684
  return status;
684
 
685
}
685
  return status;
686
 
686
}
687
/**
687
 
688
  * @brief  Unregister the USB PCD Iso OUT incomplete Callback
688
/**
689
  *         USB PCD Iso OUT incomplete Callback is redirected
689
  * @brief  Unregister the USB PCD Iso OUT incomplete Callback
690
  *         to the weak HAL_PCD_ISOOUTIncompleteCallback() predefined callback
690
  *         USB PCD Iso OUT incomplete Callback is redirected
691
  * @param  hpcd PCD handle
691
  *         to the weak HAL_PCD_ISOOUTIncompleteCallback() predefined callback
692
  * @retval HAL status
692
  * @param  hpcd PCD handle
693
  */
693
  * @retval HAL status
694
HAL_StatusTypeDef HAL_PCD_UnRegisterIsoOutIncpltCallback(PCD_HandleTypeDef *hpcd)
694
  */
695
{
695
HAL_StatusTypeDef HAL_PCD_UnRegisterIsoOutIncpltCallback(PCD_HandleTypeDef *hpcd)
696
  HAL_StatusTypeDef status = HAL_OK;
696
{
697
 
697
  HAL_StatusTypeDef status = HAL_OK;
698
  /* Process locked */
698
 
699
  __HAL_LOCK(hpcd);
699
  /* Process locked */
700
 
700
  __HAL_LOCK(hpcd);
701
  if (hpcd->State == HAL_PCD_STATE_READY)
701
 
702
  {
702
  if (hpcd->State == HAL_PCD_STATE_READY)
703
    hpcd->ISOOUTIncompleteCallback = HAL_PCD_ISOOUTIncompleteCallback; /* Legacy weak ISOOUTIncompleteCallback  */
703
  {
704
  }
704
    hpcd->ISOOUTIncompleteCallback = HAL_PCD_ISOOUTIncompleteCallback; /* Legacy weak ISOOUTIncompleteCallback  */
705
  else
705
  }
706
  {
706
  else
707
    /* Update the error code */
707
  {
708
    hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK;
708
    /* Update the error code */
709
 
709
    hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK;
710
    /* Return error status */
710
 
711
    status =  HAL_ERROR;
711
    /* Return error status */
712
  }
712
    status =  HAL_ERROR;
713
 
713
  }
714
  /* Release Lock */
714
 
715
  __HAL_UNLOCK(hpcd);
715
  /* Release Lock */
716
 
716
  __HAL_UNLOCK(hpcd);
717
  return status;
717
 
718
}
718
  return status;
719
 
719
}
720
/**
720
 
721
  * @brief  Register USB PCD Iso IN incomplete Callback
721
/**
722
  *         To be used instead of the weak HAL_PCD_ISOINIncompleteCallback() predefined callback
722
  * @brief  Register USB PCD Iso IN incomplete Callback
723
  * @param  hpcd PCD handle
723
  *         To be used instead of the weak HAL_PCD_ISOINIncompleteCallback() predefined callback
724
  * @param  pCallback pointer to the USB PCD Iso IN incomplete Callback function
724
  * @param  hpcd PCD handle
725
  * @retval HAL status
725
  * @param  pCallback pointer to the USB PCD Iso IN incomplete Callback function
726
  */
726
  * @retval HAL status
727
HAL_StatusTypeDef HAL_PCD_RegisterIsoInIncpltCallback(PCD_HandleTypeDef *hpcd,
727
  */
728
                                                      pPCD_IsoInIncpltCallbackTypeDef pCallback)
728
HAL_StatusTypeDef HAL_PCD_RegisterIsoInIncpltCallback(PCD_HandleTypeDef *hpcd,
729
{
729
                                                      pPCD_IsoInIncpltCallbackTypeDef pCallback)
730
  HAL_StatusTypeDef status = HAL_OK;
730
{
731
 
731
  HAL_StatusTypeDef status = HAL_OK;
732
  if (pCallback == NULL)
732
 
733
  {
733
  if (pCallback == NULL)
734
    /* Update the error code */
734
  {
735
    hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK;
735
    /* Update the error code */
736
 
736
    hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK;
737
    return HAL_ERROR;
737
 
738
  }
738
    return HAL_ERROR;
739
 
739
  }
740
  /* Process locked */
740
 
741
  __HAL_LOCK(hpcd);
741
  /* Process locked */
742
 
742
  __HAL_LOCK(hpcd);
743
  if (hpcd->State == HAL_PCD_STATE_READY)
743
 
744
  {
744
  if (hpcd->State == HAL_PCD_STATE_READY)
745
    hpcd->ISOINIncompleteCallback = pCallback;
745
  {
746
  }
746
    hpcd->ISOINIncompleteCallback = pCallback;
747
  else
747
  }
748
  {
748
  else
749
    /* Update the error code */
749
  {
750
    hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK;
750
    /* Update the error code */
751
 
751
    hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK;
752
    /* Return error status */
752
 
753
    status =  HAL_ERROR;
753
    /* Return error status */
754
  }
754
    status =  HAL_ERROR;
755
 
755
  }
756
  /* Release Lock */
756
 
757
  __HAL_UNLOCK(hpcd);
757
  /* Release Lock */
758
 
758
  __HAL_UNLOCK(hpcd);
759
  return status;
759
 
760
}
760
  return status;
761
 
761
}
762
/**
762
 
763
  * @brief  Unregister the USB PCD Iso IN incomplete Callback
763
/**
764
  *         USB PCD Iso IN incomplete Callback is redirected
764
  * @brief  Unregister the USB PCD Iso IN incomplete Callback
765
  *         to the weak HAL_PCD_ISOINIncompleteCallback() predefined callback
765
  *         USB PCD Iso IN incomplete Callback is redirected
766
  * @param  hpcd PCD handle
766
  *         to the weak HAL_PCD_ISOINIncompleteCallback() predefined callback
767
  * @retval HAL status
767
  * @param  hpcd PCD handle
768
  */
768
  * @retval HAL status
769
HAL_StatusTypeDef HAL_PCD_UnRegisterIsoInIncpltCallback(PCD_HandleTypeDef *hpcd)
769
  */
770
{
770
HAL_StatusTypeDef HAL_PCD_UnRegisterIsoInIncpltCallback(PCD_HandleTypeDef *hpcd)
771
  HAL_StatusTypeDef status = HAL_OK;
771
{
772
 
772
  HAL_StatusTypeDef status = HAL_OK;
773
  /* Process locked */
773
 
774
  __HAL_LOCK(hpcd);
774
  /* Process locked */
775
 
775
  __HAL_LOCK(hpcd);
776
  if (hpcd->State == HAL_PCD_STATE_READY)
776
 
777
  {
777
  if (hpcd->State == HAL_PCD_STATE_READY)
778
    hpcd->ISOINIncompleteCallback = HAL_PCD_ISOINIncompleteCallback; /* Legacy weak ISOINIncompleteCallback  */
778
  {
779
  }
779
    hpcd->ISOINIncompleteCallback = HAL_PCD_ISOINIncompleteCallback; /* Legacy weak ISOINIncompleteCallback  */
780
  else
780
  }
781
  {
781
  else
782
    /* Update the error code */
782
  {
783
    hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK;
783
    /* Update the error code */
784
 
784
    hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK;
785
    /* Return error status */
785
 
786
    status =  HAL_ERROR;
786
    /* Return error status */
787
  }
787
    status =  HAL_ERROR;
788
 
788
  }
789
  /* Release Lock */
789
 
790
  __HAL_UNLOCK(hpcd);
790
  /* Release Lock */
791
 
791
  __HAL_UNLOCK(hpcd);
792
  return status;
792
 
793
}
793
  return status;
794
 
794
}
795
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
795
 
796
 
796
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
797
/**
797
 
798
  * @}
798
/**
799
  */
799
  * @}
800
 
800
  */
801
/** @defgroup PCD_Exported_Functions_Group2 Input and Output operation functions
801
 
802
  *  @brief   Data transfers functions
802
/** @defgroup PCD_Exported_Functions_Group2 Input and Output operation functions
803
  *
803
  *  @brief   Data transfers functions
804
@verbatim
804
  *
805
 ===============================================================================
805
@verbatim
806
                      ##### IO operation functions #####
806
 ===============================================================================
807
 ===============================================================================
807
                      ##### IO operation functions #####
808
    [..]
808
 ===============================================================================
809
    This subsection provides a set of functions allowing to manage the PCD data
809
    [..]
810
    transfers.
810
    This subsection provides a set of functions allowing to manage the PCD data
811
 
811
    transfers.
812
@endverbatim
812
 
813
  * @{
813
@endverbatim
814
  */
814
  * @{
815
 
815
  */
816
/**
816
 
817
  * @brief  Start the USB device
817
/**
818
  * @param  hpcd PCD handle
818
  * @brief  Start the USB device
819
  * @retval HAL status
819
  * @param  hpcd PCD handle
820
  */
820
  * @retval HAL status
821
HAL_StatusTypeDef HAL_PCD_Start(PCD_HandleTypeDef *hpcd)
821
  */
822
{
822
HAL_StatusTypeDef HAL_PCD_Start(PCD_HandleTypeDef *hpcd)
823
  __HAL_LOCK(hpcd);
823
{
824
  __HAL_PCD_ENABLE(hpcd);
824
  __HAL_LOCK(hpcd);
825
 
825
  __HAL_PCD_ENABLE(hpcd);
826
  HAL_PCDEx_SetConnectionState(hpcd, 1U);
826
 
827
 
827
  HAL_PCDEx_SetConnectionState(hpcd, 1U);
828
  (void)USB_DevConnect(hpcd->Instance);
828
 
829
  __HAL_UNLOCK(hpcd);
829
  (void)USB_DevConnect(hpcd->Instance);
830
 
830
  __HAL_UNLOCK(hpcd);
831
  return HAL_OK;
831
 
832
}
832
  return HAL_OK;
833
 
833
}
834
/**
834
 
835
  * @brief  Stop the USB device.
835
/**
836
  * @param  hpcd PCD handle
836
  * @brief  Stop the USB device.
837
  * @retval HAL status
837
  * @param  hpcd PCD handle
838
  */
838
  * @retval HAL status
839
HAL_StatusTypeDef HAL_PCD_Stop(PCD_HandleTypeDef *hpcd)
839
  */
840
{
840
HAL_StatusTypeDef HAL_PCD_Stop(PCD_HandleTypeDef *hpcd)
841
  __HAL_LOCK(hpcd);
841
{
842
  __HAL_PCD_DISABLE(hpcd);
842
  __HAL_LOCK(hpcd);
843
 
843
  __HAL_PCD_DISABLE(hpcd);
844
  HAL_PCDEx_SetConnectionState(hpcd, 0U);
844
 
845
 
845
  HAL_PCDEx_SetConnectionState(hpcd, 0U);
846
  (void)USB_DevDisconnect(hpcd->Instance);
846
 
847
  __HAL_UNLOCK(hpcd);
847
  (void)USB_DevDisconnect(hpcd->Instance);
848
 
848
  __HAL_UNLOCK(hpcd);
849
  return HAL_OK;
849
 
850
}
850
  return HAL_OK;
851
 
851
}
852
 
852
 
853
/**
853
 
854
  * @brief  This function handles PCD interrupt request.
854
/**
855
  * @param  hpcd PCD handle
855
  * @brief  This function handles PCD interrupt request.
856
  * @retval HAL status
856
  * @param  hpcd PCD handle
857
  */
857
  * @retval HAL status
858
void HAL_PCD_IRQHandler(PCD_HandleTypeDef *hpcd)
858
  */
859
{
859
void HAL_PCD_IRQHandler(PCD_HandleTypeDef *hpcd)
860
  if (__HAL_PCD_GET_FLAG(hpcd, USB_ISTR_CTR))
860
{
861
  {
861
  uint32_t wIstr = USB_ReadInterrupts(hpcd->Instance);
862
    /* servicing of the endpoint correct transfer interrupt */
862
 
863
    /* clear of the CTR flag into the sub */
863
  if ((wIstr & USB_ISTR_CTR) == USB_ISTR_CTR)
864
    (void)PCD_EP_ISR_Handler(hpcd);
864
  {
865
  }
865
    /* servicing of the endpoint correct transfer interrupt */
866
 
866
    /* clear of the CTR flag into the sub */
867
  if (__HAL_PCD_GET_FLAG(hpcd, USB_ISTR_RESET))
867
    (void)PCD_EP_ISR_Handler(hpcd);
868
  {
868
 
869
    __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_RESET);
869
    return;
870
 
870
  }
871
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
871
 
872
    hpcd->ResetCallback(hpcd);
872
  if ((wIstr & USB_ISTR_RESET) == USB_ISTR_RESET)
873
#else
873
  {
874
    HAL_PCD_ResetCallback(hpcd);
874
    __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_RESET);
875
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
875
 
876
 
876
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
877
    (void)HAL_PCD_SetAddress(hpcd, 0U);
877
    hpcd->ResetCallback(hpcd);
878
  }
878
#else
879
 
879
    HAL_PCD_ResetCallback(hpcd);
880
  if (__HAL_PCD_GET_FLAG(hpcd, USB_ISTR_PMAOVR))
880
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
881
  {
881
 
882
    __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_PMAOVR);
882
    (void)HAL_PCD_SetAddress(hpcd, 0U);
883
  }
883
 
884
 
884
    return;
885
  if (__HAL_PCD_GET_FLAG(hpcd, USB_ISTR_ERR))
885
  }
886
  {
886
 
887
    __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_ERR);
887
  if ((wIstr & USB_ISTR_PMAOVR) == USB_ISTR_PMAOVR)
888
  }
888
  {
889
 
889
    __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_PMAOVR);
890
  if (__HAL_PCD_GET_FLAG(hpcd, USB_ISTR_WKUP))
890
 
891
  {
891
    return;
892
    hpcd->Instance->CNTR &= (uint16_t) ~(USB_CNTR_LPMODE);
892
  }
893
    hpcd->Instance->CNTR &= (uint16_t) ~(USB_CNTR_FSUSP);
893
 
894
 
894
  if ((wIstr & USB_ISTR_ERR) == USB_ISTR_ERR)
895
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
895
  {
896
    hpcd->ResumeCallback(hpcd);
896
    __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_ERR);
897
#else
897
 
898
    HAL_PCD_ResumeCallback(hpcd);
898
    return;
899
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
899
  }
900
 
900
 
901
    __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_WKUP);
901
  if ((wIstr & USB_ISTR_WKUP) == USB_ISTR_WKUP)
902
  }
902
  {
903
 
903
    hpcd->Instance->CNTR &= (uint16_t) ~(USB_CNTR_LPMODE);
904
  if (__HAL_PCD_GET_FLAG(hpcd, USB_ISTR_SUSP))
904
    hpcd->Instance->CNTR &= (uint16_t) ~(USB_CNTR_FSUSP);
905
  {
905
 
906
    /* Force low-power mode in the macrocell */
906
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
907
    hpcd->Instance->CNTR |= (uint16_t)USB_CNTR_FSUSP;
907
    hpcd->ResumeCallback(hpcd);
908
 
908
#else
909
    /* clear of the ISTR bit must be done after setting of CNTR_FSUSP */
909
    HAL_PCD_ResumeCallback(hpcd);
910
    __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_SUSP);
910
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
911
 
911
 
912
    hpcd->Instance->CNTR |= (uint16_t)USB_CNTR_LPMODE;
912
    __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_WKUP);
913
 
913
 
914
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
914
    return;
915
    hpcd->SuspendCallback(hpcd);
915
  }
916
#else
916
 
917
    HAL_PCD_SuspendCallback(hpcd);
917
  if ((wIstr & USB_ISTR_SUSP) == USB_ISTR_SUSP)
918
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
918
  {
919
  }
919
    /* Force low-power mode in the macrocell */
920
 
920
    hpcd->Instance->CNTR |= (uint16_t)USB_CNTR_FSUSP;
921
  if (__HAL_PCD_GET_FLAG(hpcd, USB_ISTR_SOF))
921
 
922
  {
922
    /* clear of the ISTR bit must be done after setting of CNTR_FSUSP */
923
    __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_SOF);
923
    __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_SUSP);
924
 
924
 
925
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
925
    hpcd->Instance->CNTR |= (uint16_t)USB_CNTR_LPMODE;
926
    hpcd->SOFCallback(hpcd);
926
 
927
#else
927
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
928
    HAL_PCD_SOFCallback(hpcd);
928
    hpcd->SuspendCallback(hpcd);
929
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
929
#else
930
  }
930
    HAL_PCD_SuspendCallback(hpcd);
931
 
931
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
932
  if (__HAL_PCD_GET_FLAG(hpcd, USB_ISTR_ESOF))
932
 
933
  {
933
    return;
934
    /* clear ESOF flag in ISTR */
934
  }
935
    __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_ESOF);
935
 
936
  }
936
  if ((wIstr & USB_ISTR_SOF) == USB_ISTR_SOF)
937
}
937
  {
938
 
938
    __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_SOF);
939
 
939
 
940
/**
940
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
941
  * @brief  Handles PCD Wakeup interrupt request.
941
    hpcd->SOFCallback(hpcd);
942
  * @param  hpcd PCD handle
942
#else
943
  * @retval HAL status
943
    HAL_PCD_SOFCallback(hpcd);
944
  */
944
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
945
void HAL_PCD_WKUP_IRQHandler(PCD_HandleTypeDef *hpcd)
945
 
946
{
946
    return;
947
  /* Clear EXTI pending Bit */
947
  }
948
  __HAL_USB_WAKEUP_EXTI_CLEAR_FLAG();
948
 
949
}
949
  if ((wIstr & USB_ISTR_ESOF) == USB_ISTR_ESOF)
950
 
950
  {
951
 
951
    /* clear ESOF flag in ISTR */
952
/**
952
    __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_ESOF);
953
  * @brief  Data OUT stage callback.
953
 
954
  * @param  hpcd PCD handle
954
    return;
955
  * @param  epnum endpoint number
955
  }
956
  * @retval None
956
}
957
  */
957
 
958
__weak void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
958
 
959
{
959
/**
960
  /* Prevent unused argument(s) compilation warning */
960
  * @brief  Handles PCD Wakeup interrupt request.
961
  UNUSED(hpcd);
961
  * @param  hpcd PCD handle
962
  UNUSED(epnum);
962
  * @retval HAL status
963
 
963
  */
964
  /* NOTE : This function should not be modified, when the callback is needed,
964
void HAL_PCD_WKUP_IRQHandler(PCD_HandleTypeDef *hpcd)
965
            the HAL_PCD_DataOutStageCallback could be implemented in the user file
965
{
966
   */
966
  /* Clear EXTI pending Bit */
967
}
967
  __HAL_USB_WAKEUP_EXTI_CLEAR_FLAG();
968
 
968
}
969
/**
969
 
970
  * @brief  Data IN stage callback
970
 
971
  * @param  hpcd PCD handle
971
/**
972
  * @param  epnum endpoint number
972
  * @brief  Data OUT stage callback.
973
  * @retval None
973
  * @param  hpcd PCD handle
974
  */
974
  * @param  epnum endpoint number
975
__weak void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
975
  * @retval None
976
{
976
  */
977
  /* Prevent unused argument(s) compilation warning */
977
__weak void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
978
  UNUSED(hpcd);
978
{
979
  UNUSED(epnum);
979
  /* Prevent unused argument(s) compilation warning */
980
 
980
  UNUSED(hpcd);
981
  /* NOTE : This function should not be modified, when the callback is needed,
981
  UNUSED(epnum);
982
            the HAL_PCD_DataInStageCallback could be implemented in the user file
982
 
983
   */
983
  /* NOTE : This function should not be modified, when the callback is needed,
984
}
984
            the HAL_PCD_DataOutStageCallback could be implemented in the user file
985
/**
985
   */
986
  * @brief  Setup stage callback
986
}
987
  * @param  hpcd PCD handle
987
 
988
  * @retval None
988
/**
989
  */
989
  * @brief  Data IN stage callback
990
__weak void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd)
990
  * @param  hpcd PCD handle
991
{
991
  * @param  epnum endpoint number
992
  /* Prevent unused argument(s) compilation warning */
992
  * @retval None
993
  UNUSED(hpcd);
993
  */
994
 
994
__weak void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
995
  /* NOTE : This function should not be modified, when the callback is needed,
995
{
996
            the HAL_PCD_SetupStageCallback could be implemented in the user file
996
  /* Prevent unused argument(s) compilation warning */
997
   */
997
  UNUSED(hpcd);
998
}
998
  UNUSED(epnum);
999
 
999
 
1000
/**
1000
  /* NOTE : This function should not be modified, when the callback is needed,
1001
  * @brief  USB Start Of Frame callback.
1001
            the HAL_PCD_DataInStageCallback could be implemented in the user file
1002
  * @param  hpcd PCD handle
1002
   */
1003
  * @retval None
1003
}
1004
  */
1004
/**
1005
__weak void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd)
1005
  * @brief  Setup stage callback
1006
{
1006
  * @param  hpcd PCD handle
1007
  /* Prevent unused argument(s) compilation warning */
1007
  * @retval None
1008
  UNUSED(hpcd);
1008
  */
1009
 
1009
__weak void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd)
1010
  /* NOTE : This function should not be modified, when the callback is needed,
1010
{
1011
            the HAL_PCD_SOFCallback could be implemented in the user file
1011
  /* Prevent unused argument(s) compilation warning */
1012
   */
1012
  UNUSED(hpcd);
1013
}
1013
 
1014
 
1014
  /* NOTE : This function should not be modified, when the callback is needed,
1015
/**
1015
            the HAL_PCD_SetupStageCallback could be implemented in the user file
1016
  * @brief  USB Reset callback.
1016
   */
1017
  * @param  hpcd PCD handle
1017
}
1018
  * @retval None
1018
 
1019
  */
1019
/**
1020
__weak void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd)
1020
  * @brief  USB Start Of Frame callback.
1021
{
1021
  * @param  hpcd PCD handle
1022
  /* Prevent unused argument(s) compilation warning */
1022
  * @retval None
1023
  UNUSED(hpcd);
1023
  */
1024
 
1024
__weak void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd)
1025
  /* NOTE : This function should not be modified, when the callback is needed,
1025
{
1026
            the HAL_PCD_ResetCallback could be implemented in the user file
1026
  /* Prevent unused argument(s) compilation warning */
1027
   */
1027
  UNUSED(hpcd);
1028
}
1028
 
1029
 
1029
  /* NOTE : This function should not be modified, when the callback is needed,
1030
/**
1030
            the HAL_PCD_SOFCallback could be implemented in the user file
1031
  * @brief  Suspend event callback.
1031
   */
1032
  * @param  hpcd PCD handle
1032
}
1033
  * @retval None
1033
 
1034
  */
1034
/**
1035
__weak void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd)
1035
  * @brief  USB Reset callback.
1036
{
1036
  * @param  hpcd PCD handle
1037
  /* Prevent unused argument(s) compilation warning */
1037
  * @retval None
1038
  UNUSED(hpcd);
1038
  */
1039
 
1039
__weak void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd)
1040
  /* NOTE : This function should not be modified, when the callback is needed,
1040
{
1041
            the HAL_PCD_SuspendCallback could be implemented in the user file
1041
  /* Prevent unused argument(s) compilation warning */
1042
   */
1042
  UNUSED(hpcd);
1043
}
1043
 
1044
 
1044
  /* NOTE : This function should not be modified, when the callback is needed,
1045
/**
1045
            the HAL_PCD_ResetCallback could be implemented in the user file
1046
  * @brief  Resume event callback.
1046
   */
1047
  * @param  hpcd PCD handle
1047
}
1048
  * @retval None
1048
 
1049
  */
1049
/**
1050
__weak void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd)
1050
  * @brief  Suspend event callback.
1051
{
1051
  * @param  hpcd PCD handle
1052
  /* Prevent unused argument(s) compilation warning */
1052
  * @retval None
1053
  UNUSED(hpcd);
1053
  */
1054
 
1054
__weak void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd)
1055
  /* NOTE : This function should not be modified, when the callback is needed,
1055
{
1056
            the HAL_PCD_ResumeCallback could be implemented in the user file
1056
  /* Prevent unused argument(s) compilation warning */
1057
   */
1057
  UNUSED(hpcd);
1058
}
1058
 
1059
 
1059
  /* NOTE : This function should not be modified, when the callback is needed,
1060
/**
1060
            the HAL_PCD_SuspendCallback could be implemented in the user file
1061
  * @brief  Incomplete ISO OUT callback.
1061
   */
1062
  * @param  hpcd PCD handle
1062
}
1063
  * @param  epnum endpoint number
1063
 
1064
  * @retval None
1064
/**
1065
  */
1065
  * @brief  Resume event callback.
1066
__weak void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
1066
  * @param  hpcd PCD handle
1067
{
1067
  * @retval None
1068
  /* Prevent unused argument(s) compilation warning */
1068
  */
1069
  UNUSED(hpcd);
1069
__weak void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd)
1070
  UNUSED(epnum);
1070
{
1071
 
1071
  /* Prevent unused argument(s) compilation warning */
1072
  /* NOTE : This function should not be modified, when the callback is needed,
1072
  UNUSED(hpcd);
1073
            the HAL_PCD_ISOOUTIncompleteCallback could be implemented in the user file
1073
 
1074
   */
1074
  /* NOTE : This function should not be modified, when the callback is needed,
1075
}
1075
            the HAL_PCD_ResumeCallback could be implemented in the user file
1076
 
1076
   */
1077
/**
1077
}
1078
  * @brief  Incomplete ISO IN callback.
1078
 
1079
  * @param  hpcd PCD handle
1079
/**
1080
  * @param  epnum endpoint number
1080
  * @brief  Incomplete ISO OUT callback.
1081
  * @retval None
1081
  * @param  hpcd PCD handle
1082
  */
1082
  * @param  epnum endpoint number
1083
__weak void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
1083
  * @retval None
1084
{
1084
  */
1085
  /* Prevent unused argument(s) compilation warning */
1085
__weak void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
1086
  UNUSED(hpcd);
1086
{
1087
  UNUSED(epnum);
1087
  /* Prevent unused argument(s) compilation warning */
1088
 
1088
  UNUSED(hpcd);
1089
  /* NOTE : This function should not be modified, when the callback is needed,
1089
  UNUSED(epnum);
1090
            the HAL_PCD_ISOINIncompleteCallback could be implemented in the user file
1090
 
1091
   */
1091
  /* NOTE : This function should not be modified, when the callback is needed,
1092
}
1092
            the HAL_PCD_ISOOUTIncompleteCallback could be implemented in the user file
1093
 
1093
   */
1094
/**
1094
}
1095
  * @brief  Connection event callback.
1095
 
1096
  * @param  hpcd PCD handle
1096
/**
1097
  * @retval None
1097
  * @brief  Incomplete ISO IN callback.
1098
  */
1098
  * @param  hpcd PCD handle
1099
__weak void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd)
1099
  * @param  epnum endpoint number
1100
{
1100
  * @retval None
1101
  /* Prevent unused argument(s) compilation warning */
1101
  */
1102
  UNUSED(hpcd);
1102
__weak void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
1103
 
1103
{
1104
  /* NOTE : This function should not be modified, when the callback is needed,
1104
  /* Prevent unused argument(s) compilation warning */
1105
            the HAL_PCD_ConnectCallback could be implemented in the user file
1105
  UNUSED(hpcd);
1106
   */
1106
  UNUSED(epnum);
1107
}
1107
 
1108
 
1108
  /* NOTE : This function should not be modified, when the callback is needed,
1109
/**
1109
            the HAL_PCD_ISOINIncompleteCallback could be implemented in the user file
1110
  * @brief  Disconnection event callback.
1110
   */
1111
  * @param  hpcd PCD handle
1111
}
1112
  * @retval None
1112
 
1113
  */
1113
/**
1114
__weak void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd)
1114
  * @brief  Connection event callback.
1115
{
1115
  * @param  hpcd PCD handle
1116
  /* Prevent unused argument(s) compilation warning */
1116
  * @retval None
1117
  UNUSED(hpcd);
1117
  */
1118
 
1118
__weak void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd)
1119
  /* NOTE : This function should not be modified, when the callback is needed,
1119
{
1120
            the HAL_PCD_DisconnectCallback could be implemented in the user file
1120
  /* Prevent unused argument(s) compilation warning */
1121
   */
1121
  UNUSED(hpcd);
1122
}
1122
 
1123
 
1123
  /* NOTE : This function should not be modified, when the callback is needed,
1124
/**
1124
            the HAL_PCD_ConnectCallback could be implemented in the user file
1125
  * @}
1125
   */
1126
  */
1126
}
1127
 
1127
 
1128
/** @defgroup PCD_Exported_Functions_Group3 Peripheral Control functions
1128
/**
1129
  *  @brief   management functions
1129
  * @brief  Disconnection event callback.
1130
  *
1130
  * @param  hpcd PCD handle
1131
@verbatim
1131
  * @retval None
1132
 ===============================================================================
1132
  */
1133
                      ##### Peripheral Control functions #####
1133
__weak void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd)
1134
 ===============================================================================
1134
{
1135
    [..]
1135
  /* Prevent unused argument(s) compilation warning */
1136
    This subsection provides a set of functions allowing to control the PCD data
1136
  UNUSED(hpcd);
1137
    transfers.
1137
 
1138
 
1138
  /* NOTE : This function should not be modified, when the callback is needed,
1139
@endverbatim
1139
            the HAL_PCD_DisconnectCallback could be implemented in the user file
1140
  * @{
1140
   */
1141
  */
1141
}
1142
 
1142
 
1143
/**
1143
/**
1144
  * @brief  Connect the USB device
1144
  * @}
1145
  * @param  hpcd PCD handle
1145
  */
1146
  * @retval HAL status
1146
 
1147
  */
1147
/** @defgroup PCD_Exported_Functions_Group3 Peripheral Control functions
1148
HAL_StatusTypeDef HAL_PCD_DevConnect(PCD_HandleTypeDef *hpcd)
1148
  *  @brief   management functions
1149
{
1149
  *
1150
  __HAL_LOCK(hpcd);
1150
@verbatim
1151
 
1151
 ===============================================================================
1152
  HAL_PCDEx_SetConnectionState(hpcd, 1U);
1152
                      ##### Peripheral Control functions #####
1153
 
1153
 ===============================================================================
1154
  (void)USB_DevConnect(hpcd->Instance);
1154
    [..]
1155
  __HAL_UNLOCK(hpcd);
1155
    This subsection provides a set of functions allowing to control the PCD data
1156
 
1156
    transfers.
1157
  return HAL_OK;
1157
 
1158
}
1158
@endverbatim
1159
 
1159
  * @{
1160
/**
1160
  */
1161
  * @brief  Disconnect the USB device.
1161
 
1162
  * @param  hpcd PCD handle
1162
/**
1163
  * @retval HAL status
1163
  * @brief  Connect the USB device
1164
  */
1164
  * @param  hpcd PCD handle
1165
HAL_StatusTypeDef HAL_PCD_DevDisconnect(PCD_HandleTypeDef *hpcd)
1165
  * @retval HAL status
1166
{
1166
  */
1167
  __HAL_LOCK(hpcd);
1167
HAL_StatusTypeDef HAL_PCD_DevConnect(PCD_HandleTypeDef *hpcd)
1168
 
1168
{
1169
  HAL_PCDEx_SetConnectionState(hpcd, 0U);
1169
  __HAL_LOCK(hpcd);
1170
 
1170
 
1171
  (void)USB_DevDisconnect(hpcd->Instance);
1171
  HAL_PCDEx_SetConnectionState(hpcd, 1U);
1172
  __HAL_UNLOCK(hpcd);
1172
 
1173
 
1173
  (void)USB_DevConnect(hpcd->Instance);
1174
  return HAL_OK;
1174
  __HAL_UNLOCK(hpcd);
1175
}
1175
 
1176
 
1176
  return HAL_OK;
1177
/**
1177
}
1178
  * @brief  Set the USB Device address.
1178
 
1179
  * @param  hpcd PCD handle
1179
/**
1180
  * @param  address new device address
1180
  * @brief  Disconnect the USB device.
1181
  * @retval HAL status
1181
  * @param  hpcd PCD handle
1182
  */
1182
  * @retval HAL status
1183
HAL_StatusTypeDef HAL_PCD_SetAddress(PCD_HandleTypeDef *hpcd, uint8_t address)
1183
  */
1184
{
1184
HAL_StatusTypeDef HAL_PCD_DevDisconnect(PCD_HandleTypeDef *hpcd)
1185
  __HAL_LOCK(hpcd);
1185
{
1186
  hpcd->USB_Address = address;
1186
  __HAL_LOCK(hpcd);
1187
  (void)USB_SetDevAddress(hpcd->Instance, address);
1187
 
1188
  __HAL_UNLOCK(hpcd);
1188
  HAL_PCDEx_SetConnectionState(hpcd, 0U);
1189
 
1189
 
1190
  return HAL_OK;
1190
  (void)USB_DevDisconnect(hpcd->Instance);
1191
}
1191
  __HAL_UNLOCK(hpcd);
1192
/**
1192
 
1193
  * @brief  Open and configure an endpoint.
1193
  return HAL_OK;
1194
  * @param  hpcd PCD handle
1194
}
1195
  * @param  ep_addr endpoint address
1195
 
1196
  * @param  ep_mps endpoint max packet size
1196
/**
1197
  * @param  ep_type endpoint type
1197
  * @brief  Set the USB Device address.
1198
  * @retval HAL status
1198
  * @param  hpcd PCD handle
1199
  */
1199
  * @param  address new device address
1200
HAL_StatusTypeDef HAL_PCD_EP_Open(PCD_HandleTypeDef *hpcd, uint8_t ep_addr,
1200
  * @retval HAL status
1201
                                  uint16_t ep_mps, uint8_t ep_type)
1201
  */
1202
{
1202
HAL_StatusTypeDef HAL_PCD_SetAddress(PCD_HandleTypeDef *hpcd, uint8_t address)
1203
  HAL_StatusTypeDef  ret = HAL_OK;
1203
{
1204
  PCD_EPTypeDef *ep;
1204
  __HAL_LOCK(hpcd);
1205
 
1205
  hpcd->USB_Address = address;
1206
  if ((ep_addr & 0x80U) == 0x80U)
1206
  (void)USB_SetDevAddress(hpcd->Instance, address);
1207
  {
1207
  __HAL_UNLOCK(hpcd);
1208
    ep = &hpcd->IN_ep[ep_addr & EP_ADDR_MSK];
1208
 
1209
    ep->is_in = 1U;
1209
  return HAL_OK;
1210
  }
1210
}
1211
  else
1211
/**
1212
  {
1212
  * @brief  Open and configure an endpoint.
1213
    ep = &hpcd->OUT_ep[ep_addr & EP_ADDR_MSK];
1213
  * @param  hpcd PCD handle
1214
    ep->is_in = 0U;
1214
  * @param  ep_addr endpoint address
1215
  }
1215
  * @param  ep_mps endpoint max packet size
1216
 
1216
  * @param  ep_type endpoint type
1217
  ep->num = ep_addr & EP_ADDR_MSK;
1217
  * @retval HAL status
1218
  ep->maxpacket = ep_mps;
1218
  */
1219
  ep->type = ep_type;
1219
HAL_StatusTypeDef HAL_PCD_EP_Open(PCD_HandleTypeDef *hpcd, uint8_t ep_addr,
1220
 
1220
                                  uint16_t ep_mps, uint8_t ep_type)
1221
  if (ep->is_in != 0U)
1221
{
1222
  {
1222
  HAL_StatusTypeDef  ret = HAL_OK;
1223
    /* Assign a Tx FIFO */
1223
  PCD_EPTypeDef *ep;
1224
    ep->tx_fifo_num = ep->num;
1224
 
1225
  }
1225
  if ((ep_addr & 0x80U) == 0x80U)
1226
  /* Set initial data PID. */
1226
  {
1227
  if (ep_type == EP_TYPE_BULK)
1227
    ep = &hpcd->IN_ep[ep_addr & EP_ADDR_MSK];
1228
  {
1228
    ep->is_in = 1U;
1229
    ep->data_pid_start = 0U;
1229
  }
1230
  }
1230
  else
1231
 
1231
  {
1232
  __HAL_LOCK(hpcd);
1232
    ep = &hpcd->OUT_ep[ep_addr & EP_ADDR_MSK];
1233
  (void)USB_ActivateEndpoint(hpcd->Instance, ep);
1233
    ep->is_in = 0U;
1234
  __HAL_UNLOCK(hpcd);
1234
  }
1235
 
1235
 
1236
  return ret;
1236
  ep->num = ep_addr & EP_ADDR_MSK;
1237
}
1237
  ep->maxpacket = ep_mps;
1238
 
1238
  ep->type = ep_type;
1239
/**
1239
 
1240
  * @brief  Deactivate an endpoint.
1240
  /* Set initial data PID. */
1241
  * @param  hpcd PCD handle
1241
  if (ep_type == EP_TYPE_BULK)
1242
  * @param  ep_addr endpoint address
1242
  {
1243
  * @retval HAL status
1243
    ep->data_pid_start = 0U;
1244
  */
1244
  }
1245
HAL_StatusTypeDef HAL_PCD_EP_Close(PCD_HandleTypeDef *hpcd, uint8_t ep_addr)
1245
 
1246
{
1246
  __HAL_LOCK(hpcd);
1247
  PCD_EPTypeDef *ep;
1247
  (void)USB_ActivateEndpoint(hpcd->Instance, ep);
1248
 
1248
  __HAL_UNLOCK(hpcd);
1249
  if ((ep_addr & 0x80U) == 0x80U)
1249
 
1250
  {
1250
  return ret;
1251
    ep = &hpcd->IN_ep[ep_addr & EP_ADDR_MSK];
1251
}
1252
    ep->is_in = 1U;
1252
 
1253
  }
1253
/**
1254
  else
1254
  * @brief  Deactivate an endpoint.
1255
  {
1255
  * @param  hpcd PCD handle
1256
    ep = &hpcd->OUT_ep[ep_addr & EP_ADDR_MSK];
1256
  * @param  ep_addr endpoint address
1257
    ep->is_in = 0U;
1257
  * @retval HAL status
1258
  }
1258
  */
1259
  ep->num   = ep_addr & EP_ADDR_MSK;
1259
HAL_StatusTypeDef HAL_PCD_EP_Close(PCD_HandleTypeDef *hpcd, uint8_t ep_addr)
1260
 
1260
{
1261
  __HAL_LOCK(hpcd);
1261
  PCD_EPTypeDef *ep;
1262
  (void)USB_DeactivateEndpoint(hpcd->Instance, ep);
1262
 
1263
  __HAL_UNLOCK(hpcd);
1263
  if ((ep_addr & 0x80U) == 0x80U)
1264
  return HAL_OK;
1264
  {
1265
}
1265
    ep = &hpcd->IN_ep[ep_addr & EP_ADDR_MSK];
1266
 
1266
    ep->is_in = 1U;
1267
 
1267
  }
1268
/**
1268
  else
1269
  * @brief  Receive an amount of data.
1269
  {
1270
  * @param  hpcd PCD handle
1270
    ep = &hpcd->OUT_ep[ep_addr & EP_ADDR_MSK];
1271
  * @param  ep_addr endpoint address
1271
    ep->is_in = 0U;
1272
  * @param  pBuf pointer to the reception buffer
1272
  }
1273
  * @param  len amount of data to be received
1273
  ep->num = ep_addr & EP_ADDR_MSK;
1274
  * @retval HAL status
1274
 
1275
  */
1275
  __HAL_LOCK(hpcd);
1276
HAL_StatusTypeDef HAL_PCD_EP_Receive(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len)
1276
  (void)USB_DeactivateEndpoint(hpcd->Instance, ep);
1277
{
1277
  __HAL_UNLOCK(hpcd);
1278
  PCD_EPTypeDef *ep;
1278
  return HAL_OK;
1279
 
1279
}
1280
  ep = &hpcd->OUT_ep[ep_addr & EP_ADDR_MSK];
1280
 
1281
 
1281
 
1282
  /*setup and start the Xfer */
1282
/**
1283
  ep->xfer_buff = pBuf;
1283
  * @brief  Receive an amount of data.
1284
  ep->xfer_len = len;
1284
  * @param  hpcd PCD handle
1285
  ep->xfer_count = 0U;
1285
  * @param  ep_addr endpoint address
1286
  ep->is_in = 0U;
1286
  * @param  pBuf pointer to the reception buffer
1287
  ep->num = ep_addr & EP_ADDR_MSK;
1287
  * @param  len amount of data to be received
1288
 
1288
  * @retval HAL status
1289
  if ((ep_addr & EP_ADDR_MSK) == 0U)
1289
  */
1290
  {
1290
HAL_StatusTypeDef HAL_PCD_EP_Receive(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len)
1291
    (void)USB_EP0StartXfer(hpcd->Instance, ep);
1291
{
1292
  }
1292
  PCD_EPTypeDef *ep;
1293
  else
1293
 
1294
  {
1294
  ep = &hpcd->OUT_ep[ep_addr & EP_ADDR_MSK];
1295
    (void)USB_EPStartXfer(hpcd->Instance, ep);
1295
 
1296
  }
1296
  /*setup and start the Xfer */
1297
 
1297
  ep->xfer_buff = pBuf;
1298
  return HAL_OK;
1298
  ep->xfer_len = len;
1299
}
1299
  ep->xfer_count = 0U;
1300
 
1300
  ep->is_in = 0U;
1301
/**
1301
  ep->num = ep_addr & EP_ADDR_MSK;
1302
  * @brief  Get Received Data Size
1302
 
1303
  * @param  hpcd PCD handle
1303
  (void)USB_EPStartXfer(hpcd->Instance, ep);
1304
  * @param  ep_addr endpoint address
1304
 
1305
  * @retval Data Size
1305
  return HAL_OK;
1306
  */
1306
}
1307
uint32_t HAL_PCD_EP_GetRxCount(PCD_HandleTypeDef *hpcd, uint8_t ep_addr)
1307
 
1308
{
1308
/**
1309
  return hpcd->OUT_ep[ep_addr & EP_ADDR_MSK].xfer_count;
1309
  * @brief  Get Received Data Size
1310
}
1310
  * @param  hpcd PCD handle
1311
/**
1311
  * @param  ep_addr endpoint address
1312
  * @brief  Send an amount of data
1312
  * @retval Data Size
1313
  * @param  hpcd PCD handle
1313
  */
1314
  * @param  ep_addr endpoint address
1314
uint32_t HAL_PCD_EP_GetRxCount(PCD_HandleTypeDef const *hpcd, uint8_t ep_addr)
1315
  * @param  pBuf pointer to the transmission buffer
1315
{
1316
  * @param  len amount of data to be sent
1316
  return hpcd->OUT_ep[ep_addr & EP_ADDR_MSK].xfer_count;
1317
  * @retval HAL status
1317
}
1318
  */
1318
/**
1319
HAL_StatusTypeDef HAL_PCD_EP_Transmit(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len)
1319
  * @brief  Send an amount of data
1320
{
1320
  * @param  hpcd PCD handle
1321
  PCD_EPTypeDef *ep;
1321
  * @param  ep_addr endpoint address
1322
 
1322
  * @param  pBuf pointer to the transmission buffer
1323
  ep = &hpcd->IN_ep[ep_addr & EP_ADDR_MSK];
1323
  * @param  len amount of data to be sent
1324
 
1324
  * @retval HAL status
1325
  /*setup and start the Xfer */
1325
  */
1326
  ep->xfer_buff = pBuf;
1326
HAL_StatusTypeDef HAL_PCD_EP_Transmit(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len)
1327
  ep->xfer_len = len;
1327
{
1328
  ep->xfer_fill_db = 1U;
1328
  PCD_EPTypeDef *ep;
1329
  ep->xfer_len_db = len;
1329
 
1330
  ep->xfer_count = 0U;
1330
  ep = &hpcd->IN_ep[ep_addr & EP_ADDR_MSK];
1331
  ep->is_in = 1U;
1331
 
1332
  ep->num = ep_addr & EP_ADDR_MSK;
1332
  /*setup and start the Xfer */
1333
 
1333
  ep->xfer_buff = pBuf;
1334
  if ((ep_addr & EP_ADDR_MSK) == 0U)
1334
  ep->xfer_len = len;
1335
  {
1335
  ep->xfer_fill_db = 1U;
1336
    (void)USB_EP0StartXfer(hpcd->Instance, ep);
1336
  ep->xfer_len_db = len;
1337
  }
1337
  ep->xfer_count = 0U;
1338
  else
1338
  ep->is_in = 1U;
1339
  {
1339
  ep->num = ep_addr & EP_ADDR_MSK;
1340
    (void)USB_EPStartXfer(hpcd->Instance, ep);
1340
 
1341
  }
1341
  (void)USB_EPStartXfer(hpcd->Instance, ep);
1342
 
1342
 
1343
  return HAL_OK;
1343
  return HAL_OK;
1344
}
1344
}
1345
 
1345
 
1346
/**
1346
/**
1347
  * @brief  Set a STALL condition over an endpoint
1347
  * @brief  Set a STALL condition over an endpoint
1348
  * @param  hpcd PCD handle
1348
  * @param  hpcd PCD handle
1349
  * @param  ep_addr endpoint address
1349
  * @param  ep_addr endpoint address
1350
  * @retval HAL status
1350
  * @retval HAL status
1351
  */
1351
  */
1352
HAL_StatusTypeDef HAL_PCD_EP_SetStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr)
1352
HAL_StatusTypeDef HAL_PCD_EP_SetStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr)
1353
{
1353
{
1354
  PCD_EPTypeDef *ep;
1354
  PCD_EPTypeDef *ep;
1355
 
1355
 
1356
  if (((uint32_t)ep_addr & EP_ADDR_MSK) > hpcd->Init.dev_endpoints)
1356
  if (((uint32_t)ep_addr & EP_ADDR_MSK) > hpcd->Init.dev_endpoints)
1357
  {
1357
  {
1358
    return HAL_ERROR;
1358
    return HAL_ERROR;
1359
  }
1359
  }
1360
 
1360
 
1361
  if ((0x80U & ep_addr) == 0x80U)
1361
  if ((0x80U & ep_addr) == 0x80U)
1362
  {
1362
  {
1363
    ep = &hpcd->IN_ep[ep_addr & EP_ADDR_MSK];
1363
    ep = &hpcd->IN_ep[ep_addr & EP_ADDR_MSK];
1364
    ep->is_in = 1U;
1364
    ep->is_in = 1U;
1365
  }
1365
  }
1366
  else
1366
  else
1367
  {
1367
  {
1368
    ep = &hpcd->OUT_ep[ep_addr];
1368
    ep = &hpcd->OUT_ep[ep_addr];
1369
    ep->is_in = 0U;
1369
    ep->is_in = 0U;
1370
  }
1370
  }
1371
 
1371
 
1372
  ep->is_stall = 1U;
1372
  ep->is_stall = 1U;
1373
  ep->num = ep_addr & EP_ADDR_MSK;
1373
  ep->num = ep_addr & EP_ADDR_MSK;
1374
 
1374
 
1375
  __HAL_LOCK(hpcd);
1375
  __HAL_LOCK(hpcd);
1376
 
1376
 
1377
  (void)USB_EPSetStall(hpcd->Instance, ep);
1377
  (void)USB_EPSetStall(hpcd->Instance, ep);
1378
 
1378
 
1379
  __HAL_UNLOCK(hpcd);
1379
  __HAL_UNLOCK(hpcd);
1380
 
1380
 
1381
  return HAL_OK;
1381
  return HAL_OK;
1382
}
1382
}
1383
 
1383
 
1384
/**
1384
/**
1385
  * @brief  Clear a STALL condition over in an endpoint
1385
  * @brief  Clear a STALL condition over in an endpoint
1386
  * @param  hpcd PCD handle
1386
  * @param  hpcd PCD handle
1387
  * @param  ep_addr endpoint address
1387
  * @param  ep_addr endpoint address
1388
  * @retval HAL status
1388
  * @retval HAL status
1389
  */
1389
  */
1390
HAL_StatusTypeDef HAL_PCD_EP_ClrStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr)
1390
HAL_StatusTypeDef HAL_PCD_EP_ClrStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr)
1391
{
1391
{
1392
  PCD_EPTypeDef *ep;
1392
  PCD_EPTypeDef *ep;
1393
 
1393
 
1394
  if (((uint32_t)ep_addr & 0x0FU) > hpcd->Init.dev_endpoints)
1394
  if (((uint32_t)ep_addr & 0x0FU) > hpcd->Init.dev_endpoints)
1395
  {
1395
  {
1396
    return HAL_ERROR;
1396
    return HAL_ERROR;
1397
  }
1397
  }
1398
 
1398
 
1399
  if ((0x80U & ep_addr) == 0x80U)
1399
  if ((0x80U & ep_addr) == 0x80U)
1400
  {
1400
  {
1401
    ep = &hpcd->IN_ep[ep_addr & EP_ADDR_MSK];
1401
    ep = &hpcd->IN_ep[ep_addr & EP_ADDR_MSK];
1402
    ep->is_in = 1U;
1402
    ep->is_in = 1U;
1403
  }
1403
  }
1404
  else
1404
  else
1405
  {
1405
  {
1406
    ep = &hpcd->OUT_ep[ep_addr & EP_ADDR_MSK];
1406
    ep = &hpcd->OUT_ep[ep_addr & EP_ADDR_MSK];
1407
    ep->is_in = 0U;
1407
    ep->is_in = 0U;
1408
  }
1408
  }
1409
 
1409
 
1410
  ep->is_stall = 0U;
1410
  ep->is_stall = 0U;
1411
  ep->num = ep_addr & EP_ADDR_MSK;
1411
  ep->num = ep_addr & EP_ADDR_MSK;
1412
 
1412
 
1413
  __HAL_LOCK(hpcd);
1413
  __HAL_LOCK(hpcd);
1414
  (void)USB_EPClearStall(hpcd->Instance, ep);
1414
  (void)USB_EPClearStall(hpcd->Instance, ep);
1415
  __HAL_UNLOCK(hpcd);
1415
  __HAL_UNLOCK(hpcd);
1416
 
1416
 
1417
  return HAL_OK;
1417
  return HAL_OK;
1418
}
1418
}
1419
 
1419
 
1420
/**
1420
/**
1421
  * @brief  Flush an endpoint
1421
   * @brief  Abort an USB EP transaction.
1422
  * @param  hpcd PCD handle
1422
   * @param  hpcd PCD handle
1423
  * @param  ep_addr endpoint address
1423
   * @param  ep_addr endpoint address
1424
  * @retval HAL status
1424
   * @retval HAL status
1425
  */
1425
   */
1426
HAL_StatusTypeDef HAL_PCD_EP_Flush(PCD_HandleTypeDef *hpcd, uint8_t ep_addr)
1426
HAL_StatusTypeDef HAL_PCD_EP_Abort(PCD_HandleTypeDef *hpcd, uint8_t ep_addr)
1427
{
1427
{
1428
  /* Prevent unused argument(s) compilation warning */
1428
  HAL_StatusTypeDef ret;
1429
  UNUSED(hpcd);
1429
  PCD_EPTypeDef *ep;
1430
  UNUSED(ep_addr);
1430
 
1431
 
1431
  if ((0x80U & ep_addr) == 0x80U)
1432
  return HAL_OK;
1432
  {
1433
}
1433
    ep = &hpcd->IN_ep[ep_addr & EP_ADDR_MSK];
1434
 
1434
  }
1435
/**
1435
  else
1436
  * @brief  Activate remote wakeup signalling
1436
  {
1437
  * @param  hpcd PCD handle
1437
    ep = &hpcd->OUT_ep[ep_addr & EP_ADDR_MSK];
1438
  * @retval HAL status
1438
  }
1439
  */
1439
 
1440
HAL_StatusTypeDef HAL_PCD_ActivateRemoteWakeup(PCD_HandleTypeDef *hpcd)
1440
  /* Stop Xfer */
1441
{
1441
  ret = USB_EPStopXfer(hpcd->Instance, ep);
1442
  return (USB_ActivateRemoteWakeup(hpcd->Instance));
1442
 
1443
}
1443
  return ret;
1444
 
1444
}
1445
/**
1445
 
1446
  * @brief  De-activate remote wakeup signalling.
1446
/**
1447
  * @param  hpcd PCD handle
1447
  * @brief  Flush an endpoint
1448
  * @retval HAL status
1448
  * @param  hpcd PCD handle
1449
  */
1449
  * @param  ep_addr endpoint address
1450
HAL_StatusTypeDef HAL_PCD_DeActivateRemoteWakeup(PCD_HandleTypeDef *hpcd)
1450
  * @retval HAL status
1451
{
1451
  */
1452
  return (USB_DeActivateRemoteWakeup(hpcd->Instance));
1452
HAL_StatusTypeDef HAL_PCD_EP_Flush(PCD_HandleTypeDef *hpcd, uint8_t ep_addr)
1453
}
1453
{
1454
 
1454
  __HAL_LOCK(hpcd);
1455
/**
1455
 
1456
  * @}
1456
  if ((ep_addr & 0x80U) == 0x80U)
1457
  */
1457
  {
1458
 
1458
    (void)USB_FlushTxFifo(hpcd->Instance, (uint32_t)ep_addr & EP_ADDR_MSK);
1459
/** @defgroup PCD_Exported_Functions_Group4 Peripheral State functions
1459
  }
1460
  *  @brief   Peripheral State functions
1460
  else
1461
  *
1461
  {
1462
@verbatim
1462
    (void)USB_FlushRxFifo(hpcd->Instance);
1463
 ===============================================================================
1463
  }
1464
                      ##### Peripheral State functions #####
1464
 
1465
 ===============================================================================
1465
  __HAL_UNLOCK(hpcd);
1466
    [..]
1466
 
1467
    This subsection permits to get in run-time the status of the peripheral
1467
  return HAL_OK;
1468
    and the data flow.
1468
}
1469
 
1469
 
1470
@endverbatim
1470
/**
1471
  * @{
1471
  * @brief  Activate remote wakeup signalling
1472
  */
1472
  * @param  hpcd PCD handle
1473
 
1473
  * @retval HAL status
1474
/**
1474
  */
1475
  * @brief  Return the PCD handle state.
1475
HAL_StatusTypeDef HAL_PCD_ActivateRemoteWakeup(PCD_HandleTypeDef *hpcd)
1476
  * @param  hpcd PCD handle
1476
{
1477
  * @retval HAL state
1477
  return (USB_ActivateRemoteWakeup(hpcd->Instance));
1478
  */
1478
}
1479
PCD_StateTypeDef HAL_PCD_GetState(PCD_HandleTypeDef *hpcd)
1479
 
1480
{
1480
/**
1481
  return hpcd->State;
1481
  * @brief  De-activate remote wakeup signalling.
1482
}
1482
  * @param  hpcd PCD handle
1483
 
1483
  * @retval HAL status
1484
/**
1484
  */
1485
  * @}
1485
HAL_StatusTypeDef HAL_PCD_DeActivateRemoteWakeup(PCD_HandleTypeDef *hpcd)
1486
  */
1486
{
1487
 
1487
  return (USB_DeActivateRemoteWakeup(hpcd->Instance));
1488
/**
1488
}
1489
  * @}
1489
 
1490
  */
1490
/**
1491
 
1491
  * @}
1492
/* Private functions ---------------------------------------------------------*/
1492
  */
1493
/** @addtogroup PCD_Private_Functions
1493
 
1494
  * @{
1494
/** @defgroup PCD_Exported_Functions_Group4 Peripheral State functions
1495
  */
1495
  *  @brief   Peripheral State functions
1496
 
1496
  *
1497
 
1497
@verbatim
1498
/**
1498
 ===============================================================================
1499
  * @brief  This function handles PCD Endpoint interrupt request.
1499
                      ##### Peripheral State functions #####
1500
  * @param  hpcd PCD handle
1500
 ===============================================================================
1501
  * @retval HAL status
1501
    [..]
1502
  */
1502
    This subsection permits to get in run-time the status of the peripheral
1503
static HAL_StatusTypeDef PCD_EP_ISR_Handler(PCD_HandleTypeDef *hpcd)
1503
    and the data flow.
1504
{
1504
 
1505
  PCD_EPTypeDef *ep;
1505
@endverbatim
1506
  uint16_t count, wIstr, wEPVal, TxByteNbre;
1506
  * @{
1507
  uint8_t epindex;
1507
  */
1508
 
1508
 
1509
  /* stay in loop while pending interrupts */
1509
/**
1510
  while ((hpcd->Instance->ISTR & USB_ISTR_CTR) != 0U)
1510
  * @brief  Return the PCD handle state.
1511
  {
1511
  * @param  hpcd PCD handle
1512
    wIstr = hpcd->Instance->ISTR;
1512
  * @retval HAL state
1513
 
1513
  */
1514
    /* extract highest priority endpoint number */
1514
PCD_StateTypeDef HAL_PCD_GetState(PCD_HandleTypeDef const *hpcd)
1515
    epindex = (uint8_t)(wIstr & USB_ISTR_EP_ID);
1515
{
1516
 
1516
  return hpcd->State;
1517
    if (epindex == 0U)
1517
}
1518
    {
1518
 
1519
      /* Decode and service control endpoint interrupt */
1519
/**
1520
 
1520
  * @}
1521
      /* DIR bit = origin of the interrupt */
1521
  */
1522
      if ((wIstr & USB_ISTR_DIR) == 0U)
1522
 
1523
      {
1523
/**
1524
        /* DIR = 0 */
1524
  * @}
1525
 
1525
  */
1526
        /* DIR = 0 => IN  int */
1526
 
1527
        /* DIR = 0 implies that (EP_CTR_TX = 1) always */
1527
/* Private functions ---------------------------------------------------------*/
1528
        PCD_CLEAR_TX_EP_CTR(hpcd->Instance, PCD_ENDP0);
1528
/** @addtogroup PCD_Private_Functions
1529
        ep = &hpcd->IN_ep[0];
1529
  * @{
1530
 
1530
  */
1531
        ep->xfer_count = PCD_GET_EP_TX_CNT(hpcd->Instance, ep->num);
1531
 
1532
        ep->xfer_buff += ep->xfer_count;
1532
 
1533
 
1533
/**
1534
        /* TX COMPLETE */
1534
  * @brief  This function handles PCD Endpoint interrupt request.
1535
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
1535
  * @param  hpcd PCD handle
1536
        hpcd->DataInStageCallback(hpcd, 0U);
1536
  * @retval HAL status
1537
#else
1537
  */
1538
        HAL_PCD_DataInStageCallback(hpcd, 0U);
1538
static HAL_StatusTypeDef PCD_EP_ISR_Handler(PCD_HandleTypeDef *hpcd)
1539
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
1539
{
1540
 
1540
  PCD_EPTypeDef *ep;
1541
        if ((hpcd->USB_Address > 0U) && (ep->xfer_len == 0U))
1541
  uint16_t count;
1542
        {
1542
  uint16_t wIstr;
1543
          hpcd->Instance->DADDR = ((uint16_t)hpcd->USB_Address | USB_DADDR_EF);
1543
  uint16_t wEPVal;
1544
          hpcd->USB_Address = 0U;
1544
  uint16_t TxPctSize;
1545
        }
1545
  uint8_t epindex;
1546
      }
1546
 
1547
      else
1547
#if (USE_USB_DOUBLE_BUFFER != 1U)
1548
      {
1548
  count = 0U;
1549
        /* DIR = 1 */
1549
#endif /* USE_USB_DOUBLE_BUFFER */
1550
 
1550
 
1551
        /* DIR = 1 & CTR_RX => SETUP or OUT int */
1551
  /* stay in loop while pending interrupts */
1552
        /* DIR = 1 & (CTR_TX | CTR_RX) => 2 int pending */
1552
  while ((hpcd->Instance->ISTR & USB_ISTR_CTR) != 0U)
1553
        ep = &hpcd->OUT_ep[0];
1553
  {
1554
        wEPVal = PCD_GET_ENDPOINT(hpcd->Instance, PCD_ENDP0);
1554
    wIstr = hpcd->Instance->ISTR;
1555
 
1555
 
1556
        if ((wEPVal & USB_EP_SETUP) != 0U)
1556
    /* extract highest priority endpoint number */
1557
        {
1557
    epindex = (uint8_t)(wIstr & USB_ISTR_EP_ID);
1558
          /* Get SETUP Packet */
1558
 
1559
          ep->xfer_count = PCD_GET_EP_RX_CNT(hpcd->Instance, ep->num);
1559
    if (epindex == 0U)
1560
 
1560
    {
1561
          USB_ReadPMA(hpcd->Instance, (uint8_t *)hpcd->Setup,
1561
      /* Decode and service control endpoint interrupt */
1562
                      ep->pmaadress, (uint16_t)ep->xfer_count);
1562
 
1563
 
1563
      /* DIR bit = origin of the interrupt */
1564
          /* SETUP bit kept frozen while CTR_RX = 1 */
1564
      if ((wIstr & USB_ISTR_DIR) == 0U)
1565
          PCD_CLEAR_RX_EP_CTR(hpcd->Instance, PCD_ENDP0);
1565
      {
1566
 
1566
        /* DIR = 0 */
1567
          /* Process SETUP Packet*/
1567
 
1568
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
1568
        /* DIR = 0 => IN  int */
1569
          hpcd->SetupStageCallback(hpcd);
1569
        /* DIR = 0 implies that (EP_CTR_TX = 1) always */
1570
#else
1570
        PCD_CLEAR_TX_EP_CTR(hpcd->Instance, PCD_ENDP0);
1571
          HAL_PCD_SetupStageCallback(hpcd);
1571
        ep = &hpcd->IN_ep[0];
1572
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
1572
 
1573
        }
1573
        ep->xfer_count = PCD_GET_EP_TX_CNT(hpcd->Instance, ep->num);
1574
        else if ((wEPVal & USB_EP_CTR_RX) != 0U)
1574
        ep->xfer_buff += ep->xfer_count;
1575
        {
1575
 
1576
          PCD_CLEAR_RX_EP_CTR(hpcd->Instance, PCD_ENDP0);
1576
        /* TX COMPLETE */
1577
 
1577
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
1578
          /* Get Control Data OUT Packet */
1578
        hpcd->DataInStageCallback(hpcd, 0U);
1579
          ep->xfer_count = PCD_GET_EP_RX_CNT(hpcd->Instance, ep->num);
1579
#else
1580
 
1580
        HAL_PCD_DataInStageCallback(hpcd, 0U);
1581
          if ((ep->xfer_count != 0U) && (ep->xfer_buff != 0U))
1581
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
1582
          {
1582
 
1583
            USB_ReadPMA(hpcd->Instance, ep->xfer_buff,
1583
        if ((hpcd->USB_Address > 0U) && (ep->xfer_len == 0U))
1584
                        ep->pmaadress, (uint16_t)ep->xfer_count);
1584
        {
1585
 
1585
          hpcd->Instance->DADDR = ((uint16_t)hpcd->USB_Address | USB_DADDR_EF);
1586
            ep->xfer_buff += ep->xfer_count;
1586
          hpcd->USB_Address = 0U;
1587
 
1587
        }
1588
            /* Process Control Data OUT Packet */
1588
      }
1589
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
1589
      else
1590
            hpcd->DataOutStageCallback(hpcd, 0U);
1590
      {
1591
#else
1591
        /* DIR = 1 */
1592
            HAL_PCD_DataOutStageCallback(hpcd, 0U);
1592
 
1593
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
1593
        /* DIR = 1 & CTR_RX => SETUP or OUT int */
1594
          }
1594
        /* DIR = 1 & (CTR_TX | CTR_RX) => 2 int pending */
1595
 
1595
        ep = &hpcd->OUT_ep[0];
1596
          if ((PCD_GET_ENDPOINT(hpcd->Instance, PCD_ENDP0) & USB_EP_SETUP) == 0U)
1596
        wEPVal = PCD_GET_ENDPOINT(hpcd->Instance, PCD_ENDP0);
1597
          {
1597
 
1598
            PCD_SET_EP_RX_CNT(hpcd->Instance, PCD_ENDP0, ep->maxpacket);
1598
        if ((wEPVal & USB_EP_SETUP) != 0U)
1599
            PCD_SET_EP_RX_STATUS(hpcd->Instance, PCD_ENDP0, USB_EP_RX_VALID);
1599
        {
1600
          }
1600
          /* Get SETUP Packet */
1601
        }
1601
          ep->xfer_count = PCD_GET_EP_RX_CNT(hpcd->Instance, ep->num);
1602
      }
1602
 
1603
    }
1603
          USB_ReadPMA(hpcd->Instance, (uint8_t *)hpcd->Setup,
1604
    else
1604
                      ep->pmaadress, (uint16_t)ep->xfer_count);
1605
    {
1605
 
1606
      /* Decode and service non control endpoints interrupt */
1606
          /* SETUP bit kept frozen while CTR_RX = 1 */
1607
      /* process related endpoint register */
1607
          PCD_CLEAR_RX_EP_CTR(hpcd->Instance, PCD_ENDP0);
1608
      wEPVal = PCD_GET_ENDPOINT(hpcd->Instance, epindex);
1608
 
1609
 
1609
          /* Process SETUP Packet*/
1610
      if ((wEPVal & USB_EP_CTR_RX) != 0U)
1610
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
1611
      {
1611
          hpcd->SetupStageCallback(hpcd);
1612
        /* clear int flag */
1612
#else
1613
        PCD_CLEAR_RX_EP_CTR(hpcd->Instance, epindex);
1613
          HAL_PCD_SetupStageCallback(hpcd);
1614
        ep = &hpcd->OUT_ep[epindex];
1614
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
1615
 
1615
        }
1616
        /* OUT Single Buffering */
1616
        else if ((wEPVal & USB_EP_CTR_RX) != 0U)
1617
        if (ep->doublebuffer == 0U)
1617
        {
1618
        {
1618
          PCD_CLEAR_RX_EP_CTR(hpcd->Instance, PCD_ENDP0);
1619
          count = (uint16_t)PCD_GET_EP_RX_CNT(hpcd->Instance, ep->num);
1619
 
1620
 
1620
          /* Get Control Data OUT Packet */
1621
          if (count != 0U)
1621
          ep->xfer_count = PCD_GET_EP_RX_CNT(hpcd->Instance, ep->num);
1622
          {
1622
 
1623
            USB_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaadress, count);
1623
          if ((ep->xfer_count != 0U) && (ep->xfer_buff != 0U))
1624
          }
1624
          {
1625
        }
1625
            USB_ReadPMA(hpcd->Instance, ep->xfer_buff,
1626
        else
1626
                        ep->pmaadress, (uint16_t)ep->xfer_count);
1627
        {
1627
 
1628
          /* manage double buffer bulk out */
1628
            ep->xfer_buff += ep->xfer_count;
1629
          if (ep->type == EP_TYPE_BULK)
1629
 
1630
          {
1630
            /* Process Control Data OUT Packet */
1631
            count = HAL_PCD_EP_DB_Receive(hpcd, ep, wEPVal);
1631
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
1632
          }
1632
            hpcd->DataOutStageCallback(hpcd, 0U);
1633
          else /* manage double buffer iso out */
1633
#else
1634
          {
1634
            HAL_PCD_DataOutStageCallback(hpcd, 0U);
1635
            /* free EP OUT Buffer */
1635
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
1636
            PCD_FreeUserBuffer(hpcd->Instance, ep->num, 0U);
1636
          }
1637
 
1637
 
1638
            if ((PCD_GET_ENDPOINT(hpcd->Instance, ep->num) & USB_EP_DTOG_RX) != 0U)
1638
          wEPVal = (uint16_t)PCD_GET_ENDPOINT(hpcd->Instance, PCD_ENDP0);
1639
            {
1639
 
1640
              /* read from endpoint BUF0Addr buffer */
1640
          if (((wEPVal & USB_EP_SETUP) == 0U) && ((wEPVal & USB_EP_RX_STRX) != USB_EP_RX_VALID))
1641
              count = (uint16_t)PCD_GET_EP_DBUF0_CNT(hpcd->Instance, ep->num);
1641
          {
1642
 
1642
            PCD_SET_EP_RX_CNT(hpcd->Instance, PCD_ENDP0, ep->maxpacket);
1643
              if (count != 0U)
1643
            PCD_SET_EP_RX_STATUS(hpcd->Instance, PCD_ENDP0, USB_EP_RX_VALID);
1644
              {
1644
          }
1645
                USB_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr0, count);
1645
        }
1646
              }
1646
      }
1647
            }
1647
    }
1648
            else
1648
    else
1649
            {
1649
    {
1650
              /* read from endpoint BUF1Addr buffer */
1650
      /* Decode and service non control endpoints interrupt */
1651
              count = (uint16_t)PCD_GET_EP_DBUF1_CNT(hpcd->Instance, ep->num);
1651
      /* process related endpoint register */
1652
 
1652
      wEPVal = PCD_GET_ENDPOINT(hpcd->Instance, epindex);
1653
              if (count != 0U)
1653
 
1654
              {
1654
      if ((wEPVal & USB_EP_CTR_RX) != 0U)
1655
                USB_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr1, count);
1655
      {
1656
              }
1656
        /* clear int flag */
1657
            }
1657
        PCD_CLEAR_RX_EP_CTR(hpcd->Instance, epindex);
1658
          }
1658
        ep = &hpcd->OUT_ep[epindex];
1659
        }
1659
 
1660
        /* multi-packet on the NON control OUT endpoint */
1660
        /* OUT Single Buffering */
1661
        ep->xfer_count += count;
1661
        if (ep->doublebuffer == 0U)
1662
        ep->xfer_buff += count;
1662
        {
1663
 
1663
          count = (uint16_t)PCD_GET_EP_RX_CNT(hpcd->Instance, ep->num);
1664
        if ((ep->xfer_len == 0U) || (count < ep->maxpacket))
1664
 
1665
        {
1665
          if (count != 0U)
1666
          /* RX COMPLETE */
1666
          {
1667
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
1667
            USB_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaadress, count);
1668
          hpcd->DataOutStageCallback(hpcd, ep->num);
1668
          }
1669
#else
1669
        }
1670
          HAL_PCD_DataOutStageCallback(hpcd, ep->num);
1670
#if (USE_USB_DOUBLE_BUFFER == 1U)
1671
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
1671
        else
1672
        }
1672
        {
1673
        else
1673
          /* manage double buffer bulk out */
1674
        {
1674
          if (ep->type == EP_TYPE_BULK)
1675
          (void) USB_EPStartXfer(hpcd->Instance, ep);
1675
          {
1676
        }
1676
            count = HAL_PCD_EP_DB_Receive(hpcd, ep, wEPVal);
1677
 
1677
          }
1678
      }
1678
          else /* manage double buffer iso out */
1679
 
1679
          {
1680
      if ((wEPVal & USB_EP_CTR_TX) != 0U)
1680
            /* free EP OUT Buffer */
1681
      {
1681
            PCD_FREE_USER_BUFFER(hpcd->Instance, ep->num, 0U);
1682
        ep = &hpcd->IN_ep[epindex];
1682
 
1683
 
1683
            if ((PCD_GET_ENDPOINT(hpcd->Instance, ep->num) & USB_EP_DTOG_RX) != 0U)
1684
        /* clear int flag */
1684
            {
1685
        PCD_CLEAR_TX_EP_CTR(hpcd->Instance, epindex);
1685
              /* read from endpoint BUF0Addr buffer */
1686
 
1686
              count = (uint16_t)PCD_GET_EP_DBUF0_CNT(hpcd->Instance, ep->num);
1687
        /* Manage all non bulk/isoc transaction Bulk Single Buffer Transaction */
1687
 
1688
        if ((ep->type == EP_TYPE_INTR) || (ep->type == EP_TYPE_CTRL) ||
1688
              if (count != 0U)
1689
           ((ep->type == EP_TYPE_BULK) && ((wEPVal & USB_EP_KIND) == 0U)))
1689
              {
1690
        {
1690
                USB_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr0, count);
1691
          /* multi-packet on the NON control IN endpoint */
1691
              }
1692
          TxByteNbre = (uint16_t)PCD_GET_EP_TX_CNT(hpcd->Instance, ep->num);
1692
            }
1693
 
1693
            else
1694
          if (ep->xfer_len > TxByteNbre)
1694
            {
1695
          {
1695
              /* read from endpoint BUF1Addr buffer */
1696
            ep->xfer_len -= TxByteNbre;
1696
              count = (uint16_t)PCD_GET_EP_DBUF1_CNT(hpcd->Instance, ep->num);
1697
          }
1697
 
1698
          else
1698
              if (count != 0U)
1699
          {
1699
              {
1700
            ep->xfer_len = 0U;
1700
                USB_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr1, count);
1701
          }
1701
              }
1702
 
1702
            }
1703
          /* Zero Length Packet? */
1703
          }
1704
          if (ep->xfer_len == 0U)
1704
        }
1705
          {
1705
#endif /* (USE_USB_DOUBLE_BUFFER == 1U) */
1706
            /* TX COMPLETE */
1706
 
1707
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
1707
        /* multi-packet on the NON control OUT endpoint */
1708
            hpcd->DataInStageCallback(hpcd, ep->num);
1708
        ep->xfer_count += count;
1709
#else
1709
        ep->xfer_buff += count;
1710
            HAL_PCD_DataInStageCallback(hpcd, ep->num);
1710
 
1711
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
1711
        if ((ep->xfer_len == 0U) || (count < ep->maxpacket))
1712
          }
1712
        {
1713
          else
1713
          /* RX COMPLETE */
1714
          {
1714
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
1715
            /* Transfer is not yet Done */
1715
          hpcd->DataOutStageCallback(hpcd, ep->num);
1716
            ep->xfer_buff += TxByteNbre;
1716
#else
1717
            ep->xfer_count += TxByteNbre;
1717
          HAL_PCD_DataOutStageCallback(hpcd, ep->num);
1718
            (void)USB_EPStartXfer(hpcd->Instance, ep);
1718
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
1719
          }
1719
        }
1720
        }
1720
        else
1721
        /* Double Buffer Iso/bulk IN (bulk transfer Len > Ep_Mps) */
1721
        {
1722
        else
1722
          (void)USB_EPStartXfer(hpcd->Instance, ep);
1723
        {
1723
        }
1724
          (void)HAL_PCD_EP_DB_Transmit(hpcd, ep, wEPVal);
1724
      }
1725
        }
1725
 
1726
      }
1726
      if ((wEPVal & USB_EP_CTR_TX) != 0U)
1727
    }
1727
      {
1728
  }
1728
        ep = &hpcd->IN_ep[epindex];
1729
 
1729
 
1730
  return HAL_OK;
1730
        /* clear int flag */
1731
}
1731
        PCD_CLEAR_TX_EP_CTR(hpcd->Instance, epindex);
1732
 
1732
 
1733
 
1733
        if (ep->type == EP_TYPE_ISOC)
1734
/**
1734
        {
1735
  * @brief  Manage double buffer bulk out transaction from ISR
1735
          ep->xfer_len = 0U;
1736
  * @param  hpcd PCD handle
1736
 
1737
  * @param  ep current endpoint handle
1737
#if (USE_USB_DOUBLE_BUFFER == 1U)
1738
  * @param  wEPVal Last snapshot of EPRx register value taken in ISR
1738
          if (ep->doublebuffer != 0U)
1739
  * @retval HAL status
1739
          {
1740
  */
1740
            if ((wEPVal & USB_EP_DTOG_TX) != 0U)
1741
static uint16_t HAL_PCD_EP_DB_Receive(PCD_HandleTypeDef *hpcd,
1741
            {
1742
                                      PCD_EPTypeDef *ep, uint16_t wEPVal)
1742
              PCD_SET_EP_DBUF0_CNT(hpcd->Instance, ep->num, ep->is_in, 0U);
1743
{
1743
            }
1744
  uint16_t count;
1744
            else
1745
 
1745
            {
1746
  /* Manage Buffer0 OUT */
1746
              PCD_SET_EP_DBUF1_CNT(hpcd->Instance, ep->num, ep->is_in, 0U);
1747
  if ((wEPVal & USB_EP_DTOG_RX) != 0U)
1747
            }
1748
  {
1748
          }
1749
    /* Get count of received Data on buffer0 */
1749
#endif /* (USE_USB_DOUBLE_BUFFER == 1U) */
1750
    count = (uint16_t)PCD_GET_EP_DBUF0_CNT(hpcd->Instance, ep->num);
1750
 
1751
 
1751
          /* TX COMPLETE */
1752
    if (ep->xfer_len >= count)
1752
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
1753
    {
1753
          hpcd->DataInStageCallback(hpcd, ep->num);
1754
      ep->xfer_len -= count;
1754
#else
1755
    }
1755
          HAL_PCD_DataInStageCallback(hpcd, ep->num);
1756
    else
1756
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
1757
    {
1757
        }
1758
      ep->xfer_len = 0U;
1758
        else
1759
    }
1759
        {
1760
 
1760
          /* Manage Single Buffer Transaction */
1761
    if (ep->xfer_len == 0U)
1761
          if ((wEPVal & USB_EP_KIND) == 0U)
1762
    {
1762
          {
1763
      /* set NAK to OUT endpoint since double buffer is enabled */
1763
            /* multi-packet on the NON control IN endpoint */
1764
      PCD_SET_EP_RX_STATUS(hpcd->Instance, ep->num, USB_EP_RX_NAK);
1764
            TxPctSize = (uint16_t)PCD_GET_EP_TX_CNT(hpcd->Instance, ep->num);
1765
    }
1765
 
1766
 
1766
            if (ep->xfer_len > TxPctSize)
1767
    /* Check if Buffer1 is in blocked sate which requires to toggle */
1767
            {
1768
    if ((wEPVal & USB_EP_DTOG_TX) != 0U)
1768
              ep->xfer_len -= TxPctSize;
1769
    {
1769
            }
1770
      PCD_FreeUserBuffer(hpcd->Instance, ep->num, 0U);
1770
            else
1771
    }
1771
            {
1772
 
1772
              ep->xfer_len = 0U;
1773
    if (count != 0U)
1773
            }
1774
    {
1774
 
1775
      USB_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr0, count);
1775
            /* Zero Length Packet? */
1776
    }
1776
            if (ep->xfer_len == 0U)
1777
  }
1777
            {
1778
  /* Manage Buffer 1 DTOG_RX=0 */
1778
              /* TX COMPLETE */
1779
  else
1779
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
1780
  {
1780
              hpcd->DataInStageCallback(hpcd, ep->num);
1781
    /* Get count of received data */
1781
#else
1782
    count = (uint16_t)PCD_GET_EP_DBUF1_CNT(hpcd->Instance, ep->num);
1782
              HAL_PCD_DataInStageCallback(hpcd, ep->num);
1783
 
1783
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
1784
    if (ep->xfer_len >= count)
1784
            }
1785
    {
1785
            else
1786
      ep->xfer_len -= count;
1786
            {
1787
    }
1787
              /* Transfer is not yet Done */
1788
    else
1788
              ep->xfer_buff += TxPctSize;
1789
    {
1789
              ep->xfer_count += TxPctSize;
1790
      ep->xfer_len = 0U;
1790
              (void)USB_EPStartXfer(hpcd->Instance, ep);
1791
    }
1791
            }
1792
 
1792
          }
1793
    if (ep->xfer_len == 0U)
1793
#if (USE_USB_DOUBLE_BUFFER == 1U)
1794
    {
1794
          /* Double Buffer bulk IN (bulk transfer Len > Ep_Mps) */
1795
      /* set NAK on the current endpoint */
1795
          else
1796
      PCD_SET_EP_RX_STATUS(hpcd->Instance, ep->num, USB_EP_RX_NAK);
1796
          {
1797
    }
1797
            (void)HAL_PCD_EP_DB_Transmit(hpcd, ep, wEPVal);
1798
 
1798
          }
1799
    /*Need to FreeUser Buffer*/
1799
#endif /* (USE_USB_DOUBLE_BUFFER == 1U) */
1800
    if ((wEPVal & USB_EP_DTOG_TX) == 0U)
1800
        }
1801
    {
1801
      }
1802
      PCD_FreeUserBuffer(hpcd->Instance, ep->num, 0U);
1802
    }
1803
    }
1803
  }
1804
 
1804
 
1805
    if (count != 0U)
1805
  return HAL_OK;
1806
    {
1806
}
1807
      USB_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr1, count);
1807
 
1808
    }
1808
 
1809
  }
1809
#if (USE_USB_DOUBLE_BUFFER == 1U)
1810
 
1810
/**
1811
  return count;
1811
  * @brief  Manage double buffer bulk out transaction from ISR
1812
}
1812
  * @param  hpcd PCD handle
1813
 
1813
  * @param  ep current endpoint handle
1814
 
1814
  * @param  wEPVal Last snapshot of EPRx register value taken in ISR
1815
/**
1815
  * @retval HAL status
1816
  * @brief  Manage double buffer bulk IN transaction from ISR
1816
  */
1817
  * @param  hpcd PCD handle
1817
static uint16_t HAL_PCD_EP_DB_Receive(PCD_HandleTypeDef *hpcd,
1818
  * @param  ep current endpoint handle
1818
                                      PCD_EPTypeDef *ep, uint16_t wEPVal)
1819
  * @param  wEPVal Last snapshot of EPRx register value taken in ISR
1819
{
1820
  * @retval HAL status
1820
  uint16_t count;
1821
  */
1821
 
1822
static HAL_StatusTypeDef HAL_PCD_EP_DB_Transmit(PCD_HandleTypeDef *hpcd,
1822
  /* Manage Buffer0 OUT */
1823
                                                PCD_EPTypeDef *ep, uint16_t wEPVal)
1823
  if ((wEPVal & USB_EP_DTOG_RX) != 0U)
1824
{
1824
  {
1825
  uint32_t len;
1825
    /* Get count of received Data on buffer0 */
1826
  uint16_t TxByteNbre;
1826
    count = (uint16_t)PCD_GET_EP_DBUF0_CNT(hpcd->Instance, ep->num);
1827
 
1827
 
1828
  /* Data Buffer0 ACK received */
1828
    if (ep->xfer_len >= count)
1829
  if ((wEPVal & USB_EP_DTOG_TX) != 0U)
1829
    {
1830
  {
1830
      ep->xfer_len -= count;
1831
    /* multi-packet on the NON control IN endpoint */
1831
    }
1832
    TxByteNbre = (uint16_t)PCD_GET_EP_DBUF0_CNT(hpcd->Instance, ep->num);
1832
    else
1833
 
1833
    {
1834
    if (ep->xfer_len > TxByteNbre)
1834
      ep->xfer_len = 0U;
1835
    {
1835
    }
1836
      ep->xfer_len -= TxByteNbre;
1836
 
1837
    }
1837
    if (ep->xfer_len == 0U)
1838
    else
1838
    {
1839
    {
1839
      /* set NAK to OUT endpoint since double buffer is enabled */
1840
      ep->xfer_len = 0U;
1840
      PCD_SET_EP_RX_STATUS(hpcd->Instance, ep->num, USB_EP_RX_NAK);
1841
    }
1841
    }
1842
    /* Transfer is completed */
1842
 
1843
    if (ep->xfer_len == 0U)
1843
    /* Check if Buffer1 is in blocked state which requires to toggle */
1844
    {
1844
    if ((wEPVal & USB_EP_DTOG_TX) != 0U)
1845
      PCD_SET_EP_DBUF0_CNT(hpcd->Instance, ep->num, ep->is_in, 0U);
1845
    {
1846
      PCD_SET_EP_DBUF1_CNT(hpcd->Instance, ep->num, ep->is_in, 0U);
1846
      PCD_FREE_USER_BUFFER(hpcd->Instance, ep->num, 0U);
1847
 
1847
    }
1848
      /* TX COMPLETE */
1848
 
1849
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
1849
    if (count != 0U)
1850
      hpcd->DataInStageCallback(hpcd, ep->num);
1850
    {
1851
#else
1851
      USB_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr0, count);
1852
      HAL_PCD_DataInStageCallback(hpcd, ep->num);
1852
    }
1853
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
1853
  }
1854
 
1854
  /* Manage Buffer 1 DTOG_RX=0 */
1855
      if ((wEPVal & USB_EP_DTOG_RX) != 0U)
1855
  else
1856
      {
1856
  {
1857
        PCD_FreeUserBuffer(hpcd->Instance, ep->num, 1U);
1857
    /* Get count of received data */
1858
      }
1858
    count = (uint16_t)PCD_GET_EP_DBUF1_CNT(hpcd->Instance, ep->num);
1859
    }
1859
 
1860
    else /* Transfer is not yet Done */
1860
    if (ep->xfer_len >= count)
1861
    {
1861
    {
1862
      /* need to Free USB Buff */
1862
      ep->xfer_len -= count;
1863
      if ((wEPVal & USB_EP_DTOG_RX) != 0U)
1863
    }
1864
      {
1864
    else
1865
        PCD_FreeUserBuffer(hpcd->Instance, ep->num, 1U);
1865
    {
1866
      }
1866
      ep->xfer_len = 0U;
1867
 
1867
    }
1868
      /* Still there is data to Fill in the next Buffer */
1868
 
1869
      if (ep->xfer_fill_db == 1U)
1869
    if (ep->xfer_len == 0U)
1870
      {
1870
    {
1871
        ep->xfer_buff += TxByteNbre;
1871
      /* set NAK on the current endpoint */
1872
        ep->xfer_count += TxByteNbre;
1872
      PCD_SET_EP_RX_STATUS(hpcd->Instance, ep->num, USB_EP_RX_NAK);
1873
 
1873
    }
1874
        /* Calculate the len of the new buffer to fill */
1874
 
1875
        if (ep->xfer_len_db >= ep->maxpacket)
1875
    /*Need to FreeUser Buffer*/
1876
        {
1876
    if ((wEPVal & USB_EP_DTOG_TX) == 0U)
1877
          len = ep->maxpacket;
1877
    {
1878
          ep->xfer_len_db -= len;
1878
      PCD_FREE_USER_BUFFER(hpcd->Instance, ep->num, 0U);
1879
        }
1879
    }
1880
        else if (ep->xfer_len_db == 0U)
1880
 
1881
        {
1881
    if (count != 0U)
1882
          len = TxByteNbre;
1882
    {
1883
          ep->xfer_fill_db = 0U;
1883
      USB_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr1, count);
1884
        }
1884
    }
1885
        else
1885
  }
1886
        {
1886
 
1887
          ep->xfer_fill_db = 0U;
1887
  return count;
1888
          len = ep->xfer_len_db;
1888
}
1889
          ep->xfer_len_db = 0U;
1889
 
1890
        }
1890
 
1891
 
1891
/**
1892
        /* Write remaining Data to Buffer */
1892
  * @brief  Manage double buffer bulk IN transaction from ISR
1893
        /* Set the Double buffer counter for pma buffer1 */
1893
  * @param  hpcd PCD handle
1894
        PCD_SET_EP_DBUF0_CNT(hpcd->Instance, ep->num, ep->is_in, len);
1894
  * @param  ep current endpoint handle
1895
 
1895
  * @param  wEPVal Last snapshot of EPRx register value taken in ISR
1896
        /* Copy user buffer to USB PMA */
1896
  * @retval HAL status
1897
        USB_WritePMA(hpcd->Instance, ep->xfer_buff,  ep->pmaaddr0, (uint16_t)len);
1897
  */
1898
      }
1898
static HAL_StatusTypeDef HAL_PCD_EP_DB_Transmit(PCD_HandleTypeDef *hpcd,
1899
    }
1899
                                                PCD_EPTypeDef *ep, uint16_t wEPVal)
1900
  }
1900
{
1901
  else /* Data Buffer1 ACK received */
1901
  uint32_t len;
1902
  {
1902
  uint16_t TxPctSize;
1903
    /* multi-packet on the NON control IN endpoint */
1903
 
1904
    TxByteNbre = (uint16_t)PCD_GET_EP_DBUF1_CNT(hpcd->Instance, ep->num);
1904
  /* Data Buffer0 ACK received */
1905
 
1905
  if ((wEPVal & USB_EP_DTOG_TX) != 0U)
1906
    if (ep->xfer_len >= TxByteNbre)
1906
  {
1907
    {
1907
    /* multi-packet on the NON control IN endpoint */
1908
      ep->xfer_len -= TxByteNbre;
1908
    TxPctSize = (uint16_t)PCD_GET_EP_DBUF0_CNT(hpcd->Instance, ep->num);
1909
    }
1909
 
1910
    else
1910
    if (ep->xfer_len > TxPctSize)
1911
    {
1911
    {
1912
      ep->xfer_len = 0U;
1912
      ep->xfer_len -= TxPctSize;
1913
    }
1913
    }
1914
 
1914
    else
1915
    /* Transfer is completed */
1915
    {
1916
    if (ep->xfer_len == 0U)
1916
      ep->xfer_len = 0U;
1917
    {
1917
    }
1918
      PCD_SET_EP_DBUF0_CNT(hpcd->Instance, ep->num, ep->is_in, 0U);
1918
 
1919
      PCD_SET_EP_DBUF1_CNT(hpcd->Instance, ep->num, ep->is_in, 0U);
1919
    /* Transfer is completed */
1920
 
1920
    if (ep->xfer_len == 0U)
1921
      /* TX COMPLETE */
1921
    {
1922
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
1922
      PCD_SET_EP_DBUF0_CNT(hpcd->Instance, ep->num, ep->is_in, 0U);
1923
      hpcd->DataInStageCallback(hpcd, ep->num);
1923
      PCD_SET_EP_DBUF1_CNT(hpcd->Instance, ep->num, ep->is_in, 0U);
1924
#else
1924
 
1925
      HAL_PCD_DataInStageCallback(hpcd, ep->num);
1925
      /* TX COMPLETE */
1926
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
1926
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
1927
 
1927
      hpcd->DataInStageCallback(hpcd, ep->num);
1928
      /* need to Free USB Buff */
1928
#else
1929
      if ((wEPVal & USB_EP_DTOG_RX) == 0U)
1929
      HAL_PCD_DataInStageCallback(hpcd, ep->num);
1930
      {
1930
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
1931
        PCD_FreeUserBuffer(hpcd->Instance, ep->num, 1U);
1931
 
1932
      }
1932
      if ((wEPVal & USB_EP_DTOG_RX) != 0U)
1933
    }
1933
      {
1934
    else /* Transfer is not yet Done */
1934
        PCD_FREE_USER_BUFFER(hpcd->Instance, ep->num, 1U);
1935
    {
1935
      }
1936
      /* need to Free USB Buff */
1936
    }
1937
      if ((wEPVal & USB_EP_DTOG_RX) == 0U)
1937
    else /* Transfer is not yet Done */
1938
      {
1938
    {
1939
        PCD_FreeUserBuffer(hpcd->Instance, ep->num, 1U);
1939
      /* need to Free USB Buff */
1940
      }
1940
      if ((wEPVal & USB_EP_DTOG_RX) != 0U)
1941
 
1941
      {
1942
      /* Still there is data to Fill in the next Buffer */
1942
        PCD_FREE_USER_BUFFER(hpcd->Instance, ep->num, 1U);
1943
      if (ep->xfer_fill_db == 1U)
1943
      }
1944
      {
1944
 
1945
        ep->xfer_buff += TxByteNbre;
1945
      /* Still there is data to Fill in the next Buffer */
1946
        ep->xfer_count += TxByteNbre;
1946
      if (ep->xfer_fill_db == 1U)
1947
 
1947
      {
1948
        /* Calculate the len of the new buffer to fill */
1948
        ep->xfer_buff += TxPctSize;
1949
        if (ep->xfer_len_db >= ep->maxpacket)
1949
        ep->xfer_count += TxPctSize;
1950
        {
1950
 
1951
          len = ep->maxpacket;
1951
        /* Calculate the len of the new buffer to fill */
1952
          ep->xfer_len_db -= len;
1952
        if (ep->xfer_len_db >= ep->maxpacket)
1953
        }
1953
        {
1954
        else if (ep->xfer_len_db == 0U)
1954
          len = ep->maxpacket;
1955
        {
1955
          ep->xfer_len_db -= len;
1956
          len = TxByteNbre;
1956
        }
1957
          ep->xfer_fill_db = 0U;
1957
        else if (ep->xfer_len_db == 0U)
1958
        }
1958
        {
1959
        else
1959
          len = TxPctSize;
1960
        {
1960
          ep->xfer_fill_db = 0U;
1961
          len = ep->xfer_len_db;
1961
        }
1962
          ep->xfer_len_db = 0U;
1962
        else
1963
          ep->xfer_fill_db = 0;
1963
        {
1964
        }
1964
          ep->xfer_fill_db = 0U;
1965
 
1965
          len = ep->xfer_len_db;
1966
        /* Set the Double buffer counter for pmabuffer1 */
1966
          ep->xfer_len_db = 0U;
1967
        PCD_SET_EP_DBUF1_CNT(hpcd->Instance, ep->num, ep->is_in, len);
1967
        }
1968
 
1968
 
1969
        /* Copy the user buffer to USB PMA */
1969
        /* Write remaining Data to Buffer */
1970
        USB_WritePMA(hpcd->Instance, ep->xfer_buff,  ep->pmaaddr1, (uint16_t)len);
1970
        /* Set the Double buffer counter for pma buffer1 */
1971
      }
1971
        PCD_SET_EP_DBUF0_CNT(hpcd->Instance, ep->num, ep->is_in, len);
1972
    }
1972
 
1973
  }
1973
        /* Copy user buffer to USB PMA */
1974
 
1974
        USB_WritePMA(hpcd->Instance, ep->xfer_buff,  ep->pmaaddr0, (uint16_t)len);
1975
  /*enable endpoint IN*/
1975
      }
1976
  PCD_SET_EP_TX_STATUS(hpcd->Instance, ep->num, USB_EP_TX_VALID);
1976
    }
1977
 
1977
  }
1978
  return HAL_OK;
1978
  else /* Data Buffer1 ACK received */
1979
}
1979
  {
1980
 
1980
    /* multi-packet on the NON control IN endpoint */
1981
 
1981
    TxPctSize = (uint16_t)PCD_GET_EP_DBUF1_CNT(hpcd->Instance, ep->num);
1982
 
1982
 
1983
/**
1983
    if (ep->xfer_len >= TxPctSize)
1984
  * @}
1984
    {
1985
  */
1985
      ep->xfer_len -= TxPctSize;
1986
#endif /* defined (USB) */
1986
    }
1987
#endif /* HAL_PCD_MODULE_ENABLED */
1987
    else
1988
 
1988
    {
1989
/**
1989
      ep->xfer_len = 0U;
1990
  * @}
1990
    }
1991
  */
1991
 
1992
 
1992
    /* Transfer is completed */
1993
/**
1993
    if (ep->xfer_len == 0U)
1994
  * @}
1994
    {
1995
  */
1995
      PCD_SET_EP_DBUF0_CNT(hpcd->Instance, ep->num, ep->is_in, 0U);
1996
 
1996
      PCD_SET_EP_DBUF1_CNT(hpcd->Instance, ep->num, ep->is_in, 0U);
1997
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
1997
 
-
 
1998
      /* TX COMPLETE */
-
 
1999
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
-
 
2000
      hpcd->DataInStageCallback(hpcd, ep->num);
-
 
2001
#else
-
 
2002
      HAL_PCD_DataInStageCallback(hpcd, ep->num);
-
 
2003
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
-
 
2004
 
-
 
2005
      /* need to Free USB Buff */
-
 
2006
      if ((wEPVal & USB_EP_DTOG_RX) == 0U)
-
 
2007
      {
-
 
2008
        PCD_FREE_USER_BUFFER(hpcd->Instance, ep->num, 1U);
-
 
2009
      }
-
 
2010
    }
-
 
2011
    else /* Transfer is not yet Done */
-
 
2012
    {
-
 
2013
      /* need to Free USB Buff */
-
 
2014
      if ((wEPVal & USB_EP_DTOG_RX) == 0U)
-
 
2015
      {
-
 
2016
        PCD_FREE_USER_BUFFER(hpcd->Instance, ep->num, 1U);
-
 
2017
      }
-
 
2018
 
-
 
2019
      /* Still there is data to Fill in the next Buffer */
-
 
2020
      if (ep->xfer_fill_db == 1U)
-
 
2021
      {
-
 
2022
        ep->xfer_buff += TxPctSize;
-
 
2023
        ep->xfer_count += TxPctSize;
-
 
2024
 
-
 
2025
        /* Calculate the len of the new buffer to fill */
-
 
2026
        if (ep->xfer_len_db >= ep->maxpacket)
-
 
2027
        {
-
 
2028
          len = ep->maxpacket;
-
 
2029
          ep->xfer_len_db -= len;
-
 
2030
        }
-
 
2031
        else if (ep->xfer_len_db == 0U)
-
 
2032
        {
-
 
2033
          len = TxPctSize;
-
 
2034
          ep->xfer_fill_db = 0U;
-
 
2035
        }
-
 
2036
        else
-
 
2037
        {
-
 
2038
          len = ep->xfer_len_db;
-
 
2039
          ep->xfer_len_db = 0U;
-
 
2040
          ep->xfer_fill_db = 0;
-
 
2041
        }
-
 
2042
 
-
 
2043
        /* Set the Double buffer counter for pmabuffer1 */
-
 
2044
        PCD_SET_EP_DBUF1_CNT(hpcd->Instance, ep->num, ep->is_in, len);
-
 
2045
 
-
 
2046
        /* Copy the user buffer to USB PMA */
-
 
2047
        USB_WritePMA(hpcd->Instance, ep->xfer_buff,  ep->pmaaddr1, (uint16_t)len);
-
 
2048
      }
-
 
2049
    }
-
 
2050
  }
-
 
2051
 
-
 
2052
  /*enable endpoint IN*/
-
 
2053
  PCD_SET_EP_TX_STATUS(hpcd->Instance, ep->num, USB_EP_TX_VALID);
-
 
2054
 
-
 
2055
  return HAL_OK;
-
 
2056
}
-
 
2057
#endif /* (USE_USB_DOUBLE_BUFFER == 1U) */
-
 
2058
 
-
 
2059
 
-
 
2060
 
-
 
2061
/**
-
 
2062
  * @}
-
 
2063
  */
-
 
2064
#endif /* defined (USB) */
-
 
2065
#endif /* HAL_PCD_MODULE_ENABLED */
-
 
2066
 
-
 
2067
/**
-
 
2068
  * @}
-
 
2069
  */
-
 
2070
 
-
 
2071
/**
-
 
2072
  * @}
-
 
2073
  */