This file implements Ethernet network interface drivers for Arduino STM32Ethernet library. More...
#include "Arduino.h"#include "stm32_eth.h"#include "lwip/init.h"#include "lwip/netif.h"#include "lwip/timeouts.h"#include "netif/ethernet.h"#include "ethernetif.h"#include "lwip/dhcp.h"#include "lwip/prot/dhcp.h"#include "lwip/dns.h"
Classes | |
| struct | stm32_eth_config |
Macros | |
| #define | TIME_CHECK_ETH_LINK_STATE 500U |
| #define | TIMEOUT_DNS_REQUEST 10000U |
| #define | MAX_DHCP_TRIES 4 |
| #define | DEFAULT_ETHERNET_TIMER TIM14 |
| #define | ETH_TIM_IRQ_PRIO 15 |
| #define | ETH_TIM_IRQ_SUBPRIO 0 |
Functions | |
| void | _stm32_eth_scheduler (void) |
| Run one LwIP scheduler pass. | |
| 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_set_macaddr (const uint8_t *mac) |
| Set the MAC address of the Ethernet interface. | |
| void | stm32_eth_get_macaddr (uint8_t *mac) |
| Copy 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. | |
| 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. | |
| void | User_notification (struct netif *netif) |
| Notify the user about the network interface status. | |
| 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. | |
| 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. | |
Variables | |
| struct netif | gnetif |
| __IO uint8_t | DHCP_state = DHCP_OFF |
This file implements Ethernet network interface drivers for Arduino STM32Ethernet library.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
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.
| #define DEFAULT_ETHERNET_TIMER TIM14 |
| #define ETH_TIM_IRQ_PRIO 15 |
| #define ETH_TIM_IRQ_SUBPRIO 0 |
| #define MAX_DHCP_TRIES 4 |
| #define TIME_CHECK_ETH_LINK_STATE 500U |
| #define TIMEOUT_DNS_REQUEST 10000U |
| void _stm32_eth_scheduler | ( | void | ) |
Run one LwIP scheduler pass.
Reads received packets (unless ETH_INPUT_USE_IT is defined), checks the link status every TIME_CHECK_ETH_LINK_STATE ms, handles LwIP timeouts and runs the periodic DHCP processing. Called by the timer callback and, on older cores, by stm32_eth_scheduler().
| uint32_t ip_addr_to_u32 | ( | ip_addr_t * | ipaddr | ) |
Convert an ip_addr_t IPv4 address into a uint32_t.
| ipaddr | Address to convert. |
| uint32_t stm32_eth_get_dhcpaddr | ( | void | ) |
Return the address of the DHCP server.
| uint32_t stm32_eth_get_dnsaddr | ( | void | ) |
Return the first DNS server address.
| uint32_t stm32_eth_get_gwaddr | ( | void | ) |
Return the gateway address of the network interface.
| uint32_t stm32_eth_get_ipaddr | ( | void | ) |
Return the IPv4 address of the network interface.
| void stm32_eth_get_macaddr | ( | uint8_t * | mac | ) |
Copy the MAC address of the Ethernet interface.
| mac | Receives the MAC address (6 bytes). Nothing is copied if NULL. |
| uint32_t stm32_eth_get_netmaskaddr | ( | void | ) |
Return the netmask of the network interface.
| 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 | MAC address (6 bytes), or NULL to keep the default MAC address. |
| ip | IPv4 address (4 bytes), or NULL for the default. |
| gw | Gateway address (4 bytes), or NULL for the default. |
| netmask | Netmask (4 bytes), or NULL for the default. |
| uint8_t stm32_eth_is_init | ( | void | ) |
Check whether the Ethernet interface has been initialized.
| uint8_t stm32_eth_link_up | ( | void | ) |
Check whether the Ethernet link is up.
| 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.
| 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.
| mac | MAC address (6 bytes). Ignored if NULL. |
| struct pbuf * stm32_free_data | ( | struct pbuf * | p | ) |
Free a pbuf chain.
| p | Pbuf to free; NULL is ignored. |
| 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.
| data | Source of the received data. |
| buffer | Destination buffer. |
| size | Maximum number of bytes to copy. |
| 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.
| p | Existing pbuf to extend, or NULL to create a new one. |
| buffer | Data to store. |
| size | Number of bytes to store from 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.
| ipu8 | Address bytes (4 bytes). |
| ipaddr | Receives the converted address. |
| 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.
| netif | Network interface to check. |
| __IO uint8_t DHCP_state = DHCP_OFF |
| struct netif gnetif |