STM32Ethernet
Arduino Ethernet library for STM32 boards
Loading...
Searching...
No Matches
stm32_eth.h
Go to the documentation of this file.
1
38#ifndef __STM32_ETH_H__
39#define __STM32_ETH_H__
40
41/* Includes ------------------------------------------------------------------*/
42#include "stm32_def.h"
43#include "lwip/ip_addr.h"
44#include "lwip/dhcp.h"
45#include "lwip/udp.h"
46#include "lwip/tcp.h"
47#include "lwip/opt.h"
48#include <functional>
49
50/* Exported types ------------------------------------------------------------*/
51/* TCP connection state */
60
61/* Struct to store received data */
62struct pbuf_data {
63 struct pbuf *p; // the packet buffer that was received
64 uint16_t available; // number of data
65};
66
67/* UDP structure */
68struct udp_struct {
69 struct udp_pcb *pcb; /* pointer on the current udp_pcb */
71 ip_addr_t ip; // the remote IP address from which the packet was received
72 u16_t port; // the remote port from which the packet was received
73 std::function<void()> onDataArrival;
74};
75
76/* TCP structure */
77struct tcp_struct {
78 struct tcp_pcb *pcb; /* pointer on the current tcp_pcb */
80 tcp_client_states state; /* current connection state */
81};
82
83/* Exported constants --------------------------------------------------------*/
84/*Static IP ADDRESS: IP_ADDR0.IP_ADDR1.IP_ADDR2.IP_ADDR3 */
85#define IP_ADDR0 (uint8_t) 192
86#define IP_ADDR1 (uint8_t) 168
87#define IP_ADDR2 (uint8_t) 0
88#define IP_ADDR3 (uint8_t) 10
89
90/*NETMASK*/
91#define NETMASK_ADDR0 (uint8_t) 255
92#define NETMASK_ADDR1 (uint8_t) 255
93#define NETMASK_ADDR2 (uint8_t) 255
94#define NETMASK_ADDR3 (uint8_t) 0
95
96/*Gateway Address*/
97#define GW_ADDR0 (uint8_t) 192
98#define GW_ADDR1 (uint8_t) 168
99#define GW_ADDR2 (uint8_t) 0
100#define GW_ADDR3 (uint8_t) 1
101
102/* DHCP process states */
103#define DHCP_OFF (uint8_t) 0
104#define DHCP_START (uint8_t) 1
105#define DHCP_WAIT_ADDRESS (uint8_t) 2
106#define DHCP_ADDRESS_ASSIGNED (uint8_t) 3
107#define DHCP_TIMEOUT (uint8_t) 4
108#define DHCP_LINK_DOWN (uint8_t) 5
109#define DHCP_ASK_RELEASE (uint8_t) 6
110
111/* Maximum number of client per server */
112#define MAX_CLIENT 32
113
114#ifdef ETH_INPUT_USE_IT
115 extern struct netif gnetif;
116#endif
117
118
119/* Exported functions ------------------------------------------------------- */
137void stm32_eth_init(const uint8_t *mac, const uint8_t *ip, const uint8_t *gw, const uint8_t *netmask);
143uint8_t stm32_eth_is_init(void);
149void stm32_eth_get_macaddr(uint8_t *mac);
157void stm32_eth_set_macaddr(const uint8_t *mac);
163uint8_t stm32_eth_link_up(void);
170void stm32_eth_scheduler(void);
171
180void User_notification(struct netif *netif);
181
182#if LWIP_DHCP
188 void stm32_DHCP_process(struct netif *netif);
197 void stm32_DHCP_Periodic_Handle(struct netif *netif);
203 void stm32_DHCP_manual_config(void);
209 uint8_t stm32_get_DHCP_lease_state(void);
216 void stm32_set_DHCP_state(uint8_t state);
222 uint8_t stm32_get_DHCP_state(void);
228 uint8_t stm32_dhcp_started(void);
229#else
230 #error "LWIP_DHCP must be enabled in lwipopts.h"
231#endif
232
233#if LWIP_DNS
242 void stm32_dns_init(const uint8_t *dnsaddr);
255 int8_t stm32_dns_gethostbyname(const char *hostname, uint32_t *ipaddr);
256#else
257 #error "LWIP_DNS must be enabled in lwipopts.h"
258#endif
259
260#if LWIP_UDP
273void udp_receive_callback(void *arg, struct udp_pcb *pcb, struct pbuf *p,
274 const ip_addr_t *addr, u16_t port);
275#else
276#error "LWIP_UDP must be enabled in lwipopts.h"
277#endif
278
284uint32_t stm32_eth_get_ipaddr(void);
290uint32_t stm32_eth_get_gwaddr(void);
296uint32_t stm32_eth_get_netmaskaddr(void);
303uint32_t stm32_eth_get_dnsaddr(void);
309uint32_t stm32_eth_get_dhcpaddr(void);
310
323struct pbuf *stm32_new_data(struct pbuf *p, const uint8_t *buffer, size_t size);
330struct pbuf *stm32_free_data(struct pbuf *p);
342uint16_t stm32_get_data(struct pbuf_data *data, uint8_t *buffer, size_t size);
343
351ip_addr_t *u8_to_ip_addr(uint8_t *ipu8, ip_addr_t *ipaddr);
358uint32_t ip_addr_to_u32(ip_addr_t *ipaddr);
359
360#if LWIP_TCP
374 err_t tcp_connected_callback(void *arg, struct tcp_pcb *tpcb, err_t err);
391 err_t tcp_accept_callback(void *arg, struct tcp_pcb *newpcb, err_t err);
401 void tcp_connection_close(struct tcp_pcb *tpcb, struct tcp_struct *tcp);
402#else
403 #error "LWIP_TCP must be enabled in lwipopts.h"
404#endif
405
406#endif /* __STM32_ETH_H__ */
struct netif gnetif
Definition stm32_eth.cpp:88
void stm32_eth_set_macaddr(const uint8_t *mac)
Set the MAC address of the Ethernet interface.
Definition stm32_eth.cpp:273
void stm32_eth_get_macaddr(uint8_t *mac)
Copy the MAC address of the Ethernet interface.
Definition stm32_eth.cpp:277
struct pbuf * stm32_free_data(struct pbuf *p)
Free a pbuf chain.
Definition stm32_eth.cpp:644
uint32_t stm32_eth_get_ipaddr(void)
Return the IPv4 address of the network interface.
Definition stm32_eth.cpp:443
uint32_t stm32_eth_get_dhcpaddr(void)
Return the address of the DHCP server.
Definition stm32_eth.cpp:465
void stm32_eth_scheduler(void)
Run one LwIP scheduler pass.
Definition stm32_eth.cpp:287
uint16_t stm32_get_data(struct pbuf_data *data, uint8_t *buffer, size_t size)
Copy received data from a pbuf_data into a user buffer.
Definition stm32_eth.cpp:660
ip_addr_t * u8_to_ip_addr(uint8_t *ipu8, ip_addr_t *ipaddr)
Convert an IPv4 address from 4 bytes into an ip_addr_t.
Definition stm32_eth.cpp:595
uint8_t stm32_eth_is_init(void)
Check whether the Ethernet interface has been initialized.
Definition stm32_eth.cpp:268
tcp_client_states
Definition stm32_eth.h:52
@ TCP_RECEIVED
Definition stm32_eth.h:55
@ TCP_CLOSING
Definition stm32_eth.h:58
@ TCP_CONNECTED
Definition stm32_eth.h:54
@ TCP_ACCEPTED
Definition stm32_eth.h:57
@ TCP_NONE
Definition stm32_eth.h:53
@ TCP_SENT
Definition stm32_eth.h:56
uint32_t stm32_eth_get_netmaskaddr(void)
Return the netmask of the network interface.
Definition stm32_eth.cpp:453
uint32_t stm32_eth_get_gwaddr(void)
Return the gateway address of the network interface.
Definition stm32_eth.cpp:448
void User_notification(struct netif *netif)
Notify the user about the network interface status.
Definition stm32_eth.cpp:499
uint32_t ip_addr_to_u32(ip_addr_t *ipaddr)
Convert an ip_addr_t IPv4 address into a uint32_t.
Definition stm32_eth.cpp:601
uint32_t stm32_eth_get_dnsaddr(void)
Return the first DNS server address.
Definition stm32_eth.cpp:458
struct pbuf * stm32_new_data(struct pbuf *p, const uint8_t *buffer, size_t size)
Allocate a pbuf holding the given data.
Definition stm32_eth.cpp:606
void stm32_eth_init(const uint8_t *mac, const uint8_t *ip, const uint8_t *gw, const uint8_t *netmask)
Initialize the Ethernet interface and the LwIP stack.
Definition stm32_eth.cpp:209
uint8_t stm32_eth_link_up(void)
Check whether the Ethernet link is up.
Definition stm32_eth.cpp:282
Definition stm32_eth.h:62
struct pbuf * p
Definition stm32_eth.h:63
uint16_t available
Definition stm32_eth.h:64
Definition stm32_eth.h:77
struct pbuf_data data
Definition stm32_eth.h:79
struct tcp_pcb * pcb
Definition stm32_eth.h:78
tcp_client_states state
Definition stm32_eth.h:80
Definition stm32_eth.h:68
struct pbuf_data data
Definition stm32_eth.h:70
ip_addr_t ip
Definition stm32_eth.h:71
u16_t port
Definition stm32_eth.h:72
std::function< void()> onDataArrival
Definition stm32_eth.h:73
struct udp_pcb * pcb
Definition stm32_eth.h:69