Random crashes, infinite loops, and other lockups were happening to the PicoW
while under high load from multiple clients.
This seems to have been due to two issues:
* The periodic sys_check_timeouts() call from an alarm/IRQ was happening while
the core was in LWIP code. LWIP is not re-entrant or multi-core/thread safe
so this is a bad thing. Some calls may not have been locked with a manual
addition of the LWIPMutex object to hit this.
* The WiFi driver supplies packet data during an interrupt. PBUF work is
legal in an interrupt, but actually calling netif->input() from an IRQ to
queue up the Ethernet packet for processing is illegal if LWIP is already
in progress.
Rearchitect the LWIP interface to fix these problems:
* Disable interrupts during malloc/etc. to avoid the possibility of the
periodic LWIP timeout check interrupting and potentially calling user
code which did a memory operation
* Wrap all used LWIP calls to note LWIP code will be executing, instead of
manually eyeballing and adding in protection in user code.
* Remove all user code LWIPMutex blocking, the wrapping takes care of it.
* When an Ethernet packet is received by interrupt and we're in LWIP code,
just throw the packet away for now. The upper layers can handle retransmit.
(A possible optimization would be to set the packet aside and add a
housekeeping portion to the LWIP wrappers to netif->input() them when safe).
* Ignore callbacks during TCP connection teardown when the ClientContext
passed from LWIP == nullptr
Fixes#795
Replace all CoreMutex and Newlib mutex accesses with FreeRTOS calls
when in FreeRTOS mode. Avoid issues with hange/etc. due to priority
inversion.
No changes to normal operating mode.
Add a FreeRTOS stress test that caught the issue fixed here.
FreeRTOS SMP was updated to:
a) Move ths SYSTICK handler, which cannot be disabled and can fire
even with IRQs disabled, to RAM
b) Add a flag from the core to the SYSTICK handler to hold off on
any PendSV (task switch) calls while we are doing the idleOtherCore.
The core now sets this flag, _holdPendSV, and adds add'l FreeRTOS SMP
calls to really, really tell the OS we can't, don't, and better not
be swapped out while writing to flash.
Fixes#719
* Add support for the WiFi chip on the Pico W board.
* USB interrupt now no longer hard coded (conflicted with the WiFi IRQ).
* Add in Pico W board to makeboards.py
* Add in GPIO and variant support
* Initialize WiFi in the Variant
* Use manual LWIP, fix size accounting
* Remove the SDK WiFi overrides
* Pulling in work done in the ESP8266 core.
* Make IPAddress support IPv6
* Build LWIP with IPv4 and IPv6 support
* Use proper MAC
* Avoid cyw_warn crash. Make macro to a comment while building
* Add WiFiServer
* Add WiFiUdp
* Move LWIP-specific support files to LWIP_Ethernet
* Add WiFi::ping (ICMP ping)
* Move ICMP echo (ping) to LWIPIntfDev
* Move hostByName to LwipIntfDev
* Add AP mode with simple DHCP server
* Add some examples and basic ESP8266 compat hacks
* Update Adafruit TinyUSB to fix crash
* Set DHCP hostname
* Make Wifi.begin() return CONNECTED with link + IP
* Return connected() on WiFi::begin
* Fix spurious TCP retransmission
* Protect LWIP from reentrancy
The Pico SDK calls "sys_check_timeouts() from inside a periodic interrupt.
This appears unsafe, as the interrupt could happen while already in the
(non-reentrant) LWIP code.
Block the interrupt from calling sys_check_timeouts by using a global flag
manually set via an RAII recursive lock.
Add interrupt protection macros around critical sections inside LWIP via
the standard defines.
These two changes should make LWIP significantly more stable and long
running.
* Support disconnecting and reconnecting WiFi
* Add WiFiServer simple example
* Update documentation
Fixes#666Fixed#665
No idea why, but when a Picoprobe upload and reset is used, the 2nd core
does not start w/o a __wfe() call on the first one before launch.
Fixes#674Fixes#402
Instead of wrapping the memory functions in the link stage, rebuild
Newlib and enable retargetable locks. Override the weak definitions
in the libc.a with our own, SDK based ones.
The wrapping utilized before catches app-level memory allocations
but misses allocations inside Newlib libc (like printf/etc.).
Each core needs its own _impure_ptr or else crashes like the one seen
in parallel printf_floats can happen. Enable it in the toolchain
build and implement a simple swapper here.
FreeRTOS SMP doesn't support Newlib's dynamic reent which is needed
to allow save MT support. Minor patch to FreeRTOS and update the
FreeRTOS variant.cpp and setup to support it.
Using all the work from @hfellner and others, add FreeRTOS
SMP support.
Allow idling cores through the FreeRTOS FIFO queue to
allow for file system and EEPROM support.
Make delay a weak function so FreeRTOS can override.
Add cycle count support under FreeRTOS using a PIO SM.
Use a task-based approach for handling the USB periodic work
instead of the IRQ-based one in the main core.
Set 8 prio levels so it fits in 3 bits nicely (0..7).
* initial tinyusb lib port
* add Adafruit_TinyUSB_Arduino as submodules
* add yield() to main loop
* sync with tinyusb lib latest
* add USB manufacturer and product
* fix typo in tinyusb lib
* sync with master
updating implementation
* Rationalize link stage command line
Make the build process less insane.
* clean up delay
* clean up platform and board
* update makeboards.py for generating usbstack menu
* update tinyusb lib to 1.0.0
Older builds included C++ locale information in RAM/flash as well as a
bunch of exception code which can't get called since they're not enabled.
Remove them by adjusting final link command and not instantiating them
in main.cpp in the first place.
Blink went from:
> Sketch uses 215604 bytes (10%) of program storage space. Maximum is 2093056 bytes.
> Global variables use 18152 bytes (6%) of dynamic memory, leaving 243992 bytes for local variables. Maximum is 262144 bytes.
To:
> Sketch uses 56112 bytes (5%) of program storage space. Maximum is 1044480 bytes.
> Global variables use 12152 bytes (4%) of dynamic memory, leaving 249992 bytes for local variables. Maximum is 262144 bytes.
For a savings of **155KB of flash** and **6KB of RAM**
BOOTSEL needs to be multicore protected, too.
Reading BOOTSEL required disabling the flash interface, so the other
core needs to be idles while this runs.
Make the PIO program object multicore safe, too, so that if both cores
try to load a program they won't step on each other.
Update pico-sdk to 1.1.2
Add methods to block the opposite core while doing flash updates.
Ensure opposite core is stopped in LittleFS and EEPROM while doing
flash updates.
Update documentation with new calls.
Support running code on the second core by adding a setup1() and/or
a loop1() routine to a sketch. These functions operate exactly like
the normal Arduino ones, and anything they call will be run on
the second core automatically.
Add a simple multicore example.
Add support for Adafruit Feather RP2040 (8MB). Identified with a unique
USB PID so it displays properly once programmed one time. Moved LED to
pin 13 (per the website docs), but have no board to test.
Add over/underclocking menus, applied at boot. Use at your own risk, as
usual.
Add shims to allocate flash space for a filesystem (but not implemented
yet).
Add a "generic" RP2040 board
Allow ::print() to go to a serial port instead of dropping.
Will allow for full VFS/etc. with standard FILE semantics, or at least
::putc and ::getc on STDOUT/STDERR to work.
Add smarts to the UF2 uploader to potentially trigger a reboot if the
device passed in is /dev/tty* or COM*. Will cause reboot to USB
bootloader and standard UF2 upload will happen w/o any user
intervention.
Some paths hardcoded to my custom toolchain build dir, will be updated
to a package.json tools setup soon.
https://github.com/earlephilhower/pico-quick-toolchain
Blink and Fade examples work (i.e. digitalWrite/analogWrite/delay).
Includes a discovery script which will detect RPI Picos in UF2 bootmode.