Subversion Repositories FuelGauge

Rev

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

Rev 2 Rev 6
Line 54... Line 54...
54
/* Private functions ---------------------------------------------------------*/
54
/* Private functions ---------------------------------------------------------*/
55
 
55
 
56
 
56
 
57
/**
57
/**
58
  * @brief  Initializes the USB Core
58
  * @brief  Initializes the USB Core
59
  * @param  USBx: USB Instance
59
  * @param  USBx USB Instance
60
  * @param  cfg : pointer to a USB_CfgTypeDef structure that contains
60
  * @param  cfg pointer to a USB_CfgTypeDef structure that contains
61
  *         the configuration information for the specified USBx peripheral.
61
  *         the configuration information for the specified USBx peripheral.
62
  * @retval HAL status
62
  * @retval HAL status
63
  */
63
  */
64
HAL_StatusTypeDef USB_CoreInit(USB_TypeDef *USBx, USB_CfgTypeDef cfg)
64
HAL_StatusTypeDef USB_CoreInit(USB_TypeDef *USBx, USB_CfgTypeDef cfg)
65
{
65
{
Line 76... Line 76...
76
}
76
}
77
 
77
 
78
/**
78
/**
79
  * @brief  USB_EnableGlobalInt
79
  * @brief  USB_EnableGlobalInt
80
  *         Enables the controller's Global Int in the AHB Config reg
80
  *         Enables the controller's Global Int in the AHB Config reg
81
  * @param  USBx : Selected device
81
  * @param  USBx Selected device
82
  * @retval HAL status
82
  * @retval HAL status
83
  */
83
  */
84
HAL_StatusTypeDef USB_EnableGlobalInt(USB_TypeDef *USBx)
84
HAL_StatusTypeDef USB_EnableGlobalInt(USB_TypeDef *USBx)
85
{
85
{
86
  uint16_t winterruptmask;
86
  uint32_t winterruptmask;
-
 
87
 
-
 
88
  /* Clear pending interrupts */
-
 
89
  USBx->ISTR = 0U;
87
 
90
 
88
  /* Set winterruptmask variable */
91
  /* Set winterruptmask variable */
89
  winterruptmask = USB_CNTR_CTRM  | USB_CNTR_WKUPM |
92
  winterruptmask = USB_CNTR_CTRM  | USB_CNTR_WKUPM |
90
                   USB_CNTR_SUSPM | USB_CNTR_ERRM |
93
                   USB_CNTR_SUSPM | USB_CNTR_ERRM |
91
                   USB_CNTR_SOFM | USB_CNTR_ESOFM |
94
                   USB_CNTR_SOFM | USB_CNTR_ESOFM |
92
                   USB_CNTR_RESETM | USB_CNTR_L1REQM;
95
                   USB_CNTR_RESETM | USB_CNTR_L1REQM;
93
 
96
 
94
  /* Set interrupt mask */
97
  /* Set interrupt mask */
95
  USBx->CNTR |= winterruptmask;
98
  USBx->CNTR = (uint16_t)winterruptmask;
96
 
99
 
97
  return HAL_OK;
100
  return HAL_OK;
98
}
101
}
99
 
102
 
100
/**
103
/**
101
  * @brief  USB_DisableGlobalInt
104
  * @brief  USB_DisableGlobalInt
102
  *         Disable the controller's Global Int in the AHB Config reg
105
  *         Disable the controller's Global Int in the AHB Config reg
103
  * @param  USBx : Selected device
106
  * @param  USBx Selected device
104
  * @retval HAL status
107
  * @retval HAL status
105
*/
108
  */
106
HAL_StatusTypeDef USB_DisableGlobalInt(USB_TypeDef *USBx)
109
HAL_StatusTypeDef USB_DisableGlobalInt(USB_TypeDef *USBx)
107
{
110
{
108
  uint16_t winterruptmask;
111
  uint32_t winterruptmask;
109
 
112
 
110
  /* Set winterruptmask variable */
113
  /* Set winterruptmask variable */
111
  winterruptmask = USB_CNTR_CTRM  | USB_CNTR_WKUPM |
114
  winterruptmask = USB_CNTR_CTRM  | USB_CNTR_WKUPM |
112
                   USB_CNTR_SUSPM | USB_CNTR_ERRM |
115
                   USB_CNTR_SUSPM | USB_CNTR_ERRM |
113
                   USB_CNTR_SOFM | USB_CNTR_ESOFM |
116
                   USB_CNTR_SOFM | USB_CNTR_ESOFM |
114
                   USB_CNTR_RESETM | USB_CNTR_L1REQM;
117
                   USB_CNTR_RESETM | USB_CNTR_L1REQM;
115
 
118
 
116
  /* Clear interrupt mask */
119
  /* Clear interrupt mask */
117
  USBx->CNTR &= ~winterruptmask;
120
  USBx->CNTR &= (uint16_t)(~winterruptmask);
118
 
121
 
119
  return HAL_OK;
122
  return HAL_OK;
120
}
123
}
121
 
124
 
122
/**
125
/**
123
  * @brief  USB_SetCurrentMode : Set functional mode
126
  * @brief  USB_SetCurrentMode Set functional mode
124
  * @param  USBx : Selected device
127
  * @param  USBx Selected device
125
  * @param  mode :  current core mode
128
  * @param  mode current core mode
126
  *          This parameter can be one of the these values:
129
  *          This parameter can be one of the these values:
127
  *            @arg USB_DEVICE_MODE: Peripheral mode mode
130
  *            @arg USB_DEVICE_MODE Peripheral mode
128
  * @retval HAL status
131
  * @retval HAL status
129
  */
132
  */
130
HAL_StatusTypeDef USB_SetCurrentMode(USB_TypeDef *USBx, USB_ModeTypeDef mode)
133
HAL_StatusTypeDef USB_SetCurrentMode(USB_TypeDef *USBx, USB_ModeTypeDef mode)
131
{
134
{
132
  /* Prevent unused argument(s) compilation warning */
135
  /* Prevent unused argument(s) compilation warning */
Line 139... Line 142...
139
   */
142
   */
140
  return HAL_OK;
143
  return HAL_OK;
141
}
144
}
142
 
145
 
143
/**
146
/**
144
  * @brief  USB_DevInit : Initializes the USB controller registers
147
  * @brief  USB_DevInit Initializes the USB controller registers
145
  *         for device mode
148
  *         for device mode
146
  * @param  USBx : Selected device
149
  * @param  USBx Selected device
147
  * @param  cfg  : pointer to a USB_CfgTypeDef structure that contains
150
  * @param  cfg  pointer to a USB_CfgTypeDef structure that contains
148
  *         the configuration information for the specified USBx peripheral.
151
  *         the configuration information for the specified USBx peripheral.
149
  * @retval HAL status
152
  * @retval HAL status
150
  */
153
  */
151
HAL_StatusTypeDef USB_DevInit(USB_TypeDef *USBx, USB_CfgTypeDef cfg)
154
HAL_StatusTypeDef USB_DevInit(USB_TypeDef *USBx, USB_CfgTypeDef cfg)
152
{
155
{
153
  /* Prevent unused argument(s) compilation warning */
156
  /* Prevent unused argument(s) compilation warning */
154
  UNUSED(cfg);
157
  UNUSED(cfg);
155
 
158
 
156
  /* Init Device */
159
  /* Init Device */
157
  /*CNTR_FRES = 1*/
160
  /* CNTR_FRES = 1 */
158
  USBx->CNTR = USB_CNTR_FRES;
161
  USBx->CNTR = (uint16_t)USB_CNTR_FRES;
159
 
162
 
160
  /*CNTR_FRES = 0*/
163
  /* CNTR_FRES = 0 */
161
  USBx->CNTR = 0;
164
  USBx->CNTR = 0U;
162
 
165
 
163
  /*Clear pending interrupts*/
166
  /* Clear pending interrupts */
164
  USBx->ISTR = 0;
167
  USBx->ISTR = 0U;
165
 
168
 
166
  /*Set Btable Address*/
169
  /*Set Btable Address*/
167
  USBx->BTABLE = BTABLE_ADDRESS;
170
  USBx->BTABLE = BTABLE_ADDRESS;
168
 
171
 
169
  /* Enable USB Device Interrupt mask */
-
 
170
  (void)USB_EnableGlobalInt(USBx);
-
 
171
 
-
 
172
  return HAL_OK;
-
 
173
}
-
 
174
 
-
 
175
/**
-
 
176
  * @brief  USB_SetDevSpeed :Initializes the device speed
-
 
177
  *         depending on the PHY type and the enumeration speed of the device.
-
 
178
  * @param  USBx  Selected device
-
 
179
  * @param  speed  device speed
-
 
180
  * @retval  Hal status
-
 
181
  */
-
 
182
HAL_StatusTypeDef USB_SetDevSpeed(USB_TypeDef *USBx, uint8_t speed)
-
 
183
{
-
 
184
  /* Prevent unused argument(s) compilation warning */
-
 
185
  UNUSED(USBx);
-
 
186
  UNUSED(speed);
-
 
187
 
-
 
188
  /* NOTE : - This function is not required by USB Device FS peripheral, it is used
-
 
189
              only by USB OTG FS peripheral.
-
 
190
            - This function is added to ensure compatibility across platforms.
-
 
191
   */
-
 
192
 
-
 
193
  return HAL_OK;
-
 
194
}
-
 
195
 
-
 
196
/**
-
 
197
  * @brief  USB_FlushTxFifo : Flush a Tx FIFO
-
 
198
  * @param  USBx : Selected device
-
 
199
  * @param  num : FIFO number
-
 
200
  *         This parameter can be a value from 1 to 15
-
 
201
            15 means Flush all Tx FIFOs
-
 
202
  * @retval HAL status
-
 
203
  */
-
 
204
HAL_StatusTypeDef USB_FlushTxFifo(USB_TypeDef *USBx, uint32_t num)
-
 
205
{
-
 
206
  /* Prevent unused argument(s) compilation warning */
-
 
207
  UNUSED(USBx);
-
 
208
  UNUSED(num);
-
 
209
 
-
 
210
  /* NOTE : - This function is not required by USB Device FS peripheral, it is used
-
 
211
              only by USB OTG FS peripheral.
-
 
212
            - This function is added to ensure compatibility across platforms.
-
 
213
   */
-
 
214
 
-
 
215
  return HAL_OK;
-
 
216
}
-
 
217
 
-
 
218
/**
-
 
219
  * @brief  USB_FlushRxFifo : Flush Rx FIFO
-
 
220
  * @param  USBx : Selected device
-
 
221
  * @retval HAL status
-
 
222
  */
-
 
223
HAL_StatusTypeDef USB_FlushRxFifo(USB_TypeDef *USBx)
-
 
224
{
-
 
225
  /* Prevent unused argument(s) compilation warning */
-
 
226
  UNUSED(USBx);
-
 
227
 
-
 
228
  /* NOTE : - This function is not required by USB Device FS peripheral, it is used
-
 
229
              only by USB OTG FS peripheral.
-
 
230
            - This function is added to ensure compatibility across platforms.
-
 
231
   */
-
 
232
 
-
 
233
  return HAL_OK;
172
  return HAL_OK;
234
}
173
}
235
 
174
 
-
 
175
#if defined (HAL_PCD_MODULE_ENABLED)
236
/**
176
/**
237
  * @brief  Activate and configure an endpoint
177
  * @brief  Activate and configure an endpoint
238
  * @param  USBx : Selected device
178
  * @param  USBx Selected device
239
  * @param  ep: pointer to endpoint structure
179
  * @param  ep pointer to endpoint structure
240
  * @retval HAL status
180
  * @retval HAL status
241
  */
181
  */
242
HAL_StatusTypeDef USB_ActivateEndpoint(USB_TypeDef *USBx, USB_EPTypeDef *ep)
182
HAL_StatusTypeDef USB_ActivateEndpoint(USB_TypeDef *USBx, USB_EPTypeDef *ep)
243
{
183
{
244
  HAL_StatusTypeDef ret = HAL_OK;
184
  HAL_StatusTypeDef ret = HAL_OK;
Line 268... Line 208...
268
    default:
208
    default:
269
      ret = HAL_ERROR;
209
      ret = HAL_ERROR;
270
      break;
210
      break;
271
  }
211
  }
272
 
212
 
273
  PCD_SET_ENDPOINT(USBx, ep->num, wEpRegVal | USB_EP_CTR_RX | USB_EP_CTR_TX);
213
  PCD_SET_ENDPOINT(USBx, ep->num, (wEpRegVal | USB_EP_CTR_RX | USB_EP_CTR_TX));
274
 
214
 
275
  PCD_SET_EP_ADDRESS(USBx, ep->num, ep->num);
215
  PCD_SET_EP_ADDRESS(USBx, ep->num, ep->num);
276
 
216
 
277
  if (ep->doublebuffer == 0U)
217
  if (ep->doublebuffer == 0U)
278
  {
218
  {
Line 293... Line 233...
293
        PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_DIS);
233
        PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_DIS);
294
      }
234
      }
295
    }
235
    }
296
    else
236
    else
297
    {
237
    {
298
      /*Set the endpoint Receive buffer address */
238
      /* Set the endpoint Receive buffer address */
299
      PCD_SET_EP_RX_ADDRESS(USBx, ep->num, ep->pmaadress);
239
      PCD_SET_EP_RX_ADDRESS(USBx, ep->num, ep->pmaadress);
-
 
240
 
300
      /*Set the endpoint Receive buffer counter*/
241
      /* Set the endpoint Receive buffer counter */
301
      PCD_SET_EP_RX_CNT(USBx, ep->num, ep->maxpacket);
242
      PCD_SET_EP_RX_CNT(USBx, ep->num, ep->maxpacket);
302
      PCD_CLEAR_RX_DTOG(USBx, ep->num);
243
      PCD_CLEAR_RX_DTOG(USBx, ep->num);
-
 
244
 
303
      /* Configure VALID status for the Endpoint*/
245
      /* Configure VALID status for the Endpoint */
304
      PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_VALID);
246
      PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_VALID);
305
    }
247
    }
306
  }
248
  }
307
  /*Double Buffer*/
249
  /* Double Buffer */
308
  else
250
  else
309
  {
251
  {
-
 
252
    if (ep->type == EP_TYPE_BULK)
-
 
253
    {
310
    /* Set the endpoint as double buffered */
254
      /* Set bulk endpoint as double buffered */
311
    PCD_SET_EP_DBUF(USBx, ep->num);
255
      PCD_SET_BULK_EP_DBUF(USBx, ep->num);
-
 
256
    }
-
 
257
    else
-
 
258
    {
-
 
259
      /* Set the ISOC endpoint in double buffer mode */
-
 
260
      PCD_CLEAR_EP_KIND(USBx, ep->num);
-
 
261
    }
-
 
262
 
312
    /* Set buffer address for double buffered mode */
263
    /* Set buffer address for double buffered mode */
313
    PCD_SET_EP_DBUF_ADDR(USBx, ep->num, ep->pmaaddr0, ep->pmaaddr1);
264
    PCD_SET_EP_DBUF_ADDR(USBx, ep->num, ep->pmaaddr0, ep->pmaaddr1);
314
 
265
 
315
    if (ep->is_in == 0U)
266
    if (ep->is_in == 0U)
316
    {
267
    {
317
      /* Clear the data toggle bits for the endpoint IN/OUT */
268
      /* Clear the data toggle bits for the endpoint IN/OUT */
318
      PCD_CLEAR_RX_DTOG(USBx, ep->num);
269
      PCD_CLEAR_RX_DTOG(USBx, ep->num);
319
      PCD_CLEAR_TX_DTOG(USBx, ep->num);
270
      PCD_CLEAR_TX_DTOG(USBx, ep->num);
320
 
271
 
321
      /* Reset value of the data toggle bits for the endpoint out */
-
 
322
      PCD_TX_DTOG(USBx, ep->num);
-
 
323
 
-
 
324
      PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_VALID);
272
      PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_VALID);
325
      PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_DIS);
273
      PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_DIS);
326
    }
274
    }
327
    else
275
    else
328
    {
276
    {
329
      /* Clear the data toggle bits for the endpoint IN/OUT */
277
      /* Clear the data toggle bits for the endpoint IN/OUT */
330
      PCD_CLEAR_RX_DTOG(USBx, ep->num);
278
      PCD_CLEAR_RX_DTOG(USBx, ep->num);
331
      PCD_CLEAR_TX_DTOG(USBx, ep->num);
279
      PCD_CLEAR_TX_DTOG(USBx, ep->num);
332
      PCD_RX_DTOG(USBx, ep->num);
-
 
333
 
280
 
334
      if (ep->type != EP_TYPE_ISOC)
281
      if (ep->type != EP_TYPE_ISOC)
335
      {
282
      {
336
        /* Configure NAK status for the Endpoint */
283
        /* Configure NAK status for the Endpoint */
337
        PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_NAK);
284
        PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_NAK);
Line 349... Line 296...
349
  return ret;
296
  return ret;
350
}
297
}
351
 
298
 
352
/**
299
/**
353
  * @brief  De-activate and de-initialize an endpoint
300
  * @brief  De-activate and de-initialize an endpoint
354
  * @param  USBx : Selected device
301
  * @param  USBx Selected device
355
  * @param  ep: pointer to endpoint structure
302
  * @param  ep pointer to endpoint structure
356
  * @retval HAL status
303
  * @retval HAL status
357
  */
304
  */
358
HAL_StatusTypeDef USB_DeactivateEndpoint(USB_TypeDef *USBx, USB_EPTypeDef *ep)
305
HAL_StatusTypeDef USB_DeactivateEndpoint(USB_TypeDef *USBx, USB_EPTypeDef *ep)
359
{
306
{
360
  if (ep->doublebuffer == 0U)
307
  if (ep->doublebuffer == 0U)
361
  {
308
  {
362
    if (ep->is_in != 0U)
309
    if (ep->is_in != 0U)
363
    {
310
    {
364
      PCD_CLEAR_TX_DTOG(USBx, ep->num);
311
      PCD_CLEAR_TX_DTOG(USBx, ep->num);
-
 
312
 
365
      /* Configure DISABLE status for the Endpoint*/
313
      /* Configure DISABLE status for the Endpoint*/
366
      PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_DIS);
314
      PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_DIS);
367
    }
315
    }
368
    else
316
    else
369
    {
317
    {
370
      PCD_CLEAR_RX_DTOG(USBx, ep->num);
318
      PCD_CLEAR_RX_DTOG(USBx, ep->num);
-
 
319
 
371
      /* Configure DISABLE status for the Endpoint*/
320
      /* Configure DISABLE status for the Endpoint*/
372
      PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_DIS);
321
      PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_DIS);
373
    }
322
    }
374
  }
323
  }
375
  /*Double Buffer*/
324
  /*Double Buffer*/
Line 391... Line 340...
391
    {
340
    {
392
      /* Clear the data toggle bits for the endpoint IN/OUT*/
341
      /* Clear the data toggle bits for the endpoint IN/OUT*/
393
      PCD_CLEAR_RX_DTOG(USBx, ep->num);
342
      PCD_CLEAR_RX_DTOG(USBx, ep->num);
394
      PCD_CLEAR_TX_DTOG(USBx, ep->num);
343
      PCD_CLEAR_TX_DTOG(USBx, ep->num);
395
      PCD_RX_DTOG(USBx, ep->num);
344
      PCD_RX_DTOG(USBx, ep->num);
-
 
345
 
396
      /* Configure DISABLE status for the Endpoint*/
346
      /* Configure DISABLE status for the Endpoint*/
397
      PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_DIS);
347
      PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_DIS);
