Skip to content

Commit 919a754

Browse files
Add double-mem LWIP option (earlephilhower#2187)
Add a "-32K" option to all the IP stack options that doubles the PCB and memory pools from default. For most use cases this is not necessary, but it could be helpful in cases where large numbers of TCP clients are connected or high bandwidth applications. Fixes earlephilhower#2050
1 parent 0a2b616 commit 919a754

14 files changed

+1031
-19
lines changed

boards.txt

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

include/lwipopts.h

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ extern void interrupts();
1414
extern unsigned long __lwip_rand(void);
1515
#define LWIP_RAND() __lwip_rand()
1616

17+
#ifndef __LWIP_MEMMULT
18+
#define __LWIP_MEMMULT 1
19+
#endif
20+
1721
// Common settings used in most of the pico_w examples
1822
// (see https://www.nongnu.org/lwip/2_1_x/group__lwip__opts.html for details)
1923

@@ -22,10 +26,10 @@ extern unsigned long __lwip_rand(void);
2226
#define MEM_LIBC_MALLOC 0
2327

2428
#define MEM_ALIGNMENT 4
25-
#define MEM_SIZE 16384
26-
#define MEMP_NUM_TCP_SEG 32
27-
#define MEMP_NUM_ARP_QUEUE 10
28-
#define PBUF_POOL_SIZE 24
29+
#define MEM_SIZE (__LWIP_MEMMULT * 16384)
30+
#define MEMP_NUM_TCP_SEG (32)
31+
#define MEMP_NUM_ARP_QUEUE (10)
32+
#define PBUF_POOL_SIZE (__LWIP_MEMMULT > 1 ? 32 : 24)
2933
#define LWIP_ARP 2
3034
#define LWIP_ETHERNET 1
3135
#define LWIP_ICMP 1
@@ -38,11 +42,10 @@ extern unsigned long __lwip_rand(void);
3842
#define LWIP_NETIF_LINK_CALLBACK 1
3943
#define LWIP_NETIF_HOSTNAME 1
4044
#define LWIP_NETCONN 0
41-
#define MEM_STATS 1
42-
#define SYS_STATS 1
43-
#define MEMP_STATS 1
45+
#define MEM_STATS 0
46+
#define SYS_STATS 0
47+
#define MEMP_STATS 0
4448
#define LINK_STATS 0
45-
// #define ETH_PAD_SIZE 2
4649
#define LWIP_CHKSUM_ALGORITHM 0
4750
#define LWIP_DHCP 1
4851
#define LWIP_IPV4 1
@@ -55,7 +58,8 @@ extern unsigned long __lwip_rand(void);
5558
#define LWIP_DHCP_DOES_ACD_CHECK 0
5659

5760
// See #1285
58-
#define MEMP_NUM_UDP_PCB 6
61+
#define MEMP_NUM_UDP_PCB (__LWIP_MEMMULT * 6)
62+
#define MEMP_NUM_TCP_PCB (__LWIP_MEMMULT * 5)
5963

6064
#if LWIP_IPV6
6165
#define LWIP_IPV6_DHCP6 1

lib/libpico.a

0 Bytes
Binary file not shown.

lib/libpicow-ipv6-btc-ble-big.a

7.24 MB
Binary file not shown.

lib/libpicow-ipv6-btc-ble.a

-14.7 KB
Binary file not shown.

lib/libpicow-ipv6-nobtc-noble-big.a

2.46 MB
Binary file not shown.

lib/libpicow-ipv6-nobtc-noble.a

-14.7 KB
Binary file not shown.

lib/libpicow-noipv6-btc-ble-big.a

6.87 MB
Binary file not shown.

lib/libpicow-noipv6-btc-ble.a

-11.3 KB
Binary file not shown.

lib/libpicow-noipv6-nobtc-noble-big.a

2.1 MB
Binary file not shown.

lib/libpicow-noipv6-nobtc-noble.a

-11.3 KB
Binary file not shown.

tools/libpico/CMakeLists.txt

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ target_compile_definitions(picow-noipv6-nobtc-noble PUBLIC
103103
LWIP_IPV6=0
104104
)
105105

106+
add_library(picow-noipv6-nobtc-noble-big STATIC)
107+
target_compile_definitions(picow-noipv6-nobtc-noble-big PUBLIC
108+
__LWIP_MEMMULT=2
109+
LWIP_IPV6=0
110+
)
111+
106112
set(picow_link_libraries
107113
common
108114
cyw43_driver
@@ -121,20 +127,40 @@ target_link_libraries(picow-noipv6-nobtc-noble
121127
${picow_link_libraries}
122128
)
123129

130+
target_link_libraries(picow-noipv6-nobtc-noble-big
131+
${picow_link_libraries}
132+
)
133+
124134
add_library(picow-ipv6-nobtc-noble STATIC)
125135
target_compile_definitions(picow-ipv6-nobtc-noble PUBLIC
126136
LWIP_IPV6=1
127137
)
128138

139+
add_library(picow-ipv6-nobtc-noble-big STATIC)
140+
target_compile_definitions(picow-ipv6-nobtc-noble-big PUBLIC
141+
__LWIP_MEMMULT=2
142+
LWIP_IPV6=1
143+
)
144+
129145
target_link_libraries(picow-ipv6-nobtc-noble
130146
${picow_link_libraries}
131147
)
132148

149+
target_link_libraries(picow-ipv6-nobtc-noble-big
150+
${picow_link_libraries}
151+
)
152+
133153
add_library(picow-noipv6-btc-ble STATIC)
134154
target_compile_definitions(picow-noipv6-btc-ble PUBLIC
135155
LWIP_IPV6=0
136156
)
137157

158+
add_library(picow-noipv6-btc-ble-big STATIC)
159+
target_compile_definitions(picow-noipv6-btc-ble-big PUBLIC
160+
__LWIP_MEMMULT=2
161+
LWIP_IPV6=0
162+
)
163+
138164
set(picow_bt_link_libraries
139165
pico_btstack_cyw43
140166
pico_btstack_ble
@@ -148,17 +174,34 @@ target_link_libraries(picow-noipv6-btc-ble
148174
${picow_bt_link_libraries}
149175
)
150176

177+
target_link_libraries(picow-noipv6-btc-ble-big
178+
${picow_link_libraries}
179+
${picow_bt_link_libraries}
180+
)
181+
151182
add_library(picow-ipv6-btc-ble STATIC)
152183
target_compile_definitions(picow-ipv6-btc-ble PUBLIC
153184
LWIP_IPV6=1
154185
)
155186

187+
add_library(picow-ipv6-btc-ble-big STATIC)
188+
target_compile_definitions(picow-ipv6-btc-ble-big PUBLIC
189+
__LWIP_MEMMULT=2
190+
LWIP_IPV6=1
191+
)
192+
156193
target_link_libraries(picow-ipv6-btc-ble
157194
${picow_link_libraries}
158195
${picow_bt_link_libraries}
159196
)
160197

161-
foreach(tgt pico picow-noipv6-nobtc-noble picow-ipv6-nobtc-noble picow-noipv6-btc-ble picow-ipv6-btc-ble)
198+
target_link_libraries(picow-ipv6-btc-ble-big
199+
${picow_link_libraries}
200+
${picow_bt_link_libraries}
201+
)
202+
203+
204+
foreach(tgt pico picow-noipv6-nobtc-noble picow-ipv6-nobtc-noble picow-noipv6-btc-ble picow-ipv6-btc-ble picow-noipv6-nobtc-noble-big picow-ipv6-nobtc-noble-big picow-noipv6-btc-ble-big picow-ipv6-btc-ble-big)
162205
add_custom_command(TARGET ${tgt} POST_BUILD
163206
COMMAND ar d lib${tgt}.a stdio.c.obj stdio_uart.c.obj stdio_usb.c.obj stdio_usb_descriptors.c.obj pico_malloc.c.obj
164207
COMMAND ar d lib${tgt}.a btstack_flash_bank.c.obj # Need to override with our own implementation

tools/libpico/lwipopts.h

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ extern void interrupts();
1414
extern unsigned long __lwip_rand(void);
1515
#define LWIP_RAND() __lwip_rand()
1616

17+
#ifndef __LWIP_MEMMULT
18+
#define __LWIP_MEMMULT 1
19+
#endif
20+
1721
// Common settings used in most of the pico_w examples
1822
// (see https://www.nongnu.org/lwip/2_1_x/group__lwip__opts.html for details)
1923

@@ -22,10 +26,10 @@ extern unsigned long __lwip_rand(void);
2226
#define MEM_LIBC_MALLOC 0
2327

2428
#define MEM_ALIGNMENT 4
25-
#define MEM_SIZE 16384
26-
#define MEMP_NUM_TCP_SEG 32
27-
#define MEMP_NUM_ARP_QUEUE 10
28-
#define PBUF_POOL_SIZE 24
29+
#define MEM_SIZE (__LWIP_MEMMULT * 16384)
30+
#define MEMP_NUM_TCP_SEG (32)
31+
#define MEMP_NUM_ARP_QUEUE (10)
32+
#define PBUF_POOL_SIZE (__LWIP_MEMMULT > 1 ? 32 : 24)
2933
#define LWIP_ARP 2
3034
#define LWIP_ETHERNET 1
3135
#define LWIP_ICMP 1
@@ -38,11 +42,10 @@ extern unsigned long __lwip_rand(void);
3842
#define LWIP_NETIF_LINK_CALLBACK 1
3943
#define LWIP_NETIF_HOSTNAME 1
4044
#define LWIP_NETCONN 0
41-
#define MEM_STATS 1
42-
#define SYS_STATS 1
43-
#define MEMP_STATS 1
45+
#define MEM_STATS 0
46+
#define SYS_STATS 0
47+
#define MEMP_STATS 0
4448
#define LINK_STATS 0
45-
// #define ETH_PAD_SIZE 2
4649
#define LWIP_CHKSUM_ALGORITHM 0
4750
#define LWIP_DHCP 1
4851
#define LWIP_IPV4 1
@@ -55,7 +58,8 @@ extern unsigned long __lwip_rand(void);
5558
#define LWIP_DHCP_DOES_ACD_CHECK 0
5659

5760
// See #1285
58-
#define MEMP_NUM_UDP_PCB 6
61+
#define MEMP_NUM_UDP_PCB (__LWIP_MEMMULT * 6)
62+
#define MEMP_NUM_TCP_PCB (__LWIP_MEMMULT * 5)
5963

6064
#if LWIP_IPV6
6165
#define LWIP_IPV6_DHCP6 1

tools/makeboards.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,19 @@ def BuildIPBTStack(name):
117117
print("%s.menu.ipbtstack.ipv4ipv6btcble=IPv4 + IPv6 + Bluetooth" % (name))
118118
print('%s.menu.ipbtstack.ipv4ipv6btcble.build.libpicow=libpicow-ipv6-btc-ble.a' % (name))
119119
print('%s.menu.ipbtstack.ipv4ipv6btcble.build.libpicowdefs=-DLWIP_IPV6=1 -DLWIP_IPV4=1 -DENABLE_CLASSIC=1 -DENABLE_BLE=1' % (name))
120+
print("%s.menu.ipbtstack.ipv4onlybig=IPv4 Only - 32K" % (name))
121+
print('%s.menu.ipbtstack.ipv4onlybig.build.libpicow=libpicow-noipv6-nobtc-noble-big.a' % (name))
122+
print('%s.menu.ipbtstack.ipv4onlybig.build.libpicowdefs=-DLWIP_IPV6=0 -DLWIP_IPV4=1 -D__LWIP_MEMMULT=2' % (name))
123+
print("%s.menu.ipbtstack.ipv4ipv6big=IPv4 + IPv6 - 32K" % (name))
124+
print('%s.menu.ipbtstack.ipv4ipv6big.build.libpicow=libpicow-ipv6-nobtc-noble-big.a' % (name))
125+
print('%s.menu.ipbtstack.ipv4ipv6big.build.libpicowdefs=-DLWIP_IPV6=1 -DLWIP_IPV4=1 -D__LWIP_MEMMULT=2' % (name))
126+
print("%s.menu.ipbtstack.ipv4btcblebig=IPv4 + Bluetooth - 32K" % (name))
127+
print('%s.menu.ipbtstack.ipv4btcblebig.build.libpicow=libpicow-noipv6-btc-ble-big.a' % (name))
128+
print('%s.menu.ipbtstack.ipv4btcblebig.build.libpicowdefs=-DLWIP_IPV6=0 -DLWIP_IPV4=1 -DENABLE_CLASSIC=1 -DENABLE_BLE=1 -D__LWIP_MEMMULT=2' % (name))
129+
print("%s.menu.ipbtstack.ipv4ipv6btcblebig=IPv4 + IPv6 + Bluetooth - 32K" % (name))
130+
print('%s.menu.ipbtstack.ipv4ipv6btcblebig.build.libpicow=libpicow-ipv6-btc-ble-big.a' % (name))
131+
print('%s.menu.ipbtstack.ipv4ipv6btcblebig.build.libpicowdefs=-DLWIP_IPV6=1 -DLWIP_IPV4=1 -DENABLE_CLASSIC=1 -DENABLE_BLE=1 -D__LWIP_MEMMULT=2' % (name))
132+
120133

121134
def BuildUploadMethodMenu(name):
122135
for a, b, c, d, e, f in [ ["default", "Default (UF2)", 256, "picoprobe_cmsis_dap.tcl", "uf2conv", "uf2conv-network"],

0 commit comments

Comments
 (0)