Select one of the symbols to view example projects that use it.
 
Outline
Includes
#include "usbh_msc_bot.h"
#include "usbh_msc.h"
USBH_MSC_BOT_REQ_Reset(USBH_HandleTypeDef *)
USBH_MSC_BOT_REQ_GetMaxLUN(USBH_HandleTypeDef *, uint8_t *)
USBH_MSC_BOT_Init(USBH_HandleTypeDef *)
USBH_MSC_BOT_Process(USBH_HandleTypeDef *, uint8_t)
USBH_MSC_BOT_Abort(USBH_HandleTypeDef *, uint8_t, uint8_t)
USBH_MSC_DecodeCSW(USBH_HandleTypeDef *)
Files
loading...
SourceVuSTM32 Libraries and SamplesSTM32_USB_Host_LibraryClass/MSC/Src/usbh_msc_bot.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file usbh_msc_bot.c * @author MCD Application Team * @brief This file includes the BOT protocol related functions ****************************************************************************** * @attention * * Copyright (c) 2015 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** *//* ... */ /* BSPDependencies - "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" - "stm32xxxxx_{eval}{discovery}_io.c" - "stm32xxxxx_{eval}{discovery}{adafruit}_lcd.c" - "stm32xxxxx_{eval}{discovery}_sdram.c" EndBSPDependencies *//* ... */ /* Includes ------------------------------------------------------------------*/ #include "usbh_msc_bot.h" #include "usbh_msc.h" /** @addtogroup USBH_LIB * @{ *//* ... */ /** @addtogroup USBH_CLASS * @{ *//* ... */ /** @addtogroup USBH_MSC_CLASS * @{ *//* ... */ /** @defgroup USBH_MSC_BOT * @brief This file includes the mass storage related functions * @{ *//* ... */ /** @defgroup USBH_MSC_BOT_Private_TypesDefinitions * @{ *//* ... */ /** * @} *//* ... */ /** @defgroup USBH_MSC_BOT_Private_Defines * @{ *//* ... */ /** * @} *//* ... */ /** @defgroup USBH_MSC_BOT_Private_Macros * @{ *//* ... */ /** * @} *//* ... */ /** @defgroup USBH_MSC_BOT_Private_Variables * @{ *//* ... */ /** * @} *//* ... */ /** @defgroup USBH_MSC_BOT_Private_FunctionPrototypes * @{ *//* ... */ static USBH_StatusTypeDef USBH_MSC_BOT_Abort(USBH_HandleTypeDef *phost, uint8_t lun, uint8_t dir); static BOT_CSWStatusTypeDef USBH_MSC_DecodeCSW(USBH_HandleTypeDef *phost); /** * @} *//* ... */ /** @defgroup USBH_MSC_BOT_Exported_Variables * @{ *//* ... */ /** * @} *//* ... */ /** @defgroup USBH_MSC_BOT_Private_Functions * @{ *//* ... */ /** * @brief USBH_MSC_BOT_REQ_Reset * The function the MSC BOT Reset request. * @param phost: Host handle * @retval USBH Status *//* ... */ USBH_StatusTypeDef USBH_MSC_BOT_REQ_Reset(USBH_HandleTypeDef *phost) { phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_TYPE_CLASS | USB_REQ_RECIPIENT_INTERFACE; phost->Control.setup.b.bRequest = USB_REQ_BOT_RESET; phost->Control.setup.b.wValue.w = 0U; phost->Control.setup.b.wIndex.w = 0U; phost->Control.setup.b.wLength.w = 0U; return USBH_CtlReq(phost, NULL, 0U); }{ ... } /** * @brief USBH_MSC_BOT_REQ_GetMaxLUN * The function the MSC BOT GetMaxLUN request. * @param phost: Host handle * @param Maxlun: pointer to Maxlun variable * @retval USBH Status *//* ... */ USBH_StatusTypeDef USBH_MSC_BOT_REQ_GetMaxLUN(USBH_HandleTypeDef *phost, uint8_t *Maxlun) { phost->Control.setup.b.bmRequestType = USB_D2H | USB_REQ_TYPE_CLASS | USB_REQ_RECIPIENT_INTERFACE; phost->Control.setup.b.bRequest = USB_REQ_GET_MAX_LUN; phost->Control.setup.b.wValue.w = 0U; phost->Control.setup.b.wIndex.w = 0U; phost->Control.setup.b.wLength.w = 1U; return USBH_CtlReq(phost, Maxlun, 1U); }{ ... } /** * @brief USBH_MSC_BOT_Init * The function Initializes the BOT protocol. * @param phost: Host handle * @retval USBH Status *//* ... */ USBH_StatusTypeDef USBH_MSC_BOT_Init(USBH_HandleTypeDef *phost) { MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; MSC_Handle->hbot.cbw.field.Signature = BOT_CBW_SIGNATURE; MSC_Handle->hbot.cbw.field.Tag = BOT_CBW_TAG; MSC_Handle->hbot.state = BOT_SEND_CBW; MSC_Handle->hbot.cmd_state = BOT_CMD_SEND; return USBH_OK; }{ ... } /** * @brief USBH_MSC_BOT_Process * The function handle the BOT protocol. * @param phost: Host handle * @param lun: Logical Unit Number * @retval USBH Status *//* ... */ USBH_StatusTypeDef USBH_MSC_BOT_Process(USBH_HandleTypeDef *phost, uint8_t lun) { USBH_StatusTypeDef status = USBH_BUSY; USBH_StatusTypeDef error = USBH_BUSY; BOT_CSWStatusTypeDef CSW_Status = BOT_CSW_CMD_FAILED; USBH_URBStateTypeDef URB_Status = USBH_URB_IDLE; MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; uint8_t toggle = 0U; switch (MSC_Handle->hbot.state) { case BOT_SEND_CBW: MSC_Handle->hbot.cbw.field.LUN = lun; MSC_Handle->hbot.state = BOT_SEND_CBW_WAIT; (void)USBH_BulkSendData(phost, MSC_Handle->hbot.cbw.data, BOT_CBW_LENGTH, MSC_Handle->OutPipe, 1U); break; case BOT_SEND_CBW: case BOT_SEND_CBW_WAIT: URB_Status = USBH_LL_GetURBState(phost, MSC_Handle->OutPipe); if (URB_Status == USBH_URB_DONE) { if (MSC_Handle->hbot.cbw.field.DataTransferLength != 0U) { /* If there is Data Transfer Stage */ if (((MSC_Handle->hbot.cbw.field.Flags) & USB_REQ_DIR_MASK) == USB_D2H) { /* Data Direction is IN */ MSC_Handle->hbot.state = BOT_DATA_IN; }if (((MSC_Handle->hbot.cbw.field.Flags) & USB_REQ_DIR_MASK) == USB_D2H) { ... } else { /* Data Direction is OUT */ MSC_Handle->hbot.state = BOT_DATA_OUT; }else { ... } }if (MSC_Handle->hbot.cbw.field.DataTransferLength != 0U) { ... } else { /* If there is NO Data Transfer Stage */ MSC_Handle->hbot.state = BOT_RECEIVE_CSW; }else { ... } #if (USBH_USE_OS == 1U) phost->os_msg = (uint32_t)USBH_URB_EVENT; #if (osCMSIS < 0x20000U) (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, 0U); #endif/* ... */ #endif }if (URB_Status == USBH_URB_DONE) { ... } else if (URB_Status == USBH_URB_NOTREADY) { /* Re-send CBW */ MSC_Handle->hbot.state = BOT_SEND_CBW; #if (USBH_USE_OS == 1U) phost->os_msg = (uint32_t)USBH_URB_EVENT; #if (osCMSIS < 0x20000U) (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, 0U); #endif/* ... */ #endif }else if (URB_Status == USBH_URB_NOTREADY) { ... } else { if (URB_Status == USBH_URB_STALL) { MSC_Handle->hbot.state = BOT_ERROR_OUT; #if (USBH_USE_OS == 1U) phost->os_msg = (uint32_t)USBH_URB_EVENT; #if (osCMSIS < 0x20000U) (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, 0U); #endif/* ... */ #endif }if (URB_Status == USBH_URB_STALL) { ... } }else { ... } break; case BOT_SEND_CBW_WAIT: case BOT_DATA_IN: /* Send first packet */ (void)USBH_BulkReceiveData(phost, MSC_Handle->hbot.pbuf, MSC_Handle->InEpSize, MSC_Handle->InPipe); MSC_Handle->hbot.state = BOT_DATA_IN_WAIT; break; case BOT_DATA_IN: case BOT_DATA_IN_WAIT: URB_Status = USBH_LL_GetURBState(phost, MSC_Handle->InPipe); if (URB_Status == USBH_URB_DONE) { /* Adjust Data pointer and data length */ if (MSC_Handle->hbot.cbw.field.DataTransferLength > MSC_Handle->InEpSize) { MSC_Handle->hbot.pbuf += MSC_Handle->InEpSize; MSC_Handle->hbot.cbw.field.DataTransferLength -= MSC_Handle->InEpSize; }if (MSC_Handle->hbot.cbw.field.DataTransferLength > MSC_Handle->InEpSize) { ... } else { MSC_Handle->hbot.cbw.field.DataTransferLength = 0U; }else { ... } /* More Data To be Received */ if (MSC_Handle->hbot.cbw.field.DataTransferLength > 0U) { /* Send next packet */ (void)USBH_BulkReceiveData(phost, MSC_Handle->hbot.pbuf, MSC_Handle->InEpSize, MSC_Handle->InPipe); }if (MSC_Handle->hbot.cbw.field.DataTransferLength > 0U) { ... } else { /* If value was 0, and successful transfer, then change the state */ MSC_Handle->hbot.state = BOT_RECEIVE_CSW; #if (USBH_USE_OS == 1U) phost->os_msg = (uint32_t)USBH_URB_EVENT; #if (osCMSIS < 0x20000U) (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, 0U); #endif/* ... */ #endif }else { ... } }if (URB_Status == USBH_URB_DONE) { ... } else if (URB_Status == USBH_URB_STALL) { /* This is Data IN Stage STALL Condition */ MSC_Handle->hbot.state = BOT_ERROR_IN; /* Refer to USB Mass-Storage Class : BOT (www.usb.org) 6.7.2 Host expects to receive data from the device 3. On a STALL condition receiving data, then: The host shall accept the data received. The host shall clear the Bulk-In pipe. 4. The host shall attempt to receive a CSW.*//* ... */ #if (USBH_USE_OS == 1U) phost->os_msg = (uint32_t)USBH_URB_EVENT; #if (osCMSIS < 0x20000U) (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, 0U); #endif/* ... */ #endif }else if (URB_Status == USBH_URB_STALL) { ... } else { }else { ... } break; case BOT_DATA_IN_WAIT: case BOT_DATA_OUT: (void)USBH_BulkSendData(phost, MSC_Handle->hbot.pbuf, MSC_Handle->OutEpSize, MSC_Handle->OutPipe, 1U); MSC_Handle->hbot.state = BOT_DATA_OUT_WAIT; break; case BOT_DATA_OUT: case BOT_DATA_OUT_WAIT: URB_Status = USBH_LL_GetURBState(phost, MSC_Handle->OutPipe); if (URB_Status == USBH_URB_DONE) { /* Adjust Data pointer and data length */ if (MSC_Handle->hbot.cbw.field.DataTransferLength > MSC_Handle->OutEpSize) { MSC_Handle->hbot.pbuf += MSC_Handle->OutEpSize; MSC_Handle->hbot.cbw.field.DataTransferLength -= MSC_Handle->OutEpSize; }if (MSC_Handle->hbot.cbw.field.DataTransferLength > MSC_Handle->OutEpSize) { ... } else { MSC_Handle->hbot.cbw.field.DataTransferLength = 0U; }else { ... } /* More Data To be Sent */ if (MSC_Handle->hbot.cbw.field.DataTransferLength > 0U) { (void)USBH_BulkSendData(phost, MSC_Handle->hbot.pbuf, MSC_Handle->OutEpSize, MSC_Handle->OutPipe, 1U); }if (MSC_Handle->hbot.cbw.field.DataTransferLength > 0U) { ... } else { /* If value was 0, and successful transfer, then change the state */ MSC_Handle->hbot.state = BOT_RECEIVE_CSW; }else { ... } #if (USBH_USE_OS == 1U) phost->os_msg = (uint32_t)USBH_URB_EVENT; #if (osCMSIS < 0x20000U) (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, 0U); #endif/* ... */ #endif }if (URB_Status == USBH_URB_DONE) { ... } else if (URB_Status == USBH_URB_NOTREADY) { /* Resend same data */ MSC_Handle->hbot.state = BOT_DATA_OUT; #if (USBH_USE_OS == 1U) phost->os_msg = (uint32_t)USBH_URB_EVENT; #if (osCMSIS < 0x20000U) (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, 0U); #endif/* ... */ #endif }else if (URB_Status == USBH_URB_NOTREADY) { ... } else if (URB_Status == USBH_URB_STALL) { MSC_Handle->hbot.state = BOT_ERROR_OUT; /* Refer to USB Mass-Storage Class : BOT (www.usb.org) 6.7.3 Ho - Host expects to send data to the device 3. On a STALL condition sending data, then: " The host shall clear the Bulk-Out pipe. 4. The host shall attempt to receive a CSW. *//* ... */ #if (USBH_USE_OS == 1U) phost->os_msg = (uint32_t)USBH_URB_EVENT; #if (osCMSIS < 0x20000U) (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, 0U); #endif/* ... */ #endif }else if (URB_Status == USBH_URB_STALL) { ... } else { }else { ... } break; case BOT_DATA_OUT_WAIT: case BOT_RECEIVE_CSW: (void)USBH_BulkReceiveData(phost, MSC_Handle->hbot.csw.data, BOT_CSW_LENGTH, MSC_Handle->InPipe); MSC_Handle->hbot.state = BOT_RECEIVE_CSW_WAIT; break; case BOT_RECEIVE_CSW: case BOT_RECEIVE_CSW_WAIT: URB_Status = USBH_LL_GetURBState(phost, MSC_Handle->InPipe); /* Decode CSW */ if (URB_Status == USBH_URB_DONE) { MSC_Handle->hbot.state = BOT_SEND_CBW; MSC_Handle->hbot.cmd_state = BOT_CMD_SEND; CSW_Status = USBH_MSC_DecodeCSW(phost); if (CSW_Status == BOT_CSW_CMD_PASSED) { status = USBH_OK; }if (CSW_Status == BOT_CSW_CMD_PASSED) { ... } else { status = USBH_FAIL; }else { ... } #if (USBH_USE_OS == 1U) phost->os_msg = (uint32_t)USBH_URB_EVENT; #if (osCMSIS < 0x20000U) (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, 0U); #endif/* ... */ #endif }if (URB_Status == USBH_URB_DONE) { ... } else if (URB_Status == USBH_URB_STALL) { MSC_Handle->hbot.state = BOT_ERROR_IN; #if (USBH_USE_OS == 1U) phost->os_msg = (uint32_t)USBH_URB_EVENT; #if (osCMSIS < 0x20000U) (void)osMessagePut(phost->os_event, phost->os_msg, 0U); #else (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, 0U); #endif/* ... */ #endif }else if (URB_Status == USBH_URB_STALL) { ... } else { }else { ... } break; case BOT_RECEIVE_CSW_WAIT: case BOT_ERROR_IN: error = USBH_MSC_BOT_Abort(phost, lun, BOT_DIR_IN); if (error == USBH_OK) { MSC_Handle->hbot.state = BOT_RECEIVE_CSW; }if (error == USBH_OK) { ... } else if (error == USBH_UNRECOVERED_ERROR) { /* This means that there is a STALL Error limit, Do Reset Recovery */ MSC_Handle->hbot.state = BOT_UNRECOVERED_ERROR; }else if (error == USBH_UNRECOVERED_ERROR) { ... } else { }else { ... } break; case BOT_ERROR_IN: case BOT_ERROR_OUT: error = USBH_MSC_BOT_Abort(phost, lun, BOT_DIR_OUT); if (error == USBH_OK) { toggle = USBH_LL_GetToggle(phost, MSC_Handle->OutPipe); (void)USBH_LL_SetToggle(phost, MSC_Handle->OutPipe, 1U - toggle); (void)USBH_LL_SetToggle(phost, MSC_Handle->InPipe, 0U); MSC_Handle->hbot.state = BOT_ERROR_IN; }if (error == USBH_OK) { ... } else { if (error == USBH_UNRECOVERED_ERROR) { MSC_Handle->hbot.state = BOT_UNRECOVERED_ERROR; }if (error == USBH_UNRECOVERED_ERROR) { ... } }else { ... } break; case BOT_ERROR_OUT: case BOT_UNRECOVERED_ERROR: status = USBH_MSC_BOT_REQ_Reset(phost); if (status == USBH_OK) { MSC_Handle->hbot.state = BOT_SEND_CBW; }if (status == USBH_OK) { ... } break; case BOT_UNRECOVERED_ERROR: default: break;default }switch (MSC_Handle->hbot.state) { ... } return status; }{ ... } /** * @brief USBH_MSC_BOT_Abort * The function handle the BOT Abort process. * @param phost: Host handle * @param lun: Logical Unit Number * @param dir: direction (0: out / 1 : in) * @retval USBH Status *//* ... */ static USBH_StatusTypeDef USBH_MSC_BOT_Abort(USBH_HandleTypeDef *phost, uint8_t lun, uint8_t dir) { /* Prevent unused argument(s) compilation warning */ UNUSED(lun); USBH_StatusTypeDef status = USBH_FAIL; MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; switch (dir) { case BOT_DIR_IN : /* send ClrFeture on Bulk IN endpoint */ status = USBH_ClrFeature(phost, MSC_Handle->InEp); break; case BOT_DIR_IN : case BOT_DIR_OUT : /*send ClrFeature on Bulk OUT endpoint */ status = USBH_ClrFeature(phost, MSC_Handle->OutEp); break; case BOT_DIR_OUT : default: break;default }switch (dir) { ... } return status; }{ ... } /** * @brief USBH_MSC_BOT_DecodeCSW * This function decodes the CSW received by the device and updates the * same to upper layer. * @param phost: Host handle * @retval USBH Status * @notes * Refer to USB Mass-Storage Class : BOT (www.usb.org) * 6.3.1 Valid CSW Conditions : * The host shall consider the CSW valid when: * 1. dCSWSignature is equal to 53425355h * 2. the CSW is 13 (Dh) bytes in length, * 3. dCSWTag matches the dCBWTag from the corresponding CBW. *//* ... */ static BOT_CSWStatusTypeDef USBH_MSC_DecodeCSW(USBH_HandleTypeDef *phost) { MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; BOT_CSWStatusTypeDef status = BOT_CSW_CMD_FAILED; /*Checking if the transfer length is different than 13*/ if (USBH_LL_GetLastXferSize(phost, MSC_Handle->InPipe) != BOT_CSW_LENGTH) { /*(4) Hi > Dn (Host expects to receive data from the device, Device intends to transfer no data) (5) Hi > Di (Host expects to receive data from the device, Device intends to send data to the host) (9) Ho > Dn (Host expects to send data to the device, Device intends to transfer no data) (11) Ho > Do (Host expects to send data to the device, Device intends to receive data from the host)*//* ... */ status = BOT_CSW_PHASE_ERROR; }if (USBH_LL_GetLastXferSize(phost, MSC_Handle->InPipe) != BOT_CSW_LENGTH) { ... } else { /* CSW length is Correct */ /* Check validity of the CSW Signature and CSWStatus */ if (MSC_Handle->hbot.csw.field.Signature == BOT_CSW_SIGNATURE) { /* Check Condition 1. dCSWSignature is equal to 53425355h */ if (MSC_Handle->hbot.csw.field.Tag == MSC_Handle->hbot.cbw.field.Tag) { /* Check Condition 3. dCSWTag matches the dCBWTag from the corresponding CBW *//* ... */ if (MSC_Handle->hbot.csw.field.Status == 0U) { /* Refer to USB Mass-Storage Class : BOT (www.usb.org) Hn Host expects no data transfers Hi Host expects to receive data from the device Ho Host expects to send data to the device Dn Device intends to transfer no data Di Device intends to send data to the host Do Device intends to receive data from the host Section 6.7 (1) Hn = Dn (Host expects no data transfers, Device intends to transfer no data) (6) Hi = Di (Host expects to receive data from the device, Device intends to send data to the host) (12) Ho = Do (Host expects to send data to the device, Device intends to receive data from the host) *//* ... */ status = BOT_CSW_CMD_PASSED; }if (MSC_Handle->hbot.csw.field.Status == 0U) { ... } else if (MSC_Handle->hbot.csw.field.Status == 1U) { status = BOT_CSW_CMD_FAILED; }else if (MSC_Handle->hbot.csw.field.Status == 1U) { ... } else if (MSC_Handle->hbot.csw.field.Status == 2U) { /* Refer to USB Mass-Storage Class : BOT (www.usb.org) Section 6.7 (2) Hn < Di ( Host expects no data transfers, Device intends to send data to the host) (3) Hn < Do ( Host expects no data transfers, Device intends to receive data from the host) (7) Hi < Di ( Host expects to receive data from the device, Device intends to send data to the host) (8) Hi <> Do ( Host expects to receive data from the device, Device intends to receive data from the host) (10) Ho <> Di (Host expects to send data to the device, Di Device intends to send data to the host) (13) Ho < Do (Host expects to send data to the device, Device intends to receive data from the host) *//* ... */ status = BOT_CSW_PHASE_ERROR; }else if (MSC_Handle->hbot.csw.field.Status == 2U) { ... } else { }else { ... } }if (MSC_Handle->hbot.csw.field.Tag == MSC_Handle->hbot.cbw.field.Tag) { ... } /* CSW Tag Matching is Checked */ }if (MSC_Handle->hbot.csw.field.Signature == BOT_CSW_SIGNATURE) { ... } /* CSW Signature Correct Checking */ else { /* If the CSW Signature is not valid, We sall return the Phase Error to Upper Layers for Reset Recovery *//* ... */ status = BOT_CSW_PHASE_ERROR; }else { ... } }else { ... } /* CSW Length Check*/ return status; }{ ... } /** * @} *//* ... */ /** * @} *//* ... */ /** * @} *//* ... */ /** * @} *//* ... */ /** * @} *//* ... */ Includes
Details
Show:
from
Types: Columns:
This file uses the notable symbols shown below. Click anywhere in the file to view more details.