8000 Enable IPv4 or IPv4/IPv6 stacks, Ethernet class (#695) · earlephilhower/arduino-pico@0e18f09 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0e18f09

Browse files
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
1 parent 40f4fdf commit 0e18f09

File tree

13 files changed

+662
-26
lines changed

13 files changed

+662
-26
lines changed

.github/workflows/pull-request.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,14 @@ jobs:
185185
steps:
186186
- uses: actions/checkout@v3
187187
with:
188-
submodules: 'recursive'
188+
submodules: 'true'
189+
- name: Initialize needed submodules
190+
run: |
191+
cd pico-sdk
192+
git submodule update --init
193+
cd ../libraries/Adafruit_TinyUSB_Arduino
194+
git submodule update --init
195+
cd ../..
189196
- name: Cache pip
190197
uses: actions/cache@v2
191198
with:

boards.txt

Lines changed: 577 additions & 0 deletions
Large diffs are not rendered by default.

cores/rp2040/api/IPAddress.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,10 @@ bool IPAddress::isValid(const char* arg) {
179179
return IPAddress().fromString(arg);
180180
}
181181

182+
namespace arduino {
182183
const IPAddress INADDR_ANY; // generic "0.0.0.0" for IPv4 & IPv6
183184
const IPAddress INADDR_NONE(255,255,255,255);
185+
};
184186

185187
void IPAddress::clear() {
186188
(*this) = INADDR_ANY;

cores/rp2040/api/IPAddress.h

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,14 @@
2727
#include <lwip/ip_addr.h>
2828
#include <lwip/ip4_addr.h>
2929

30-
namespa 8000 ce arduino {
3130

32-
#if !LWIP_IPV6
33-
struct ip_addr: ipv4_addr { };
34-
#endif // !LWIP_IPV6
31+
// forward declarations of global name space friend classes
32+
class EthernetClass;
33+
class DhcpClass;
34+
class DNSClient;
35+
36+
37+
namespace arduino {
3538

3639
// to display a netif id with printf:
3740
#define NETIFID_STR "%c%c%u"
@@ -48,8 +51,19 @@ struct ip_addr: ipv4_addr { };
4851

4952
class IPAddress: public Printable {
5053
private:
51-
54+
#if !LWIP_IPV6
55+
// Ugly hack to allow Arduino Ethernet library to twiddle internal bits.
56+
// This can only work in IPv4-only mode, of course.
57+
union {
58+
ip_addr_t _ip;
59+
struct {
60+
uint8_t bytes[4];
61+
} _address;
62+
};
63+
static_assert(sizeof(_ip) == sizeof(_address), "IP_ADDR_T size != _ADDRESS size");
64+
#else
5265
ip_addr_t _ip;
66+
#endif
5367

5468
// Access the raw byte array containing the address. Because this returns a pointer
5569
// to the internal structure rather than a copy of the address this function should only
@@ -149,6 +163,10 @@ class IPAddress: public Printable {
149163
friend class DhcpClass;
150164
friend class DNSClient;
151165

166+
friend ::EthernetClass;
167+
friend ::DhcpClass;
168+
friend ::DNSClient;
169+
152170
/*
153171
lwIP address compatibility
154172
*/
@@ -167,14 +185,14 @@ class IPAddress: public Printable {
167185

168186
bool isLocal () const { return ip_addr_islinklocal(&_ip); }
169187

170-
#if LWIP_IPV6
171188

172189
IPAddress(const ip_addr_t& lwip_addr) { ip_addr_copy(_ip, lwip_addr); }
173190
IPAddress(const ip_addr_t* lwip_addr) { ip_addr_copy(_ip, *lwip_addr); }
174191

175192
IPAddress& operator=(const ip_addr_t& lwip_addr) { ip_addr_copy(_ip, lwip_addr); return *this; }
176193
IPAddress& operator=(const ip_addr_t* lwip_addr) { ip_addr_copy(_ip, *lwip_addr); return *this; }
177194

195+
#if LWIP_IPV6
178196
uint16_t* raw6()
179197
{
180198
setV6();

docs/platformio.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,18 @@ default Pico SDK USB stack. To change it, add
222222
Note that the special "No USB" setting is also supported, through the
223223
shortcut-define ``PIO_FRAMEWORK_ARDUINO_NO_USB``.
224224

225+
IP Stack
226+
---------
227+
228+
The lwIP stack can be configured to support only IPv4 (default) or additionally IPv6. To activate IPv6 support, add
229+
230+
.. code:: ini
231+
232+
; IPv6
233+
build_flags = -DPIO_FRAMEWORK_ARDUINO_ENABLE_IPV6
234+
235+
to the ``platformio.ini``.
236+
225237

226238
Selecting a different core version
227239
----------------------------------

lib/libpico-ipv6.a

2.91 MB
Binary file not shown.

lib/libpico.a

-374 KB
Binary file not shown.

libraries/lwIP_Ethernet/src/LwipIntfDev.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ int LwipIntfDev<RawDev>::hostByName(const char* aHostname, IPAddress& aResult, i
179179
#if LWIP_IPV4 && LWIP_IPV6
180180
err_t err = dns_gethostbyname_addrtype(aHostname, &addr, &_dns_found_callback, &cb, LWIP_DNS_ADDRTYPE_DEFAULT);
181181
#else
182-
err_t err = dns_gethostbyname(aHostname, &addr, &wifi_dns_found_callback, &cb);
182+
err_t err = dns_gethostbyname(aHostname, &addr, &_dns_found_callback, &cb);
183183
#endif
184184
if (err == ERR_OK) {
185185
aResult = IPAddress(&addr);

platform.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,11 @@ compiler.warning_flags.default=-Werror=return-type
4141
compiler.warning_flags.more=-Wall -Werror=return-type -Wno-ignored-qualifiers
4242
compiler.warning_flags.all=-Wall -Wextra -Werror=return-type -Wno-ignored-qualifiers
4343

44-
compiler.netdefines=-DPICO_CYW43_ARCH_THREADSAFE_BACKGROUND=1 -DCYW43_LWIP=0 -DLWIP_IPV6=1 -DLWIP_IPV4=1 -DLWIP_IGMP=1 -DLWIP_CHECKSUM_CTRL_PER_NETIF=1
44+
compiler.netdefines=-DPICO_CYW43_ARCH_THREADSAFE_BACKGROUND=1 -DCYW43_LWIP=0 {build.lwipdefs} -DLWIP_IGMP=1 -DLWIP_CHECKSUM_CTRL_PER_NETIF=1
4545
compiler.defines={build.led} {build.usbstack_flags} -DCFG_TUSB_MCU=OPT_MCU_RP2040 -DUSB_VID={build.vid} -DUSB_PID={build.pid} '-DUSB_MANUFACTURER={build.usb_manufacturer}' '-DUSB_PRODUCT={build.usb_product}' {compiler.netdefines}
4646
compiler.includes="-iprefix{runtime.platform.path}/" "@{runtime.platform.path}/lib/platform_inc.txt" "-I{runtime.platform.path}/include"
4747
compiler.flags=-march=armv6-m -mcpu=cortex-m0plus -mthumb -ffunction-sections -fdata-sections {build.flags.exceptions} {build.flags.stackprotect}
4848
compiler.wrap="@{runtime.platform.path}/lib/platform_wrap.txt"
49-
compiler.libpico="{runtime.platform.path}/lib/libpico.a"
5049
compiler.libbearssl="{runtime.platform.path}/lib/libbearssl.a"
5150

5251
compiler.c.cmd=arm-none-eabi-gcc
@@ -92,8 +91,9 @@ build.usbstack_flags=
9291
build.flags.libstdcpp=-lstdc++
9392
build.flags.exceptions=-fno-exceptions
9493
build.flags.stackprotect=
95-
94+
build.libpico=libpico.a
9695
build.boot2=boot2_generic_03h_4_padded_checksum
96+
build.lwipdefs=-DLWIP_IPV6=0 -DLWIP_IPV4=1
9797

9898
# Allow Pico boards do be auto-discovered by the IDE
9999
discovery.rp2040.pattern="{runtime.tools.pqt-python3.path}/python3" -I "{runtime.platform.path}/tools/discovery.py"
@@ -123,7 +123,7 @@ recipe.hooks.linking.prelink.1.pattern="{runtime.tools.pqt-python3.path}/python3
123123
recipe.hooks.linking.prelink.2.pattern="{compiler.path}{compiler.S.cmd}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} -c "{runtime.platform.path}/boot2/{build.boot2}.S" "-I{runtime.platform.path}/pico-sdk/src/rp2040/hardware_regs/include/" "-I{runtime.platform.path}/pico-sdk/src/common/pico_binary_info/include" -o "{build.path}/boot2.o"
124124

125125
## Combine gc-sections, archives, and objects
126-
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" "-L{build.path}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} {compiler.ldflags} "-Wl,--script={build.path}/memmap_default.ld" "-Wl,-Map,{build.path}/{build.project_name}.map" -o "{build.path}/{build.project_name}.elf" -Wl,--start-group {object_files} "{build.path}/{archive_file}" "{build.path}/boot2.o" {compiler.libraries.ldflags} {compiler.libpico} {compiler.libbearssl} -lm -lc {build.flags.libstdcpp} -lc -Wl,--end-group
126+
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" "-L{build.path}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} {compiler.ldflags} "-Wl,--script={build.path}/memmap_default.ld" "-Wl,-Map,{build.path}/{build.project_name}.map" -o "{build.path}/{build.project_name}.elf" -Wl,--start-group {object_files} "{build.path}/{archive_file}" "{build.path}/boot2.o" {compiler.libraries.ldflags} "{runtime.platform.path}/lib/{build.libpico}" {compiler.libbearssl} -lm -lc {build.flags.libstdcpp} -lc -Wl,--end-group
127127

128128
## Create output (UF2 file)
129129
recipe.objcopy.uf2.pattern="{runtime.tools.pqt-elf2uf2.path}/elf2uf2" "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.uf2"

tools/libpico/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ target_compile_definitions(pico PUBLIC
2121
PICO_FLASH_SIZE_BYTES=16777216
2222
PICO_XOSC_STARTUP_DELAY_MULTIPLIER=64
2323
LWIP_IPV4=1
24-
LWIP_IPV6=1
24+
LWIP_IPV6=${IPV6}
2525
LWIP_UDP=1
2626
LWIP_IGMP=1
2727
LWIP_CHECKSUM_CTRL_PER_NETIF=1

0 commit comments

Comments
 (0)
0