web server and _thread not working #12843
-
Hi Group, I use Micropython v1.21.0 on RP2040 with simple code:
it is almost ok, expect that after 2nd connection to RP2040 it no longer accept connections and stops responding to ping. There is no crash on RP2040 and it seems program is still running awaiting on connections, but nothing happens. try section does not trigger as there is no connection error, it simply does not even start. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 9 replies
-
Your code looks like it should work, so this makes me think there must be a bug with the network stack running on the second core. Does it work if you run the web server on the main thread, and do your other work on the second thread? |
Beta Was this translation helpful? Give feedback.
-
Hi, Thanks for looking into this.
then it works correctly. If i create just a test function that holds loop with some simple math and print then thread works.
There is an issue with network support. Network works just in 1 loop run. Ping of the RP2040 before connecting to port 80 works, after connection to port 80 no longer works. It looks like network stack stop working correctly and i have no clue how to debug this. If i put web server within thread then it stops working after 1 loop run, so i stared with something simple like above to see where is the issue. I need 1 thread that will either run web server or will send data. Since sending data function is simpler i prefer to put that one in the thread. But if i do this:
then i get:
and Error reffers to line with: s.connect(("10.254.7.6", 10051)) if i do:
then all is perfect:
|
Beta Was this translation helpful? Give feedback.
-
It is: RP2040 Datasheet, pages 9–10, “Why is the chip called RP2040?”:
There are two M0+ cores sharing memory, but there's no explicit thread management in the hardware. MicroPython expects the user to manage memory between threads on RP2040. There is no OS to manage it. Don't bring IRQs into it, please — they mean something else in MicroPython. The Threads · micropython/micropython Wiki maybe be of help. My previous |
Beta Was this translation helpful? Give feedback.
Yes, both processors (i.e. both ARM cortex M0+ cores) have full access to the hardware. They are symmetric. Still in Micropython the network and interrupt stuff is by standard only fully established (and tested) on Proc0 (i.e core 0).
By programming in C you would have to control all inter-processor task assignment and scheduling by yourself.
I'm not an expert. So I don't know what kind of libraries are there that might help you.
On the other hand, my impression (as non-expert) is that the solution of the MP threading problems is just a time consuming task of tracing many subtle details that are involved in the current partly unsatisfactory state: threading works, but interrupts function …