398
      PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_DIS);
348
      PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_DIS);
399
    }
349
    }
400
  }
350
  }
401
 
351
 
402
  return HAL_OK;
352
  return HAL_OK;
403
}
353
}
404
 
354
 
405
/**
355
/**
406
  * @brief  USB_EPStartXfer : setup and starts a transfer over an EP
356
  * @brief  USB_EPStartXfer setup and starts a transfer over an EP
407
  * @param  USBx : Selected device
357
  * @param  USBx Selected device
408
  * @param  ep: pointer to endpoint structure
358
  * @param  ep pointer to endpoint structure
409
  * @retval HAL status
359
  * @retval HAL status
410
  */
360
  */
411
HAL_StatusTypeDef USB_EPStartXfer(USB_TypeDef *USBx, USB_EPTypeDef *ep)
361
HAL_StatusTypeDef USB_EPStartXfer(USB_TypeDef *USBx, USB_EPTypeDef *ep)
412
{
362
{
413
  uint16_t pmabuffer;
-
 
414
  uint32_t len;
363
  uint32_t len;
-
 
364
  uint16_t pmabuffer;
-
 
365
  uint16_t wEPVal;
415
 
366
 
416
  /* IN endpoint */
367
  /* IN endpoint */
417
  if (ep->is_in == 1U)
368
  if (ep->is_in == 1U)
418
  {
369
  {
419
    /*Multi packet transfer*/
370
    /*Multi packet transfer*/
420
    if (ep->xfer_len > ep->maxpacket)
371
    if (ep->xfer_len > ep->maxpacket)
421
    {
372
    {
422
      len = ep->maxpacket;
373
      len = ep->maxpacket;
423
      ep->xfer_len -= len;
-
 
424
    }
374
    }
425
    else
375
    else
426
    {
376
    {
427
      len = ep->xfer_len;
377
      len = ep->xfer_len;
428
      ep->xfer_len = 0U;
-
 
429
    }
378
    }
430
 
379
 
431
    /* configure and validate Tx endpoint */
380
    /* configure and validate Tx endpoint */
432
    if (ep->doublebuffer == 0U)
381
    if (ep->doublebuffer == 0U)
433
    {
382
    {
434
      USB_WritePMA(USBx, ep->xfer_buff, ep->pmaadress, (uint16_t)len);
383
      USB_WritePMA(USBx, ep->xfer_buff, ep->pmaadress, (uint16_t)len);
435
      PCD_SET_EP_TX_CNT(USBx, ep->num, len);
384
      PCD_SET_EP_TX_CNT(USBx, ep->num, len);
436
    }
385
    }
437
    else
386
    else
438
    {
387
    {
439
      /* Write the data to the USB endpoint */
388
      /* double buffer bulk management */
440
      if ((PCD_GET_ENDPOINT(USBx, ep->num) & USB_EP_DTOG_TX) != 0U)
389
      if (ep->type == EP_TYPE_BULK)
441
      {
390
      {
-
 
391
        if (ep->xfer_len_db > ep->maxpacket)
-
 
392
        {
-
 
393
          /* enable double buffer */
-
 
394
          PCD_SET_BULK_EP_DBUF(USBx, ep->num);
-
 
395
 
-
 
396
          /* each Time to write in PMA xfer_len_db will */
-
 
397
          ep->xfer_len_db -= len;
-
 
398
 
-
 
399
          /* Fill the two first buffer in the Buffer0 & Buffer1 */
-
 
400
          if ((PCD_GET_ENDPOINT(USBx, ep->num) & USB_EP_DTOG_TX) != 0U)
-
 
401
          {
-
 
402
            /* Set the Double buffer counter for pmabuffer1 */
-
 
403
            PCD_SET_EP_DBUF1_CNT(USBx, ep->num, ep->is_in, len);
-
 
404
            pmabuffer = ep->pmaaddr1;
-
 
405
 
-
 
406
            /* Write the user buffer to USB PMA */
-
 
407
            USB_WritePMA(USBx, ep->xfer_buff, pmabuffer, (uint16_t)len);
-
 
408
            ep->xfer_buff += len;
-
 
409
 
-
 
410
            if (ep->xfer_len_db > ep->maxpacket)
-
 
411
            {
-
 
412
              ep->xfer_len_db -= len;
-
 
413
            }
-
 
414
            else
-
 
415
            {
-
 
416
              len = ep->xfer_len_db;
-
 
417
              ep->xfer_len_db = 0U;
-
 
418
            }
-
 
419
 
-
 
420
            /* Set the Double buffer counter for pmabuffer0 */
-
 
421
            PCD_SET_EP_DBUF0_CNT(USBx, ep->num, ep->is_in, len);
-
 
422
            pmabuffer = ep->pmaaddr0;
-
 
423
 
-
 
424
            /* Write the user buffer to USB PMA */
-
 
425
            USB_WritePMA(USBx, ep->xfer_buff, pmabuffer, (uint16_t)len);
-
 
426
          }
-
 
427
          else
-
 
428
          {
-
 
429
            /* Set the Double buffer counter for pmabuffer0 */
-
 
430
            PCD_SET_EP_DBUF0_CNT(USBx, ep->num, ep->is_in, len);
-
 
431
            pmabuffer = ep->pmaaddr0;
-
 
432
 
-
 
433
            /* Write the user buffer to USB PMA */
-
 
434
            USB_WritePMA(USBx, ep->xfer_buff, pmabuffer, (uint16_t)len);
-
 
435
            ep->xfer_buff += len;
-
 
436
 
-
 
437
            if (ep->xfer_len_db > ep->maxpacket)
-
 
438
            {
-
 
439
              ep->xfer_len_db -= len;
-
 
440
            }
-
 
441
            else
-
 
442
            {
-
 
443
              len = ep->xfer_len_db;
-
 
444
              ep->xfer_len_db = 0U;
-
 
445
            }
-
 
446
 
442
        /* Set the Double buffer counter for pmabuffer1 */
447
            /* Set the Double buffer counter for pmabuffer1 */
443
        PCD_SET_EP_DBUF1_CNT(USBx, ep->num, ep->is_in, len);
448
            PCD_SET_EP_DBUF1_CNT(USBx, ep->num, ep->is_in, len);
-
 
449
            pmabuffer = ep->pmaaddr1;
-
 
450
 
-
 
451
            /* Write the user buffer to USB PMA */
-
 
452
            USB_WritePMA(USBx, ep->xfer_buff, pmabuffer, (uint16_t)len);
-
 
453
          }
-
 
454
        }
-
 
455
        /* auto Switch to single buffer mode when transfer <Mps no need to manage in double buffer */
-
 
456
        else
-
 
457
        {
-
 
458
          len = ep->xfer_len_db;
-
 
459
 
-
 
460
          /* disable double buffer mode for Bulk endpoint */
-
 
461
          PCD_CLEAR_BULK_EP_DBUF(USBx, ep->num);
-
 
462
 
-
 
463
          /* Set Tx count with nbre of byte to be transmitted */
-
 
464
          PCD_SET_EP_TX_CNT(USBx, ep->num, len);
444
        pmabuffer = ep->pmaaddr1;
465
          pmabuffer = ep->pmaaddr0;
-
 
466
 
-
 
467
          /* Write the user buffer to USB PMA */
-
 
468
          USB_WritePMA(USBx, ep->xfer_buff, pmabuffer, (uint16_t)len);
-
 
469
        }
445
      }
470
      }
446
      else
471
      else /* manage isochronous double buffer IN mode */
447
      {
472
      {
-
 
473
        /* each Time to write in PMA xfer_len_db will */
-
 
474
        ep->xfer_len_db -= len;
-
 
475
 
-
 
476
        /* Fill the data buffer */
-
 
477
        if ((PCD_GET_ENDPOINT(USBx, ep->num) & USB_EP_DTOG_TX) != 0U)
-
 
478
        {
-
 
479
          /* Set the Double buffer counter for pmabuffer1 */
-
 
480
          PCD_SET_EP_DBUF1_CNT(USBx, ep->num, ep->is_in, len);
-
 
481
          pmabuffer = ep->pmaaddr1;
-
 
482
 
-
 
483
          /* Write the user buffer to USB PMA */
-
 
484
          USB_WritePMA(USBx, ep->xfer_buff, pmabuffer, (uint16_t)len);
-
 
485
        }
-
 
486
        else
-
 
487
        {
448
        /* Set the Double buffer counter for pmabuffer0 */
488
          /* Set the Double buffer counter for pmabuffer0 */
449
        PCD_SET_EP_DBUF0_CNT(USBx, ep->num, ep->is_in, len);
489
          PCD_SET_EP_DBUF0_CNT(USBx, ep->num, ep->is_in, len);
450
        pmabuffer = ep->pmaaddr0;
490
          pmabuffer = ep->pmaaddr0;
-
 
491
 
-
 
492
          /* Write the user buffer to USB PMA */
-
 
493
          USB_WritePMA(USBx, ep->xfer_buff, pmabuffer, (uint16_t)len);
-
 
494
        }
451
      }
495
      }
452
      USB_WritePMA(USBx, ep->xfer_buff, pmabuffer, (uint16_t)len);
-
 
453
      PCD_FreeUserBuffer(USBx, ep->num, ep->is_in);
-
 
454
    }
496
    }
455
 
497
 
456
    PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_VALID);
498
    PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_VALID);
457
  }
499
  }
