Open shuanglengyunji opened 10 months ago
Update:
I found a walk-around: add sleep between spawner.spawn(usb_task(usb))
and spawner.spawn(usb_ncm_task(runner))
will make it work on ubuntu 22.04.
// Build the builder.
let usb = builder.build();
unwrap!(spawner.spawn(usb_task(usb)));
Timer::after_millis(1000).await; <====== ADD SLEEP HERE
static NET_STATE: StaticCell<NetState<MTU, 4, 4>> = StaticCell::new();
let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(NET_STATE.init(NetState::new()), our_mac_addr);
unwrap!(spawner.spawn(usb_ncm_task(runner)));
In debugging it, I found the usb_ncm_task(runner)
has been scheduled before usb_task(usb)
on stm32f407 by the scheduler, although the usb_task
is spawned before the usb_ncm_task
. Adding a sleep before usb_ncm_task
will ensure the usb_task
to be executed first, and it seems to address the problem. However, I still don't understand the root cause of the problem.
Thanks @shuanglengyunji - can confirm the workaround fixes usb_ethernet on stm32h753zi as well :+1:
I have run into the same issue on the STM32F429ZI, and for me a sleep of 1s was not sufficient, but 3s did the trick. I assume the difference might be that I'm running my Linux in a VMware VM, so what often happens is:
In the embassy_usb::class::cdc_ncm::embassy_net
trace, this is visible as a quick succession of "WAITING for connection" - "Connected" - "WAITING for connection". The second time cdc_ncm::wait_connection()
is run, self.read_ep.wait_enabled()
and self.comm_ep.wait_enabled()
finish successfully, but self.comm_ep.write(&buf)
hangs forever.
The same issue also occurs when I disconnect and reconnect the USB interface physically, and there is no place where I could add a sleep to work around this.
Some other observations I've made:
The hanging comm_ep.write()
outputs the following tracing messages:
TRACE write ep=EndpointAddress(129) data=[161, 0, 1, 0, 1, 0, 0, 0]
└─ embassy_usb_synopsys_otg::{impl#16}::write::{async_fn#0} @ /home/schifferm/Devel/rtos/embassy/embassy-usb-synopsys-otg/src/lib.rs:1129
TRACE write ep=EndpointAddress(129): diepctl 804c8008 ftxfsts 00000010
└─ embassy_usb_synopsys_otg::{impl#16}::write::{async_fn#0}::{closure#0} @ /home/schifferm/Devel/rtos/embassy/embassy-usb-synopsys-otg/src/lib.rs:1142
After returning Poll::Pending
, the future is never woken again.
embassy_usb_synopsys_otg::on_interrupt
a few times before this happensI assume something is going wrong with the setup sequence if the USB connection is reset while the setup is happening, but I don't know enough about the USB controller (or USB in general) to debug this much further.
Update: comm_ep.write()
is hanging because the EPENA flag is never cleared (probably because the previous transfer got interrupted?).
I run the stm32f4/usb_ethernet example on a stm32f4discovery board with static ip. It works on an iPhone 15 runs IOS17, while doesn't work on ubuntu 22.04 running on DELL Precision 15. On the ubuntu 22.04, I manually configured IP address on the ubuntu, while it shows:
I have also tried:
It works on the iPhone. I had also made it similar implementation work on this board with TinyUSB RNDIS driver. Could someone please give me some direction on debugging it?
On the device log, it shows USB goes into suspend mode on its own:
Thank you all