Closed mischif closed 2 months ago
Hi @mischif,
Thanks for the report, I can reproduce this here. The CDC class currently uses EDIT: This is wrong, machine.disable_irq() locks a mutex.machine.disable_irq()
and machine.enable_irq()
to control concurrent access to the serial buffer, but this doesn't prevent a thread on CPU1 from accessing it at the same time a USB callback is running.
Will look into an alternative locking mechanism for this.
Root cause is not quite that actually, it's that the current USB transfer callback code marks the endpoint as free (no pending transfer) before it calls the transfer callback, so the callback code can call submit_xfer() if needed to submit a new transfer immediately.
However when the thread on the other CPU is submitting transfers, there's a race where it may see the endpoint has no pending transfer and submit a new transfer before the callback is done executing. Need to redesign the callbacks to handle this sequence.
Is there an update for this bug? I see one PR related to this was merged, but it's apparently only a partial fix.
There is, I was going to return to these fixes this week but I got sick instead. I should have something soon.
Running on a Pi Pico with MicroPython 1.23.0 and whatever the latest version of usb-device-cdc is in mip; code to reproduce:
If you connect to both ports with
mpremote a0
andmpremote a1
, you'll see this error sporadically:But I did see this error once: