aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLasse Dalegaard <dalegaard@gmail.com>2021-10-27 11:02:10 +0100
committerKevinOConnor <kevin@koconnor.net>2021-10-27 11:10:17 -0400
commitde331802365020f3a13ab6ffa97a3c96609af161 (patch)
treefeb397ea53070da6eb82e7f7c5a60359fc44e90c /src
parentaa481fd9c3fc915537a51966320773fcf7008e7b (diff)
downloadkutter-de331802365020f3a13ab6ffa97a3c96609af161.tar.gz
kutter-de331802365020f3a13ab6ffa97a3c96609af161.tar.xz
kutter-de331802365020f3a13ab6ffa97a3c96609af161.zip
rp2040: add barrier in usb_read_ep0_setup
Some versions of gcc, in some cases, decide that it is OK to move the read to `INTR` to right after clearing the `SETUP_REC` bit of `SIE_STATUS`, instead of after the `memcpy`. The rp2040 datasheet doesn't appear to say anything about how quickly the `SETUP_REC` bit will be cleared in `INTR`, but regardless the compiler should not be re-ordering the read like this. Here we force the correct ordering using a memory barrier. Signed-off-by: Lasse Dalegaard <dalegaard@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/rp2040/usbserial.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/src/rp2040/usbserial.c b/src/rp2040/usbserial.c
index 3cd2e9d8..030f4752 100644
--- a/src/rp2040/usbserial.c
+++ b/src/rp2040/usbserial.c
@@ -96,6 +96,7 @@ usb_read_ep0_setup(void *data, uint_fast8_t max_len)
| USB_BUF_CTRL_AVAIL | DPBUF_SIZE);
usb_hw->sie_status = USB_SIE_STATUS_SETUP_REC_BITS;
memcpy(data, (void*)usb_dpram->setup_packet, max_len);
+ barrier();
if (usb_hw->intr & USB_INTR_SETUP_REQ_BITS) {
// Raced with next setup packet
usb_notify_ep0();