Skip to content

Commit abb13b1

Browse files
committed
extmod/lwip-include: Factor common lwIP config into lwipopts_common.h.
This lwIP configuration file has options that are common to all ports, and the ports are updated to use this file. This change is a no-op, the lwIP configuration remains the same for the four ports using this common file. This reduces code duplication, keeps the ports in sync, and makes it easier to update the configuration for all ports at once. Signed-off-by: Damien George <[email protected]>
1 parent 22353e9 commit abb13b1

File tree

5 files changed

+122
-209
lines changed

5 files changed

+122
-209
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2025 Damien P. George
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
#ifndef MICROPY_INCLUDED_LWIPOPTS_COMMON_H
27+
#define MICROPY_INCLUDED_LWIPOPTS_COMMON_H
28+
29+
#include "py/mpconfig.h"
30+
31+
// This sys-arch protection is not needed.
32+
// Ports either protect lwIP code with flags, or run it at PendSV priority.
33+
#define SYS_ARCH_DECL_PROTECT(lev) do { } while (0)
34+
#define SYS_ARCH_PROTECT(lev) do { } while (0)
35+
#define SYS_ARCH_UNPROTECT(lev) do { } while (0)
36+
37+
#define NO_SYS 1
38+
#define SYS_LIGHTWEIGHT_PROT 1
39+
#define MEM_ALIGNMENT 4
40+
41+
#define LWIP_CHKSUM_ALGORITHM 3
42+
#define LWIP_CHECKSUM_CTRL_PER_NETIF 1
43+
44+
#define LWIP_ARP 1
45+
#define LWIP_ETHERNET 1
46+
#define LWIP_RAW 1
47+
#define LWIP_NETCONN 0
48+
#define LWIP_SOCKET 0
49+
#define LWIP_STATS 0
50+
#define LWIP_NETIF_HOSTNAME 1
51+
52+
#define LWIP_DHCP 1
53+
#define LWIP_DHCP_CHECK_LINK_UP 1
54+
#define LWIP_DHCP_DOES_ACD_CHECK 0 // to speed DHCP up
55+
#define LWIP_DNS 1
56+
#define LWIP_DNS_SUPPORT_MDNS_QUERIES 1
57+
#define LWIP_MDNS_RESPONDER 1
58+
#define LWIP_IGMP 1
59+
60+
#if MICROPY_PY_LWIP_PPP
61+
#define PPP_SUPPORT 1
62+
#define PAP_SUPPORT 1
63+
#define CHAP_SUPPORT 1
64+
#endif
65+
66+
#define LWIP_NUM_NETIF_CLIENT_DATA LWIP_MDNS_RESPONDER
67+
#define MEMP_NUM_UDP_PCB (4 + LWIP_MDNS_RESPONDER)
68+
#define MEMP_NUM_SYS_TIMEOUT (LWIP_NUM_SYS_TIMEOUT_INTERNAL + LWIP_MDNS_RESPONDER)
69+
70+
#define SO_REUSE 1
71+
#define TCP_LISTEN_BACKLOG 1
72+
73+
// TCP memory settings.
74+
// Default lwIP settings takes 15800 bytes; TCP d/l: 380k/s local, 7.2k/s remote; TCP u/l is very slow.
75+
#ifndef MEM_SIZE
76+
77+
#if 0
78+
// lwIP takes 19159 bytes; TCP d/l and u/l are around 320k/s on local network.
79+
#define MEM_SIZE (5000)
80+
#define TCP_WND (4 * TCP_MSS)
81+
#define TCP_SND_BUF (4 * TCP_MSS)
82+
#endif
83+
84+
#if 1
85+
// lwIP takes 26700 bytes; TCP dl/ul are around 750/600 k/s on local network.
86+
#define MEM_SIZE (8000)
87+
#define TCP_MSS (800)
88+
#define TCP_WND (8 * TCP_MSS)
89+
#define TCP_SND_BUF (8 * TCP_MSS)
90+
#define MEMP_NUM_TCP_SEG (32)
91+
#endif
92+
93+
#if 0
94+
// lwIP takes 45600 bytes; TCP dl/ul are around 1200/1000 k/s on local network.
95+
#define MEM_SIZE (16000)
96+
#define TCP_MSS (1460)
97+
#define TCP_WND (8 * TCP_MSS)
98+
#define TCP_SND_BUF (8 * TCP_MSS)
99+
#define MEMP_NUM_TCP_SEG (32)
100+
#endif
101+
102+
#endif // MEM_SIZE
103+
104+
// Needed for PPP.
105+
#define sys_jiffies sys_now
106+
107+
typedef uint32_t sys_prot_t;
108+
109+
#endif // MICROPY_INCLUDED_LWIPOPTS_COMMON_H

