Commit graph

34 commits

Author SHA1 Message Date
Earle F. Philhower, III
e25d382732
Support WiFi/BT/BLT with RP2350 CYW43 boards (#2616)
Using pico-sdk develop branch, add in support for CYW43-based
WiFi/BT/BLE boards on the RP2350 such as the
SparkFun Thing Plus RP2350 or the Pimoroni Pico Plus 2W.

Fixes #2608

Rolls in dynamic SPI divider #2600

* Support LED digitalWrite on RP2350+CYW

Also move "special GPIO" to 64 since the Pimoroni Pico 2W uses the
RP2350B with 48 GPIOs.

* Enable CYW43_PIN_WL_DYNAMIC in IDE and P.IO

Allows calling `cyw43_set_pins_wl(cyw43_pin_array);` to redefine the
CYW43 hookup in the variant initialization.
2024-11-19 10:28:12 -08:00
Kjell Braden
7a0adfebd1
lwIP_Ethernet: rename copied cyw43 mac function (#2604)
Prevent symbol conflicts when including both Wifi.h and cyw43.h

Fixes #2602
2024-11-13 03:35:26 -08:00
Earle F. Philhower, III
f5c4136b94
Add SimpleMDNS, IGMP, and .local lookup (#2582)
* Enable LWIP IGMP, MDNS internal server
* Enable MDNS lookup from LWIP DNS
* Add SimpleMDNS responder, small code and no malloc
* Ensure we copy out lwipopts in make-libpico

Adds a small wrapper around the LWIP-provided MDNS responder application.
Drop-in replacement in many basic cases for LEAmDNS.

For FreeRTOS it is important to not allocate memory on an LWIP callback.
LEAmDNS needs to do this to create response objects, leading to crashes.

Increase LWIP timers by bumping the LWIP_ARP number (as done before).

Replace ArduinoOTA LEAmDNS with SimpleMDNS and update a
HTTPUpdateServer example.
2024-11-07 10:09:44 -08:00
Earle F. Philhower, III
5f6e4aff5c
Allow LWIP Ethernet HW IRQs > 32 (#2464)
Allow RP2350B boards to use GPIOs 31+ for the Ethernet HW IRQ line.
Also update SPI debug output with the new registers.
2024-09-16 12:35:46 -07:00
Earle F. Philhower, III
33694a1fcc
Add RP2350 support, new boards (#2337)
* Migrate RP2040-specific bits to separate dirs
* Add chip to boards.txt, isolate RP2040-specifics
* Add RP2350 boot2, bearssl, and libraries
* Platform.IO adjust to new paths
* Add RPIPICO2 JSON for P.IO
* Add RP2350 to Platform.io
* Update Picotool and OpenOCD for all hosts
* Use picotool to generate UF2s
* Build separate libpico blobs serially
Thanks for the review, @aarturo182 !
* Add RP2350 to CI
* Allow Ethernet/WiFi building for RP2350
* Update Adafruit TinyUSB to latest
* Test skip fix
* Make RP2350 Picotool work. update USB ID
* Fix EEPROM/FS flash locations
RP2350 adds a 4K header sector to the UF2, meaning we have 4K less total
flash to work with.  Adjust all constants appropriately on the RP2350.
* Adds ilabs board and PSRAM support. (#2342)
* Adds iLabs boards and basic PSRAM support.
* Make PSRAM come up as part of chip init
Uses SparkFun psram.cpp to set timings on clocks which are defined in the
variant file.  Prefix things with RP2350_PSRAM_xxx for sanity.
Users don't need to call anything, PSRAM "just appears".  Still need to
add in malloc-type allocation.
* Add board SparkFun ProMicro RP2350
Same pinout as the SparkFun ProMicro RP2040 with 8MB PSRAM and RP2350
* Add TLSF library for use w/PSRAM
Fork of upstream to include add'l C++ warning fixes.
* Add pmalloc/pcalloc to use PSRAM memory
free() and realloc() all look at the pointer passed in and jump to the
appropriate handler.  Also takes care of stopping IRQs and taking the
malloc mutex to support multicore and FreeRTOS (when that workd)
* Fix BOOTSEL for RP2350
* Add simple rp2040.idleOtherCore test
* Add Generic RP2350 and clean up PSRAM menus
Commercial boards now only have 1 size PSRAM, no need to have menu for them.
* Add Solder Party RP2350 Stamp boards (#2352)
* Add PSRAM heap info helpers, mutex lock mallinfo
* Add RP2350 docs
* FreeRTOS and OTA unsupported warnings for RP2350
2024-08-25 11:21:46 -07:00
Earle F. Philhower, III
f45db86cc2
Migrate to 2.0.0 SDK (#2336)
* Update to 2.0.0 SDK
* Board type needs to be set before earliest SDK setup
* Platform includes update
* Boot2 files
* Simple compilation issues
* Build and link
* PIO rebuild with version
* Newlib wrapper update
* Force inclusion of runtime_init_* fcns
The linker was dropping all references to the library's included
runtime_init_xxx functions and hence things like the IRQ vector
table and mutexes and alarms weren't properly set up leading to
instant crashes on start up..

Explicitly call out one function from the object file stored in
the .A to force the inclusion of all the functions.  May be a better
way, heppy to hear any ideas.
* Fix SPI GPIO calls
* Fix Ethernet GPIO
* Remove SDK warnings
Remove the skipped error messages once the following PR merged:
https://github.com/raspberrypi/pico-sdk/pull/1786
* BTStack moved SBC encode/decode paths
* Platform.IO fixes
* BT No longer has special absolute mouse
* Rebuild and update OTA
* Rebuild BearSSL, too
* Update liker file to latest SDK
* Clean up libpicocmake
* Clean up LWIP/BT library names
2024-08-17 10:39:13 -07:00
Earle F. Philhower, III
4f4e638aee
Replace most remaining ESP_ debug macros (#2305)
In ported libraries there were still some remaining DEBUG_ESP_PORT
references.  Moved to their RP2040 equivalents.
2024-07-28 09:36:10 -07:00
Earle F. Philhower, III
34f386a21b
LwIpIntfDev.end() check _started to prevent crash (#2304)
From @JAndrassy https://github.com/esp8266/Arduino/pull/9173
2024-07-27 11:46:39 -07:00
Earle F. Philhower, III
d4cdb3ea69
Fix LWIP crash on unexpected ping packets (#2159)
When a ping is sent from the Pico, a raw_recv callback is added which
sees all raw incoming packets to detect the response from the ping target.
If while waiting for the target response an external ping packet arrives
this incoming ping request packet will be processed by the
LwipIntfDev<>::_pingCB which will return "0" not processed and which
*should* not change the payload unless it handles the actual packet.

Unfortunately, the 20 byte header was unconditionally stripped off of
the packet before checking if this was our response, changing the
payload address and causing an assertion in LWIP.

Fix by using absolute offsets inside the raw packet for the ping
response checks.

Fixes #2156
Fixes #2149
2024-05-14 17:37:54 -07:00
Earle F. Philhower, III
016bf80e3b
Protect againt calling LWIP_Ethernet::begin twice (#2158)
As seen in debug of #2149, if the LwipIntfDev is already _started,
return false for a ::begin() call.

Also, protect netif_add/_remove on the very small possibilty of being
called by LwipIntfDev devices while the CYW43 driver is doing work.
2024-05-13 19:08:38 -07:00
Juraj Andrássy
8673da2505
Ethernet legacy API compatibility layer (#2147)
With example from the Arduino Ethernet library
2024-05-06 10:06:51 -07:00
Juraj Andrássy
2a256f9c25
LwipIntfDev - linkStatus added (#2081) 2024-03-29 09:14:05 -07:00
Juraj Andrássy
9c94bab290
Add RawDev::interruptMode (#2042) 2024-03-06 11:58:37 -08:00
Earle F. Philhower, III
842ec245ac
Add W5100, W5500, and ECN28J60 interrupt-driven mode (#1986)
No polling needed and massively reduces latency by using the GPIO interrupt to
signal the Pico to read a received packet.  Also drops CPU load when no packets
are incoming.
2024-02-06 14:15:37 -08:00
Earle F. Philhower, III
12702717e3
Undo #1864, fix LWIP offline error (#1979)
Fixes #1973

The periodic LWIP pump/Ethernet packet reader async_context stopped
firing occasionally under high packet loads, causing the LWIP stack
to become unresponsive to any incoming data.

Re-implement the 2-step process for polling (like the CYW43 driver
from the RPI folks does) and undoes #1864 change.
2024-02-01 19:09:09 -08:00
Earle F. Philhower, III
2aa85e3263
Minor LWIPEthernet cleanup (#1906) 2023-12-20 07:49:48 -08:00
Earle F. Philhower, III
269c579846
Remove IPv6 compile warning (#1867) 2023-12-01 12:10:16 -08:00
Juraj Andrássy
91183ca22f
LwipIntfDev - disconnect()/end() should not clear static IP settings (#1866) 2023-12-01 11:53:01 -08:00
Earle F. Philhower, III
971c235e8d
Remove unneeded intermediate async for Ethernet (#1864)
Remove the always pending worker whose job it was to fire another async
worker after a timeout.
2023-12-01 10:50:15 -08:00
Juraj Andrássy
abd3547711
WiFi and Ethernet - config static IP auto gw,mask,dns as in Arduino libs (#1862) 2023-12-01 10:24:11 -08:00
Juraj Andrássy
9181ec055d
LwipIntfDev - hostByName default value for the timeout parameter (#1858)
to have standard version with two parameters
2023-11-30 08:58:15 -08:00
Juraj Andrássy
4f62e0a4ba
LwipIntfDev - added macAddress getter and DNS IP getter and setter (#1856)
and dnsIP(n) getter in WiFiClass too
2023-11-29 13:24:16 -08:00
Earle F. Philhower, III
4625d2c8ab
Avoid memory allocation in Ethernet callbacks (#1815)
std::bind can cause a memory allocation to occur during the periodic
polling interrupt which is a very bad thing.  Use a lambda instead.

Fixes #1812
2023-11-14 10:01:06 -08:00
Dom
7e8fcc5afa
Allow Ethernet devices on SPI1 (#1725)
_spiUnit is a reference, and when initialized with SPI, it cannot be changed in the constructor afterwards.
So initialize it in the constructor's declaration.
2023-09-22 11:54:53 -07:00
Earle F. Philhower, III
1f3d5011b2
Support wired network interfaces (W5500, W5100, ENC28J60) (#1703)
Enable use of wired Ethernet modules as first-class LWIP citizens.  All
networking classes like MDNS, WebServer, HTTPClient, WiFiClient, and OTA
can use a wired Ethernet adapter just like built-in WiFi.

Two examples updated to show proper use.

Uses the Async Context support built into the Pico SDK.  When running on the
Pico  it will use the CYW43 async instance.

Uses modified wired Ethernet drivers, thanks Nicholas Humfrey!

Note, the classic, non-LWIP integrated `Ethernet` and related libraries
should still work fine (but not be able to use WebServer/HTTPS/etc.)

Fixes #775
2023-09-14 19:04:39 -07:00
Earle F. Philhower, III
0f437e4db2
Remove leftover debug printf in LWIP_Ethernet (#1572)
See #1161
2023-07-02 13:12:22 -07:00
Earle F. Philhower, III
10090b60a9
Rewrite PicoW LWIP interface for stability (#916)
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
2022-10-15 12:00:35 -07:00
Earle F. Philhower, III
25ceb08f93
Clear LWIP started flag on LWIPIntfDev::end (#905)
When moving between different modes or even WiFi.begin/ends, any setting
of the IPs will fail because the internal flag _started was not cleared.
Clear _started on a ::end call.

Fixes #884
2022-10-09 18:25:24 -07:00
Earle F. Philhower, III
064dd4794f
Minor header/directrory cleanup (#802) 2022-08-27 13:04:57 -07:00
Earle F. Philhower, III
da86a8942b
Add OTA update support (#711)
Adds a 12K OTA stub 3rd stage bootloader, which reads new firmware
from the LittleFS filesystem and flashes on reboot.

By storing the OTA commands in a file in flash, it is possible to
recover from a power failure during OTA programming.  On power
resume, the OTA block will simply re-program from the beginning.

Support cryptographic signed OTA updates, if desired.  Includes
host-side signing logic via openssl.

Add PicoOTA library which encapsulates the file format for
the updater, including CRC32 checking.

Add LEAmDNS support to allow Arduino IDE discovery

Add ArduinoOTA class for IDE uploads

Add MD5Builder class

Add Updater class which supports writing and validating
cryptographically signed binaries from any source (http,
Ethernet, WiFi, Serial, etc.)

Add documentation and readmes.
2022-08-12 00:26:51 -07:00
Earle F. Philhower, III
af2671d8eb
IPv6 initial support from @oddstr13 (#748)
* Apply @oddstr13 multicast patch to cyw43 driver
* Initial work for enabling IPv6
* Allow accessing CYW43 stats when LWIP_SYS_CHECK_MS is not set
* Use cyw43_set_allmulti to allow receiving multicast
* Add tools/libpico/build to gitignore

Co-authored-by: Odd Stråbø <oddstr13@openshell.no>
2022-08-09 18:05:43 -07:00
Earle F. Philhower, III
2397d034e3 Remove SPI init from CYW43 ethernet shim 2022-07-23 14:20:10 -07:00
Earle F. Philhower, III
0e18f0986a
Enable IPv4 or IPv4/IPv6 stacks, Ethernet class (#695)
IPv4-only mode saves 20KB+ of flash memory.

Add some backwards compatibility with the global Arduino Ethernet
class when running in IPv4 only mode.

Fixes #687

* Speed P.IO build by not cloning 2GB of sources
* Document P.IO new option
2022-07-21 11:57:21 -07:00
Earle F. Philhower, III
abf2c586c7
Add Pico W WiFi support (#670)
* 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 #666
Fixed #665
2022-07-15 16:47:53 -07:00