458
  else /* OUT endpoint */
500
  else /* OUT endpoint */
459
  {
501
  {
460
    /* Multi packet transfer*/
-
 
461
    if (ep->xfer_len > ep->maxpacket)
-
 
462
    {
-
 
463
      len = ep->maxpacket;
-
 
464
      ep->xfer_len -= len;
-
 
465
    }
-
 
466
    else
-
 
467
    {
-
 
468
      len = ep->xfer_len;
-
 
469
      ep->xfer_len = 0U;
-
 
470
    }
-
 
471
 
-
 
472
    /* configure and validate Rx endpoint */
-
 
473
    if (ep->doublebuffer == 0U)
502
    if (ep->doublebuffer == 0U)
474
    {
503
    {
475
      /*Set RX buffer count*/
504
      /* Multi packet transfer */
-
 
505
      if (ep->xfer_len > ep->maxpacket)
-
 
506
      {
-
 
507
        len = ep->maxpacket;
-
 
508
        ep->xfer_len -= len;
-
 
509
      }
-
 
510
      else
-
 
511
      {
-
 
512
        len = ep->xfer_len;
-
 
513
        ep->xfer_len = 0U;
-
 
514
      }
-
 
515
      /* configure and validate Rx endpoint */
476
      PCD_SET_EP_RX_CNT(USBx, ep->num, len);
516
      PCD_SET_EP_RX_CNT(USBx, ep->num, len);
477
    }
517
    }
478
    else
518
    else
479
    {
519
    {
-
 
520
      /* First Transfer Coming From HAL_PCD_EP_Receive & From ISR */
480
      /*Set the Double buffer counter*/
521
      /* Set the Double buffer counter */
-
 
522
      if (ep->type == EP_TYPE_BULK)
-
 
523
      {
-
 
524
        PCD_SET_EP_DBUF_CNT(USBx, ep->num, ep->is_in, ep->maxpacket);
-
 
525
 
-
 
526
        /* Coming from ISR */
-
 
527
        if (ep->xfer_count != 0U)
-
 
528
        {
-
 
529
          /* update last value to check if there is blocking state */
-
 
530
          wEPVal = PCD_GET_ENDPOINT(USBx, ep->num);
-
 
531
 
-
 
532
          /*Blocking State */
-
 
533
          if ((((wEPVal & USB_EP_DTOG_RX) != 0U) && ((wEPVal & USB_EP_DTOG_TX) != 0U)) ||
-
 
534
              (((wEPVal & USB_EP_DTOG_RX) == 0U) && ((wEPVal & USB_EP_DTOG_TX) == 0U)))
-
 
535
          {
-
 
536
            PCD_FreeUserBuffer(USBx, ep->num, 0U);
-
 
537
          }
-
 
538
        }
-
 
539
      }
-
 
540
      /* iso out double */
-
 
541
      else if (ep->type == EP_TYPE_ISOC)
-
 
542
      {
-
 
543
        /* Multi packet transfer */
-
 
544
        if (ep->xfer_len > ep->maxpacket)
-
 
545
        {
-
 
546
          len = ep->maxpacket;
-
 
547
          ep->xfer_len -= len;
-
 
548
        }
-
 
549
        else
-
 
550
        {
-
 
551
          len = ep->xfer_len;
-
 
552
          ep->xfer_len = 0U;
-
 
553
        }
481
      PCD_SET_EP_DBUF_CNT(USBx, ep->num, ep->is_in, len);
554
        PCD_SET_EP_DBUF_CNT(USBx, ep->num, ep->is_in, len);
-
 
555
      }
-
 
556
      else
-
 
557
      {
-
 
558
        return HAL_ERROR;
-
 
559
      }
482
    }
560
    }
483
 
561
 
484
    PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_VALID);
562
    PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_VALID);