ports/mimxrt/lwip_inc/lwipopts.h

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,15 @@
11
#ifndef MICROPY_INCLUDED_MIMXRT_LWIP_LWIPOPTS_H
22
#define MICROPY_INCLUDED_MIMXRT_LWIP_LWIPOPTS_H
33

4-
#include <stdint.h>
5-
6-
// This protection is not needed, instead we execute all lwIP code at PendSV priority
7-
#define SYS_ARCH_DECL_PROTECT(lev) do { } while (0)
8-
#define SYS_ARCH_PROTECT(lev) do { } while (0)
9-
#define SYS_ARCH_UNPROTECT(lev) do { } while (0)
10-
11-
#define NO_SYS 1
12-
#define SYS_LIGHTWEIGHT_PROT 1
13-
#define MEM_ALIGNMENT 4
14-
15-
#define LWIP_CHKSUM_ALGORITHM 3
16-
// The checksum flags are set in eth.c
17-
#define LWIP_CHECKSUM_CTRL_PER_NETIF 1
18-
19-
#define LWIP_ARP 1
20-
#define LWIP_ETHERNET 1
21-
#define LWIP_RAW 1
22-
#define LWIP_NETCONN 0
23-
#define LWIP_SOCKET 0
24-
#define LWIP_STATS 0
25-
#define LWIP_NETIF_HOSTNAME 1
264
#define LWIP_NETIF_EXT_STATUS_CALLBACK 1
275

286
#define LWIP_IPV6 0
29-
#define LWIP_DHCP 1
30-
#define LWIP_DHCP_CHECK_LINK_UP 1
31-
#define LWIP_DHCP_DOES_ACD_CHECK 0 // to speed DHCP up
32-
#define LWIP_DNS 1
33-
#define LWIP_DNS_SUPPORT_MDNS_QUERIES 1
34-
#define LWIP_MDNS_RESPONDER 1
35-
#define LWIP_IGMP 1
367

37-
#define LWIP_NUM_NETIF_CLIENT_DATA LWIP_MDNS_RESPONDER
38-
#define MEMP_NUM_UDP_PCB (4 + LWIP_MDNS_RESPONDER)
39-
#define MEMP_NUM_SYS_TIMEOUT (LWIP_NUM_SYS_TIMEOUT_INTERNAL + LWIP_MDNS_RESPONDER)
40-
41-
#define SO_REUSE 1
42-
#define TCP_LISTEN_BACKLOG 1
43-
44-
extern uint32_t trng_random_u32(void);
458
#define LWIP_RAND() trng_random_u32()
469

47-
// lwip takes 26700 bytes
48-
#define MEM_SIZE (8000)
49-
#define TCP_MSS (800)
50-
#define TCP_WND (8 * TCP_MSS)
51-
#define TCP_SND_BUF (8 * TCP_MSS)
52-
#define MEMP_NUM_TCP_SEG (32)
10+
// Include common lwIP configuration.
11+
#include "extmod/lwip-include/lwipopts_common.h"
5312

54-
typedef uint32_t sys_prot_t;
13+
extern uint32_t trng_random_u32(void);
5514

5615
#endif // MICROPY_INCLUDED_MIMXRT_LWIP_LWIPOPTS_H
Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,8 @@
11
#ifndef MICROPY_INCLUDED_RA_LWIP_LWIPOPTS_H
22
#define MICROPY_INCLUDED_RA_LWIP_LWIPOPTS_H
33

4-
#include <stdint.h>
5-
6-
// This protection is not needed, instead protect lwIP code with flags
7-
#define SYS_ARCH_DECL_PROTECT(lev) do { } while (0)
8-
#define SYS_ARCH_PROTECT(lev) do { } while (0)
9-
#define SYS_ARCH_UNPROTECT(lev) do { } while (0)
10-
11-
#define NO_SYS 1
12-
#define SYS_LIGHTWEIGHT_PROT 1
13-
#define MEM_ALIGNMENT 4
14-
15-
#define LWIP_CHKSUM_ALGORITHM 3
16-
#define LWIP_CHECKSUM_CTRL_PER_NETIF 1
17-
18-
#define LWIP_ARP 1
19-
#define LWIP_ETHERNET 1
20-
#define LWIP_RAW 1
21-
#define LWIP_NETCONN 0
22-
#define LWIP_SOCKET 0
23-
#define LWIP_STATS 0
24-
#define LWIP_NETIF_HOSTNAME 1
25-
264
#define LWIP_IPV6 0
27-
#define LWIP_DHCP 1
28-
#define LWIP_DHCP_CHECK_LINK_UP 1
29-
#define LWIP_DHCP_DOES_ACD_CHECK 0 // to speed DHCP up
30-
#define LWIP_DNS 1
31-
#define LWIP_DNS_SUPPORT_MDNS_QUERIES 1
32-
#define LWIP_MDNS_RESPONDER 1
33-
#define LWIP_IGMP 1
345

