-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rp2: Use local tinyusb submodule rather than pico-sdk one #6835
Conversation
We're on https://github.com/hathach/tinyusb/tree/045674745afa59028fbeed6dac5cb5a9c4a6033e and haven't heard of any issues across our ports. |
The error is
so I guess you need to tweak the include flags passed to the rp2 port? |
I had that error too initially. You have to update the submodules for tinyusb and pico-sdk with the --recursive flag. |
I've had bad experiences with recursively updating submodules - it seems to pull in much more than you actually need and just generally slows things down. IMHO in this case it's better to be explicit (choose which specific submodules to update) than implicit (recursively updating all submodules)! |
Looks like I was a bit too hasty with my reply last night (oops) - the include flags are of course managed by CMake. Looking again at the build log, the actual cause of the error is actually displayed slightly earlier:
I'm afraid I dunno enough about CMake and/or the MicroPython build environment to suggest a suitable fix. But I can confirm that a local build of
|
45bc349
to
e796a42
Compare
Actually all it needed was for the CI environment to check out tinyusb! |
I've now updated all the ports that use tinyusb (nrf, samd, mimxrt) to build with this new version. |
The problem is, these other ports don't work reliably with tinyusb and updating tinyusb seems to make it worse (at least for mimxrt). These other ports call |
@hathach can you please confirm if this is indeed the case, that we must call |
Thach is taking vacation this week for the Chinese New Year I believe.
In cp we’ve always called tud_task from the main task. Generally the usb interrupt handler queues events into the fifo so they are processed on the main task.
Calling tud_task from the irq could cause issues if the task takes a while and the interrupt causes events to be missed and not queued up.
…On Mon, Feb 8, 2021, at 9:26 PM, Damien George wrote:
> These other ports call `tud_task()` from IRQ context which is apparently not allowed within tinyusb's execution model
@hathach <https://github.com/hathach> can you please confirm if this is indeed the case, that we must call `tud_task()` from a thread (top level) execution context, ie never from within the USB IRQ handler? What are the constraints around calling `tud_task()`?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub <#6835 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAAM3KPDK4HBYXQAFJWHZ43S6DBRLANCNFSM4XAGTBGQ>.
|
Yeah, you should not call Sum up please call tud_int_handler() in ISR and tud_task() in main/background |
Thank Scott, today is my last working day before the holiday, though I probably still be around whenever I could :) |
It may be much better, but is it absolutely necessary to call
Does it matter if there is a large latency within the USB IRQ handler? As long as the USB IRQ is low priority (but still higher than thread context) it shouldn't matter, the hardware should block any IRQs from coming in until the handler is done. On stm32 (where we use ST's USB device driver) we process all USB code within USB IRQs, including MSC operations that call disk IO. This has never been a problem. The latency in the IRQ is actually good because it introduces flow control with the host PC (the PC's USB is blocked until the MSC operation completes, for example). From another point of view, what if the |
No, it isn't absolutely necessary, at least I cannot think of any reasons, though I haven't tested it invoked with ISR context. So I may miss something. Could you tell what is the reliability issue you are dealing with and how to reproduce it, I will try to analyze to see what is the underlying issue.
Yeah, I guess it depends on design choice and execution. Some RTOS like FreeRTOS does not like to run on ISR context, they have separated API for thread and ISR. But since MP doesn't use RTOS, it may not be an issue.
|
Ok, thanks for the reply. I will do some more investigation on this.
I don't have a minimal reproduction of the problem. But you can just build the mimxrt port and run it against the test suite, on a Teensy 4.0:
That last line will run the test suite, and usually locks up the device part way through. |
thank you for your instruction, I am able to reproduce the issue, with imxrt, REPL doesn't seem to work much at all. I will try my best to look at the issue and post the update here. |
Update: I couldn't do much of debugging since somehow the imxrt board manage to cause my PC (ubuntu) to disable all usb port when testing the issue. I will spend more time on this later on. Though I have an theory why it could cause the issue.
To be honest, I am not sure if IRQ will be triggered again or not (may depend on MCU), and not sure why it isn't a issue before this PR. But is is quite possible. I will try to have a better test setup with better analysis during/after the Lunar New Year (aka TET). |
Copy-paste two comments, edited slightly, from #6866: We had a similar-sounding problem [to #6866] in CircuitPython recently. Copying multiple large files to the MSC drive would stall, then there would be a 30-second timeout, and USB would re-enumerate. The problem did not occur if there was a CDC REPL connection open to the board, even if there was no activity on that connection. The problem was that In CircuitPython 5.x and before, we used to schedule a call to We subsequently revised the mechanism so that not every background task was called when 1ms had passed. Instead the tasks are enqueued when there is work to do. We no longer have a 1ms tick scheduling the overall set of background task. We still use |
I tried to fix mimxrt and samd USB behaviour (with the older tinyusb, not this PR) but ran in to other issues (like the fact that i.mx SysTick cannot wake the CPU from WFI). So I propose to just merge this PR to get the latest tinyusb for all ports, then move on to fix things from there. |
Yeah, systick behaves the same with nrf as well and Nordic advises user to use rtc1 as tick timer instead for low power. My guess is that systick run on cpu clock which got suspended by wfi/wfe, this may (or not) be true for many of arm coterx-m. |
Includes support for RP2040. Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Damien George <damien@micropython.org>
So that all MicroPython ports that use tinyusb use the same version. Also requires fewer submodule checkouts when building rp2 along with other ports that use tinyusb. Signed-off-by: Damien George <damien@micropython.org>
e796a42
to
c9260dd
Compare
So that all MicroPython ports that use tinyusb use the same version. Also requires fewer submodule checkouts when building rp2 along with other ports that use tinyusb.
TODO: check that other ports using tinyusb still work with this version.