diff options
| author | hathach <[email protected]> | 2026-04-02 23:50:12 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2026-04-02 23:50:12 +0700 |
| commit | c0c1566bea34419a8b165a489278114363de5a5e (patch) | |
| tree | 6e4500a66ff1e0fe67a2e7dba73627939c21dc21 /src | |
| parent | 871b843245666786857f54b7ffc1454d4acad7a0 (diff) | |
rp2040: fix RP2350 hard fault in unaligned_memcpy to USB DPRAM
Use volatile byte accesses to prevent the compiler from widening
the byte-by-byte copy loop into 16/32-bit accesses, which cause
a hard fault on RP2350 when targeting USB DPRAM (device memory).
Closes #3554
Diffstat (limited to 'src')
| -rw-r--r-- | src/portable/raspberrypi/rp2040/rp2040_usb.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/portable/raspberrypi/rp2040/rp2040_usb.c b/src/portable/raspberrypi/rp2040/rp2040_usb.c index 1b13934d3..f5ba81dd7 100644 --- a/src/portable/raspberrypi/rp2040/rp2040_usb.c +++ b/src/portable/raspberrypi/rp2040/rp2040_usb.c @@ -51,10 +51,14 @@ critical_section_t rp2usb_lock; //--------------------------------------------------------------------+ // Implementation //--------------------------------------------------------------------+ -// Provide own byte by byte memcpy as not all copies are aligned +// Provide own byte by byte memcpy as not all copies are aligned. +// Use volatile to prevent compiler from widening to 16/32-bit accesses +// which cause hard fault on RP2350 when dst/src points to USB DPRAM. static void unaligned_memcpy(uint8_t *dst, const uint8_t *src, size_t n) { + volatile uint8_t *vdst = dst; + const volatile uint8_t *vsrc = src; while (n--) { - *dst++ = *src++; + *vdst++ = *vsrc++; } } |
