* Add FatFS for onboard flash use/sharing of FAT
* Move all to "fatfs" namespace
The FatFS library defines commonly used names like WORD which could conflict
with user code otherwise.
* Restyle
* FTL-based, wear-leveling FatFS with USB export
Allow using FAT filesystem with onboard flash in a safer, wear-leveled
way and to export the onboard flash to the host as a USB drive for easy
data transfer.
* Update documentation
* Fix submodule reference
* Don't spellehcek ChaN FatFS files
* Disable FTL debugging
* More codespell skips
* Move to latest SPIFTL library
* Allow using raw flash instead of FTL
* Remove unneeded static FIL 4k allocation
* Expose FAT FS format configuration options
* Update documentation
* Remove USB partial flash rewrites
* Remove unneeded dups of FatFS sources
Leave the LICENSE.md and README.md to point to upstream.
* Clean up comments
WiFiMulti specifies a specific BSSID, in addition to the AP name and
password. In the WiFi core the BSSID is stored as the raw 6-byte MAC
address, but the ESPHostedFG firmware expects a formatted C-String
(i.e. "ab💿ef:01:02:03" instead of {0xab, 0xcd, 0xef, 1, 2, 3})
Convert the raw bytes to the string format expected in the ESP FW.
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.
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.
The Arduino WiFi normalization ended up calling the underlying LWIP
::config after the AP was begin, resulting in a failure to set the
IP configuration of the AP. Move the _wifi.begin() call to after
the IP configuration is set.
Fixes#1989
If the BLE connection is severed, don't wait for the needToSend
flag to clear in the HID::send routine since it may never actually
clear unless the BLE connection is restored.
Partial #1817
With HW chip select enabled, transfer16's 2 individual byte transfers will
actualy deassert CS for a brief instant between bytes. Avoid this by doing
a single multi-byte (2) tranfer of 16b.
Fixes#1749
Defining a global true `bool core1_separate_stack = true` will separate
the two cores' stacks, with core 0 using the scratch RAM while core 1
will use 8K from the heap.
* Adapted all libraries to support multiprotocol HID over BT & BLE
* Added ATT DB depending on setup; still no success with working connection
* Added hids_device from BTStack develop branch as override
* Fixing the GATT handle patching, added working ATT DB
* ran astyle on example
* Updates in BLE implementation; WORKING! (but only if all are activated). Removed sdkoverride again, doesn't work.
* Moved ATT DB handles to correct places
* Finally functioning for Mouse+KBD+Joy, and each individual
* Cleaned up code & ran astyle
* Added sdkoverrides to pull develop functions from BTSTack
* Changed a few typos by BTStack to run codespell successfully
* Ran astyle on sdkoverride files
* Added some #if guards for including BTSTack file only if BT is enabled
* Fixed Feature Report value characteristics handle assignment; fixed too long HID report
* Ran astyle
_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.
It would be possible for an IRQ-driven SPI user to fire
while the main app's SPI.beginTransaction was in process.
This would result in incorrect state for the main app since
the IRQ may overwrite some settings that the app already
set.
Disable all IRQs around the begin and end processes to avoid
the possibility.
Fixes#1147
When SPI.beginTransaction() is called, disable all GPIO IRQs that were
registered using SPI.usingInterrupt(). On SPI.endTransaction(), restore
all the IRQs to their prior state.
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
If another packet comes in between freeing `_rx_buf` and setting `_rx_buf` to 0, that new packet could get put into the same memory address and get concatenated to itself, which leads to an infinite loop.
New solution assigns a temp pointer, sets `rx_buf` to 0, then frees the memory, which guarantees `_rx_buf` always points to valid data.
The ABM had an off-by-one error in the DMA buffer swapover. Instead of
setting the DMA address to the newly added buffer in active[], it set it
to the buffer that was currently running.
This would effectively disable the ping-pong and cause clicks/lost data.
Fixes#1491
Since FreeRTOS has real tasks and mutexes with support for priority bumping, actually always try and take a `CoreMutex` instead of seeing if someone else already has it and aborting immediately.
This fix helps ensure things like Serial output in a multi-task system won't get lost.
* Implement the BD_ADDR(char * address_string) constructor.
* Updating implementation to use sscanf.
There is an extra step after the sscanf that checks that we got
six bytes back and if we did not, it will set all bytes in the
address to zero.
* Example using BD_ADDR(const char * address_string)
This example shows how BD_ADDR(const char * address_string) can
be used to create BD_ADDR objects to use for comparisons etc.
* Update LEDeviceScanner.ino formatting
* Fix FreeRTOS CoreMutex shim to handle ISRs
Automatically check, when in FreeRTOS, if we're in an ISR and
if so call the correct mutex grab.
Thanks to @caveman99 for finding and proposing a solution!
Fixes#1441
* Fix the CoreMutex destructor, too
Update to head of upstream FreeRTOS/SMP branch. Very minor changes.
Remove the custom getreent implementation, use the one that was defined
in the upstream FreeRTOS/smp branch (callback related vs. static vars).
Fixes#1439
Use a real FreeRTOS task, at the highest priority, to idle the other core
while doing flash accesses.
The USB stack seems to have some timing dependent bits which get broken
if FreeRTOS switches out the current task when it's running. Avoid any
issue by disabling preemption on the core for all tud_task calls.
The PendSV handler disable flag can live completely inside the FreeRTOS
variant port, so remove any reference to it in the main core.
Tested using Multicode-FreeRTOS, #1402 and #1441
The USB FIFO interrupts were still being serviced even when the core was
frozen, leading to crashes. Explicitly shut off IRQs on both the victim
and the initiator core when freezing.
Removed the need for hack __holdUpPendSV flag
Fixes#1408
The wl_* types are required in multiple libraries which in turn seem
to have a circular dependency that Platform.IO has issues with in certain
modes.
Avoid the issue by moving the common headers into the core directories
so they will be accessible by all libs.
Move StackThunk to core directory, too
Fixes#1402
The global USB mutex is auto-shadowed with a FreeRTOS semaphore while in
FreeRTOS mode. Unfortunately, while the core was using the proper
FreeRTOS semaphore to lock access to the USB port, the actual FreeRTOS
USB task was using the naked Pico SDK mutex, leading to cases where it
could acquire the mutex even though some other FreeRTOS task actually
owned the shadowed mutex.
Properly lock the shadowed Semaphore, not mutex_t, in the FreeRTOS
USB periodic task.
Fixes#1370
Adds a simple helper assertion to tell the user how to enable BT if it's
not enabled, instead of some odd compilation warnings about undefined
functions.
Fixes#1356
Mac and Windows have case-insensitive filesystems, so the will find
the internal (all-lowercase) "btstack.h" and not the library's "BTstack.h",
causing compilation errors.
Rename the library and header to avoid the issue.
Allow sending thigns like KEY_MUTE or KEY_SCAN_NEXT from the USB and
Bluetooth Classic keyboard libraries.
BLE requires some add'l magic, not yet discovered.
Pull in latest upstream Keyboard library changes
SDK 1.5 changed the behavior of the underlying CYW43 blob, and it seems
to block MDNS multicast by default. Manually add back the Ethernet MACs
used for MDNS multicast in IPV4 and IPV6.
Fixes#1267
It seems possible now for TCP connection _pcbs to disappear while being
processed, due to the new async context configuration. This would cause
LWIP to panic when a NULL pcb was passed in.
Check for and avoid passing in null PCBs in the ClientContext.
Undo special-casing of sys_check_timeouts wrapper
AdvancedWebServer with heavy F5-refresh and #1274 test both pass.
Fixes#1274
Move the Joystick, Keyboard, and Mouse into a base class which handles
the operation/input, and a subclass which will implement the reporting
as a HID device via USB, Bluetooth Classic, or Bluetooth Low Energy (BLE).
Reduce copies of library code and makes maintainability much better.
* Update to Pico-SDK v1.5
* Hook in pico_rand, use ioctl to set ipv6 allmulti
* Move into PicoSDK LWIP mutex, hack timer sizes
* Utilize much of the PicoSDK infrastructure for WiFi
* Add WiFi::begin(ssid, pass, bssid)
* WiFiMulti to use BSSID, make more robust
WiFiMulti will now be more aggressive and try all matching SSIDs, in order
of RSSI, using the BSSID to identify individual APs in a mesh.
Before, if the highest RSSI AP didn't connect, it would fail immediately.
Now, it will go down the list, ordered by RSSI, to attempt to get a link.
* Add Bluetooth support from Pico-SDK
Able to build and run the HID Keyboard Demo from the Arduino IDE, almost
as-is.
Will probably need to make BT configurable. Enabling BT on a plain WiFi
sketch uses 50KB of flash and 16KB of RAM even if no BT is used.
* Separate picow libs, BT through menus, example
Build normal Pico.a and 4 different options for PicoW IP/BT configuration.
Use IP=>IP/Bluetooth menu to select between options.
* CMakefile rationalization
* Move BT TLV(pairing) out of last 2 flash sectors
The pairing keys for BT are stored at the end of flash by default, but
we use the last sector of flash for EPROM and the penultimate one for
the filesystem. Overwriting those in BT could cause some real exciting
crashes down the line.
Move the store to an app-build specific address using a dummy const
array to allocate space in the application image itself.
* PicoBluetoothHID with BT Mouse, Joystick, Keyboard
Add simple Bluetooth Classic HID helper function and port the existing
USB HID devices to it. Port their examples.
* Protect BT key storage from multicore
* Add short-n-sweet Bluetooth documents
* Add Bluetooth Serial port library
* Turn off BT when the BT libraries exit
The PWMAudio lib is expecting an int16_t value but the example passes a sample cast to uint16_t
So any values from the lookup table that are negative are recast to 0 i think.
So half the sine wave in the case of the example is lost.
Implement the method used in the ESP8266 Web Server to allow user apps to hook into
the HTTP server (to support hooked WebSockets, etc._)
Add example of hook usage
Mimics the I2S/PWMAudio/Stream interface for ease of use.
* Fix non-32b DMA size transfer calculation in ABM
* Rename wasHolding to isHolding in the I2S/PWM
It is the **current** number of bits left, not the past number.
* Add commented microphone example
* Add docs
Now that we have a default parameter, need to only allow it in C++ since
default values are not part of C spec. Should not affect any users since
only legacy code is in C.
Only 4K total stack, so allocating 400 bytes for a local C string
or 600 bytes for a DHCP response is dangerous. Use static allocations
instead on the heap.
Use the PWM hardware to generate a signal suitable for filtering and
amplifying 16bps audio output.
Refactor the AudioBufferManager to allow sharing with I2S
Add example
The ring buffer worked but had issues with IRQs and the available()
procesing. Because it was a pain to debug, move to a linked list
setup where there are filled and empty buffers to work from,
simplifying the underlying logic.
Allow I2S::available() to return free writing space in OUTPUT mode
to make it saner.
* Increase default number of buffers for 32bps
Gives 2x the time between interrutps to handle I2S callbacks.
* Add setBuffers keyword
Fixes#963
The available space calculation didn't account for the fact that one
of the buffers was currently being output, causing ::available() to
be too large and ::write() to block in that case.
Other parts of the core use temp 256 byte chunks to transmit/move/operate
on data, so do the same here. Will increase effective WebServer sendFile
speeds.
SingleFileDisk allows for exporting a file from the onboard LittleFS
filesystem to a PC through an emulated FAT drive when connected. The
PC can open and copy the file, as well as delete it, but the PC has no
access to the main onboard LittleFS and no actual on-flash FAT
structures are used.
This is handy for things like data loggers. They can run connected to
USB power for some time, and then connected to a PC to dowmload the CSV
log recorded.
It's almost 2023, allow LFN (long file names) on the emulated USB disk.
Reduce the disk buffer size to 64 bytes. The buffer is statically
allocated so it's always present, even in non-USB disk mode, meaning
all apps will pay the RAM price for it. 64 bytes is slower to read
but works and saves ~1/2KB of heap for all apps.
The memcpy to unallocated memory was done in two cases:
1) The 'size' parameter was not multiple of 256.
2) The begin() was called two times and the 2nd call 'size' was greater than 1st time 'size'. (e.g. 1st size=256, 2nd size=512)
Fixes#979
Make sure to read the last byte of I2C data in the case where the IRQ happens
and the STOP signal is also asserted.
Also ensure all branches of the IRQ handler look at the same point in time
value for the IRQ status.
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
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
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.
* 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
* Add HTTPUpdate class to pull updates from HTTP(S)
* Increase GH runners for pulls
WiFi builds and examples are taking some serious time now
* HTTPUpdate tests build on Pico W
OTA text error messages were getting lost because they were sent in
multiple UDP packets, one per print(). Now collect the full error and
report in a single print, allowing text messages to appear in ESPOTA.