485
  }
563
  }
486
 
564
 
487
  return HAL_OK;
565
  return HAL_OK;
488
}
566
}
489
 
567
 
490
/**
-
 
491
  * @brief  USB_WritePacket : Writes a packet into the Tx FIFO associated
-
 
492
  *         with the EP/channel
-
 
493
  * @param  USBx : Selected device
-
 
494
  * @param  src :  pointer to source buffer
-
 
495
  * @param  ch_ep_num : endpoint or host channel number
-
 
496
  * @param  len : Number of bytes to write
-
 
497
  * @retval HAL status
-
 
498
  */
-
 
499
HAL_StatusTypeDef USB_WritePacket(USB_TypeDef *USBx, uint8_t *src, uint8_t ch_ep_num, uint16_t len)
-
 
500
{
-
 
501
  /* Prevent unused argument(s) compilation warning */
-
 
502
  UNUSED(USBx);
-
 
503
  UNUSED(src);
-
 
504
  UNUSED(ch_ep_num);
-
 
505
  UNUSED(len);
-
 
506
  /* NOTE : - This function is not required by USB Device FS peripheral, it is used
-
 
507
              only by USB OTG FS peripheral.
-
 
508
            - This function is added to ensure compatibility across platforms.
-
 
509
   */
-
 
510
  return HAL_OK;
-
 
511
}
-
 
512
 
568
 
513
/**
569
/**
514
  * @brief  USB_ReadPacket : read a packet from the Tx FIFO associated
-
 
515
  *         with the EP/channel
-
 
516
  * @param  USBx : Selected device
-
 
517
  * @param  dest : destination pointer
-
 
518
  * @param  len : Number of bytes to read
-
 
519
  * @retval pointer to destination buffer
-
 
520
  */
-
 
521
void *USB_ReadPacket(USB_TypeDef *USBx, uint8_t *dest, uint16_t len)
-
 
522
{
-
 
523
  /* Prevent unused argument(s) compilation warning */
-
 
524
  UNUSED(USBx);
-
 
525
  UNUSED(dest);
-
 
526
  UNUSED(len);
-
 
527
  /* NOTE : - This function is not required by USB Device FS peripheral, it is used
-
 
528
              only by USB OTG FS peripheral.
-
 
529
            - This function is added to ensure compatibility across platforms.
-
 
530
   */
-
 
531
  return ((void *)NULL);
-
 
532
}
-
 
533
 
-
 
534
/**
-
 
535
  * @brief  USB_EPSetStall : set a stall condition over an EP
570
  * @brief  USB_EPSetStall set a stall condition over an EP
536
  * @param  USBx : Selected device
571
  * @param  USBx Selected device
537
  * @param  ep: pointer to endpoint structure
572
  * @param  ep pointer to endpoint structure
538
  * @retval HAL status
573
  * @retval HAL status
539
  */
574
  */
540
HAL_StatusTypeDef USB_EPSetStall(USB_TypeDef *USBx, USB_EPTypeDef *ep)
575
HAL_StatusTypeDef USB_EPSetStall(USB_TypeDef *USBx, USB_EPTypeDef *ep)
541
{
576
{
542
  if (ep->is_in != 0U)
577
  if (ep->is_in != 0U)
Line 550... Line 585...
550
 
585
 
551
  return HAL_OK;
586
  return HAL_OK;
552
}
587
}
553
 
588
 
554
/**
589
/**
555
  * @brief  USB_EPClearStall : Clear a stall condition over an EP
590
  * @brief  USB_EPClearStall Clear a stall condition over an EP
556
  * @param  USBx : Selected device
591
  * @param  USBx Selected device
557
  * @param  ep: pointer to endpoint structure
592
  * @param  ep pointer to endpoint structure
558
  * @retval HAL status
593
  * @retval HAL status
559
  */
594
  */
560
HAL_StatusTypeDef USB_EPClearStall(USB_TypeDef *USBx, USB_EPTypeDef *ep)
595
HAL_StatusTypeDef USB_EPClearStall(USB_TypeDef *USBx, USB_EPTypeDef *ep)
561
{
596
{
562
  if (ep->doublebuffer == 0U)
597
  if (ep->doublebuffer == 0U)
Line 573... Line 608...
573
    }
608
    }
574
    else
609
    else
575
    {
610
    {
576
      PCD_CLEAR_RX_DTOG(USBx, ep->num);
611
      PCD_CLEAR_RX_DTOG(USBx, ep->num);
577
 
612
 
578
      /* Configure VALID status for the Endpoint*/
613
      /* Configure VALID status for the Endpoint */
579
      PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_VALID);
614
      PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_VALID);
580
    }
615
    }
581
  }
616
  }
582
 
617
 
583
  return HAL_OK;
618
  return HAL_OK;
584
}
619
}
-
 
620
#endif /* defined (HAL_PCD_MODULE_ENABLED) */
585
 
621
 
586
/**
622
/**
587
  * @brief  USB_StopDevice : Stop the usb device mode
623
  * @brief  USB_StopDevice Stop the usb device mode
588
  * @param  USBx : Selected device
624
  * @param  USBx Selected device
589
  * @retval HAL status
625
  * @retval HAL status
590
  */
626
  */
591
HAL_StatusTypeDef USB_StopDevice(USB_TypeDef *USBx)
627
HAL_StatusTypeDef USB_StopDevice(USB_TypeDef *USBx)
592
{
628
{
593
  /* disable all interrupts and force USB reset */
629
  /* disable all interrupts and force USB reset */
594
  USBx->CNTR = USB_CNTR_FRES;
630
  USBx->CNTR = (uint16_t)USB_CNTR_FRES;
595
 
631
 
596
  /* clear interrupt status register */
632
  /* clear interrupt status register */
597
  USBx->ISTR = 0;
633
  USBx->ISTR = 0U;
598
 
634
 
599
  /* switch-off device */
635
  /* switch-off device */
600
  USBx->CNTR = (USB_CNTR_FRES | USB_CNTR_PDWN);
636
  USBx->CNTR = (uint16_t)(USB_CNTR_FRES | USB_CNTR_PDWN);
601
 
637
 
602
  return HAL_OK;
638
  return HAL_OK;
603
}
639
}
604
 
640
 
