diff --git a/lib/usb/usb_standard.c b/lib/usb/usb_standard.c index d94ceed9..d927942f 100644 --- a/lib/usb/usb_standard.c +++ b/lib/usb/usb_standard.c @@ -129,8 +129,9 @@ static uint16_t build_config_descriptor(usbd_device *usbd_dev, } } - /* Fill in wTotalLength. */ - *(uint16_t *)(tmpbuf + 2) = totallen; + /* Fill in wTotalLength. + * Note that tmpbuf is sometimes not halfword-aligned */ + memcpy((tmpbuf + 2), &totallen, sizeof(uint16_t)); return total; }