-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
RP2: Pico W hangs shortly after start of main.py when connected to USB host #8904
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 see this same issue with Ubuntu, albeit it requires a more complicated The above code seems to work fine for me, but if I run any code that does something useful then it seems to lock up on reset and dmesg shows me:
If I connect this same board running the same, failing, code to a dumb microUSB power supply it works 100% of the time. If I run the same code via Thonny it also works 100% of the time. I had dismissed this as a bad USB cable or voltage drop, but testing with multiple boards and USB cables gets the same result. |
I tested the proof of concept script with the latest v1.19.1-129-g5bf376563 (2022-07-13).uf2 on a M1 Macbook Pro with OS X 11.6.6 and the Pico W locked up 17 times out of 20 resets. On the 3 successful tries it seems to keep running long-term with no issues and the board shows up in the USB System Information list correctly. |
@Gadgetoid can you share your main.py please? I see this on my M1 Mac and we also see it on an Intel Mac. |
So from internal testing, it looks like the wireless firmware is being loaded during USB device enumeration. We're seeing problems primarily on Apple hardware as it looks like the Mac is being a bit fussier about timings than other platforms. Since the wireless stack is loaded on demand, adding a few seconds of delay before pulling it in — in this case to talk to the LED via the 43439 — means it all "just works",
this isn't a solution, but at least we (think) we know what's going on. |
Does |
No, import network doesn't load the wifi stack. It looks like it might be firmware loading being slow and taking time from the usb stack. I can't repro the problem on ubuntu so can't say if it will fix your problem. |
@Gadgetoid can you share your main.py please so we can try and replicate on Ubuntu. I've also tried and can't get it to fall over. |
I don't have a minimal test case, the full blown example code I had encountered as failing on Ubuntu was tied to our baked-in libraries. I'll see if I can pare it back. |
Loading the wifi firmware can cause delays on startup which causes problems for USB. Add some hooks so we can allow background processes to run. See micropython/micropython#8904 and note that a change will be needed in micropython and pico-sdk to define the hook. Fixes georgerobotics#11
This should allow USB to work while we're loading firmware Requires: georgerobotics/cyw43-driver#12 Fixes: micropython#8904
I don't suppose anyone could test these two changes? You'll have to build the code yourself. I don't have one of these mac things to test at the moment. |
I have access to one. Will test today. Thanks for the quick fix @peterharperuk ! |
Some experimentation suggests that what I'm seeing might be a different but related issue, where USB, Network and our own libraries are contesting for (outside of gc_heap) RAM. I can't reproduce with any kind of reliability, but I definitely manage to break things if I get beyond a certain complexity. I think the extra RAM pressure is the culprit in my cases, but I will test the fixes nonetheless. |
Loading the wifi firmware can cause delays on startup which causes problems for USB. Add some hooks so we can allow background processes to run. See micropython/micropython#8904 and note that a change will be needed in micropython and pico-sdk to define the hook. Fixes georgerobotics#11
For @lowfatcode @nkotilainen - upstream with these patches compiled in. |
The .uf2 in the above .zip seems to be corrupted, but I supplied a fresh build to @nkotilainen and he reports 10/10 success rate. I didn't want to muddy the waters here, but my own tests built with our modules seemed to be more stable, too. Hopefully this build will work, should anyone wish to test it but not have the time to compile from source: |
I had a PicoW with what looks to be this issue, and something in my application was triggering it, just tried with @Gadgetoid's fix above and it seems to be happy now. Thanks, hopefully that patch can get merged in ASAP |
Loading the WiFi firmware can cause delays on startup which causes problems for tasks like USB that must be executed periodically. Add some hooks to allow such background processes to run. See micropython/micropython#8904. Fixes issue #11.
Works great, not only the sample code above but also with my code mentioned here Looks like a good fix to me. |
This should allow USB to work while we're loading firmware Requires: georgerobotics/cyw43-driver#12 Fixes: micropython#8904
This should allow USB to work while we're loading firmware Requires: georgerobotics/cyw43-driver#12 Fixes: micropython#8904
This should allow USB to work while we're loading WiFi firmware. Fixes issue #8904.
Should be fixed by 33d6994 |
Can someone confirm if this build fixes the issue? https://micropython.org/resources/firmware/rp2-pico-w-20220725-unstable-v1.19.1-209-g0c45a28d2.uf2 |
@peterharperuk yes, it should. @dpgeorge merged this at rev 33d6994 which was (two commits) before that build at 0c45a28. See the commit history on master for more details. |
I'd like someone to test it. |
I am sorry to inform that this build ( Edit/Addition: # https://gist.github.com/aallan/3d45a062f26bc425b22a17ec9c81e3b6
import network
import socket
import time
from machine import Pin
import uasyncio as asyncio
led = Pin(15, Pin.OUT)
onboard = Pin("LED", Pin.OUT, value=0)
ssid = 'ssid'
password = 'password'
html = """<!DOCTYPE html>
<html>
<head> <title>Pico W</title> </head>
<body> <h1>Pico W</h1>
<p>%s</p>
</body>
</html>
"""
wlan = network.WLAN(network.STA_IF)
def connect_to_network():
wlan.active(True)
wlan.config(pm = 0xa11140) # Disable power-save mode
wlan.connect(ssid, password)
max_wait = 10
while max_wait > 0:
if wlan.status() < 0 or wlan.status() >= 3:
break
max_wait -= 1
print('waiting for connection...')
onboard.on()
time.sleep(.1)
onboard.off()
time.sleep(1)
if wlan.status() != 3:
raise RuntimeError('network connection failed')
else:
print('connected')
status = wlan.ifconfig()
print('ip = ' + status[0])
async def serve_client(reader, writer):
print("Client connected")
request_line = await reader.readline()
print("Request:", request_line)
# We are not interested in HTTP request headers, skip them
while await reader.readline() != b"\r\n":
pass
request = str(request_line)
led_on = request.find('/light/on')
led_off = request.find('/light/off')
print( 'led on = ' + str(led_on))
print( 'led off = ' + str(led_off))
stateis = ""
if led_on == 6:
print("led on")
led.value(1)
stateis = "LED is ON"
if led_off == 6:
print("led off")
led.value(0)
stateis = "LED is OFF"
response = html % stateis
writer.write('HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n')
writer.write(response)
await writer.drain()
await writer.wait_closed()
print("Client disconnected")
async def main():
print('Connecting to Network...')
connect_to_network()
print('Setting up webserver...')
asyncio.create_task(asyncio.start_server(serve_client, "0.0.0.0", 80))
while True:
print("heartbeat")
onboard.on()
await asyncio.sleep(0.1)
onboard.off()
await asyncio.sleep(0.2)
onboard.on()
await asyncio.sleep(0.1)
onboard.off()
await asyncio.sleep(5)
try:
asyncio.run(main())
finally:
asyncio.new_event_loop() |
ok - I have access to a mac now and I can repro your issue. |
To avoid confusion (maybe) I raised a new issue #8963 |
@SebasZH Can you test the latest nightly? I tested your script on a mac and it worked. https://micropython.org/resources/firmware/rp2-pico-w-20220727-unstable-v1.19.1-216-g45ab801c3.uf2 |
@peterharperuk I can confirm the webserver script now works on MacOS. Thanks! |
This should allow USB to work while we're loading WiFi firmware. Fixes issue micropython#8904.
This should allow USB to work while we're loading WiFi firmware. Fixes issue micropython#8904.
We had reports on our repo that users were having issues with their Pico W locking up: pimoroni/pimoroni-pico#392
I can recreate this issue (using an M1 Macbook Air) with a very simple script:
If that is saved as
main.py
then when the Pico starts up it will run for perhaps 20-30 iterations of the loop and then lock up hard every single time. Weirdly if I remotely execute the script using thempremote
tool then it runs flawlessly every time.rp2-pico-w-20220712-unstable-v1.19.1-127-g74794d42b.uf2
) and also our build (pimoroni-picow-v1.19.2-micropython.uf2
)I'm pretty sure something is causing the USB stack to fall over on the Pico W which is then causing it to hang completely.
The text was updated successfully, but these errors were encountered: