Commit graph

101 commits

Author SHA1 Message Date
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
1e7098c1cb
Add OpenOCD/GDB support for IDE 2.0 (#900)
Add (undocumented) support for the debugger in the IDE 2.0.
2022-10-05 12:19:18 -07:00
Earle F. Philhower, III
36d5cebde6
Remove binary info header, was crashing picotool (#831)
Because OTA has changed the flash map from standard, picotool ends up
crashing or hanging while trying to operate on the current built files.

Remove the binary_info calls and structures completely to avoid any
issue.

Fixes #803
2022-09-02 23:17:03 -07:00
Earle F. Philhower, III
0edba2ee2a
Add WebServer, WebServerSecure, HTTPUpdateServer, HTTPUpdateServerSecure (#791)
* Add HTTP-parser lib to support ESP32 WebServer
* Add WebServer from ESP32.  Only supports HTTP
* Separate HTTP server from the network server
Instead of managing the WiFiServer/WiFiServerSecure in the same object
as the HTTP handling, split them into separate objects.  This lets
HTTP and HTTPS servers work without templates or duplicating code.
The HTTP block just gets a `WiFiClient*` and works with that to only
do HTTP processing, while the upper object handles the appropriate
server and client types.
* Add HTTPS server
* Clean up some THandlerFunction refs
* Refactor into a template-ized WebServer/WebServerSecure
* Add DNSServer examples which need WebServer
* Fix CoreMutex infinite recursion crash
Core could crash while Serial debugging was going on and prints were
happening from LWIP/IRQ land and the main app.
* Add HTTPUpdateServer(Secure)
* Add MIME include, optimize WebServer::send(size,len)
When send()ing a large buffer, the WebServer::send() call would
actually convert that buffer into a String (i.e. duplicate it, and
potential issues with embedded \0s in binary data).
Make a simple override to send(size, len) to allow writing from the
source buffer instead.
* Fix WiFiClient::send(Stream), add FSBrowser example
2022-08-23 15:51:32 -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
bb029cc287
Increase LWIP MEM_SIZE to > TCP_SND_BUF (#731)
The send buffers are set to 8 * MSS = ~11.5K.  MEM_SIZE is now set to
be larger than that, 16K, in order to help avoid having tcp_write fail
with ENOMEM.  The attempt to use a smaller size is still included, which
will allow a tcp_write of up to 16 * 16K = 256K, i.e. all of memory.

Fixes #725
2022-07-29 22:35:37 -07:00
Earle F. Philhower, III
8fd56ada8b
Adjust tcp_write size when memory is tight (#729)
Increases the MEM_SIZE outstanding write buffer to 8K

Allows the ClientContext to attempt to send smaller buffer chunks in the
case where MEM_SIZE won't allow the full tcp_sndbuf() transfer.

Fixes #725
2022-07-29 13:40:03 -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
b88ad3d143
Support original Pico with ROM B0 (#693)
The SDK disabled float/double support for some functions by default on the
original B0 ROMs.  Manually re-enable it.

Fixes #689
2022-07-20 12:07:34 -07:00
Earle F. Philhower, III
c3a580ee89
Add WiFiClientSecure and WifiServerSecure (TLS) support, NTP (#683)
* Add TLS (https) support
* Add NTP server
* Clean up include path, add BearSSL headers
* Allow 2 NTP servers, add ESP8266 compat define
* Add MFLN SSL example, free/used/total heap getters
* Enable stack thunking
* Add tested SSL examples
* Add BSSL_validation demo
* Add Client Certificate example
* Add RP2040 helper docs
* Clean up doc errors, missing doc version info
* Add WiFiClientSecure documentation
* Add NTP docs

Fixes #679
2022-07-18 20:24:11 -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
Earle F. Philhower, III
d954510c9d
Update to latest pico-sdk develop branch (#653)
Fixes #651
2022-06-24 02:19:24 -07:00
Earle F. Philhower, III
7233c39166
Update to latest pico-sdk, allow lock.c->lock.cpp (#646)
Minor change to keep the core all CPP.  Patch just made it into pico-sdk
develop branch allowing recursive mutexes to be auto_init in C++.
Update and rebuild libpico.a.
2022-06-20 11:14:31 -07:00
Earle F. Philhower, III
66eb0613b0
Major multicore fixes Newlib and FreeRTOS (#640)
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.
2022-06-20 07:35:30 -07:00
Earle F. Philhower, III
857f91771f
Update to develop branch of pico-sdk (#636)
The realloc() wrapper was included in the develop branch of pico-sdk, so
use it instead of a local, unreproducible version of the SDK.

Should have no effect on code.
2022-06-17 12:13:01 -07:00
Earle F. Philhower, III
1d6f66f834
Shrink flash and RAM usage even more (#627)
Remove MIDI support from the core's main TinyUSB.  MIDI is still supported
using the Adafruit TinyUSB library, just like before (the core never
did use it).

Compile the Pico-SDK using `-Os`

Remove unneeded warning in UF2 upload

Blink.ino shows a savings of 3.5KB flash and 400 bytes of RAM.

For comparison, with this PR blink.ino reports:
````
Sketch uses 49908 bytes (3%) of program storage space. Maximum is 1568768 bytes.
Global variables use 7024 bytes (2%) of dynamic memory, leaving 255120 bytes for local variables. Maximum is 262144 bytes.
````

As comparison, using the MBED core blink.ino reports:
````
Sketch uses 78882 bytes (0%) of program storage space. Maximum is 16777216 bytes.
Global variables use 42780 bytes (15%) of dynamic memory, leaving 227556 bytes for local variables. Maximum is 270336 bytes.
````

So, with this PR we use **37% less flash** and and **87% less RAM**
for simple sketches.
2022-06-13 11:54:38 -07:00
Earle F. Philhower, III
3fb8cbf39f
Temporary fix for muilticore realloc (#625)
This PR includes a pico-sdk built using the fix in
https://github.com/raspberrypi/pico-sdk/pull/864

To properly fix it requires a new pico-sdk release. but until then I am
building against my own fork of pico-sdk and including the binary.
When 1.3.2 is out (and assuming my PR is approved) I'll update the pico-sdk
link.

Fixes #614
2022-06-12 13:38:02 -07:00
Earle F. Philhower, III
7d5e7f5dda
Remove obsolete include paths from build.inc (#616)
As noted in #615
2022-06-09 15:35:24 -07:00
Earle F. Philhower, III
65d50e4d8b
Upgrade to Pico-SDK 1.3.1 (#588)
Looks like only minor changes to the SDK, should not affect the core.
2022-05-20 11:53:20 -07:00
Earle F. Philhower, III
843630c3c7
Remove unused copy of std C++ library (#443) 2022-01-27 12:16:41 -08:00
Earle F. Philhower, III
ea4c0999d0
Add interpolater include path (#428)
Fixes #427.  The libpico.a build already includes the HW interpolator
sources, but the include was missing from the Arduino path.
2022-01-22 11:30:47 -08:00
Earle F. Philhower, III
7120a1508c
Update to SDK version 1.3.0 (#371) 2021-12-14 18:59:24 -08:00
Earle F. Philhower, III
85990ff51d
Support CMSIS and rename conflicting header file (#362) 2021-12-03 12:49:34 -08:00
Earle F. Philhower, III
1afbbaba63
Add RTC headers to path and pico_utils to link (#353)
Fixes #348

Add the RTC header path in the SDK to the Arduino build path.  Also add
pico_utils to the libpico.a for the datetime_to_str call.

Note that the pico_sdk has a bug in the datetime.h header so you need to
manually bracket the include file as "C":

extern "C" {
    #include "pico/util/datetime.h"
}
2021-11-28 09:00:14 -08:00
Earle F. Philhower, III
adf1c88c27
Fix spelling and update readme. Prep for 1.9.5 (#319) 2021-09-19 13:43:26 -07:00
Dan Halbert
ad905ae992
Build libpico.a with PICO_XOSC_STARTUP_DELAY_MULTIPLIER=64 (#315)
Fixes #312
2021-09-19 13:31:39 -07:00
Earle F. Philhower, III
e4c144829c
Remove exception handling code, save RAM and FLASH (#245)
Use a libstdc++ compiled with -fno-exceptions to avoid including the
code needed to unwind C++ exceptions.

Saves ~4K RAM and ~5K flash.
2021-07-17 10:55:47 -07:00
majbthrd
47a4d9f803
Add pico-debug support (#239) 2021-07-07 12:55:03 -07:00
Earle F. Philhower, III
d67329a2b8
Rename assembly dir to boot2, only has boot2.Ss (#230) 2021-06-30 08:42:13 -07:00
Ha Thach
3a9703fc20
Update tinyusb 1.3.0 (#228)
* update included tinyusb to 1.2.0

move tusb_config.h from core to library for more portability

* pump tinyusb

* update tinyusb to 1.3.0

* try to fix ci warning
2021-06-30 08:22:36 -07:00
Earle F. Philhower, III
856b105ab9
Clean up include paths, remove duplicates/invalids (#229) 2021-06-30 08:13:19 -07:00
Earle F. Philhower, III
03e740a511
Add CPU cycle counter accessors (#226)
Use the 24-bit SYSTICK peripheral, wrapped in logic to extend it to a
full 32 or 64bits.  W/o the wrapper, SYSTICK will wrap around in ~100ms.

Adds rp2040.getCycleCount() and rp2040.getCycleCount64()

Clean up the libpico build process as crt0.S from the pico-sdk should
be directly used.

Clean up the keywords file.
2021-06-28 20:53:40 -07:00
Ha Thach
7eca6c609f
Use correct tusb_config.h for built-in usb (pico-sdk) (#219)
Fix issue with usbd_desc_cfg value may not be initialized as zero.
2021-06-26 09:37:41 -07:00
Earle F. Philhower, III
08b6748d79
Update to PICO-SDK version 1.2.0 (#207)
Minor rev to the tinyUSB version used, new ID function.
2021-06-11 12:48:09 -07:00
Earle F. Philhower, III
f87ccacdb1
Upgrade to GCC 10.3. Fix OpenOCD packaging (#194)
GCC 10.2 has a bug which causes Windows to rebuild every library on every
compile, instead of caching the first results.

Upgrade to GCC 10.3 which has this fixed.

Add proper OpenOCD executables for non-Linux x86_64 archs.
2021-06-06 22:43:26 -07:00
Earle F. Philhower, III
4a8ac3d902
Add support for shared USB Serial, Keyboard, Mouse (#132)
Use a shared infrastructure based on TinyUSB, allow users to use sketches
with ported Arduino Keyboard and Mouse libraries.
2021-05-13 19:20:24 -07:00
Earle F. Philhower, III
a259eb7396
Clean up directory organization, libpico build (#129)
Also add a README.md to the tools directory.
2021-05-11 12:30:14 -07:00
Earle F. Philhower, III
7f8f0cc137
Clean up platform.txt, libpico build (#128)
Add -fno-exceptions and -fno-rtti where possible.
Move insanely long strings to @files to shrink platform.txt and make
build command line shorter.
2021-05-10 17:57:24 -07:00
Earle F. Philhower, III
70a30dc219
Add multicore safety, FIFO, update pico-sdk (#122)
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.
2021-05-06 19:57:21 -07:00
Earle F. Philhower, III
c1ab2b7352 Update FLASH_SIZE_BYTES to avoid assert on > 2MB
The SDK would assert if a flash write/erase happened past the end of the
flash space it was built with.  So, 8MB chips would crash when accessing
offset 3MB, for example.

Avoid this by specifying the maximum flash available so the SDK won't
trip.

Fixes #76
2021-04-02 23:54:34 -07:00
Earle F. Philhower, III
1eb48f724d
Add I2S output support and I2S class/library (#73)
Using the PIO-driven I2S from pico-extras, add I2S output support.

Be sure to `git submodule update --init` to get the new directories.
2021-04-02 16:21:36 -07:00
Earle F. Philhower, III
c35cc02aa0 Enable debug symbols in libpico.a 2021-03-31 15:32:29 -07:00
Earle F. Philhower, III
7bfffed649 Move Adafruit Feather RP2040 to w25x10cl_4
Testing in #42.  Thanks @blurfl!
2021-03-31 14:11:24 -07:00
Earle F. Philhower, III
09268fe064
Add multiple boot2 options with /2 and /4 SPI div (#67)
Build all 4 different boot_stage2 objects with SPI/2 and SPI/4 options.
Add a menu to the generic board to allow selecting between them.
Use the potato/4 boot2 for the Adafruit Feather until we have a better
version verified.

Fixes #42
2021-03-31 12:42:51 -07:00
Earle F. Philhower, III
8263068a4d Update version header when rebuilding libpico 2021-03-29 12:05:48 -07:00
Earle F. Philhower, III
b2cef8d8d6 Adafruit Feather, overclocking, flash FS shims
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
2021-03-28 10:56:53 -07:00
Earle F. Philhower, III
90ba9424d2 Remove stdio hacks from libpico.a
Fixes #35
2021-03-27 08:14:07 -07:00
Earle F. Philhower, III
0eba6f09cd Update to pico-sdk v1.1.0 2021-03-24 08:00:08 -07:00
Earle F. Philhower, III
27d9ef70ab Add library build and update via CLI
pico-sdk-lib/build.sh will compile a libpico.a file from scratch using
the selected pico SDK directory.
2021-03-20 12:19:38 -07:00
Earle F. Philhower, III
c892443b5b Adjust directories for cleaner use w/Arduino
/system is only downloaded tools
/tools is all scripts/submodules that are part of the main core
/lib is the linker libs
2021-03-17 08:33:51 -07:00