605
/**
641
/**
606
  * @brief  USB_SetDevAddress : Stop the usb device mode
642
  * @brief  USB_SetDevAddress Stop the usb device mode
607
  * @param  USBx : Selected device
643
  * @param  USBx Selected device
608
  * @param  address : new device address to be assigned
644
  * @param  address new device address to be assigned
609
  *          This parameter can be a value from 0 to 255
645
  *          This parameter can be a value from 0 to 255
610
  * @retval HAL status
646
  * @retval HAL status
611
  */
647
  */
612
HAL_StatusTypeDef  USB_SetDevAddress(USB_TypeDef *USBx, uint8_t address)
648
HAL_StatusTypeDef  USB_SetDevAddress(USB_TypeDef *USBx, uint8_t address)
613
{
649
{
614
  if (address == 0U)
650
  if (address == 0U)
615
  {
651
  {
616
    /* set device address and enable function */
652
    /* set device address and enable function */
617
    USBx->DADDR = USB_DADDR_EF;
653
    USBx->DADDR = (uint16_t)USB_DADDR_EF;
618
  }
654
  }
619
 
655
 
620
  return HAL_OK;
656
  return HAL_OK;
621
}
657
}
622
 
658
 
623
/**
659
/**
624
  * @brief  USB_DevConnect : Connect the USB device by enabling the pull-up/pull-down
660
  * @brief  USB_DevConnect Connect the USB device by enabling the pull-up/pull-down
625
  * @param  USBx : Selected device
661
  * @param  USBx Selected device
626
  * @retval HAL status
662
  * @retval HAL status
627
  */
663
  */
628
HAL_StatusTypeDef  USB_DevConnect(USB_TypeDef *USBx)
664
HAL_StatusTypeDef  USB_DevConnect(USB_TypeDef *USBx)
629
{
665
{
630
  /* Enabling DP Pull-UP bit to Connect internal PU resistor on USB DP line */
666
  /* Enabling DP Pull-UP bit to Connect internal PU resistor on USB DP line */
631
  USBx->BCDR |= USB_BCDR_DPPU;
667
  USBx->BCDR |= (uint16_t)USB_BCDR_DPPU;
632
 
668
 
633
  return HAL_OK;
669
  return HAL_OK;
634
}
670
}
635
 
671
 
636
/**
672
/**
637
  * @brief  USB_DevDisconnect : Disconnect the USB device by disabling the pull-up/pull-down
673
  * @brief  USB_DevDisconnect Disconnect the USB device by disabling the pull-up/pull-down
638
  * @param  USBx : Selected device
674
  * @param  USBx Selected device
639
  * @retval HAL status
675
  * @retval HAL status
640
  */
676
  */
641
HAL_StatusTypeDef  USB_DevDisconnect(USB_TypeDef *USBx)
677
HAL_StatusTypeDef  USB_DevDisconnect(USB_TypeDef *USBx)
642
{
678
{
643
  /* Disable DP Pull-Up bit to disconnect the Internal PU resistor on USB DP line */
679
  /* Disable DP Pull-Up bit to disconnect the Internal PU resistor on USB DP line */
Line 645... Line 681...
645
 
681
 
646
  return HAL_OK;
682
  return HAL_OK;
647
}
683
}
648
 
684
 
649
/**
685
/**
650
  * @brief  USB_ReadInterrupts: return the global USB interrupt status
686
  * @brief  USB_ReadInterrupts return the global USB interrupt status
651
  * @param  USBx : Selected device
687
  * @param  USBx Selected device
652
  * @retval HAL status
688
  * @retval HAL status
653
  */
689
  */
654
uint32_t  USB_ReadInterrupts(USB_TypeDef *USBx)
690
uint32_t  USB_ReadInterrupts(USB_TypeDef *USBx)
655
{
691
{
656
  uint32_t tmpreg;
692
  uint32_t tmpreg;
Line 658... Line 694...
658
  tmpreg = USBx->ISTR;
694
  tmpreg = USBx->ISTR;
659
  return tmpreg;
695
  return tmpreg;
660
}
696
}
661
 
697
 
662
/**
698
/**
663
  * @brief  USB_ReadDevAllOutEpInterrupt: return the USB device OUT endpoints interrupt status
-
 
664
  * @param  USBx : Selected device
-
 
665
  * @retval HAL status
-
 
666
  */
-
 
667
uint32_t USB_ReadDevAllOutEpInterrupt(USB_TypeDef *USBx)
-
 
668
{
-
 
669
  /* Prevent unused argument(s) compilation warning */
-
 
670
  UNUSED(USBx);
-
 
671
  /* NOTE : - This function is not required by USB Device FS peripheral, it is used
-
 
672
              only by USB OTG FS peripheral.
-
 
673
            - This function is added to ensure compatibility across platforms.
-
 
674
   */
-
 
675
  return (0);
-
 
676
}
-
 
677
 
-
 
678
/**
-
 
679
  * @brief  USB_ReadDevAllInEpInterrupt: return the USB device IN endpoints interrupt status
-
 
680
  * @param  USBx : Selected device
-
 
681
  * @retval HAL status
-
 
682
  */
-
 
683
uint32_t USB_ReadDevAllInEpInterrupt(USB_TypeDef *USBx)
-
 
684
{
-
 
685
  /* Prevent unused argument(s) compilation warning */
-
 
686
  UNUSED(USBx);
-
 
687
  /* NOTE : - This function is not required by USB Device FS peripheral, it is used
-
 
688
              only by USB OTG FS peripheral.
-
 
689
            - This function is added to ensure compatibility across platforms.
-
 
690
   */
-
 
691
  return (0);
-
 
692
}
-
 
693
 
-
 
694
/**
-
 
695
  * @brief  Returns Device OUT EP Interrupt register
-
 
696
  * @param  USBx : Selected device
-
 
697
  * @param  epnum : endpoint number
-
 
698
  *          This parameter can be a value from 0 to 15
-
 
699
  * @retval Device OUT EP Interrupt register
-
 
700
  */
-
 
701
uint32_t USB_ReadDevOutEPInterrupt(USB_TypeDef *USBx, uint8_t epnum)
-
 
702
{
-
 
703
  /* Prevent unused argument(s) compilation warning */
-
 
704
  UNUSED(USBx);
-
 
705
  UNUSED(epnum);
-
 
706
  /* NOTE : - This function is not required by USB Device FS peripheral, it is used
-
 
707
              only by USB OTG FS peripheral.
-
 
708
            - This function is added to ensure compatibility across platforms.
-
 
709
   */
-
 
710
  return (0);
-
 
711
}
-
 
712
 
-
 
