@@ -267,7 +267,6 @@ static int usbh_msc_connect(struct usbh_hubport *hport, uint8_t intf)
267267 struct usb_endpoint_descriptor * ep_desc ;
268268 struct usbh_msc_modeswitch_config * config ;
269269 int ret ;
270- int cnt ;
271270
272271 struct usbh_msc * msc_class = usbh_msc_class_alloc ();
273272 if (msc_class == NULL ) {
@@ -319,38 +318,6 @@ static int usbh_msc_connect(struct usbh_hubport *hport, uint8_t intf)
319318 }
320319 }
321320
322- cnt = 0 ;
323- while (usbh_msc_scsi_testunitready (msc_class ) < 0 ) {
324- USB_LOG_WRN ("Device not ready, try again...\r\n" );
325- ret = usbh_msc_scsi_requestsense (msc_class );
326- if (ret < 0 ) {
327- USB_LOG_ERR ("Fail to scsi_testunitready\r\n" );
328- }
329- cnt ++ ;
330- if (cnt > CONFIG_USBHOST_MSC_READY_CHECK_TIMES ) {
331- return - USB_ERR_BUSY ;
332- }
333- }
334-
335- ret = usbh_msc_scsi_inquiry (msc_class );
336- if (ret < 0 ) {
337- USB_LOG_ERR ("Fail to scsi_inquiry\r\n" );
338- return ret ;
339- }
340- ret = usbh_msc_scsi_readcapacity10 (msc_class );
341- if (ret < 0 ) {
342- USB_LOG_ERR ("Fail to scsi_readcapacity10\r\n" );
343- return ret ;
344- }
345-
346- if (msc_class -> blocksize > 0 ) {
347- USB_LOG_INFO ("Capacity info:\r\n" );
348- USB_LOG_INFO ("Block num:%d,block size:%d\r\n" , (unsigned int )msc_class -> blocknum , (unsigned int )msc_class -> blocksize );
349- } else {
350- USB_LOG_ERR ("Invalid block size\r\n" );
351- return - USB_ERR_RANGE ;
352- }
353-
354321 snprintf (hport -> config .intf [intf ].devname , CONFIG_USBHOST_DEV_NAMELEN , DEV_FORMAT , msc_class -> sdchar );
355322
356323 USB_LOG_INFO ("Register MSC Class:%s\r\n" , hport -> config .intf [intf ].devname );
@@ -385,6 +352,46 @@ static int usbh_msc_disconnect(struct usbh_hubport *hport, uint8_t intf)
385352 return ret ;
386353}
387354
355+ int usbh_msc_scsi_init (struct usbh_msc * msc_class )
356+ {
357+ int ret ;
358+ uint16_t cnt ;
359+
360+ cnt = 0 ;
361+ while (usbh_msc_scsi_testunitready (msc_class ) < 0 ) {
362+ USB_LOG_WRN ("Device not ready, try again...\r\n" );
363+ ret = usbh_msc_scsi_requestsense (msc_class );
364+ if (ret < 0 ) {
365+ USB_LOG_ERR ("Fail to scsi_testunitready\r\n" );
366+ }
367+ cnt ++ ;
368+ if (cnt > CONFIG_USBHOST_MSC_READY_CHECK_TIMES ) {
369+ return - USB_ERR_NODEV ;
370+ }
371+ }
372+ ret = usbh_msc_scsi_inquiry (msc_class );
373+ if (ret < 0 ) {
374+ USB_LOG_ERR ("Fail to scsi_inquiry\r\n" );
375+ return ret ;
376+ }
377+
378+ ret = usbh_msc_scsi_readcapacity10 (msc_class );
379+ if (ret < 0 ) {
380+ USB_LOG_ERR ("Fail to scsi_readcapacity10\r\n" );
381+ return ret ;
382+ }
383+
384+ if (msc_class -> blocksize > 0 ) {
385+ USB_LOG_INFO ("Capacity info:\r\n" );
386+ USB_LOG_INFO ("Block num:%d,block size:%d\r\n" , (unsigned int )msc_class -> blocknum , (unsigned int )msc_class -> blocksize );
387+ } else {
388+ USB_LOG_ERR ("Invalid block size\r\n" );
389+ return - USB_ERR_RANGE ;
390+ }
391+
392+ return 0 ;
393+ }
394+
388395int usbh_msc_scsi_write10 (struct usbh_msc * msc_class , uint32_t start_sector , const uint8_t * buffer , uint32_t nsectors )
389396{
390397 struct CBW * cbw ;
0 commit comments