Skip to content

Commit abf2c58

Browse files
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
1 parent c025c4a commit abf2c58

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+7511
-241
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ See https://arduino-pico.readthedocs.io/en/latest/ along with the examples for m
1111

1212
# Supported Boards
1313
* Raspberry Pi Pico
14+
* Raspberry Pi Pico W
1415
* Adafruit Feather RP2040
1516
* Adafruit ItsyBitsy RP2040
1617
* Adafruit KB2040
@@ -177,8 +178,10 @@ If you want to contribute or have bugfixes, drop me a note at <earlephilhower@ya
177178
* [Arduino-Pico](https://github.com/earlephilhower/arduino-pico) core files are licensed under the LGPL.
178179
* [LittleFS](https://github.com/ARMmbed/littlefs) library written by ARM Limited and released under the [BSD 3-clause license](https://github.com/ARMmbed/littlefs/blob/master/LICENSE.md).
179180
* [UF2CONV.PY](https://github.com/microsoft/uf2) is by Microsoft Corporation and licensed under the MIT license.
180-
* Some filesystem code taken from the [ESP8266 Arduino Core](https://github.com/esp8266/Arduino) and licensed under the LGPL.
181+
* Networking and filesystem code taken from the [ESP8266 Arduino Core](https://github.com/esp8266/Arduino) and licensed under the LGPL.
182+
* DHCP server for AP host mode from the [Micropython Project](https://micropython.org), distributed under the MIT License.
181183
* [FreeRTOS](https://freertos.org) is Copyright Amazon.com, Inc. or its affiliates, and distributed under the MIT license.
184+
* [lwIP](https://savannah.nongnu.org/projects/lwip/) is (c) the Swedish Institute of Computer Science and licenced under the BSD license.
182185
183186
-Earle F. Philhower, III
184187

boards.txt

Lines changed: 483 additions & 62 deletions
Large diffs are not rendered by default.

cores/rp2040/Arduino.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1919
*/
2020

21-
#ifndef Arduino_h
22-
#define Arduino_h
21+
#pragma once
2322

2423
#include <stdint.h>
2524
#include <stdlib.h>
@@ -112,5 +111,3 @@ constexpr uint32_t __bitset(const int (&a)[N], size_t i = 0U) {
112111
return i < N ? (1L << a[i]) | __bitset(a, i + 1) : 0;
113112
}
114113
#endif
115-
116-
#endif // Arduino_h

cores/rp2040/FS.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1919
*/
2020

21-
#ifndef FS_H
22-
#define FS_H
21+
#pragma once
2322

2423
#include <memory>
2524
#include <Arduino.h>
@@ -264,5 +263,3 @@ using fs::SeekEnd;
264263
using fs::FSInfo;
265264
using fs::FSConfig;
266265
#endif //FS_NO_GLOBALS
267-
268-
#endif //FS_H

cores/rp2040/FSImpl.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
License along with this library; if not, write to the Free Software
1818
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1919
*/
20-
#ifndef FSIMPL_H
21-
#define FSIMPL_H
20+
21+
#pragma once
2222

2323
#include <stddef.h>
2424
#include <stdint.h>
@@ -149,5 +149,3 @@ class FSImpl {
149149
};
150150

151151
} // namespace fs
152-
153-
#endif //FSIMPL_H

cores/rp2040/LWIPMutex.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
WiFiMutex.h - Ensure the timer-driven sys_check_timeouts doesn't
3+
get executed while we're in the user-level TCP stack.
4+
Copyright (c) 2022 Earle F. Philhower, III. All rights reserved.
5+
6+
Implements the API defined by the Arduino WiFiNINA library,
7+
copyright (c) 2018 Arduino SA. All rights reserved.
8+
9+
This library is free software; you can redistribute it and/or
10+
modify it under the terms of the GNU Lesser General Public
11+
License as published by the Free Software Foundation; either
12+
version 2.1 of the License, or (at your option) any later version.
13+
14+
This library is distributed in the hope that it will be useful,
15+
but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
Lesser General Public License for more details.
18+
19+
You should have received a copy of the GNU Lesser General Public
20+
License along with this library; if not, write to the Free Software
21+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22+
*/
23+
24+
#pragma once
25+
26+
extern "C" volatile bool __inLWIP;
27+
28+
class LWIPMutex {
29+
public:
30+
LWIPMutex() {
31+
__inLWIP = true;
32+
_ref++;
33+
}
34+
~LWIPMutex() {
35+
if (0 == --_ref) {
36+
__inLWIP = false;
37+
}
38+
}
39+
private:
40+
static int _ref;
41+
};

cores/rp2040/RP2040USB.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ mutex_t __usb_mutex;
4040

4141
// USB processing will be a periodic timer task
4242
#define USB_TASK_INTERVAL 1000
43-
#define USB_TASK_IRQ 31
43+
static int __usb_task_irq;
4444

4545
// USB VID/PID (note that PID can change depending on the add'l interfaces)
4646
#define USBD_VID (0x2E8A) // Raspberry Pi
@@ -284,7 +284,7 @@ static void usb_irq() {
284284
}
285285

286286
static int64_t timer_task(__unused alarm_id_t id, __unused void *user_data) {
287-
irq_set_pending(USB_TASK_IRQ);
287+
irq_set_pending(__usb_task_irq);
288288
return USB_TASK_INTERVAL;
289289
}
290290

@@ -303,8 +303,9 @@ void __USBStart() {
303303

304304
tusb_init();
305305

306-
irq_set_exclusive_handler(USB_TASK_IRQ, usb_irq);
307-
irq_set_enabled(USB_TASK_IRQ, true);
306+
__usb_task_irq = user_irq_claim_unused(true);
307+
irq_set_exclusive_handler(__usb_task_irq, usb_irq);
308+
irq_set_enabled(__usb_task_irq, true);
308309

309310
add_alarm_in_us(USB_TASK_INTERVAL, timer_task, NULL, true);
310311
}

cores/rp2040/SerialUSB.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1919
*/
2020

21-
#ifndef __SERIALUSB_H__
22-
#define __SERIALUSB_H__
21+
#pragma once
2322

2423
#include <Arduino.h>
2524
#include "api/HardwareSerial.h"
@@ -54,5 +53,3 @@ extern SerialUSB Serial;
5453
namespace arduino {
5554
extern void serialEventRun(void) __attribute__((weak));
5655
};
57-
58-
#endif

0 commit comments

Comments
 (0)