Browse code

Add source code of the firmware for the IO Board

Pawel Jablonski authored on 05/06/2023 17:01:27
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,701 @@
1
+/**
2
+  ******************************************************************************
3
+  * @file    usbd_conf_template.c
4
+  * @author  MCD Application Team
5
+  * @brief   USB Device configuration and interface file
6
+  *          This template should be copied to the user folder,
7
+  *          renamed and customized following user needs.
8
+  ******************************************************************************
9
+  * @attention
10
+  *
11
+  * Copyright (c) 2015 STMicroelectronics.
12
+  * All rights reserved.
13
+  *
14
+  * This software is licensed under terms that can be found in the LICENSE file
15
+  * in the root directory of this software component.
16
+  * If no LICENSE file comes with this software, it is provided AS-IS.
17
+  *
18
+  ******************************************************************************
19
+  */
20
+
21
+/* Includes ------------------------------------------------------------------*/
22
+#include "usbd_core.h"
23
+#include "usbd_msc.h" /* Include class header file */
24
+/* Private typedef -----------------------------------------------------------*/
25
+/* Private define ------------------------------------------------------------*/
26
+/* Private macro -------------------------------------------------------------*/
27
+/* Private variables ---------------------------------------------------------*/
28
+PCD_HandleTypeDef USBD_PCD_Handle;
29
+
30
+/* Private function prototypes -----------------------------------------------*/
31
+/* Private functions ---------------------------------------------------------*/
32
+
33
+/*******************************************************************************
34
+                       LL Driver Callbacks (PCD -> USB Device Library)
35
+*******************************************************************************/
36
+/* MSP Init */
37
+
38
+void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle)
39
+{
40
+  if(pcdHandle->Instance==USB) {
41
+    /* Peripheral clock enable */
42
+    __HAL_RCC_USB_CLK_ENABLE();
43
+
44
+    /* Peripheral interrupt init */
45
+    HAL_NVIC_SetPriority(USB_IRQn, 0, 0);
46
+    HAL_NVIC_EnableIRQ(USB_IRQn);
47
+  }
48
+}
49
+
50
+void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle)
51
+{
52
+  if(pcdHandle->Instance==USB) {
53
+    /* Peripheral clock disable */
54
+    __HAL_RCC_USB_CLK_DISABLE();
55
+
56
+    /* Peripheral interrupt Deinit*/
57
+    HAL_NVIC_DisableIRQ(USB_IRQn);
58
+  }
59
+}
60
+
61
+/**
62
+  * @brief  Setup Stage callback
63
+  * @param  hpcd: PCD handle
64
+  * @retval None
65
+  */
66
+void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd)
67
+{
68
+  USBD_LL_SetupStage((USBD_HandleTypeDef*)hpcd->pData, (uint8_t *)hpcd->Setup);
69
+}
70
+
71
+/**
72
+  * @brief  Data Out Stage callback.
73
+  * @param  hpcd: PCD handle
74
+  * @param  epnum: Endpoint Number
75
+  * @retval None
76
+  */
77
+void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
78
+{
79
+  USBD_LL_DataOutStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->OUT_ep[epnum].xfer_buff);
80
+}
81
+
82
+/**
83
+  * @brief  Data In Stage callback..
84
+  * @param  hpcd: PCD handle
85
+  * @param  epnum: Endpoint Number
86
+  * @retval None
87
+  */
88
+void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
89
+{
90
+  USBD_LL_DataInStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->IN_ep[epnum].xfer_buff);
91
+}
92
+
93
+/**
94
+  * @brief  SOF callback.
95
+  * @param  hpcd: PCD handle
96
+  * @retval None
97
+  */
98
+void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd)
99
+{
100
+  USBD_LL_SOF((USBD_HandleTypeDef*)hpcd->pData);
101
+}
102
+
103
+/**
104
+  * @brief  Reset callback.
105
+  * @param  hpcd: PCD handle
106
+  * @retval None
107
+  */
108
+void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd)
109
+{ 
110
+  USBD_SpeedTypeDef speed = USBD_SPEED_FULL;
111
+
112
+  /*Set USB Current Speed*/
113
+  switch (hpcd->Init.speed) {
114
+  case PCD_SPEED_FULL:
115
+    speed = USBD_SPEED_FULL;
116
+    break;
117
+	
118
+  default:
119
+    speed = USBD_SPEED_FULL;
120
+    break;    
121
+  }
122
+
123
+  USBD_LL_SetSpeed((USBD_HandleTypeDef*)hpcd->pData, speed);
124
+  
125
+  /*Reset Device*/
126
+  USBD_LL_Reset((USBD_HandleTypeDef*)hpcd->pData);
127
+}
128
+
129
+/**
130
+  * @brief  Suspend callback.
131
+  * When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it)
132
+  * @param  hpcd: PCD handle
133
+  * @retval None
134
+  */
135
+void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd)
136
+{
137
+  /* Inform USB library that core enters in suspend Mode */
138
+  USBD_LL_Suspend((USBD_HandleTypeDef*)hpcd->pData);
139
+
140
+  /* Enter in STOP mode */
141
+  if(hpcd->Init.low_power_enable) {
142
+    /* Set SLEEPDEEP bit and SleepOnExit of Cortex System Control Register */
143
+    SCB->SCR |= (uint32_t)((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk));
144
+  }
145
+}
146
+
147
+/**
148
+  * @brief  Resume callback.
149
+  * When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it)
150
+  * @param  hpcd: PCD handle
151
+  * @retval None
152
+  */
153
+void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd)
154
+{
155
+  if (hpcd->Init.low_power_enable) {
156
+    /* Reset SLEEPDEEP bit of Cortex System Control Register */
157
+    SCB->SCR &= (uint32_t)~((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk));  
158
+  }
159
+
160
+  USBD_LL_Resume((USBD_HandleTypeDef*)hpcd->pData);
161
+}
162
+
163
+/**
164
+  * @brief  ISOOUTIncomplete callback.
165
+  * @param  hpcd: PCD handle
166
+  * @param  epnum: Endpoint Number
167
+  * @retval None
168
+  */
169
+void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
170
+{
171
+  USBD_LL_IsoOUTIncomplete((USBD_HandleTypeDef*)hpcd->pData, epnum);
172
+}
173
+
174
+/**
175
+  * @brief  ISOINIncomplete callback.
176
+  * @param  hpcd: PCD handle
177
+  * @param  epnum: Endpoint Number
178
+  * @retval None
179
+  */
180
+void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
181
+{
182
+  USBD_LL_IsoINIncomplete((USBD_HandleTypeDef*)hpcd->pData, epnum);
183
+}
184
+
185
+/**
186
+  * @brief  ConnectCallback callback.
187
+  * @param  hpcd: PCD handle
188
+  * @retval None
189
+  */
190
+void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd)
191
+{
192
+  USBD_LL_DevConnected((USBD_HandleTypeDef*)hpcd->pData);
193
+}
194
+
195
+/**
196
+  * @brief  Disconnect callback.
197
+  * @param  hpcd: PCD handle
198
+  * @retval None
199
+  */
200
+void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd)
201
+{
202
+  USBD_LL_DevDisconnected((USBD_HandleTypeDef*)hpcd->pData);
203
+}
204
+
205
+/*******************************************************************************
206
+                       LL Driver Interface (USB Device Library --> PCD)
207
+*******************************************************************************/
208
+
209
+/**
210
+  * @brief  Initializes the Low Level portion of the Device driver.
211
+  * @param  pdev: Device handle
212
+  * @retval USBD Status
213
+  */
214
+USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev)
215
+{
216
+  /* Init USB_IP */
217
+  /* Link The driver to the stack */
218
+  USBD_PCD_Handle.pData = pdev;
219
+  pdev->pData = &USBD_PCD_Handle;
220
+
221
+  USBD_PCD_Handle.Instance = USB;
222
+  USBD_PCD_Handle.Init.dev_endpoints = 8;
223
+  USBD_PCD_Handle.Init.speed = PCD_SPEED_FULL;
224
+  USBD_PCD_Handle.Init.ep0_mps = EP_MPS_64;
225
+  USBD_PCD_Handle.Init.phy_itface = PCD_PHY_EMBEDDED;
226
+  USBD_PCD_Handle.Init.low_power_enable = DISABLE;
227
+  USBD_PCD_Handle.Init.lpm_enable = DISABLE;
228
+  USBD_PCD_Handle.Init.battery_charging_enable = DISABLE;
229
+  
230
+  if (HAL_PCD_Init(&USBD_PCD_Handle) != HAL_OK)
231
+  {
232
+    return(USBD_FAIL);
233
+  }
234
+
235
+  HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x00 , PCD_SNG_BUF, 0x18);
236
+  HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x80 , PCD_SNG_BUF, 0x58);
237
+  HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x81 , PCD_SNG_BUF, 0x98);
238
+  HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x01 , PCD_SNG_BUF, 0xD8);
239
+
240
+  return(USBD_OK);
241
+}
242
+
243
+/**
244
+  * @brief  De-Initializes the Low Level portion of the Device driver.
245
+  * @param  pdev: Device handle
246
+  * @retval USBD Status
247
+  */
248
+USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev)
249
+{
250
+  HAL_StatusTypeDef hal_status = HAL_OK;
251
+  USBD_StatusTypeDef usb_status = USBD_OK;
252
+ 
253
+  hal_status = HAL_PCD_DeInit(pdev->pData);
254
+     
255
+  switch(hal_status) {
256
+    case HAL_OK :
257
+      usb_status = USBD_OK;
258
+    break;
259
+    case HAL_ERROR :
260
+      usb_status = USBD_FAIL;
261
+    break;
262
+    case HAL_BUSY :
263
+      usb_status = USBD_BUSY;
264
+    break;
265
+    case HAL_TIMEOUT :
266
+      usb_status = USBD_FAIL;
267
+    break;
268
+    default :
269
+      usb_status = USBD_FAIL;
270
+    break;
271
+  }
272
+
273
+  return(usb_status);
274
+ }
275
+
276
+/**
277
+  * @brief  Starts the Low Level portion of the Device driver.
278
+  * @param  pdev: Device handle
279
+  * @retval USBD Status
280
+  */
281
+USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev)
282
+{
283
+  HAL_StatusTypeDef hal_status = HAL_OK;
284
+  USBD_StatusTypeDef usb_status = USBD_OK;
285
+ 
286
+  hal_status = HAL_PCD_Start(pdev->pData);
287
+     
288
+  switch(hal_status) {
289
+    case HAL_OK :
290
+      usb_status = USBD_OK;
291
+    break;
292
+    case HAL_ERROR :
293
+      usb_status = USBD_FAIL;
294
+    break;
295
+    case HAL_BUSY :
296
+      usb_status = USBD_BUSY;
297
+    break;
298
+    case HAL_TIMEOUT :
299
+      usb_status = USBD_FAIL;
300
+    break;
301
+    default :
302
+      usb_status = USBD_FAIL;
303
+    break;
304
+  }
305
+
306
+  return(usb_status);
307
+}
308
+
309
+/**
310
+  * @brief  Stops the Low Level portion of the Device driver.
311
+  * @param  pdev: Device handle
312
+  * @retval USBD Status
313
+  */
314
+USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev)
315
+{
316
+  HAL_StatusTypeDef hal_status = HAL_OK;
317
+  USBD_StatusTypeDef usb_status = USBD_OK;
318
+ 
319
+  hal_status = HAL_PCD_Stop(pdev->pData);
320
+     
321
+  switch(hal_status) {
322
+    case HAL_OK :
323
+      usb_status = USBD_OK;
324
+    break;
325
+    case HAL_ERROR :
326
+      usb_status = USBD_FAIL;
327
+    break;
328
+    case HAL_BUSY :
329
+      usb_status = USBD_BUSY;
330
+    break;
331
+    case HAL_TIMEOUT :
332
+      usb_status = USBD_FAIL;
333
+    break;
334
+    default :
335
+      usb_status = USBD_FAIL;
336
+    break;
337
+  }
338
+
339
+  return(usb_status);
340
+}
341
+
342
+/**
343
+  * @brief  Opens an endpoint of the Low Level Driver.
344
+  * @param  pdev: Device handle
345
+  * @param  ep_addr: Endpoint Number
346
+  * @param  ep_type: Endpoint Type
347
+  * @param  ep_mps: Endpoint Max Packet Size
348
+  * @retval USBD Status
349
+  */
350
+USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr,
351
+                                  uint8_t ep_type, uint16_t ep_mps)
352
+{
353
+  HAL_StatusTypeDef hal_status = HAL_OK;
354
+  USBD_StatusTypeDef usb_status = USBD_OK;
355
+
356
+  hal_status = HAL_PCD_EP_Open(pdev->pData, 
357
+                               ep_addr, 
358
+                               ep_mps, 
359
+                               ep_type);
360
+
361
+  switch(hal_status) {
362
+    case HAL_OK :
363
+      usb_status = USBD_OK;
364
+    break;
365
+    case HAL_ERROR :
366
+      usb_status = USBD_FAIL;
367
+    break;
368
+    case HAL_BUSY :
369
+      usb_status = USBD_BUSY;
370
+    break;
371
+    case HAL_TIMEOUT :
372
+      usb_status = USBD_FAIL;
373
+    break;
374
+    default :
375
+      usb_status = USBD_FAIL;
376
+    break;
377
+  }
378
+
379
+  return(usb_status);
380
+}
381
+
382
+/**
383
+  * @brief  Closes an endpoint of the Low Level Driver.
384
+  * @param  pdev: Device handle
385
+  * @param  ep_addr: Endpoint Number
386
+  * @retval USBD Status
387
+  */
388
+USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
389
+{
390
+  HAL_StatusTypeDef hal_status = HAL_OK;
391
+  USBD_StatusTypeDef usb_status = USBD_OK;
392
+  
393
+  hal_status = HAL_PCD_EP_Close(pdev->pData, ep_addr);
394
+      
395
+  switch(hal_status) {
396
+    case HAL_OK :
397
+      usb_status = USBD_OK;
398
+    break;
399
+    case HAL_ERROR :
400
+      usb_status = USBD_FAIL;
401
+    break;
402
+    case HAL_BUSY :
403
+      usb_status = USBD_BUSY;
404
+    break;
405
+    case HAL_TIMEOUT :
406
+      usb_status = USBD_FAIL;
407
+    break;
408
+    default :
409
+      usb_status = USBD_FAIL;
410
+    break;
411
+  }
412
+
413
+  return(usb_status);
414
+}
415
+
416
+/**
417
+  * @brief  Flushes an endpoint of the Low Level Driver.
418
+  * @param  pdev: Device handle
419
+  * @param  ep_addr: Endpoint Number
420
+  * @retval USBD Status
421
+  */
422
+USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
423
+{
424
+  HAL_StatusTypeDef hal_status = HAL_OK;
425
+  USBD_StatusTypeDef usb_status = USBD_OK;
426
+  
427
+  hal_status = HAL_PCD_EP_Flush(pdev->pData, ep_addr);
428
+      
429
+  switch(hal_status) {
430
+    case HAL_OK :
431
+      usb_status = USBD_OK;
432
+    break;
433
+    case HAL_ERROR :
434
+      usb_status = USBD_FAIL;
435
+    break;
436
+    case HAL_BUSY :
437
+      usb_status = USBD_BUSY;
438
+    break;
439
+    case HAL_TIMEOUT :
440
+      usb_status = USBD_FAIL;
441
+    break;
442
+    default :
443
+      usb_status = USBD_FAIL;
444
+    break;
445
+  }
446
+
447
+  return(usb_status);
448
+}
449
+
450
+/**
451
+  * @brief  Sets a Stall condition on an endpoint of the Low Level Driver.
452
+  * @param  pdev: Device handle
453
+  * @param  ep_addr: Endpoint Number
454
+  * @retval USBD Status
455
+  */
456
+USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
457
+{
458
+  HAL_StatusTypeDef hal_status = HAL_OK;
459
+  USBD_StatusTypeDef usb_status = USBD_OK;
460
+  
461
+  hal_status = HAL_PCD_EP_SetStall(pdev->pData, ep_addr);
462
+      
463
+  switch(hal_status) {
464
+    case HAL_OK :
465
+      usb_status = USBD_OK;
466
+    break;
467
+    case HAL_ERROR :
468
+      usb_status = USBD_FAIL;
469
+    break;
470
+    case HAL_BUSY :
471
+      usb_status = USBD_BUSY;
472
+    break;
473
+    case HAL_TIMEOUT :
474
+      usb_status = USBD_FAIL;
475
+    break;
476
+    default :
477
+      usb_status = USBD_FAIL;
478
+    break;
479
+  }
480
+
481
+  return(usb_status);
482
+}
483
+
484
+/**
485
+  * @brief  Clears a Stall condition on an endpoint of the Low Level Driver.
486
+  * @param  pdev: Device handle
487
+  * @param  ep_addr: Endpoint Number
488
+  * @retval USBD Status
489
+  */
490
+USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev,
491
+                                        uint8_t ep_addr)
492
+{
493
+  HAL_StatusTypeDef hal_status = HAL_OK;
494
+  USBD_StatusTypeDef usb_status = USBD_OK;
495
+  
496
+  hal_status = HAL_PCD_EP_ClrStall(pdev->pData, ep_addr);  
497
+     
498
+  switch(hal_status) {
499
+    case HAL_OK :
500
+      usb_status = USBD_OK;
501
+    break;
502
+    case HAL_ERROR :
503
+      usb_status = USBD_FAIL;
504
+    break;
505
+    case HAL_BUSY :
506
+      usb_status = USBD_BUSY;
507
+    break;
508
+    case HAL_TIMEOUT :
509
+      usb_status = USBD_FAIL;
510
+    break;
511
+    default :
512
+      usb_status = USBD_FAIL;
513
+    break;
514
+  }
515
+
516
+  return(usb_status);
517
+}
518
+
519
+/**
520
+  * @brief  Returns Stall condition.
521
+  * @param  pdev: Device handle
522
+  * @param  ep_addr: Endpoint Number
523
+  * @retval Stall (1: Yes, 0: No)
524
+  */
525
+uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
526
+{
527
+  PCD_HandleTypeDef *hpcd = (PCD_HandleTypeDef*) pdev->pData;
528
+  
529
+  if((ep_addr & 0x80) == 0x80) {
530
+    return(hpcd->IN_ep[ep_addr & 0x7F].is_stall);
531
+  } else {
532
+    return(hpcd->OUT_ep[ep_addr & 0x7F].is_stall);
533
+  }
534
+}
535
+
536
+/**
537
+  * @brief  Assigns a USB address to the device.
538
+  * @param  pdev: Device handle
539
+  * @param  dev_addr: Endpoint Number
540
+  * @retval USBD Status
541
+  */
542
+USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev,
543
+                                         uint8_t dev_addr)
544
+{
545
+  HAL_StatusTypeDef hal_status = HAL_OK;
546
+  USBD_StatusTypeDef usb_status = USBD_OK;
547
+  
548
+  hal_status = HAL_PCD_SetAddress(pdev->pData, dev_addr);
549
+     
550
+  switch(hal_status) {
551
+    case HAL_OK :
552
+      usb_status = USBD_OK;
553
+    break;
554
+    case HAL_ERROR :
555
+      usb_status = USBD_FAIL;
556
+    break;
557
+    case HAL_BUSY :
558
+      usb_status = USBD_BUSY;
559
+    break;
560
+    case HAL_TIMEOUT :
561
+      usb_status = USBD_FAIL;
562
+    break;
563
+    default :
564
+      usb_status = USBD_FAIL;
565
+    break;
566
+  }
567
+
568
+  return(usb_status);
569
+}
570
+
571
+/**
572
+  * @brief  Transmits data over an endpoint.
573
+  * @param  pdev: Device handle
574
+  * @param  ep_addr: Endpoint Number
575
+  * @param  pbuf: Pointer to data to be sent
576
+  * @param  size: Data size
577
+  * @retval USBD Status
578
+  */
579
+USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, uint8_t ep_addr,
580
+                                    uint8_t *pbuf, uint32_t size)
581
+{
582
+  HAL_StatusTypeDef hal_status = HAL_OK;
583
+  USBD_StatusTypeDef usb_status = USBD_OK;
584
+
585
+  hal_status = HAL_PCD_EP_Transmit(pdev->pData, ep_addr, pbuf, size);
586
+     
587
+  switch(hal_status) {
588
+    case HAL_OK :
589
+      usb_status = USBD_OK;
590
+    break;
591
+    case HAL_ERROR :
592
+      usb_status = USBD_FAIL;
593
+    break;
594
+    case HAL_BUSY :
595
+      usb_status = USBD_BUSY;
596
+    break;
597
+    case HAL_TIMEOUT :
598
+      usb_status = USBD_FAIL;
599
+    break;
600
+    default :
601
+      usb_status = USBD_FAIL;
602
+    break;
603
+  }
604
+
605
+  return(usb_status);
606
+}
607
+
608
+/**
609
+  * @brief  Prepares an endpoint for reception.
610
+  * @param  pdev: Device handle
611
+  * @param  ep_addr: Endpoint Number
612
+  * @param  pbuf: Pointer to data to be received
613
+  * @param  size: Data size
614
+  * @retval USBD Status
615
+  */
616
+USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev,
617
+                                          uint8_t ep_addr, uint8_t *pbuf,
618
+                                          uint32_t size)
619
+{
620
+  HAL_StatusTypeDef hal_status = HAL_OK;
621
+  USBD_StatusTypeDef usb_status = USBD_OK;
622
+
623
+  hal_status = HAL_PCD_EP_Receive(pdev->pData, ep_addr, pbuf, size);
624
+     
625
+  switch(hal_status) {
626
+    case HAL_OK :
627
+      usb_status = USBD_OK;
628
+    break;
629
+    case HAL_ERROR :
630
+      usb_status = USBD_FAIL;
631
+    break;
632
+    case HAL_BUSY :
633
+      usb_status = USBD_BUSY;
634
+    break;
635
+    case HAL_TIMEOUT :
636
+      usb_status = USBD_FAIL;
637
+    break;
638
+    default :
639
+      usb_status = USBD_FAIL;
640
+    break;
641
+  }
642
+
643
+  return(usb_status); 
644
+}
645
+
646
+/**
647
+  * @brief  Returns the last transferred packet size.
648
+  * @param  pdev: Device handle
649
+  * @param  ep_addr: Endpoint Number
650
+  * @retval Received Data Size
651
+  */
652
+uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
653
+{
654
+  return(HAL_PCD_EP_GetRxCount((PCD_HandleTypeDef*) pdev->pData, ep_addr));
655
+}
656
+
657
+#ifdef USBD_HS_TESTMODE_ENABLE
658
+/**
659
+  * @brief  Set High speed Test mode.
660
+  * @param  pdev: Device handle
661
+  * @param  testmode: test mode
662
+  * @retval USBD Status
663
+  */
664
+USBD_StatusTypeDef USBD_LL_SetTestMode(USBD_HandleTypeDef *pdev, uint8_t testmode)
665
+{
666
+  return(USBD_OK);
667
+}
668
+#endif /* USBD_HS_TESTMODE_ENABLE */
669
+
670
+/**
671
+  * @brief  Static single allocation.
672
+  * @param  size: Size of allocated memory
673
+  * @retval None
674
+  */
675
+void *USBD_static_malloc(uint32_t size)
676
+{
677
+  static uint32_t mem[(sizeof(USBD_MSC_BOT_HandleTypeDef) / 4) + 1]; /* On 32-bit boundary */
678
+
679
+  return(mem);
680
+}
681
+
682
+/**
683
+  * @brief  Dummy memory free
684
+  * @param  p: Pointer to allocated  memory address
685
+  * @retval None
686
+  */
687
+void USBD_static_free(void *p)
688
+{
689
+
690
+}
691
+
692
+/**
693
+  * @brief  Delays routine for the USB Device Library.
694
+  * @param  Delay: Delay in ms
695
+  * @retval None
696
+  */
697
+void USBD_LL_Delay(uint32_t Delay)
698
+{
699
+  HAL_Delay(Delay);
700
+}
701
+