STM32Ethernet
Arduino Ethernet library for STM32 boards
Loading...
Searching...
No Matches
ethernetif.cpp File Reference

This file implements Ethernet network interface drivers for lwIP. More...

#include "stm32_def.h"
#include "lwip/timeouts.h"
#include "netif/etharp.h"
#include "ethernetif.h"
#include <string.h>
#include "PeripheralPins.h"
#include "lwip/igmp.h"
#include "stm32_eth.h"
#include "variant.h"
Include dependency graph for ethernetif.cpp:

Macros

#define IFNAME0   's'
 
#define IFNAME1   't'
 
#define PHY_SR_AUTODONE   ((uint16_t)0x1000)
 
#define MAC_ADDR0   0x00
 
#define MAC_ADDR1   0x80
 
#define MAC_ADDR2   0xE1
 
#define MAC_ADDR3   ((uint8_t)(((*(uint32_t *)UID_BASE) & 0x00FF0000) >> 16))
 
#define MAC_ADDR4   ((uint8_t)(((*(uint32_t *)UID_BASE) & 0x0000FF00) >> 8))
 
#define MAC_ADDR5   ((uint8_t)((*(uint32_t *)UID_BASE) & 0x000000FF))
 

Functions

void HAL_ETH_MspInit (ETH_HandleTypeDef *heth)
 Initialize the ETH MSP.
 
void ethernetif_input (struct netif *netif)
 Read one received frame from the MAC and pass it to LwIP.
 
uint8_t ethernetif_is_init (void)
 Check whether the Ethernet hardware has been initialized.
 
err_t ethernetif_init (struct netif *netif)
 LwIP network interface initialization callback.
 
u32_t sys_now (void)
 Return the current time in milliseconds.
 
void ethernetif_set_link (struct netif *netif)
 Poll the PHY and update the LwIP link state of the interface.
 
void ethernetif_update_config (struct netif *netif)
 Apply the PHY auto-negotiation result to the MAC.
 
__weak void ethernetif_notify_conn_changed (struct netif *netif)
 Notify the user that the link status has changed.
 
void ethernetif_set_mac_addr (const uint8_t *mac)
 Set the MAC address used by the driver.
 
void ethernetif_get_mac_addr (uint8_t *mac)
 Copy the MAC address used by the driver.
 

Variables

ETH_DMADescTypeDef DMARxDscrTab [ETH_RXBUFNB]
 
ETH_DMADescTypeDef DMATxDscrTab [ETH_TXBUFNB]
 
uint8_t Rx_Buff [ETH_RXBUFNB][ETH_RX_BUF_SIZE]
 
uint8_t Tx_Buff [ETH_TXBUFNB][ETH_TX_BUF_SIZE]
 

Detailed Description

This file implements Ethernet network interface drivers for lwIP.

Author
MCD Application Team & Wi6Labs
Version
V1.5.0
Date
20-june-2017
Attention

© Copyright (c) 2017 STMicroelectronics International N.V. All rights reserved.

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

  1. Redistribution 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 other contributors to this software may be used to endorse or promote products derived from this software without specific written permission.
  4. This software, including modifications and/or derivative works of this software, must execute solely and exclusively on microcontroller or microprocessor devices manufactured by or for STMicroelectronics.
  5. Redistribution and use of this software other than as permitted under this license is void and will automatically terminate your rights under this license.

THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT SHALL STMICROELECTRONICS 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

◆ IFNAME0

#define IFNAME0   's'

◆ IFNAME1

#define IFNAME1   't'

◆ MAC_ADDR0

#define MAC_ADDR0   0x00

◆ MAC_ADDR1

#define MAC_ADDR1   0x80

◆ MAC_ADDR2

#define MAC_ADDR2   0xE1

◆ MAC_ADDR3

#define MAC_ADDR3   ((uint8_t)(((*(uint32_t *)UID_BASE) & 0x00FF0000) >> 16))

◆ MAC_ADDR4

