Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.

Commit 6694d9a

Browse files
purdeaandreiwhitequark
authored andcommitted
Fix race condition in boot-cypress
I have tested the following boot-cypress writing eeprom, while executing the following in the background: `while true; do lsusb -v -d 04b4:8613 > /dev/null; done` With the old version of boot-cypress this results in corrupted data. With the new version of boot-cypress this works correctly.
1 parent 25a3951 commit 6694d9a

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

firmware/boot-cypress/main.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,14 @@ void handle_pending_usb_setup(void) {
147147
}
148148
SETUP_EP0_IN_BUF(len);
149149
} else {
150-
SETUP_EP0_BUF(0);
150+
SETUP_EP0_OUT_BUF();
151151
while(EP0CS & _BUSY);
152152
if(!eeprom_write(arg_chip, arg_addr, EP0BUF, len, arg_dbyte, page_size,
153153
/*timeout=*/166)) {
154154
STALL_EP0();
155155
break;
156156
}
157+
ACK_EP0();
157158
}
158159

159160
arg_len -= len;
@@ -179,9 +180,10 @@ void handle_pending_usb_setup(void) {
179180
xmemcpy(EP0BUF, (__xdata void *)arg_addr, len);
180181
SETUP_EP0_IN_BUF(len);
181182
} else {
182-
SETUP_EP0_BUF(0);
183+
SETUP_EP0_OUT_BUF();
183184
while(EP0CS & _BUSY);
184185
xmemcpy((__xdata void *)arg_addr, EP0BUF, arg_len);
186+
ACK_EP0();
185187
}
186188

187189
arg_len -= len;

0 commit comments

Comments
 (0)