713
/**
-
 
714
  * @brief  Returns Device IN EP Interrupt register
-
 
715
  * @param  USBx : Selected device
-
 
716
  * @param  epnum : endpoint number
-
 
717
  *          This parameter can be a value from 0 to 15
-
 
718
  * @retval Device IN EP Interrupt register
-
 
719
  */
-
 
720
uint32_t USB_ReadDevInEPInterrupt(USB_TypeDef *USBx, uint8_t epnum)
-
 
721
{
-
 
722
  /* Prevent unused argument(s) compilation warning */
-
 
723
  UNUSED(USBx);
-
 
724
  UNUSED(epnum);
-
 
725
  /* NOTE : - This function is not required by USB Device FS peripheral, it is used
-
 
726
              only by USB OTG FS peripheral.
-
 
727
            - This function is added to ensure compatibility across platforms.
-
 
728
   */
-
 
729
  return (0);
-
 
730
}
-
 
731
 
-
 
732
/**
-
 
733
  * @brief  USB_ClearInterrupts: clear a USB interrupt
-
 
734
  * @param  USBx  Selected device
-
 
735
  * @param  interrupt  interrupt flag
-
 
736
  * @retval None
-
 
737
  */
-
 
738
void  USB_ClearInterrupts(USB_TypeDef *USBx, uint32_t interrupt)
-
 
739
{
-
 
740
  /* Prevent unused argument(s) compilation warning */
-
 
741
  UNUSED(USBx);
-
 
742
  UNUSED(interrupt);
-
 
743
  /* NOTE : - This function is not required by USB Device FS peripheral, it is used
-
 
744
              only by USB OTG FS peripheral.
-
 
745
            - This function is added to ensure compatibility across platforms.
-
 
746
   */
-
 
747
}
-
 
748
 
-
 
749
/**
-
 
750
  * @brief  Prepare the EP0 to start the first control setup
-
 
751
  * @param  USBx  Selected device
-
 
752
  * @param  psetup  pointer to setup packet
-
 
753
  * @retval HAL status
-
 
754
  */
-
 
755
HAL_StatusTypeDef USB_EP0_OutStart(USB_TypeDef *USBx, uint8_t *psetup)
-
 
756
{
-
 
757
  /* Prevent unused argument(s) compilation warning */
-
 
758
  UNUSED(USBx);
-
 
759
  UNUSED(psetup);
-
 
760
  /* NOTE : - This function is not required by USB Device FS peripheral, it is used
-
 
761
              only by USB OTG FS peripheral.
-
 
762
            - This function is added to ensure compatibility across platforms.
-
 
763
   */
-
 
764
  return HAL_OK;
-
 
765
}
-
 
766
 
-
 
767
/**
-
 
768
  * @brief  USB_ActivateRemoteWakeup : active remote wakeup signalling
699
  * @brief  USB_ActivateRemoteWakeup : active remote wakeup signalling
769
  * @param  USBx  Selected device
700
  * @param  USBx Selected device
770
  * @retval HAL status
701
  * @retval HAL status
771
  */
702
  */
772
HAL_StatusTypeDef USB_ActivateRemoteWakeup(USB_TypeDef *USBx)
703
HAL_StatusTypeDef USB_ActivateRemoteWakeup(USB_TypeDef *USBx)
773
{
704
{
774
  USBx->CNTR |= USB_CNTR_RESUME;
705
  USBx->CNTR |= (uint16_t)USB_CNTR_RESUME;
775
 
706
 
776
  return HAL_OK;
707
  return HAL_OK;
777
}
708
}
778
 
709
 
779
/**
710
/**
780
  * @brief  USB_DeActivateRemoteWakeup : de-active remote wakeup signalling
711
  * @brief  USB_DeActivateRemoteWakeup de-active remote wakeup signalling
781
  * @param  USBx  Selected device
712
  * @param  USBx Selected device
782
  * @retval HAL status
713
  * @retval HAL status
783
  */
714
  */
784
HAL_StatusTypeDef USB_DeActivateRemoteWakeup(USB_TypeDef *USBx)
715
HAL_StatusTypeDef USB_DeActivateRemoteWakeup(USB_TypeDef *USBx)
785
{
716
{
786
  USBx->CNTR &= ~(USB_CNTR_RESUME);
717
  USBx->CNTR &= (uint16_t)(~USB_CNTR_RESUME);
-
 
718
 
787
  return HAL_OK;
719
  return HAL_OK;
788
}
720
}
789
 
721
 
790
/**
722
/**
791
  * @brief Copy a buffer from user memory area to packet memory area (PMA)
723
  * @brief Copy a buffer from user memory area to packet memory area (PMA)
792
  * @param   USBx USB peripheral instance register address.
724
  * @param   USBx USB peripheral instance register address.
793
  * @param   pbUsrBuf pointer to user memory area.
725
  * @param   pbUsrBuf pointer to user memory area.
794
  * @param   wPMABufAddr address into PMA.
726
  * @param   wPMABufAddr address into PMA.
795
  * @param   wNBytes: no. of bytes to be copied.
727
  * @param   wNBytes no. of bytes to be copied.
796
  * @retval None
728
  * @retval None
797
  */
729
  */
798
void USB_WritePMA(USB_TypeDef *USBx, uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes)
730
void USB_WritePMA(USB_TypeDef *USBx, uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes)
799
{
731
{
800
  uint32_t n = ((uint32_t)wNBytes + 1U) >> 1;
732
  uint32_t n = ((uint32_t)wNBytes + 1U) >> 1;
Line 820... Line 752...
820
    pBuf++;
752
    pBuf++;
821
  }
753
  }
822
}
754
}
823
 
755
 
824
/**
756
/**
825
  * @brief Copy a buffer from user memory area to packet memory area (PMA)
757
  * @brief Copy data from packet memory area (PMA) to user memory buffer
826
  * @param   USBx: USB peripheral instance register address.
758
  * @param   USBx USB peripheral instance register address.
827
  * @param   pbUsrBuf pointer to user memory area.
759
  * @param   pbUsrBuf pointer to user memory area.
828
  * @param   wPMABufAddr address into PMA.
760
  * @param   wPMABufAddr address into PMA.
829
  * @param   wNBytes: no. of bytes to be copied.
761
  * @param   wNBytes no. of bytes to be copied.
830
  * @retval None
762
  * @retval None
831
  */
763
  */
832
void USB_ReadPMA(USB_TypeDef *USBx, uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes)
764
void USB_ReadPMA(USB_TypeDef *USBx, uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes)
833
{
765
{
834
  uint32_t n = (uint32_t)wNBytes >> 1;
766
  uint32_t n = (uint32_t)wNBytes >> 1;