Select one of the symbols to view example projects that use it.
 
Outline
Includes
#include "usbd_msc_bot.h"
#include "usbd_msc.h"
#include "usbd_msc_scsi.h"
#include "usbd_ioreq.h"
MSC_BOT_Init(USBD_HandleTypeDef *)
MSC_BOT_Reset(USBD_HandleTypeDef *)
MSC_BOT_DeInit(USBD_HandleTypeDef *)
MSC_BOT_DataIn(USBD_HandleTypeDef *, uint8_t)
MSC_BOT_DataOut(USBD_HandleTypeDef *, uint8_t)
MSC_BOT_CBW_Decode(USBD_HandleTypeDef *)
MSC_BOT_SendData(USBD_HandleTypeDef *, uint8_t *, uint32_t)
MSC_BOT_SendCSW(USBD_HandleTypeDef *, uint8_t)
MSC_BOT_Abort(USBD_HandleTypeDef *)
MSC_BOT_CplClrFeature(USBD_HandleTypeDef *, uint8_t)
Files
loading...
SourceVuSTM32 Libraries and SamplesSTM32_USB_Device_LibraryClass/MSC/Src/usbd_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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file usbd_msc_bot.c * @author MCD Application Team * @brief This file provides all the BOT protocol core 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}_sd.c" EndBSPDependencies *//* ... */ /* Includes ------------------------------------------------------------------*/ #include "usbd_msc_bot.h" #include "usbd_msc.h" #include "usbd_msc_scsi.h" #include "usbd_ioreq.h" /** @addtogroup STM32_USB_DEVICE_LIBRARY * @{ *//* ... */ /** @defgroup MSC_BOT * @brief BOT protocol module * @{ *//* ... */ /** @defgroup MSC_BOT_Private_TypesDefinitions * @{ *//* ... */ /** * @} *//* ... */ /** @defgroup MSC_BOT_Private_Defines * @{ *//* ... */ /** * @} *//* ... */ /** @defgroup MSC_BOT_Private_Macros * @{ *//* ... */ /** * @} *//* ... */ /** @defgroup MSC_BOT_Private_Variables * @{ *//* ... */ extern uint8_t MSCInEpAdd; extern uint8_t MSCOutEpAdd; /** * @} *//* ... */ /** @defgroup MSC_BOT_Private_FunctionPrototypes * @{ *//* ... */ static void MSC_BOT_SendData(USBD_HandleTypeDef *pdev, uint8_t *pbuf, uint32_t len); static void MSC_BOT_CBW_Decode(USBD_HandleTypeDef *pdev); static void MSC_BOT_Abort(USBD_HandleTypeDef *pdev); /** * @} *//* ... */ /** @defgroup MSC_BOT_Private_Functions * @{ *//* ... */ /** * @brief MSC_BOT_Init * Initialize the BOT Process * @param pdev: device instance * @retval None *//* ... */ void MSC_BOT_Init(USBD_HandleTypeDef *pdev) { USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; #ifdef USE_USBD_COMPOSITE /* Get the Endpoints addresses allocated for this class instance */ MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId); MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);/* ... */ #endif /* USE_USBD_COMPOSITE */ if (hmsc == NULL) { return; }if (hmsc == NULL) { ... } hmsc->bot_state = USBD_BOT_IDLE; hmsc->bot_status = USBD_BOT_STATUS_NORMAL; hmsc->scsi_sense_tail = 0U; hmsc->scsi_sense_head = 0U; hmsc->scsi_medium_state = SCSI_MEDIUM_UNLOCKED; ((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->Init(0U); (void)USBD_LL_FlushEP(pdev, MSCOutEpAdd); (void)USBD_LL_FlushEP(pdev, MSCInEpAdd); /* Prepare EP to Receive First BOT Cmd */ (void)USBD_LL_PrepareReceive(pdev, MSCOutEpAdd, (uint8_t *)&hmsc->cbw, USBD_BOT_CBW_LENGTH); }{ ... } /** * @brief MSC_BOT_Reset * Reset the BOT Machine * @param pdev: device instance * @retval None *//* ... */ void MSC_BOT_Reset(USBD_HandleTypeDef *pdev) { USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; #ifdef USE_USBD_COMPOSITE /* Get the Endpoints addresses allocated for this class instance */ MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId); MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);/* ... */ #endif /* USE_USBD_COMPOSITE */ if (hmsc == NULL) { return; }if (hmsc == NULL) { ... } hmsc->bot_state = USBD_BOT_IDLE; hmsc->bot_status = USBD_BOT_STATUS_RECOVERY; (void)USBD_LL_ClearStallEP(pdev, MSCInEpAdd); (void)USBD_LL_ClearStallEP(pdev, MSCOutEpAdd); /* Prepare EP to Receive First BOT Cmd */ (void)USBD_LL_PrepareReceive(pdev, MSCOutEpAdd, (uint8_t *)&hmsc->cbw, USBD_BOT_CBW_LENGTH); }{ ... } /** * @brief MSC_BOT_DeInit * DeInitialize the BOT Machine * @param pdev: device instance * @retval None *//* ... */ void MSC_BOT_DeInit(USBD_HandleTypeDef *pdev) { USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; if (hmsc != NULL) { hmsc->bot_state = USBD_BOT_IDLE; }if (hmsc != NULL) { ... } }{ ... } /** * @brief MSC_BOT_DataIn * Handle BOT IN data stage * @param pdev: device instance * @param epnum: endpoint index * @retval None *//* ... */ void MSC_BOT_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum) { UNUSED(epnum); USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; if (hmsc == NULL) { return; }if (hmsc == NULL) { ... } switch (hmsc->bot_state) { case USBD_BOT_DATA_IN: if (SCSI_ProcessCmd(pdev, hmsc->cbw.bLUN, &hmsc->cbw.CB[0]) < 0) { MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_FAILED); }if (SCSI_ProcessCmd(pdev, hmsc->cbw.bLUN, &hmsc->cbw.CB[0]) < 0) { ... } break; case USBD_BOT_DATA_IN: case USBD_BOT_SEND_DATA: case USBD_BOT_LAST_DATA_IN: MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_PASSED); break; case USBD_BOT_LAST_DATA_IN: default: break;default }switch (hmsc->bot_state) { ... } }{ ... } /** * @brief MSC_BOT_DataOut * Process MSC OUT data * @param pdev: device instance * @param epnum: endpoint index * @retval None *//* ... */ void MSC_BOT_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum) { UNUSED(epnum); USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; if (hmsc == NULL) { return; }if (hmsc == NULL) { ... } switch (hmsc->bot_state) { case USBD_BOT_IDLE: MSC_BOT_CBW_Decode(pdev); break; case USBD_BOT_IDLE: case USBD_BOT_DATA_OUT: if (SCSI_ProcessCmd(pdev, hmsc->cbw.bLUN, &hmsc->cbw.CB[0]) < 0) { MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_FAILED); }if (SCSI_ProcessCmd(pdev, hmsc->cbw.bLUN, &hmsc->cbw.CB[0]) < 0) { ... } break; case USBD_BOT_DATA_OUT: default: break;default }switch (hmsc->bot_state) { ... } }{ ... } /** * @brief MSC_BOT_CBW_Decode * Decode the CBW command and set the BOT state machine accordingly * @param pdev: device instance * @retval None *//* ... */ static void MSC_BOT_CBW_Decode(USBD_HandleTypeDef *pdev) { USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; #ifdef USE_USBD_COMPOSITE /* Get the Endpoints addresses allocated for this class instance */ MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId); MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);/* ... */ #endif /* USE_USBD_COMPOSITE */ if (hmsc == NULL) { return; }if (hmsc == NULL) { ... } hmsc->csw.dTag = hmsc->cbw.dTag; hmsc->csw.dDataResidue = hmsc->cbw.dDataLength; if ((USBD_LL_GetRxDataSize(pdev, MSCOutEpAdd) != USBD_BOT_CBW_LENGTH) || (hmsc->cbw.dSignature != USBD_BOT_CBW_SIGNATURE) || (hmsc->cbw.bLUN > 1U) || (hmsc->cbw.bCBLength < 1U) || (hmsc->cbw.bCBLength > 16U)) { SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); hmsc->bot_status = USBD_BOT_STATUS_ERROR; MSC_BOT_Abort(pdev); }if ((USBD_LL_GetRxDataSize(pdev, MSCOutEpAdd) != USBD_BOT_CBW_LENGTH) || (hmsc->cbw.dSignature != USBD_BOT_CBW_SIGNATURE) || (hmsc->cbw.bLUN > 1U) || (hmsc->cbw.bCBLength < 1U) || (hmsc->cbw.bCBLength > 16U)) { ... } else { if (SCSI_ProcessCmd(pdev, hmsc->cbw.bLUN, &hmsc->cbw.CB[0]) < 0) { if (hmsc->bot_state == USBD_BOT_NO_DATA) { MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_FAILED); }if (hmsc->bot_state == USBD_BOT_NO_DATA) { ... } else { MSC_BOT_Abort(pdev); }else { ... } }if (SCSI_ProcessCmd(pdev, hmsc->cbw.bLUN, &hmsc->cbw.CB[0]) < 0) { ... } /* Burst xfer handled internally */ else if ((hmsc->bot_state != USBD_BOT_DATA_IN) && (hmsc->bot_state != USBD_BOT_DATA_OUT) && (hmsc->bot_state != USBD_BOT_LAST_DATA_IN)) { if (hmsc->bot_data_length > 0U) { MSC_BOT_SendData(pdev, hmsc->bot_data, hmsc->bot_data_length); }if (hmsc->bot_data_length > 0U) { ... } else if (hmsc->bot_data_length == 0U) { MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_PASSED); }else if (hmsc->bot_data_length == 0U) { ... } else { MSC_BOT_Abort(pdev); }else { ... } }else if ((hmsc->bot_state != USBD_BOT_DATA_IN) && (hmsc->bot_state != USBD_BOT_DATA_OUT) && (hmsc->bot_state != USBD_BOT_LAST_DATA_IN)) { ... } else { return; }else { ... } }else { ... } }{ ... } /** * @brief MSC_BOT_SendData * Send the requested data * @param pdev: device instance * @param buf: pointer to data buffer * @param len: Data Length * @retval None *//* ... */ static void MSC_BOT_SendData(USBD_HandleTypeDef *pdev, uint8_t *pbuf, uint32_t len) { USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; uint32_t length; #ifdef USE_USBD_COMPOSITE /* Get the Endpoints addresses allocated for this class instance */ MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId); MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);/* ... */ #endif /* USE_USBD_COMPOSITE */ if (hmsc == NULL) { return; }if (hmsc == NULL) { ... } length = MIN(hmsc->cbw.dDataLength, len); hmsc->csw.dDataResidue -= len; hmsc->csw.bStatus = USBD_CSW_CMD_PASSED; hmsc->bot_state = USBD_BOT_SEND_DATA; (void)USBD_LL_Transmit(pdev, MSCInEpAdd, pbuf, length); }{ ... } /** * @brief MSC_BOT_SendCSW * Send the Command Status Wrapper * @param pdev: device instance * @param status : CSW status * @retval None *//* ... */ void MSC_BOT_SendCSW(USBD_HandleTypeDef *pdev, uint8_t CSW_Status) { USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; #ifdef USE_USBD_COMPOSITE /* Get the Endpoints addresses allocated for this class instance */ MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId); MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);/* ... */ #endif /* USE_USBD_COMPOSITE */ if (hmsc == NULL) { return; }if (hmsc == NULL) { ... } hmsc->csw.dSignature = USBD_BOT_CSW_SIGNATURE; hmsc->csw.bStatus = CSW_Status; hmsc->bot_state = USBD_BOT_IDLE; (void)USBD_LL_Transmit(pdev, MSCInEpAdd, (uint8_t *)&hmsc->csw, USBD_BOT_CSW_LENGTH); /* Prepare EP to Receive next Cmd */ (void)USBD_LL_PrepareReceive(pdev, MSCOutEpAdd, (uint8_t *)&hmsc->cbw, USBD_BOT_CBW_LENGTH); }{ ... } /** * @brief MSC_BOT_Abort * Abort the current transfer * @param pdev: device instance * @retval status *//* ... */ static void MSC_BOT_Abort(USBD_HandleTypeDef *pdev) { USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; #ifdef USE_USBD_COMPOSITE /* Get the Endpoints addresses allocated for this class instance */ MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId); MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);/* ... */ #endif /* USE_USBD_COMPOSITE */ if (hmsc == NULL) { return; }if (hmsc == NULL) { ... } if ((hmsc->cbw.bmFlags == 0U) && (hmsc->cbw.dDataLength != 0U) && (hmsc->bot_status == USBD_BOT_STATUS_NORMAL)) { (void)USBD_LL_StallEP(pdev, MSCOutEpAdd); }if ((hmsc->cbw.bmFlags == 0U) && (hmsc->cbw.dDataLength != 0U) && (hmsc->bot_status == USBD_BOT_STATUS_NORMAL)) { ... } (void)USBD_LL_StallEP(pdev, MSCInEpAdd); if (hmsc->bot_status == USBD_BOT_STATUS_ERROR) { (void)USBD_LL_StallEP(pdev, MSCInEpAdd); (void)USBD_LL_StallEP(pdev, MSCOutEpAdd); }if (hmsc->bot_status == USBD_BOT_STATUS_ERROR) { ... } }{ ... } /** * @brief MSC_BOT_CplClrFeature * Complete the clear feature request * @param pdev: device instance * @param epnum: endpoint index * @retval None *//* ... */ void MSC_BOT_CplClrFeature(USBD_HandleTypeDef *pdev, uint8_t epnum) { USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; #ifdef USE_USBD_COMPOSITE /* Get the Endpoints addresses allocated for this class instance */ MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId); MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);/* ... */ #endif /* USE_USBD_COMPOSITE */ if (hmsc == NULL) { return; }if (hmsc == NULL) { ... } if (hmsc->bot_status == USBD_BOT_STATUS_ERROR) /* Bad CBW Signature */ { (void)USBD_LL_StallEP(pdev, MSCInEpAdd); (void)USBD_LL_StallEP(pdev, MSCOutEpAdd); ...} else if (((epnum & 0x80U) == 0x80U) && (hmsc->bot_status != USBD_BOT_STATUS_RECOVERY)) { MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_FAILED); }else if (((epnum & 0x80U) == 0x80U) && (hmsc->bot_status != USBD_BOT_STATUS_RECOVERY)) { ... } else { return; }else { ... } }{ ... } /** * @} *//* ... */ /** * @} *//* ... */ /** * @} *//* ... */ Includes
Details
Show:
from
Types: Columns:
This file uses the notable symbols shown below. Click anywhere in the file to view more details.