35-
#define LWIP_NUM_NETIF_CLIENT_DATA LWIP_MDNS_RESPONDER
36-
#define MEMP_NUM_UDP_PCB (4 + LWIP_MDNS_RESPONDER)
37-
#define MEMP_NUM_SYS_TIMEOUT (LWIP_NUM_SYS_TIMEOUT_INTERNAL + LWIP_MDNS_RESPONDER)
38-
39-
#define SO_REUSE 1
40-
#define TCP_LISTEN_BACKLOG 1
41-
42-
extern uint32_t rng_read(void);
436
#define LWIP_RAND() rng_read()
447

458
#define MEM_SIZE (16 * 1024)
@@ -51,6 +14,9 @@ extern uint32_t rng_read(void);
5114
#define TCP_QUEUE_OOSEQ (1)
5215
#define MEMP_NUM_TCP_SEG (2 * TCP_SND_QUEUELEN)
5316

54-
typedef uint32_t sys_prot_t;
17+
// Include common lwIP configuration.
18+
#include "extmod/lwip-include/lwipopts_common.h"
19+
20+
extern uint32_t rng_read(void);
5521

5622
#endif // MICROPY_INCLUDED_RA_LWIP_LWIPOPTS_H

ports/rp2/lwip_inc/lwipopts.h

Lines changed: 3 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,19 @@
11
#ifndef MICROPY_INCLUDED_RP2_LWIP_LWIPOPTS_H
22
#define MICROPY_INCLUDED_RP2_LWIP_LWIPOPTS_H
33

4-
#include "py/mpconfig.h"
5-
6-
// This protection is not needed, instead protect lwIP code with flags
7-
#define SYS_ARCH_DECL_PROTECT(lev) do { } while (0)
8-
#define SYS_ARCH_PROTECT(lev) do { } while (0)
9-
#define SYS_ARCH_UNPROTECT(lev) do { } while (0)
10-
11-
#define NO_SYS 1
12-
#define SYS_LIGHTWEIGHT_PROT 1
13-
#define MEM_ALIGNMENT 4
14-
15-
#define LWIP_CHKSUM_ALGORITHM 3
16-
// The checksum flags are set in eth.c
17-
#define LWIP_CHECKSUM_CTRL_PER_NETIF 1
18-
19-
#define LWIP_ARP 1
20-
#define LWIP_ETHERNET 1
21-
#define LWIP_RAW 1
22-
#define LWIP_NETCONN 0
23-
#define LWIP_SOCKET 0
24-
#define LWIP_STATS 0
25-
#define LWIP_NETIF_HOSTNAME 1
264
#define LWIP_NETIF_EXT_STATUS_CALLBACK 1
275
#define LWIP_NETIF_STATUS_CALLBACK 1
286

297
#define LWIP_IPV4 1
308
#define LWIP_IPV6 1
319
#define LWIP_ND6_NUM_DESTINATIONS 4
3210
#define LWIP_ND6_QUEUEING 0
33-
#define LWIP_DHCP 1
34-
#define LWIP_DHCP_CHECK_LINK_UP 1
35-
#define LWIP_DHCP_DOES_ACD_CHECK 0 // to speed DHCP up
36-
#define LWIP_DNS 1
37-
#define LWIP_DNS_SUPPORT_MDNS_QUERIES 1
38-
#define LWIP_MDNS_RESPONDER 1
39-
#define LWIP_IGMP 1
40-
41-
#if MICROPY_PY_LWIP_PPP
42-
#define PPP_SUPPORT 1
43-
#define PAP_SUPPORT 1
44-
#define CHAP_SUPPORT 1
45-
#endif
4611

47-
#define LWIP_NUM_NETIF_CLIENT_DATA LWIP_MDNS_RESPONDER
48-
#define MEMP_NUM_UDP_PCB (4 + LWIP_MDNS_RESPONDER)
49-
#define MEMP_NUM_SYS_TIMEOUT (LWIP_NUM_SYS_TIMEOUT_INTERNAL + LWIP_MDNS_RESPONDER)
50-
51-
#define SO_REUSE 1
52-
#define TCP_LISTEN_BACKLOG 1
53-
54-
extern uint32_t rosc_random_u32(void);
5512
#define LWIP_RAND() rosc_random_u32()
5613

57-
// lwip takes 26700 bytes
58-
#define MEM_SIZE (8000)
59-
#define TCP_MSS (800)
60-
#define TCP_WND (8 * TCP_MSS)
61-
#define TCP_SND_BUF (8 * TCP_MSS)
62-
#define MEMP_NUM_TCP_SEG (32)
14+
// Include common lwIP configuration.
15+
#include "extmod/lwip-include/lwipopts_common.h"
6316

64-
typedef uint32_t sys_prot_t;
65-
66-
// Needed for PPP.
67-
#define sys_jiffies sys_now
17+
extern uint32_t rosc_random_u32(void);
6818

