aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2021-10-27 11:11:13 -0400
committerKevin O'Connor <kevin@koconnor.net>2021-10-27 11:16:34 -0400
commit627c1c5d2a9d655d52960a17be7acff928d7ada2 (patch)
treee59b80ef15223978f072f18d76148833741911e0
parentde331802365020f3a13ab6ffa97a3c96609af161 (diff)
downloadkutter-627c1c5d2a9d655d52960a17be7acff928d7ada2.tar.gz
kutter-627c1c5d2a9d655d52960a17be7acff928d7ada2.tar.xz
kutter-627c1c5d2a9d655d52960a17be7acff928d7ada2.zip
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>
-rw-r--r--src/rp2040/usbserial.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/rp2040/usbserial.c b/src/rp2040/usbserial.c
index 030f4752..3a6736ef 100644
--- a/src/rp2040/usbserial.c
+++ b/src/rp2040/usbserial.c
@@ -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) {