GlasgowEmbedded / glasgow

Scots Army Knife for electronics
BSD Zero Clause License
1.92k stars 189 forks source link

firmware: fix race conditions in control out transfers (-2 bytes XRAM). #703

Open purdeaandrei opened 1 month ago

purdeaandrei commented 1 month ago

This PR depends on https://github.com/whitequark/libfx2/pull/18 This PR is ready for review but it should only be merged after the libfx2 PR is merged, and then this PR should also include an update to the submodule reference.

Before this change, the EP0BUF buffer used by control out transfers could be overwritten by new control transfers before the firmware is finished processing the previous control transfer.

The easiest way to illustrate this problem would be to run in a different terminal the following:

while true; do lsusb -v -d 20b7:9db1 > /dev/null; done

While this is running, glasglow is completely unusable. Presumably even a single lsusb run could cause corruption, if it happens to be issued at the wrong time.

With this change glasgow is now usable, even if the above loop is running.