Skip to content

Commit

Permalink
rp2040: add barrier in usb_read_ep0_setup
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
dalegaard authored and KevinOConnor committed Oct 27, 2021
1 parent aa481fd commit de33180
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/rp2040/usbserial.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit de33180

Please sign in to comment.