Skip to content

Commit e4103ab

Browse files
author
fpr
committed
DNS, DHCP, TCP & UDP functions under LwIP flags to give clean errors during compilation
Signed-off-by: fpr <[email protected]>
1 parent e08f8d4 commit e4103ab

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

Diff for: libraries/NativeEthernet/src/utility/stm32_eth.c

+27-3
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,10 @@ static void Netif_Config(void)
116116
netif_set_down(&gnetif);
117117
}
118118

119+
#if LWIP_NETIF_LINK_CALLBACK
119120
/* Set the link callback function, this function is called on change of link status */
120121
netif_set_link_callback(&gnetif, ethernetif_update_config);
122+
#endif /* LWIP_NETIF_LINK_CALLBACK */
121123
}
122124

123125
void stm32_eth_init(const uint8_t *mac, const uint8_t *ip, const uint8_t *gw, const uint8_t *netmask)
@@ -132,7 +134,7 @@ void stm32_eth_init(const uint8_t *mac, const uint8_t *ip, const uint8_t *gw, co
132134
if(ip != NULL) {
133135
IP_ADDR4(&(gconfig.ipaddr),ip[0],ip[1],ip[2],ip[3]);
134136
} else {
135-
#ifdef LWIP_DHCP
137+
#if LWIP_DHCP
136138
ip_addr_set_zero_ip4(&(gconfig.ipaddr));
137139
#else
138140
IP_ADDR4(&(gconfig.ipaddr),IP_ADDR0,IP_ADDR1,IP_ADDR2,IP_ADDR3);
@@ -142,7 +144,7 @@ void stm32_eth_init(const uint8_t *mac, const uint8_t *ip, const uint8_t *gw, co
142144
if(gw != NULL) {
143145
IP_ADDR4(&(gconfig.gw),gw[0],gw[1],gw[2],gw[3]);
144146
} else {
145-
#ifdef LWIP_DHCP
147+
#if LWIP_DHCP
146148
ip_addr_set_zero_ip4(&(gconfig.gw));
147149
#else
148150
IP_ADDR4(&(gconfig.gw),GW_ADDR0,GW_ADDR1,GW_ADDR2,GW_ADDR3);
@@ -152,7 +154,7 @@ void stm32_eth_init(const uint8_t *mac, const uint8_t *ip, const uint8_t *gw, co
152154
if(netmask != NULL) {
153155
IP_ADDR4(&(gconfig.netmask),netmask[0],netmask[1],netmask[2],netmask[3]);
154156
} else {
155-
#ifdef LWIP_DHCP
157+
#if LWIP_DHCP
156158
ip_addr_set_zero_ip4(&(gconfig.netmask));
157159
#else
158160
IP_ADDR4(&(gconfig.netmask),NETMASK_ADDR0,NETMASK_ADDR1,NETMASK_ADDR2,NETMASK_ADDR3);
@@ -189,9 +191,13 @@ void stm32_eth_scheduler(void) {
189191
/* Handle LwIP timeouts */
190192
sys_check_timeouts();
191193

194+
#if LWIP_DHCP
192195
stm32_DHCP_Periodic_Handle(&gnetif);
196+
#endif /* LWIP_DHCP */
193197
}
194198

199+
#if LWIP_DHCP
200+
195201
/**
196202
* @brief Returns DHCP activation state
197203
* @param None
@@ -337,6 +343,8 @@ uint8_t stm32_get_DHCP_state(void) {
337343
return DHCP_state;
338344
}
339345

346+
#endif /* LWIP_DHCP */
347+
340348
/**
341349
* @brief Converts IP address in readable format for user.
342350
* @param None
@@ -384,6 +392,8 @@ uint32_t stm32_eth_get_dhcpaddr(void) {
384392
return ip4_addr_get_u32(&(dhcp->server_ip_addr));
385393
}
386394

395+
#if LWIP_NETIF_LINK_CALLBACK
396+
387397
/**
388398
* @brief This function notify user about link status changement.
389399
* @param netif: the network interface
@@ -417,6 +427,8 @@ void ethernetif_notify_conn_changed(struct netif *netif)
417427
}
418428
}
419429

430+
#endif /* LWIP_NETIF_LINK_CALLBACK */
431+
420432
/**
421433
* @brief Notify the User about the nework interface config status
422434
* @param netif: the network interface
@@ -437,6 +449,8 @@ void User_notification(struct netif *netif)
437449
}
438450
}
439451

452+
#if LWIP_DNS
453+
440454
/**
441455
* @brief Initializes DNS
442456
* @param dnsaddr: DNS address
@@ -526,6 +540,8 @@ int8_t stm32_dns_gethostbyname(const char *hostname, uint32_t *ipaddr)
526540
return ret;
527541
}
528542

543+
#endif /* LWIP_DNS */
544+
529545
/**
530546
* @brief Converts a uint8_t IP address to a ip_addr_t address
531547
* @param ipu8: pointer to an address to convert
@@ -665,6 +681,8 @@ uint16_t stm32_get_data(struct pbuf_data *data, uint8_t *buffer, size_t size)
665681
return nb;
666682
}
667683

684+
#if LWIP_UDP
685+
668686
/**
669687
* @brief This function is called when an UDP datagram has been received on
670688
* the port UDP_PORT.
@@ -697,6 +715,10 @@ void udp_receive_callback(void *arg, struct udp_pcb *pcb, struct pbuf *p,
697715
}
698716
}
699717

718+
#endif /* LWIP_UDP */
719+
720+
#if LWIP_TCP
721+
700722
/**
701723
* @brief Function called when TCP connection established
702724
* @param arg: user supplied argument
@@ -946,6 +968,8 @@ static void tcp_connection_close(struct tcp_pcb *tpcb, struct tcp_struct *tcp)
946968
tcp->state = TCP_CLOSING;
947969
}
948970

971+
#endif /* LWIP_TCP */
972+
949973
#ifdef __cplusplus
950974
}
951975
#endif

Diff for: libraries/NativeEthernet/src/utility/stm32_eth.h

+17
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include "lwip/dhcp.h"
4949
#include "lwip/udp.h"
5050
#include "lwip/tcp.h"
51+
#include "lwip/opt.h"
5152

5253
/* Exported types ------------------------------------------------------------*/
5354
/* TCP connection state */
@@ -124,19 +125,31 @@ void stm32_eth_scheduler(void);
124125

125126
void User_notification(struct netif *netif);
126127

128+
#if LWIP_DHCP
127129
void stm32_DHCP_Process(struct netif *netif);
128130
void stm32_DHCP_Periodic_Handle(struct netif *netif);
129131
void stm32_DHCP_manual_config(void);
130132
uint8_t stm32_get_DHCP_lease_state(void);
131133
void stm32_set_DHCP_state(uint8_t state);
132134
uint8_t stm32_get_DHCP_state(void);
133135
uint8_t stm32_dhcp_started(void);
136+
#else
137+
#error "LWIP_DHCP must be enabled in lwipopts.h"
138+
#endif
134139

140+
#if LWIP_DNS
135141
void stm32_dns_init(const uint8_t *dnsaddr);
136142
int8_t stm32_dns_gethostbyname(const char *hostname, uint32_t *ipaddr);
143+
#else
144+
#error "LWIP_DNS must be enabled in lwipopts.h"
145+
#endif
137146

147+
#if LWIP_UDP
138148
void udp_receive_callback(void *arg, struct udp_pcb *pcb, struct pbuf *p,
139149
const ip_addr_t *addr, u16_t port);
150+
#else
151+
#error "LWIP_UDP must be enabled in lwipopts.h"
152+
#endif
140153

141154
uint32_t stm32_eth_get_ipaddr(void);
142155
uint32_t stm32_eth_get_gwaddr(void);
@@ -151,8 +164,12 @@ uint16_t stm32_get_data(struct pbuf_data *data, uint8_t *buffer, size_t size);
151164
ip_addr_t *u8_to_ip_addr(uint8_t *ipu8, ip_addr_t *ipaddr);
152165
uint32_t ip_addr_to_u32(ip_addr_t *ipaddr);
153166

167+
#if LWIP_TCP
154168
err_t tcp_connected_callback(void *arg, struct tcp_pcb *tpcb, err_t err);
155169
err_t tcp_accept_callback(void *arg, struct tcp_pcb *newpcb, err_t err);
170+
#else
171+
#error "LWIP_TCP must be enabled in lwipopts.h"
172+
#endif
156173

157174
#ifdef __cplusplus
158175
}

0 commit comments

Comments
 (0)