STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
usbh_msc.c
Go to the documentation of this file.
1 
40 /* Includes ------------------------------------------------------------------*/
41 
42 #include "usbh_msc.h"
43 #include "usbh_msc_bot.h"
44 #include "usbh_msc_scsi.h"
45 
46 
99 static USBH_StatusTypeDef USBH_MSC_InterfaceInit (USBH_HandleTypeDef *phost);
100 
101 static USBH_StatusTypeDef USBH_MSC_InterfaceDeInit (USBH_HandleTypeDef *phost);
102 
103 static USBH_StatusTypeDef USBH_MSC_Process(USBH_HandleTypeDef *phost);
104 
105 static USBH_StatusTypeDef USBH_MSC_ClassRequest(USBH_HandleTypeDef *phost);
106 
107 static USBH_StatusTypeDef USBH_MSC_SOFProcess(USBH_HandleTypeDef *phost);
108 
109 static USBH_StatusTypeDef USBH_MSC_RdWrProcess(USBH_HandleTypeDef *phost, uint8_t lun);
110 
112 {
113  "MSC",
115  USBH_MSC_InterfaceInit,
116  USBH_MSC_InterfaceDeInit,
117  USBH_MSC_ClassRequest,
118  USBH_MSC_Process,
119  USBH_MSC_SOFProcess,
120  NULL,
121 };
122 
123 
149 static USBH_StatusTypeDef USBH_MSC_InterfaceInit (USBH_HandleTypeDef *phost)
150 {
151  uint8_t interface = 0;
152  USBH_StatusTypeDef status = USBH_FAIL ;
153  MSC_HandleTypeDef *MSC_Handle;
154 
155  interface = USBH_FindInterface(phost, phost->pActiveClass->ClassCode, MSC_TRANSPARENT, MSC_BOT);
156 
157  if(interface == 0xFF) /* Not Valid Interface */
158  {
159  USBH_DbgLog ("Cannot Find the interface for %s class.", phost->pActiveClass->Name);
160  status = USBH_FAIL;
161  }
162  else
163  {
164  USBH_SelectInterface (phost, interface);
165 
166  phost->pActiveClass->pData = (MSC_HandleTypeDef *)USBH_malloc (sizeof(MSC_HandleTypeDef));
167  MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData;
168 
169  if(phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].bEndpointAddress & 0x80)
170  {
171  MSC_Handle->InEp = (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].bEndpointAddress);
172  MSC_Handle->InEpSize = phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].wMaxPacketSize;
173  }
174  else
175  {
176  MSC_Handle->OutEp = (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].bEndpointAddress);
177  MSC_Handle->OutEpSize = phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].wMaxPacketSize;
178  }
179 
180  if(phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[1].bEndpointAddress & 0x80)
181  {
182  MSC_Handle->InEp = (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[1].bEndpointAddress);
183  MSC_Handle->InEpSize = phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[1].wMaxPacketSize;
184  }
185  else
186  {
187  MSC_Handle->OutEp = (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[1].bEndpointAddress);
188  MSC_Handle->OutEpSize = phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[1].wMaxPacketSize;
189  }
190 
191  MSC_Handle->current_lun = 0;
192  MSC_Handle->rw_lun = 0;
193  MSC_Handle->state = MSC_INIT;
194  MSC_Handle->error = MSC_OK;
195  MSC_Handle->req_state = MSC_REQ_IDLE;
196  MSC_Handle->OutPipe = USBH_AllocPipe(phost, MSC_Handle->OutEp);
197  MSC_Handle->InPipe = USBH_AllocPipe(phost, MSC_Handle->InEp);
198 
199  USBH_MSC_BOT_Init(phost);
200 
201  /* De-Initialize LUNs information */
202  USBH_memset(MSC_Handle->unit, 0, sizeof(MSC_Handle->unit));
203 
204  /* Open the new channels */
205  USBH_OpenPipe (phost,
206  MSC_Handle->OutPipe,
207  MSC_Handle->OutEp,
208  phost->device.address,
209  phost->device.speed,
211  MSC_Handle->OutEpSize);
212 
213  USBH_OpenPipe (phost,
214  MSC_Handle->InPipe,
215  MSC_Handle->InEp,
216  phost->device.address,
217  phost->device.speed,
219  MSC_Handle->InEpSize);
220 
221 
222  USBH_LL_SetToggle (phost, MSC_Handle->InPipe,0);
223  USBH_LL_SetToggle (phost, MSC_Handle->OutPipe,0);
224  status = USBH_OK;
225  }
226  return status;
227 }
228 
235 USBH_StatusTypeDef USBH_MSC_InterfaceDeInit (USBH_HandleTypeDef *phost)
236 {
237  MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData;
238 
239  if ( MSC_Handle->OutPipe)
240  {
241  USBH_ClosePipe(phost, MSC_Handle->OutPipe);
242  USBH_FreePipe (phost, MSC_Handle->OutPipe);
243  MSC_Handle->OutPipe = 0; /* Reset the Channel as Free */
244  }
245 
246  if ( MSC_Handle->InPipe)
247  {
248  USBH_ClosePipe(phost, MSC_Handle->InPipe);
249  USBH_FreePipe (phost, MSC_Handle->InPipe);
250  MSC_Handle->InPipe = 0; /* Reset the Channel as Free */
251  }
252 
253  if(phost->pActiveClass->pData)
254  {
255  USBH_free (phost->pActiveClass->pData);
256  phost->pActiveClass->pData = 0;
257  }
258 
259  return USBH_OK;
260 }
261 
269 static USBH_StatusTypeDef USBH_MSC_ClassRequest(USBH_HandleTypeDef *phost)
270 {
271  MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData;
272  USBH_StatusTypeDef status = USBH_BUSY;
273  uint8_t i;
274 
275  /* Switch MSC REQ state machine */
276  switch (MSC_Handle->req_state)
277  {
278  case MSC_REQ_IDLE:
279  case MSC_REQ_GET_MAX_LUN:
280  /* Issue GetMaxLUN request */
281  status = USBH_MSC_BOT_REQ_GetMaxLUN(phost, (uint8_t *)&MSC_Handle->max_lun);
282 
283  /* When devices do not support the GetMaxLun request, this should
284  be considred as only one logical unit is supported */
285  if(status == USBH_NOT_SUPPORTED)
286  {
287  MSC_Handle->max_lun = 0;
288  status = USBH_OK;
289  }
290 
291  if(status == USBH_OK)
292  {
293  MSC_Handle->max_lun = (uint8_t )(MSC_Handle->max_lun) + 1;
294  USBH_UsrLog ("Number of supported LUN: %lu", (int32_t)(MSC_Handle->max_lun));
295 
296  for(i = 0; i < MSC_Handle->max_lun; i++)
297  {
298  MSC_Handle->unit[i].prev_ready_state = USBH_FAIL;
299  MSC_Handle->unit[i].state_changed = 0;
300  }
301  }
302  break;
303 
304  case MSC_REQ_ERROR :
305  /* a Clear Feature should be issued here */
306  if(USBH_ClrFeature(phost, 0x00) == USBH_OK)
307  {
308  MSC_Handle->req_state = MSC_Handle->prev_req_state;
309  }
310  break;
311 
312  default:
313  break;
314  }
315 
316  return status;
317 }
318 
325 static USBH_StatusTypeDef USBH_MSC_Process(USBH_HandleTypeDef *phost)
326 {
327  MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData;
328  USBH_StatusTypeDef error = USBH_BUSY ;
329  USBH_StatusTypeDef scsi_status = USBH_BUSY ;
330  USBH_StatusTypeDef ready_status = USBH_BUSY ;
331 
332  switch (MSC_Handle->state)
333  {
334  case MSC_INIT:
335 
336  if(MSC_Handle->current_lun < MSC_Handle->max_lun)
337  {
338 
339  MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_NOT_READY;
340  /* Switch MSC REQ state machine */
341  switch (MSC_Handle->unit[MSC_Handle->current_lun].state)
342  {
343  case MSC_INIT:
344  USBH_UsrLog ("LUN #%d: ", MSC_Handle->current_lun);
345  MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_READ_INQUIRY;
346  MSC_Handle->timer = phost->Timer;
347 
348  case MSC_READ_INQUIRY:
349  scsi_status = USBH_MSC_SCSI_Inquiry(phost, MSC_Handle->current_lun, &MSC_Handle->unit[MSC_Handle->current_lun].inquiry);
350 
351  if( scsi_status == USBH_OK)
352  {
353  USBH_UsrLog ("Inquiry Vendor : %s", MSC_Handle->unit[MSC_Handle->current_lun].inquiry.vendor_id);
354  USBH_UsrLog ("Inquiry Product : %s", MSC_Handle->unit[MSC_Handle->current_lun].inquiry.product_id);
355  USBH_UsrLog ("Inquiry Version : %s", MSC_Handle->unit[MSC_Handle->current_lun].inquiry.revision_id);
356  MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_TEST_UNIT_READY;
357  }
358  if( scsi_status == USBH_FAIL)
359  {
360  MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_REQUEST_SENSE;
361  }
362  else if(scsi_status == USBH_UNRECOVERED_ERROR)
363  {
364  MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_IDLE;
365  MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_ERROR;
366  }
367  break;
368 
369  case MSC_TEST_UNIT_READY:
370  ready_status = USBH_MSC_SCSI_TestUnitReady(phost, MSC_Handle->current_lun);
371 
372  if( ready_status == USBH_OK)
373  {
374  if( MSC_Handle->unit[MSC_Handle->current_lun].prev_ready_state != USBH_OK)
375  {
376  MSC_Handle->unit[MSC_Handle->current_lun].state_changed = 1;
377  USBH_UsrLog ("MSC Device ready");
378  }
379  else
380  {
381  MSC_Handle->unit[MSC_Handle->current_lun].state_changed = 0;
382  }
383  MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_READ_CAPACITY10;
384  MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_OK;
385  MSC_Handle->unit[MSC_Handle->current_lun].prev_ready_state = USBH_OK;
386  }
387  if( ready_status == USBH_FAIL)
388  {
389  /* Media not ready, so try to check again during 10s */
390  if( MSC_Handle->unit[MSC_Handle->current_lun].prev_ready_state != USBH_FAIL)
391  {
392  MSC_Handle->unit[MSC_Handle->current_lun].state_changed = 1;
393  USBH_UsrLog ("MSC Device NOT ready");
394  }
395  else
396  {
397  MSC_Handle->unit[MSC_Handle->current_lun].state_changed = 0;
398  }
399  MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_REQUEST_SENSE;
400  MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_NOT_READY;
401  MSC_Handle->unit[MSC_Handle->current_lun].prev_ready_state = USBH_FAIL;
402  }
403  else if(ready_status == USBH_UNRECOVERED_ERROR)
404  {
405  MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_IDLE;
406  MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_ERROR;
407  }
408  break;
409 
410  case MSC_READ_CAPACITY10:
411  scsi_status = USBH_MSC_SCSI_ReadCapacity(phost,MSC_Handle->current_lun, &MSC_Handle->unit[MSC_Handle->current_lun].capacity) ;
412 
413  if(scsi_status == USBH_OK)
414  {
415  if(MSC_Handle->unit[MSC_Handle->current_lun].state_changed == 1)
416  {
417  USBH_UsrLog ("MSC Device capacity : %lu Bytes", \
418  (int32_t)(MSC_Handle->unit[MSC_Handle->current_lun].capacity.block_nbr * MSC_Handle->unit[MSC_Handle->current_lun].capacity.block_size));
419  USBH_UsrLog ("Block number : %lu", (int32_t)(MSC_Handle->unit[MSC_Handle->current_lun].capacity.block_nbr));
420  USBH_UsrLog ("Block Size : %lu", (int32_t)(MSC_Handle->unit[MSC_Handle->current_lun].capacity.block_size));
421  }
422  MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_IDLE;
423  MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_OK;
424  MSC_Handle->current_lun++;
425  }
426  else if( scsi_status == USBH_FAIL)
427  {
428  MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_REQUEST_SENSE;
429  }
430  else if(scsi_status == USBH_UNRECOVERED_ERROR)
431  {
432  MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_IDLE;
433  MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_ERROR;
434  }
435  break;
436 
437  case MSC_REQUEST_SENSE:
438  scsi_status = USBH_MSC_SCSI_RequestSense(phost, MSC_Handle->current_lun, &MSC_Handle->unit[MSC_Handle->current_lun].sense);
439 
440  if( scsi_status == USBH_OK)
441  {
442  if((MSC_Handle->unit[MSC_Handle->current_lun].sense.key == SCSI_SENSE_KEY_UNIT_ATTENTION) ||
443  (MSC_Handle->unit[MSC_Handle->current_lun].sense.key == SCSI_SENSE_KEY_NOT_READY) )
444  {
445 
446  if((phost->Timer - MSC_Handle->timer) < 10000)
447  {
448  MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_TEST_UNIT_READY;
449  break;
450  }
451  }
452 
453  USBH_UsrLog ("Sense Key : %x", MSC_Handle->unit[MSC_Handle->current_lun].sense.key);
454  USBH_UsrLog ("Additional Sense Code : %x", MSC_Handle->unit[MSC_Handle->current_lun].sense.asc);
455  USBH_UsrLog ("Additional Sense Code Qualifier: %x", MSC_Handle->unit[MSC_Handle->current_lun].sense.ascq);
456  MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_IDLE;
457  MSC_Handle->current_lun++;
458  }
459  if( scsi_status == USBH_FAIL)
460  {
461  USBH_UsrLog ("MSC Device NOT ready");
462  MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_UNRECOVERED_ERROR;
463  }
464  else if(scsi_status == USBH_UNRECOVERED_ERROR)
465  {
466  MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_IDLE;
467  MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_ERROR;
468  }
469  break;
470 
471  case MSC_UNRECOVERED_ERROR:
472  MSC_Handle->current_lun++;
473  break;
474 
475  default:
476  break;
477  }
478 
479 #if (USBH_USE_OS == 1)
480  osMessagePut ( phost->os_event, USBH_CLASS_EVENT, 0);
481 #endif
482  }
483  else
484  {
485  MSC_Handle->current_lun = 0;
486  MSC_Handle->state = MSC_IDLE;
487 #if (USBH_USE_OS == 1)
488  osMessagePut ( phost->os_event, USBH_CLASS_EVENT, 0);
489 #endif
490  phost->pUser(phost, HOST_USER_CLASS_ACTIVE);
491  }
492  break;
493 
494  case MSC_IDLE:
495  error = USBH_OK;
496  break;
497 
498  default:
499  break;
500  }
501  return error;
502 }
503 
504 
511 static USBH_StatusTypeDef USBH_MSC_SOFProcess(USBH_HandleTypeDef *phost)
512 {
513 
514  return USBH_OK;
515 }
523 static USBH_StatusTypeDef USBH_MSC_RdWrProcess(USBH_HandleTypeDef *phost, uint8_t lun)
524 {
525  MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData;
526  USBH_StatusTypeDef error = USBH_BUSY ;
527  USBH_StatusTypeDef scsi_status = USBH_BUSY ;
528 
529  /* Switch MSC REQ state machine */
530  switch (MSC_Handle->unit[lun].state)
531  {
532 
533  case MSC_READ:
534  scsi_status = USBH_MSC_SCSI_Read(phost,lun, 0, NULL, 0) ;
535 
536  if(scsi_status == USBH_OK)
537  {
538  MSC_Handle->unit[lun].state = MSC_IDLE;
539  error = USBH_OK;
540  }
541  else if( scsi_status == USBH_FAIL)
542  {
543  MSC_Handle->unit[lun].state = MSC_REQUEST_SENSE;
544  }
545  else if(scsi_status == USBH_UNRECOVERED_ERROR)
546  {
547  MSC_Handle->unit[lun].state = MSC_UNRECOVERED_ERROR;
548  error = USBH_FAIL;
549  }
550 #if (USBH_USE_OS == 1)
551  osMessagePut ( phost->os_event, USBH_CLASS_EVENT, 0);
552 #endif
553  break;
554 
555  case MSC_WRITE:
556  scsi_status = USBH_MSC_SCSI_Write(phost,lun, 0, NULL, 0) ;
557 
558  if(scsi_status == USBH_OK)
559  {
560  MSC_Handle->unit[lun].state = MSC_IDLE;
561  error = USBH_OK;
562  }
563  else if( scsi_status == USBH_FAIL)
564  {
565  MSC_Handle->unit[lun].state = MSC_REQUEST_SENSE;
566  }
567  else if(scsi_status == USBH_UNRECOVERED_ERROR)
568  {
569  MSC_Handle->unit[lun].state = MSC_UNRECOVERED_ERROR;
570  error = USBH_FAIL;
571  }
572 #if (USBH_USE_OS == 1)
573  osMessagePut ( phost->os_event, USBH_CLASS_EVENT, 0);
574 #endif
575  break;
576 
577  case MSC_REQUEST_SENSE:
578  scsi_status = USBH_MSC_SCSI_RequestSense(phost, lun, &MSC_Handle->unit[lun].sense);
579 
580  if( scsi_status == USBH_OK)
581  {
582  USBH_UsrLog ("Sense Key : %x", MSC_Handle->unit[lun].sense.key);
583  USBH_UsrLog ("Additional Sense Code : %x", MSC_Handle->unit[lun].sense.asc);
584  USBH_UsrLog ("Additional Sense Code Qualifier: %x", MSC_Handle->unit[lun].sense.ascq);
585  MSC_Handle->unit[lun].state = MSC_IDLE;
586  MSC_Handle->unit[lun].error = MSC_ERROR;
587 
588  error = USBH_FAIL;
589  }
590  if( scsi_status == USBH_FAIL)
591  {
592  USBH_UsrLog ("MSC Device NOT ready");
593  }
594  else if(scsi_status == USBH_UNRECOVERED_ERROR)
595  {
596  MSC_Handle->unit[lun].state = MSC_UNRECOVERED_ERROR;
597  error = USBH_FAIL;
598  }
599 #if (USBH_USE_OS == 1)
600  osMessagePut ( phost->os_event, USBH_CLASS_EVENT, 0);
601 #endif
602  break;
603 
604  default:
605  break;
606 
607  }
608  return error;
609 }
610 
618 {
619  MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData;
620 
621  if(phost->gState == HOST_CLASS)
622  {
623  return (MSC_Handle->state == MSC_IDLE);
624  }
625  else
626  {
627  return 0;
628  }
629 }
630 
638 {
639  MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData;
640 
641  if ((phost->gState == HOST_CLASS) && (MSC_Handle->state == MSC_IDLE))
642  {
643  return MSC_Handle->max_lun;
644  }
645  return 0xFF;
646 }
647 
655 uint8_t USBH_MSC_UnitIsReady (USBH_HandleTypeDef *phost, uint8_t lun)
656 {
657  MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData;
658 
659  if(phost->gState == HOST_CLASS)
660  {
661  return (MSC_Handle->unit[lun].error == MSC_OK);
662  }
663  else
664  {
665  return 0;
666  }
667 }
668 
677 {
678  MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData;
679  if(phost->gState == HOST_CLASS)
680  {
681  USBH_memcpy(info,&MSC_Handle->unit[lun], sizeof(MSC_LUNTypeDef));
682  return USBH_OK;
683  }
684  else
685  {
686  return USBH_FAIL;
687  }
688 }
689 
701  uint8_t lun,
702  uint32_t address,
703  uint8_t *pbuf,
704  uint32_t length)
705 {
706  uint32_t timeout;
707  MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData;
708 
709  if ((phost->device.is_connected == 0) ||
710  (phost->gState != HOST_CLASS) ||
711  (MSC_Handle->unit[lun].state != MSC_IDLE))
712  {
713  return USBH_FAIL;
714  }
715  MSC_Handle->state = MSC_READ;
716  MSC_Handle->unit[lun].state = MSC_READ;
717  MSC_Handle->rw_lun = lun;
718  USBH_MSC_SCSI_Read(phost,
719  lun,
720  address,
721  pbuf,
722  length);
723 
724  timeout = phost->Timer;
725 
726  while (USBH_MSC_RdWrProcess(phost, lun) == USBH_BUSY)
727  {
728  if(((phost->Timer - timeout) > (10000 * length)) || (phost->device.is_connected == 0))
729  {
730  MSC_Handle->state = MSC_IDLE;
731  return USBH_FAIL;
732  }
733  }
734  MSC_Handle->state = MSC_IDLE;
735  return USBH_OK;
736 }
737 
749  uint8_t lun,
750  uint32_t address,
751  uint8_t *pbuf,
752  uint32_t length)
753 {
754  uint32_t timeout;
755  MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData;
756 
757  if ((phost->device.is_connected == 0) ||
758  (phost->gState != HOST_CLASS) ||
759  (MSC_Handle->unit[lun].state != MSC_IDLE))
760  {
761  return USBH_FAIL;
762  }
763  MSC_Handle->state = MSC_WRITE;
764  MSC_Handle->unit[lun].state = MSC_WRITE;
765  MSC_Handle->rw_lun = lun;
766  USBH_MSC_SCSI_Write(phost,
767  lun,
768  address,
769  pbuf,
770  length);
771 
772  timeout = phost->Timer;
773  while (USBH_MSC_RdWrProcess(phost, lun) == USBH_BUSY)
774  {
775  if(((phost->Timer - timeout) > (10000 * length)) || (phost->device.is_connected == 0))
776  {
777  MSC_Handle->state = MSC_IDLE;
778  return USBH_FAIL;
779  }
780  }
781  MSC_Handle->state = MSC_IDLE;
782  return USBH_OK;
783 }
784 
805 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
USBH_StatusTypeDef USBH_MSC_BOT_Init(USBH_HandleTypeDef *phost)
USBH_MSC_BOT_Init The function Initializes the BOT protocol.
Definition: usbh_msc_bot.c:151
USBH_ClassTypeDef USBH_msc
Definition: usbh_msc.c:111
uint8_t USBH_MSC_UnitIsReady(USBH_HandleTypeDef *phost, uint8_t lun)
USBH_MSC_UnitIsReady The function check whether a LUN is ready.
Definition: usbh_msc.c:655
uint8_t USBH_MSC_IsReady(USBH_HandleTypeDef *phost)
USBH_MSC_IsReady The function check if the MSC function is ready.
Definition: usbh_msc.c:617
#define USBH_memset
USBH_DeviceTypeDef device
Definition: usbh_def.h:456
Header file for usbh_msc_bot.c.
USBH_StatusTypeDef USBH_OpenPipe(USBH_HandleTypeDef *phost, uint8_t ch_num, uint8_t epnum, uint8_t dev_address, uint8_t speed, uint8_t ep_type, uint16_t mps)
USBH_Open_Pipe Open a pipe.
Definition: usbh_pipes.c:93
__IO uint32_t Timer
Definition: usbh_def.h:461
uint32_t max_lun
Definition: usbh_msc.h:118
USBH_StatusTypeDef USBH_SelectInterface(USBH_HandleTypeDef *phost, uint8_t interface)
USBH_SelectInterface Select current interface.
Definition: usbh_core.c:233
USBH_StatusTypeDef USBH_MSC_Write(USBH_HandleTypeDef *phost, uint8_t lun, uint32_t address, uint8_t *pbuf, uint32_t length)
USBH_MSC_Write The function performs a Write operation.
Definition: usbh_msc.c:748
MSC_LUNTypeDef unit[MAX_SUPPORTED_LUN]
Definition: usbh_msc.h:130
uint8_t USBH_AllocPipe(USBH_HandleTypeDef *phost, uint8_t ep_addr)
USBH_Alloc_Pipe Allocate a new Pipe.
Definition: usbh_pipes.c:138
#define USB_MSC_CLASS
Definition: usbh_msc.h:153
MSC_ErrorTypeDef error
Definition: usbh_msc.h:105
#define HOST_USER_CLASS_ACTIVE
Definition: usbh_core.h:65
uint8_t OutEp
Definition: usbh_msc.h:121
if(LCD_Lock==DISABLE)
Definition: lcd_log.c:249
#define SCSI_SENSE_KEY_UNIT_ATTENTION
uint8_t InEp
Definition: usbh_msc.h:122
USBH_StatusTypeDef USBH_FreePipe(USBH_HandleTypeDef *phost, uint8_t idx)
USBH_Free_Pipe Free the USB Pipe.
Definition: usbh_pipes.c:158
uint8_t USBH_FindInterface(USBH_HandleTypeDef *phost, uint8_t Class, uint8_t SubClass, uint8_t Protocol)
USBH_FindInterface Find the interface index for a specific class.
Definition: usbh_core.c:274
USBH_StatusTypeDef USBH_ClrFeature(USBH_HandleTypeDef *phost, uint8_t ep_num)
USBH_ClrFeature This request is used to clear or disable a specific feature.
Definition: usbh_ctlreq.c:308
void(* pUser)(struct _USBH_HandleTypeDef *pHandle, uint8_t id)
Definition: usbh_def.h:464
USBH_StatusTypeDef USBH_MSC_SCSI_Write(USBH_HandleTypeDef *phost, uint8_t lun, uint32_t address, uint8_t *pbuf, uint32_t length)
USBH_MSC_SCSI_Write Issue write10 command.
This file contains all the prototypes for the usbh_msc.c.
#define USB_EP_TYPE_BULK
Definition: usbh_def.h:172
#define NULL
Definition: usbd_def.h:53
int8_t USBH_MSC_GetMaxLUN(USBH_HandleTypeDef *phost)
USBH_MSC_GetMaxLUN The function return the Max LUN supported.
Definition: usbh_msc.c:637
USBH_StatusTypeDef USBH_MSC_BOT_REQ_GetMaxLUN(USBH_HandleTypeDef *phost, uint8_t *Maxlun)
USBH_MSC_BOT_REQ_GetMaxLUN The function the MSC BOT GetMaxLUN request.
Definition: usbh_msc_bot.c:130
uint32_t timer
Definition: usbh_msc.h:133
SCSI_StdInquiryDataTypeDef inquiry
Definition: usbh_msc.h:109
USBH_StatusTypeDef USBH_MSC_SCSI_TestUnitReady(USBH_HandleTypeDef *phost, uint8_t lun)
USBH_MSC_SCSI_TestUnitReady Issue TestUnitReady command.
Definition: pbuf.h:108
#define USBH_malloc
USBH_StatusTypeDef USBH_MSC_SCSI_Inquiry(USBH_HandleTypeDef *phost, uint8_t lun, SCSI_StdInquiryDataTypeDef *inquiry)
USBH_MSC_SCSI_Inquiry Issue Inquiry command.
#define USBH_memcpy
SCSI_CapacityTypeDef capacity
Definition: usbh_msc.h:107
USBH_StatusTypeDef USBH_MSC_SCSI_Read(USBH_HandleTypeDef *phost, uint8_t lun, uint32_t address, uint8_t *pbuf, uint32_t length)
USBH_MSC_SCSI_Read Issue Read10 command.
USBH_StatusTypeDef USBH_MSC_SCSI_RequestSense(USBH_HandleTypeDef *phost, uint8_t lun, SCSI_SenseTypeDef *sense_data)
USBH_MSC_SCSI_RequestSense Issue RequestSense command.
Header file for usbh_msc_scsi.c.
uint16_t current_lun
Definition: usbh_msc.h:131
#define SCSI_SENSE_KEY_NOT_READY
MSC_ReqStateTypeDef prev_req_state
Definition: usbh_msc.h:128
USBH_StatusTypeDef USBH_LL_SetToggle(USBH_HandleTypeDef *phost, uint8_t, uint8_t)
USBH_LL_SetToggle Set toggle for a pipe.
USBH_StatusTypeDef
Definition: usbh_def.h:302
#define USBH_DbgLog(...)
__IO HOST_StateTypeDef gState
Definition: usbh_def.h:452
uint16_t rw_lun
Definition: usbh_msc.h:132
#define USBH_UsrLog(...)
osStatus osMessagePut(osMessageQId queue_id, uint32_t info, uint32_t millisec)
Put a Message to a Queue.
Definition: cmsis_os.c:951
USBH_StatusTypeDef prev_ready_state
Definition: usbh_msc.h:106
USBH_StatusTypeDef USBH_MSC_Read(USBH_HandleTypeDef *phost, uint8_t lun, uint32_t address, uint8_t *pbuf, uint32_t length)
USBH_MSC_Read The function performs a Read operation.
Definition: usbh_msc.c:700
MSC_ErrorTypeDef error
Definition: usbh_msc.h:126
USBH_ClassTypeDef * pActiveClass
Definition: usbh_def.h:458
MSC_ReqStateTypeDef req_state
Definition: usbh_msc.h:127
uint16_t InEpSize
Definition: usbh_msc.h:124
#define USBH_free
MSC_StateTypeDef state
Definition: usbh_msc.h:125
uint16_t OutEpSize
Definition: usbh_msc.h:123
USBH_StatusTypeDef USBH_MSC_SCSI_ReadCapacity(USBH_HandleTypeDef *phost, uint8_t lun, SCSI_CapacityTypeDef *capacity)
USBH_MSC_SCSI_ReadCapacity Issue Read Capacity command.
uint8_t InPipe
Definition: usbh_msc.h:119
USBH_StatusTypeDef USBH_MSC_GetLUNInfo(USBH_HandleTypeDef *phost, uint8_t lun, MSC_LUNTypeDef *info)
USBH_MSC_GetLUNInfo The function return a LUN information.
Definition: usbh_msc.c:676
uint8_t OutPipe
Definition: usbh_msc.h:120
__IO uint8_t is_connected
Definition: usbh_def.h:427
uint8_t state_changed
Definition: usbh_msc.h:110
MSC_StateTypeDef state
Definition: usbh_msc.h:104
USBH_StatusTypeDef USBH_ClosePipe(USBH_HandleTypeDef *phost, uint8_t pipe_num)
USBH_ClosePipe Close a pipe.
Definition: usbh_pipes.c:121
SCSI_SenseTypeDef sense
Definition: usbh_msc.h:108