#define MAC_ADDR4   ((uint8_t)(((*(uint32_t *)UID_BASE) & 0x0000FF00) >> 8))

◆ MAC_ADDR5

#define MAC_ADDR5   ((uint8_t)((*(uint32_t *)UID_BASE) & 0x000000FF))

◆ PHY_SR_AUTODONE

#define PHY_SR_AUTODONE   ((uint16_t)0x1000)

Function Documentation

◆ ethernetif_get_mac_addr()

void ethernetif_get_mac_addr ( uint8_t *  mac)

Copy the MAC address used by the driver.

Parameters
macBuffer of at least 6 bytes that receives the address. Nothing is copied if NULL.

◆ ethernetif_init()

err_t ethernetif_init ( struct netif *  netif)

LwIP network interface initialization callback.

Sets the interface name, the output functions and initializes the Ethernet hardware. Pass it to netif_add().

Parameters
netifThe LwIP network interface to initialize.
Returns
ERR_OK.

◆ ethernetif_input()

void ethernetif_input ( struct netif *  netif)

Read one received frame from the MAC and pass it to LwIP.

Does nothing when no frame is available. If netif->input() fails, the frame is dropped.

Parameters
netifThe LwIP network interface.

◆ ethernetif_is_init()

uint8_t ethernetif_is_init ( void  )

Check whether the Ethernet hardware has been initialized.

Returns
1 if initialized, 0 otherwise.

◆ ethernetif_notify_conn_changed()

__weak void ethernetif_notify_conn_changed ( struct netif *  netif)

Notify the user that the link status has changed.

Weak function. The default implementation does nothing, and user code can override it.

Parameters
netifThe LwIP network interface. Not used by the default implementation.

◆ ethernetif_set_link()

void ethernetif_set_link ( struct netif *  netif)

Poll the PHY and update the LwIP link state of the interface.

The link is set down when the PHY reports a link-change interrupt, and up when the PHY reports a linked state. With LWIP_IGMP, IGMP is started on the first link-up.

Parameters
netifThe LwIP network interface.

◆ ethernetif_set_mac_addr()

void ethernetif_set_mac_addr ( const uint8_t *  mac)

Set the MAC address used by the driver.

Call it before ethernetif_init(). The address is copied only while the driver is not initialized.

Parameters
mac6-byte MAC address. Ignored if NULL.

◆ ethernetif_update_config()

void ethernetif_update_config ( struct netif *  netif)

Apply the PHY auto-negotiation result to the MAC.

Restarts the MAC with the negotiated duplex and speed, or stops the MAC when the link is down. If auto-negotiation is disabled or has not completed, the configured duplex and speed are used. Calls ethernetif_notify_conn_changed() at the end. Call it when the link status changes.

Parameters
netifThe LwIP network interface.

◆ HAL_ETH_MspInit()

void HAL_ETH_MspInit ( ETH_HandleTypeDef *  heth)

Initialize the ETH MSP.

Configures the GPIO pins listed in PinMap_Ethernet as alternate functions, enables the ETH interrupt when ETH_INPUT_USE_IT is defined, and enables the ETH peripheral clock.

Parameters
hethETH handle. Not used.

◆ sys_now()

u32_t sys_now ( void  )

Return the current time in milliseconds.

Used by LwIP when LWIP_TIMERS is 1 and NO_SYS is 1.

Returns
Current time in milliseconds, from HAL_GetTick().

Variable Documentation

◆ DMARxDscrTab

ETH_DMADescTypeDef DMARxDscrTab[ETH_RXBUFNB]

< IAR Compiler

◆ DMATxDscrTab

ETH_DMADescTypeDef DMATxDscrTab[ETH_TXBUFNB]

< IAR Compiler

◆ Rx_Buff

uint8_t Rx_Buff[ETH_RXBUFNB][ETH_RX_BUF_SIZE]

< IAR Compiler

◆ Tx_Buff

uint8_t Tx_Buff[ETH_TXBUFNB][ETH_TX_BUF_SIZE]

< IAR Compiler