cherry-embedded / CherryUSB

CherryUSB is a tiny and portable USB Stack (device & host) for embedded system with USB IP
https://cherryusb.readthedocs.io/
Apache License 2.0
1.17k stars 249 forks source link

MSC Writing very slow disk #151

Closed WGR7 closed 8 months ago

WGR7 commented 8 months ago

Hi,

I have a very slow media that needs much millisecs to write to disk.

What value should usbd_msc_sector_write return if the writing to disk has not completed yet? If Cherry can delay host to write new data while usbd_msc_sector_write is waiting media complete. How could I know if host is asking a write status or sending new data if usbd_msc_sector_write was called again by usb interrupt while write is in progress?

Regards.

sakumisu commented 8 months ago

Hi, will return -ETIMEOUT, default is 5s. So sending data and waiting for 5s,if it is not completed, will return -ETIMEOUT.

WGR7 commented 8 months ago

So, my function body should be like this?

int usbd_msc_sector_write(uint32_t sector, uint8_t *buffer, uint32_t length)
{

    if(GetDiskStatus() == WRITE_IN_PROGRESS){
          return -ETIMEOUT;
     }else{

    disk_write(buffer, sector, length);
    return 0;
    }

}
sakumisu commented 8 months ago

I said about host not device.If you are device, please wait forever until it is completed becase msc is a blocking design.

WGR7 commented 8 months ago

Thanks.