STM32Ethernet
Arduino Ethernet library for STM32 boards
Loading...
Searching...
No Matches
stm32_eth.h File Reference

Include stm32_eth source files. More...

#include "stm32_def.h"
#include "lwip/ip_addr.h"
#include "lwip/dhcp.h"
#include "lwip/udp.h"
#include "lwip/tcp.h"
#include "lwip/opt.h"
#include <functional>
Include dependency graph for stm32_eth.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  pbuf_data
 
struct  udp_struct
 
struct  tcp_struct
 

Macros

#define IP_ADDR0   (uint8_t) 192
 
#define IP_ADDR1   (uint8_t) 168
 
#define IP_ADDR2   (uint8_t) 0
 
#define IP_ADDR3   (uint8_t) 10
 
#define NETMASK_ADDR0   (uint8_t) 255
 
#define NETMASK_ADDR1   (uint8_t) 255
 
#define NETMASK_ADDR2   (uint8_t) 255
 
#define NETMASK_ADDR3   (uint8_t) 0
 
#define GW_ADDR0   (uint8_t) 192
 
#define GW_ADDR1   (uint8_t) 168
 
#define GW_ADDR2   (uint8_t) 0
 
#define GW_ADDR3   (uint8_t) 1
 
#define DHCP_OFF   (uint8_t) 0
 
#define DHCP_START   (uint8_t) 1
 
#define DHCP_WAIT_ADDRESS   (uint8_t) 2
 
#define DHCP_ADDRESS_ASSIGNED   (uint8_t) 3
 
#define DHCP_TIMEOUT   (uint8_t) 4
 
#define DHCP_LINK_DOWN   (uint8_t) 5
 
#define DHCP_ASK_RELEASE   (uint8_t) 6
 
#define MAX_CLIENT   32
 

Enumerations

enum  tcp_client_states {
  TCP_NONE = 0 , TCP_CONNECTED , TCP_RECEIVED , TCP_SENT ,
  TCP_ACCEPTED , TCP_CLOSING
}
 

Functions

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.
 
uint8_t stm32_eth_is_init (void)
 Check whether the Ethernet interface has been initialized.
 
void stm32_eth_get_macaddr (uint8_t *mac)
 Copy the MAC address of the Ethernet interface.
 
void stm32_eth_set_macaddr (const uint8_t *mac)
 Set the MAC address of the Ethernet interface.
 
uint8_t stm32_eth_link_up (void)
 Check whether the Ethernet link is up.
 
void stm32_eth_scheduler (void)
 Run one LwIP scheduler pass.
 
void User_notification (struct netif *netif)
 Notify the user about the network interface status.
 
uint32_t stm32_eth_get_ipaddr (void)
 Return the IPv4 address of the network interface.
 
uint32_t stm32_eth_get_gwaddr (void)
 Return the gateway address of the network interface.
 
uint32_t stm32_eth_get_netmaskaddr (void)
 Return the netmask of the network interface.
 
uint32_t stm32_eth_get_dnsaddr (void)
 Return the first DNS server address.
 
uint32_t stm32_eth_get_dhcpaddr (void)
 Return the address of the DHCP server.
 
struct pbuf * stm32_new_data (struct pbuf *p, const uint8_t *buffer, size_t size)
 Allocate a pbuf holding the given data.
 
struct pbuf * stm32_free_data (struct pbuf *p)
 Free a pbuf chain.
 
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.
 
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.
 
uint32_t ip_addr_to_u32 (ip_addr_t *ipaddr)
 Convert an ip_addr_t IPv4 address into a uint32_t.
 

Detailed Description

Include stm32_eth source files.

Author
WI6LABS
Version
V1.0.0
Date
24-May-2017
Attention

© COPYRIGHT(c) 2016 STMicroelectronics

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of STMicroelectronics nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Macro Definition Documentation

◆ DHCP_ADDRESS_ASSIGNED

#define DHCP_ADDRESS_ASSIGNED   (uint8_t) 3

◆ DHCP_ASK_RELEASE

#define DHCP_ASK_RELEASE   (uint8_t) 6

◆ DHCP_LINK_DOWN

#define DHCP_LINK_DOWN   (uint8_t) 5

◆ DHCP_OFF

#define DHCP_OFF   (uint8_t) 0

◆ DHCP_START

#define DHCP_START   (uint8_t) 1

◆ DHCP_TIMEOUT

#define DHCP_TIMEOUT   (uint8_t) 4

◆ DHCP_WAIT_ADDRESS

#define DHCP_WAIT_ADDRESS   (uint8_t) 2

◆ GW_ADDR0

#define GW_ADDR0   (uint8_t) 192

◆ GW_ADDR1

#define GW_ADDR1   (uint8_t) 168

◆ GW_ADDR2

#define GW_ADDR2   (uint8_t) 0

◆ GW_ADDR3

#define GW_ADDR3   (uint8_t) 1

◆ IP_ADDR0

#define IP_ADDR0   (uint8_t) 192

◆ IP_ADDR1

#define IP_ADDR1   (uint8_t) 168

◆ IP_ADDR2

#define IP_ADDR2   (uint8_t) 0

◆ IP_ADDR3

#define IP_ADDR3   (uint8_t) 10

◆ MAX_CLIENT

#define MAX_CLIENT   32

◆ NETMASK_ADDR0

