You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I had a strange issue running the usb_serial example on an STM32F401 where the serial device would work fine for the first connection from the host, but if I disconnected the terminal session and then re-connected the driver would panic with the following message.
Very strangely, if I enabled the defmt feature in embassy-stm32 crate and set DEFMT_LOG=trace the problem would go away. As an aside, enabling the defmt feature in the embassy-usb-synopsys-otg results in lots of compile errors with defmt::assert! (see #3492) (constant function errors) which makes debugging a bit tricky.
It looks like the driver is getting an unexpected response from let status = r.grxstsp().read() (status.epnum() was 12 rather than 1 when the error showed up in my testing).
The patch below fixes this by replacing the assert!(ep_num < ep_count) with a test which skips the packet rather than panic-ing.
I suspect that there is a more fundamental issue here but but this does at least fix the panic! issue.
diff --git a/embassy-usb-synopsys-otg/src/lib.rs b/embassy-usb-synopsys-otg/src/lib.rs
index f90403936..3197817ee 100644
--- a/embassy-usb-synopsys-otg/src/lib.rs
+++ b/embassy-usb-synopsys-otg/src/lib.rs
@@ -43,7 +43,16 @@ pub unsafe fn on_interrupt<const MAX_EP_COUNT: usize>(
let ep_num = status.epnum() as usize;
let len = status.bcnt() as usize;
- assert!(ep_num < ep_count);
+ if ep_num >= ep_count {
+ // Removed `assert!(ep_num < ep_count);` as this fails for second serial connection UNLESS
+ // defmt-trace level debugging is enabled in embassy-stm32 (note that the defmt feature
+ // doesnt work in embassy-usb-synopsys-otg as defmt::assert! generates multiple errors)
+ //
+ // I'm guessing this may be some sort of timing issue so instead of panic-ing skip the
+ // invalid packet :‑(
+ error!("Skipping Invalid Packet (ep_num >= ep_count): ep_num: {} ep_count: {}", ep_num, ep_count);
+ continue;
+ }
match status.pktstsd() {
vals::Pktstsd::SETUP_DATA_RX => {
The text was updated successfully, but these errors were encountered:
paulc
added a commit
to paulc/embassy
that referenced
this issue
Nov 2, 2024
I had a strange issue running the
usb_serial
example on an STM32F401 where the serial device would work fine for the first connection from the host, but if I disconnected the terminal session and then re-connected the driver would panic with the following message.Very strangely, if I enabled the
defmt
feature in embassy-stm32 crate and set DEFMT_LOG=trace the problem would go away. As an aside, enabling thedefmt
feature in the embassy-usb-synopsys-otg results in lots of compile errors withdefmt::assert!
(see #3492) (constant function errors) which makes debugging a bit tricky.It looks like the driver is getting an unexpected response from let status = r.grxstsp().read() (status.epnum() was 12 rather than 1 when the error showed up in my testing).
The patch below fixes this by replacing the assert!(ep_num < ep_count) with a test which skips the packet rather than panic-ing.
I suspect that there is a more fundamental issue here but but this does at least fix the panic! issue.
The text was updated successfully, but these errors were encountered: