diff --git a/lib/stm32/st_usbfs_v2.c b/lib/stm32/st_usbfs_v2.c index ec213fe58e..6986fef56d 100644 --- a/lib/stm32/st_usbfs_v2.c +++ b/lib/stm32/st_usbfs_v2.c @@ -69,20 +69,22 @@ void st_usbfs_copy_from_pm(void *buf, const volatile void *vPM, uint16_t len) uint8_t odd = len & 1; len >>= 1; - if (((uintptr_t) buf) & 0x01) { + if (((uintptr_t)buf) & 0x01) { + uint8_t *dest = (uint8_t *)buf; for (; len; PM++, len--) { uint16_t value = *PM; - *(uint8_t *) buf++ = value; - *(uint8_t *) buf++ = value >> 8; + *(uint8_t *)dest++ = value; + *(uint8_t *)dest++ = value >> 8; } } else { - for (; len; PM++, buf += 2, len--) { - *(uint16_t *) buf = *PM; + uint16_t *dest = (uint16_t *)buf; + for (; len; PM++, dest++, len--) { + *dest = *PM; } } if (odd) { - *(uint8_t *) buf = *(uint8_t *) PM; + *(uint8_t *)buf = *(uint8_t *)PM; } }