Skip to content

Commit 95bb2a8

Browse files
maciejbocianskimergify-bot
authored andcommitted
update USBMSD::memoryWrite implementation
Fix prevents unaligned USB transfers (cherry picked from commit 1ffb4d7)
1 parent a277db1 commit 95bb2a8

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

drivers/source/usb/USBMSD.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,14 @@ void USBMSD::_read_next()
565565

566566
void USBMSD::memoryWrite(uint8_t *buf, uint16_t size)
567567
{
568+
// Max sized packets are required to be sent until the transfer is complete
569+
MBED_ASSERT(_block_size % MAX_PACKET == 0);
570+
if ((size != MAX_PACKET) && (size != 0)) {
571+
_stage = ERROR;
572+
endpoint_stall(_bulk_out);
573+
return;
574+
}
575+
568576
if ((_addr + size) > _memory_size) {
569577
size = _memory_size - _addr;
570578
_stage = ERROR;

0 commit comments

Comments
 (0)