#define NETMASK_ADDR0   (uint8_t) 255

◆ NETMASK_ADDR1

#define NETMASK_ADDR1   (uint8_t) 255

◆ NETMASK_ADDR2

#define NETMASK_ADDR2   (uint8_t) 255

◆ NETMASK_ADDR3

#define NETMASK_ADDR3   (uint8_t) 0

Enumeration Type Documentation

◆ tcp_client_states

Enumerator
TCP_NONE 
TCP_CONNECTED 
TCP_RECEIVED 
TCP_SENT 
TCP_ACCEPTED 
TCP_CLOSING 

Function Documentation

◆ ip_addr_to_u32()

uint32_t ip_addr_to_u32 ( ip_addr_t *  ipaddr)

Convert an ip_addr_t IPv4 address into a uint32_t.

Parameters
ipaddrAddress to convert.
Returns
The address as a uint32_t (raw network byte order).

◆ stm32_eth_get_dhcpaddr()

uint32_t stm32_eth_get_dhcpaddr ( void  )

Return the address of the DHCP server.

Returns
DHCP server address as a uint32_t (raw network byte order).

◆ stm32_eth_get_dnsaddr()

uint32_t stm32_eth_get_dnsaddr ( void  )

Return the first DNS server address.

Returns
DNS server address (server 0) as a uint32_t (raw network byte order).

◆ stm32_eth_get_gwaddr()

uint32_t stm32_eth_get_gwaddr ( void  )

Return the gateway address of the network interface.

Returns
Gateway address as a uint32_t (raw network byte order).

◆ stm32_eth_get_ipaddr()

uint32_t stm32_eth_get_ipaddr ( void  )

Return the IPv4 address of the network interface.

Returns
Address as a uint32_t (raw network byte order).

◆ stm32_eth_get_macaddr()

void stm32_eth_get_macaddr ( uint8_t *  mac)

Copy the MAC address of the Ethernet interface.

Parameters
macReceives the MAC address (6 bytes). Nothing is copied if NULL.

◆ stm32_eth_get_netmaskaddr()

uint32_t stm32_eth_get_netmaskaddr ( void  )

Return the netmask of the network interface.

Returns
Netmask as a uint32_t (raw network byte order).

◆ stm32_eth_init()

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.

LwIP initialization and the scheduler timer setup run only on the first call. Every call reconfigures the network interface and runs one scheduler pass.

A NULL argument selects the default value:

  • mac: the MAC address is left unchanged.
  • ip, gw, netmask: set to zero when LWIP_DHCP is enabled, otherwise to the compile-time defaults (IP_ADDR*, GW_ADDR*, NETMASK_ADDR*).
Parameters
macMAC address (6 bytes), or NULL to keep the default MAC address.
ipIPv4 address (4 bytes), or NULL for the default.
gwGateway address (4 bytes), or NULL for the default.
netmaskNetmask (4 bytes), or NULL for the default.

◆ stm32_eth_is_init()

uint8_t stm32_eth_is_init ( void  )

Check whether the Ethernet interface has been initialized.

Returns
1 if the Ethernet hardware is initialized, 0 otherwise.

◆ stm32_eth_link_up()

uint8_t stm32_eth_link_up ( void  )

Check whether the Ethernet link is up.

Returns
Non-zero if the link is up, 0 otherwise.

◆ stm32_eth_scheduler()

void stm32_eth_scheduler ( void  )

Run one LwIP scheduler pass.

Reads received packets (unless ETH_INPUT_USE_IT is defined), checks the link status, handles LwIP timeouts and runs the periodic DHCP processing.

◆ stm32_eth_set_macaddr()

void stm32_eth_set_macaddr ( const uint8_t *  mac)

Set the MAC address of the Ethernet interface.

The address is stored only before the interface is initialized.

Parameters
macMAC address (6 bytes). Ignored if NULL.

◆ stm32_free_data()

struct pbuf * stm32_free_data ( struct pbuf *  p)

Free a pbuf chain.

Parameters
pPbuf to free; NULL is ignored.
Returns
Always NULL.

◆ stm32_get_data()

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.

Frees the pbufs that are fully consumed.

Parameters
dataSource of the received data.
bufferDestination buffer.
sizeMaximum number of bytes to copy.
Returns
Number of bytes copied, or 0 on invalid arguments or when no data is available.

◆ stm32_new_data()

struct pbuf * stm32_new_data ( struct pbuf *  p,
const uint8_t *  buffer,
size_t  size 
)

Allocate a pbuf holding the given data.

If p is NULL, allocates a new pbuf and copies buffer into it. Otherwise, allocates a larger pbuf, copies the contents of p and appends buffer, then frees p. On failure, returns NULL and leaves p unchanged.

Parameters
pExisting pbuf to extend, or NULL to create a new one.
bufferData to store.
sizeNumber of bytes to store from buffer.
Returns
Pointer to the pbuf holding the data, or NULL on failure.

◆ u8_to_ip_addr()

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.

Parameters
ipu8Address bytes (4 bytes).
ipaddrReceives the converted address.
Returns
Pointer to ipaddr.

◆ User_notification()

void User_notification ( struct netif *  netif)

Notify the user about the network interface status.

If the interface is down and DHCP was started by the user, sets the DHCP state to DHCP_LINK_DOWN.

Parameters
netifNetwork interface to check.