Skip to content

Commit 81ae2c0

Browse files
Reduce LWIP flash 5.4K by cleaning debug prints
In non-debug cases the string to `panic()` isn't actually sent to the Serial port, or anywhere in fact. When there is no debug port defined, replace the panic(str) of LWIP_PLATFORM_ASSERT with panic("lwip") instead. This doesn't effect debugging because the source line of the LWIP_ASSERT will still show the full string (GDB shows the source). Also, LWIP_DEBUG is a flag by definition, not value, so fix lwipopts.h to not define it or the LWIP_X debug defines unless LWIP_DEBUG is set by the compliation. Saves 5480 bytes of flash for LWIP (Pico W, 2W, Ethernet) apps.
1 parent 0234b2f commit 81ae2c0

File tree

1 file changed

+34
-32
lines changed

1 file changed

+34
-32
lines changed

include/lwipopts.h

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ extern void interrupts();
1111
#define SYS_ARCH_PROTECT(lev) {(void) lev; noInterrupts();}
1212
#define SYS_ARCH_UNPROTECT(lev) {(void) lev; interrupts();}
1313

14+
#ifndef DEBUG_RP2040_PORT
15+
extern void panic(const char *fmt, ...);
16+
#define LWIP_PLATFORM_ASSERT(x) panic("lwip")
17+
#endif
18+
1419
extern unsigned long __lwip_rand(void);
1520
#define LWIP_RAND() __lwip_rand()
1621

@@ -77,38 +82,6 @@ extern void __setSystemTime(unsigned long long sec, unsigned long us);
7782
#define SNTP_SERVER_DNS 1
7883

