Skip to content

Commit 5f5bee3

Browse files
committed
Use timeout for usb disk read and write
1 parent 82736e9 commit 5f5bee3

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/Storage/UsbVolume.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ static_assert(CORE_USES_TINYUSB && CFG_TUH_ENABLED, "USB drive support needs tin
1616

1717
#include "UsbVolume.h"
1818

19+
constexpr uint32_t ReadWriteTimeout = 3000;
20+
1921
static bool disk_io_complete(uint8_t address, tuh_msc_complete_data_t const *cb_data)
2022
{
2123
(void) address;
@@ -134,15 +136,13 @@ DRESULT UsbVolume::DiskStatus() noexcept
134136
DRESULT UsbVolume::DiskRead(BYTE *buff, LBA_t sector, UINT count) noexcept
135137
{
136138
tuh_msc_read10(address, lun, buff, sector, (uint16_t)count, disk_io_complete, reinterpret_cast<uintptr_t>(&ioDone));
137-
ioDone.Take();
138-
return RES_OK;
139+
return ioDone.Take(ReadWriteTimeout) ? RES_OK : RES_ERROR;
139140
}
140141

141142
DRESULT UsbVolume::DiskWrite(BYTE const *buff, LBA_t sector, UINT count) noexcept
142143
{
143144
tuh_msc_write10(address, lun, buff, sector, (uint16_t)count, disk_io_complete, reinterpret_cast<uintptr_t>(&ioDone));
144-
ioDone.Take();
145-
return RES_OK;
145+
return ioDone.Take(ReadWriteTimeout) ? RES_OK : RES_ERROR;
146146
}
147147

148148
DRESULT UsbVolume::DiskIoctl(BYTE cmd, void *buff) noexcept

0 commit comments

Comments
 (0)