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>
This commit is contained in:
Lasse Dalegaard 2021-10-27 11:02:10 +01:00 committed by KevinOConnor
parent aa481fd9c3
commit de33180236
1 changed files with 1 additions and 0 deletions

View File

@ -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();