earlephilhower / arduino-pico

Raspberry Pi Pico Arduino core, for all RP2040 boards
GNU Lesser General Public License v2.1
1.92k stars 402 forks source link

Question: What limits lwip usage within a FreeRTOS environment to setup/loop and not tasks? #2151

Closed spiderkeys closed 3 months ago

spiderkeys commented 3 months ago

I was wondering if I could get a bit of clarification/context on the following lines in the Pico core's documentation:

WiFi docs:

Multicore is supported, but only core 0 may run WiFi related code. FreeRTOS is supported only on core 0 and from within setup and ``loop`, not tasks, due to the requirement for a very different LWIP implementation. PRs always appreciated!

Ethernet Docs:

The same restrictions for WiFi apply to these Ethernet classes, namely: Only core 0 may run any networking related code. In FreeRTOS, only the setup and loop task can call networking libraries, not any tasks.

I can understand why networking code might need to be restricted to a single core, but I am not clear on why networking code can not be called within a FreeRTOS task other than the one that calls setup/loop.

I've been looking at how the zenoh-pico middleware library works with the ESP32 Arduino core, and they seem to be able to make calls to lwip functions from within additional FreeRTOS tasks (pinned to core 0). I was wondering if I could get zenoh-pico working on the rp2040, but the limitation as written suggests that zenoh's background network tasks (read and lease tasks, which you normally create in setup() and call lwip's socket functions) would be in violation of this constraint.

Any background or clarifications are appreciated - I might be reading this entirely wrong!