Skip to content

Commit cd06ebb

Browse files
committed
lwIP: Add memory configs to JSON
We currently set the lwIP pbuf pool size small - to 5 x 576-byte buffers. This is insufficient to hold a single DTLS handshake flight, so can cause cloud client connections to fail. STM-based platforms are failing handshake because of this. (K64F works because it doesn't use the pbuf pool for reception, but lwIP does recommend drivers use the pbuf pool). Not changing the default memory sizes here, as intended for a patch release, but adding mbed configuration options to allow the numbers to be adjusted for memory tuning in an application. In a future minor revision, I would recommend increasing the default PBUF_POOL_SIZE - we are well below lwIP's out-of-the-box default - and offsetting by a reduction in MEM_SIZE for the drivers that don't use PBUF_RAM.
1 parent 373e6ab commit cd06ebb

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

features/FEATURE_LWIP/lwip-interface/lwipopts.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,25 @@
137137
#define LWIP_RAM_HEAP_POINTER lwip_ram_heap
138138

139139
// Number of pool pbufs.
140-
// Each requires 684 bytes of RAM.
140+
// Each requires 684 bytes of RAM (if MSS=536 and PBUF_POOL_BUFSIZE defaulting to be based on MSS)
141+
#ifdef MBED_CONF_LWIP_PBUF_POOL_SIZE
142+
#undef PBUF_POOL_SIZE
143+
#define PBUF_POOL_SIZE MBED_CONF_LWIP_PBUF_POOL_SIZE
144+
#else
141145
#ifndef PBUF_POOL_SIZE
142146
#define PBUF_POOL_SIZE 5
143147
#endif
148+
#endif
149+
150+
#ifdef MBED_CONF_LWIP_PBUF_POOL_BUFSIZE
151+
#undef PBUF_POOL_BUFSIZE
152+
#define PBUF_POOL_BUFSIZE MBED_CONF_LWIP_PBUF_POOL_BUFSIZE
153+
#endif
154+
155+
#ifdef MBED_CONF_LWIP_MEM_SIZE
156+
#undef MEM_SIZE
157+
#define MEM_SIZE MBED_CONF_LWIP_MEM_SIZE
158+
#endif
144159

145160
// One tcp_pcb_listen is needed for each TCPServer.
146161
// Each requires 72 bytes of RAM.

features/FEATURE_LWIP/lwip-interface/mbed_lib.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@
7272
"help": "Maximum number of open UDPSocket instances allowed, including one used internally for DNS. Each requires 84 bytes of pre-allocated RAM",
7373
"value": 4
7474
},
75+
"pbuf-pool-size": {
76+
"help": "Number of pbufs in pool - usually used for received packets, so this determines how much data can be buffered between reception and the application reading. If a driver uses PBUF_RAM for reception, less pool may be needed. Current default (used if null here) is set to 5 in lwipopts.h, unless overridden by target Ethernet drivers.",
77+
"value": null
78+
},
79+
"pbuf-pool-bufsize": {
80+
"help": "Size of pbufs in pool. If set to null, lwIP will base the size on the TCP MSS, which is 536 unless overridden by the target",
81+
"value": null
82+
},
83+
"mem-size": {
84+
"help": "Size of heap (bytes) - used for outgoing packets, and also used by some drivers for reception. Current default (used if null here) is set to 1600 in opt.h, unless overridden by target Ethernet drivers.",
85+
"value": null
86+
},
7587
"tcpip-thread-stacksize": {
7688
"help": "Stack size for lwip TCPIP thread",
7789
"value": 1200

0 commit comments

Comments
 (0)