7984
#ifndef LWIP_DEBUG
80-
#define LWIP_DEBUG 0
81-
#endif
82-
#define ETHARP_DEBUG (LWIP_DEBUG ? LWIP_DBG_ON : LWIP_DBG_OFF)
83-
#define NETIF_DEBUG (LWIP_DEBUG ? LWIP_DBG_ON : LWIP_DBG_OFF)
84-
#define PBUF_DEBUG (LWIP_DEBUG ? LWIP_DBG_ON : LWIP_DBG_OFF)
85-
#define API_LIB_DEBUG (LWIP_DEBUG ? LWIP_DBG_ON : LWIP_DBG_OFF)
86-
#define API_MSG_DEBUG (LWIP_DEBUG ? LWIP_DBG_ON : LWIP_DBG_OFF)
87-
#define SOCKETS_DEBUG (LWIP_DEBUG ? LWIP_DBG_ON : LWIP_DBG_OFF)
88-
#define ICMP_DEBUG (LWIP_DEBUG ? LWIP_DBG_ON : LWIP_DBG_OFF)
89-
#define INET_DEBUG (LWIP_DEBUG ? LWIP_DBG_ON : LWIP_DBG_OFF)
90-
#define IP_DEBUG (LWIP_DEBUG ? LWIP_DBG_ON : LWIP_DBG_OFF)
91-
#define IP_REASS_DEBUG (LWIP_DEBUG ? LWIP_DBG_ON : LWIP_DBG_OFF)
92-
#define RAW_DEBUG (LWIP_DEBUG ? LWIP_DBG_ON : LWIP_DBG_OFF)
93-
#define MEM_DEBUG (LWIP_DEBUG ? LWIP_DBG_ON : LWIP_DBG_OFF)
94-
#define MEMP_DEBUG (LWIP_DEBUG ? LWIP_DBG_ON : LWIP_DBG_OFF)
95-
#define SYS_DEBUG (LWIP_DEBUG ? LWIP_DBG_ON : LWIP_DBG_OFF)
96-
#define TCP_DEBUG (LWIP_DEBUG ? LWIP_DBG_ON : LWIP_DBG_OFF)
97-
#define TCP_INPUT_DEBUG (LWIP_DEBUG ? LWIP_DBG_ON : LWIP_DBG_OFF)
98-
#define TCP_OUTPUT_DEBUG (LWIP_DEBUG ? LWIP_DBG_ON : LWIP_DBG_OFF)
99-
#define TCP_RTO_DEBUG (LWIP_DEBUG ? LWIP_DBG_ON : LWIP_DBG_OFF)
100-
#define TCP_CWND_DEBUG (LWIP_DEBUG ? LWIP_DBG_ON : LWIP_DBG_OFF)
101-
#define TCP_WND_DEBUG (LWIP_DEBUG ? LWIP_DBG_ON : LWIP_DBG_OFF)
102-
#define TCP_FR_DEBUG (LWIP_DEBUG ? LWIP_DBG_ON : LWIP_DBG_OFF)
103-
#define TCP_QLEN_DEBUG (LWIP_DEBUG ? LWIP_DBG_ON : LWIP_DBG_OFF)
104-
#define TCP_RST_DEBUG (LWIP_DEBUG ? LWIP_DBG_ON : LWIP_DBG_OFF)
105-
#define UDP_DEBUG (LWIP_DEBUG ? LWIP_DBG_ON : LWIP_DBG_OFF)
106-
#define TCPIP_DEBUG (LWIP_DEBUG ? LWIP_DBG_ON : LWIP_DBG_OFF)
107-
#define PPP_DEBUG (LWIP_DEBUG ? LWIP_DBG_ON : LWIP_DBG_OFF)
108-
#define SLIP_DEBUG (LWIP_DEBUG ? LWIP_DBG_ON : LWIP_DBG_OFF)
109-
#define DHCP_DEBUG (LWIP_DEBUG ? LWIP_DBG_ON : LWIP_DBG_OFF)
110-
111-
#if !LWIP_DEBUG
11285
#define LWIP_STATS 0
11386
#define LWIP_STATS_DISPLAY 0
11487
#define MEM_STATS 0
@@ -122,8 +95,37 @@ extern void __setSystemTime(unsigned long long sec, unsigned long us);
12295
#define SYS_STATS 1
12396
#define MEMP_STATS 1
12497
#define LINK_STATS 1
98+
#define ETHARP_DEBUG LWIP_DBG_ON
99+
#define NETIF_DEBUG LWIP_DBG_ON
100+
#define PBUF_DEBUG LWIP_DBG_ON
101+
#define API_LIB_DEBUG LWIP_DBG_ON
102+
#define API_MSG_DEBUG LWIP_DBG_ON
103+
#define SOCKETS_DEBUG LWIP_DBG_ON
104+
#define ICMP_DEBUG LWIP_DBG_ON
105+
#define INET_DEBUG LWIP_DBG_ON
106+
#define IP_DEBUG LWIP_DBG_ON
107+
#define IP_REASS_DEBUG LWIP_DBG_ON
108+
#define RAW_DEBUG LWIP_DBG_ON
109+
#define MEM_DEBUG LWIP_DBG_ON
110+
#define MEMP_DEBUG LWIP_DBG_ON
111+
#define SYS_DEBUG LWIP_DBG_ON
112+
#define TCP_DEBUG LWIP_DBG_ON
113+
#define TCP_INPUT_DEBUG LWIP_DBG_ON
114+
#define TCP_OUTPUT_DEBUG LWIP_DBG_ON
115+
#define TCP_RTO_DEBUG LWIP_DBG_ON
116+
#define TCP_CWND_DEBUG LWIP_DBG_ON
117+
#define TCP_WND_DEBUG LWIP_DBG_ON
118+
#define TCP_FR_DEBUG LWIP_DBG_ON
119+
#define TCP_QLEN_DEBUG LWIP_DBG_ON
120+
#define TCP_RST_DEBUG LWIP_DBG_ON
121+
#define UDP_DEBUG LWIP_DBG_ON
122+
#define TCPIP_DEBUG LWIP_DBG_ON
123+
#define PPP_DEBUG LWIP_DBG_ON
124+
#define SLIP_DEBUG LWIP_DBG_ON
125+
#define DHCP_DEBUG LWIP_DBG_ON
125126
#endif
126127

128+
127129
#ifdef __cplusplus
128130
}
129131
#endif // __cplusplus

0 commit comments

Comments
 (0)