Skip to content

Commit aceaebb

Browse files
fix unaligned_memcpy
1 parent d0c396f commit aceaebb

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/portable/raspberrypi/rp2040/rp2040_usb.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,14 @@ critical_section_t rp2usb_lock;
5151
//--------------------------------------------------------------------+
5252
// Implementation
5353
//--------------------------------------------------------------------+
54-
// Provide own byte by byte memcpy as not all copies are aligned
54+
// Provide own byte by byte memcpy as not all copies are aligned.
55+
// Use volatile to prevent compiler from widening to 16/32-bit accesses
56+
// which cause hard fault on RP2350 when dst/src point to USB DPRAM.
5557
static void unaligned_memcpy(uint8_t *dst, const uint8_t *src, size_t n) {
58+
volatile uint8_t *vdst = dst;
59+
const volatile uint8_t *vsrc = src;
5660
while (n--) {
57-
*dst++ = *src++;
61+
*vdst++ = *vsrc++;
5862
}
5963
}
6064

0 commit comments

Comments
 (0)