From de331802365020f3a13ab6ffa97a3c96609af161 Mon Sep 17 00:00:00 2001 From: Lasse Dalegaard Date: Wed, 27 Oct 2021 11:02:10 +0100 Subject: [PATCH] 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 --- src/rp2040/usbserial.c | 1 + 1 file changed, 1 insertion(+) 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();