6919
#endif // MICROPY_INCLUDED_RP2_LWIP_LWIPOPTS_H

ports/stm32/lwip_inc/lwipopts.h

Lines changed: 3 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,18 @@
11
#ifndef MICROPY_INCLUDED_STM32_LWIP_LWIPOPTS_H
22
#define MICROPY_INCLUDED_STM32_LWIP_LWIPOPTS_H
33

4-
#include "py/mpconfig.h"
5-
6-
// This protection is not needed, instead we execute all lwIP code at PendSV priority
7-
#define SYS_ARCH_DECL_PROTECT(lev) do { } while (0)
8-
#define SYS_ARCH_PROTECT(lev) do { } while (0)
9-
#define SYS_ARCH_UNPROTECT(lev) do { } while (0)
10-
11-
#define NO_SYS 1
12-
#define SYS_LIGHTWEIGHT_PROT 1
13-
#define MEM_ALIGNMENT 4
14-
15-
#define LWIP_CHKSUM_ALGORITHM 3
16-
#define LWIP_CHECKSUM_CTRL_PER_NETIF 1
17-
18-
#define LWIP_ARP 1
19-
#define LWIP_ETHERNET 1
20-
#define LWIP_RAW 1
21-
#define LWIP_NETCONN 0
22-
#define LWIP_SOCKET 0
23-
#define LWIP_STATS 0
24-
#define LWIP_NETIF_HOSTNAME 1
254
#define LWIP_NETIF_EXT_STATUS_CALLBACK 1
265

276
#define LWIP_LOOPIF_MULTICAST 1
287
#define LWIP_LOOPBACK_MAX_PBUFS 8
298

309
#define LWIP_IPV6 0
31-
#define LWIP_DHCP 1
32-
#define LWIP_DHCP_CHECK_LINK_UP 1
33-
#define LWIP_DHCP_DOES_ACD_CHECK 0 // to speed DHCP up
34-
#define LWIP_DNS 1
35-
#define LWIP_DNS_SUPPORT_MDNS_QUERIES 1
36-
#define LWIP_MDNS_RESPONDER 1
37-
#define LWIP_IGMP 1
38-
39-
#if MICROPY_PY_LWIP_PPP
40-
#define PPP_SUPPORT 1
41-
#define PAP_SUPPORT 1
42-
#define CHAP_SUPPORT 1
43-
#endif
44-
45-
#define LWIP_NUM_NETIF_CLIENT_DATA LWIP_MDNS_RESPONDER
46-
#define MEMP_NUM_UDP_PCB (4 + LWIP_MDNS_RESPONDER)
47-
#define MEMP_NUM_SYS_TIMEOUT (LWIP_NUM_SYS_TIMEOUT_INTERNAL + LWIP_MDNS_RESPONDER)
48-
49-
#define SO_REUSE 1
50-
#define TCP_LISTEN_BACKLOG 1
5110

52-
extern uint32_t rng_get(void);
5311
#define LWIP_RAND() rng_get()
5412

55-
// default
56-
// lwip takes 15800 bytes; TCP d/l: 380k/s local, 7.2k/s remote
57-
// TCP u/l is very slow
58-
59-
#if 0
60-
// lwip takes 19159 bytes; TCP d/l and u/l are around 320k/s on local network
61-
#define MEM_SIZE (5000)
62-
#define TCP_WND (4 * TCP_MSS)
63-
#define TCP_SND_BUF (4 * TCP_MSS)
64-
#endif
65-
66-
#if 1
67-
// lwip takes 26700 bytes; TCP dl/ul are around 750/600 k/s on local network
68-
#define MEM_SIZE (8000)
69-
#define TCP_MSS (800)
70-
#define TCP_WND (8 * TCP_MSS)
71-
#define TCP_SND_BUF (8 * TCP_MSS)
72-
#define MEMP_NUM_TCP_SEG (32)
73-
#endif
13+
// Include common lwIP configuration.
14+
#include "extmod/lwip-include/lwipopts_common.h"
7415

75-
#if 0
76-
// lwip takes 45600 bytes; TCP dl/ul are around 1200/1000 k/s on local network
77-
#define MEM_SIZE (16000)
78-
#define TCP_MSS (1460)
79-
#define TCP_WND (8 * TCP_MSS)
80-
#define TCP_SND_BUF (8 * TCP_MSS)
81-
#define MEMP_NUM_TCP_SEG (32)
82-
#endif
83-
84-
typedef uint32_t sys_prot_t;
85-
86-
// Needed for PPP.
87-
#define sys_jiffies sys_now
16+
extern uint32_t rng_get(void);
8817

8918
#endif // MICROPY_INCLUDED_STM32_LWIP_LWIPOPTS_H

0 commit comments

Comments
 (0)