-
Notifications
You must be signed in to change notification settings - Fork 946
USB CDC not flashing RP2040 reliably #3012
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
Comments
(I have reproduced this issue on a vanilla Pico) |
Thanks @sago35 - I've just tried that PR. It's not helping with my scenario unfortunately. |
It might be related to that errata. I've been having the rp2040 boards plugged into a USB hub with some other devices. Using a USB port directly on my PC it's a lot more reliable. |
#2991 code may not be well implemented yet. |
Perhaps related to same issue as micropython/micropython#8904 |
tinygo flash failed when USB-CDC exchange was executed from another microcontroller with the same USB-HUB. #2991 source will allow successful USB Enumeration. However, USB enumeration of rp2040-bootloader almost always fails after portReset. my feather-rp2040:
|
This is a dmesg from my system...
That sequence is:
|
The INFO.txt for my pico is as follows
|
The Challenger RP2040 (the dmesg above is from this board):
|
I've put some simple println debug lines in the interrupt handler that are being pushed to ( Here's one observation (not sure if useful). When I use the 'serial' example the trace output from a hard reset (button) is:
I.e. the main app isn't sending any output until USB is initialized. After flashing with TinyGo, the
I'll keep digging to see if any other differences pop up |
I've confirmed by looking at the chip - the RP2040 I have on the board is a B2, so should already have the hardware fix. At least as far as my case goes, I don't think it's related to the Errata as such - it's something more subtle... Maybe something not being fully reset after flashing or a clock / timing subtlety. |
I've found a hacky solution - by forcing a delay into USBDevice.Configure flashing is working reliably. I've also added a USB device block reset, per the examples. The delay appears to be the thing that matters. Now, why this works, I've no idea...
The definition of hardSleep is:
|
I mistakenly thought that resetBlock was running. https://github.com/tinygo-org/tinygo/blob/dev/src/machine/machine_rp2040.go#L58-L64 It needs to be added. resetBlock(rp.RESETS_RESET_USBCTRL)
unresetBlockWait(rp.RESETS_RESET_USBCTRL)
So you don't know why, but it improves. |
I can get down to 700ms delay and it works, at 600ms it doesn't work. I've abused a USB cable to hook up my logic analyzer. I'm going to see if that can shed any light on what's happening between the hub and the board. |
I think I may be hitting some kind of 'design choice' (bug?) in my USB hub. The only factor that seems to make a difference between success and failure is how long the USB DP pin is 'floating' (pulled down by Hub, indicating no device connected) and 'high' (pulled up by device, indicating high-speed device present). This is in effect what my delay loop is causing - extending the period the USB DP pin is floating. This is a table of me trying various values for the delay in USB initialization, triggered by different scenarios. 'Soft Reset' is when the boot ROM triggers the reset after flashing the UF2.
Bizarrely, the longer the DP line is floating, the longer it takes for the hub/host to issue a USB reset and query the device descriptor. I'm not sure why that is. I don't think there's any specification for how long the DP line should be left floating (or even, to be honest if this is the real root cause), or that it's even necessary. However, we don't have the option of leaving the DP line high because the boot rom lets it float... The boot rom appears to trigger a watchdog reboot that resets the USB controller (causing the DP line to float in the first place): |
(removed - was a red herring caused by debug logic) |
After much head-scratching, I think i finally found the issue :) |
It seems like
tinygo flash
only works immediately after a hardware reset and not after a soft reset.OS:
TinyGo:
tinygo version 0.25.0-dev-3047d8f3 linux/amd64 (using go version go1.18.3 and LLVM version 14.0.0)
Connections:
Scenario:
/dev/ttyACM0
present)tinygo flash -target challenger-rp2040 ./src/examples/serial/
(observe flash succeeds)tinygo flash -target challenger-rp2040 ./src/examples/serial/
(observe errorerror: unable to locate a serial port
)The text was updated successfully, but these errors were encountered: