rp2040: Add barrier() around all memcpy() calls in usbserial.c

Make sure gcc doesn't reorder any of the memcpy() calls to the usb
data ram.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2021-10-27 11:11:13 -04:00
parent de33180236
commit 627c1c5d2a
1 changed files with 5 additions and 0 deletions

View File

@ -40,7 +40,9 @@ usb_write_packet(uint32_t ep, const void *data, uint_fast8_t len)
usb_dpram->ep_buf_ctrl[ep].in = new_epb;
// Copy the packet to the hw buffer
void *addr = (void*)usb_dpram + usb_buf_offset(ep);
barrier();
memcpy(addr, data, len);
barrier();
// Inform the USB hardware of the available packet
usb_dpram->ep_buf_ctrl[ep].in = new_epb | USB_BUF_CTRL_AVAIL;
return len;
@ -61,7 +63,9 @@ usb_read_packet(uint32_t ep, void *data, uint_fast8_t max_len)
if (c > max_len)
c = max_len;
void *addr = (void*)usb_dpram + usb_buf_offset(ep);
barrier();
memcpy(data, addr, c);
barrier();
// Notify the USB hardware that the space is now available
usb_dpram->ep_buf_ctrl[ep].out = new_epb | USB_BUF_CTRL_AVAIL;
return c;
@ -95,6 +99,7 @@ usb_read_ep0_setup(void *data, uint_fast8_t max_len)
usb_dpram->ep_buf_ctrl[0].out = (USB_BUF_CTRL_DATA1_PID | USB_BUF_CTRL_LAST
| USB_BUF_CTRL_AVAIL | DPBUF_SIZE);
usb_hw->sie_status = USB_SIE_STATUS_SETUP_REC_BITS;
barrier();
memcpy(data, (void*)usb_dpram->setup_packet, max_len);
barrier();
if (usb_hw->intr & USB_INTR_SETUP_REQ_BITS) {