Add ESP32 Ethernet device driver

This driver was implemented by Dong Heng<dongheng@espressif.com>
and reviewed by Alan Carvalho de Assis
This commit is contained in:
Alan C. Assis
2020-08-06 14:50:44 -03:00
committed by Abdelatif Guettouche
parent e1d3627bb1
commit 6ea7b29088
9 changed files with 3022 additions and 84 deletions
-70
View File
@@ -1,70 +0,0 @@
/****************************************************************************
* arch/xtensa/src/common/xtensa_etherstub.c
*
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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 NuttX 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 OWNER 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include "xtensa.h"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: up_netinitialize (stub)
*
* Description:
* This is a stub version os up_netinitialize. Normally, up_netinitialize
* is defined in board/xyz_network.c for board-specific Ethernet
* implementations, or chip/xyx_ethernet.c for chip-specific Ethernet
* implementations. The stub version here is used in the corner case where
* the network is enable yet there is no Ethernet driver to be initialized.
* In this case, up_initialize will still try to call up_netinitialize()
* when one does not exist. This corner case would occur if, for example,
* only a USB network interface is being used or perhaps if a SLIP is
* being used).
*
* Use of this stub is deprecated. The preferred mechanism is to use
* CONFIG_NETDEV_LATEINIT=y to suppress the call to up_netinitialize() in
* up_initialize(). Then this stub would not be needed.
*
****************************************************************************/
void up_netinitialize(void)
{
}
+37 -2
View File
@@ -21,9 +21,9 @@ config ESP32_BT
config ESP32_EMAC
bool "Ethernet MAC"
default n
depends on EXPERIMENTAL
select NET
---help---
No yet implemented
Enable ESP32 ethernet support.
config ESP32_I2C
bool
@@ -436,4 +436,39 @@ config ESP32_SPIFLASH_DEBUG
will show input arguments and result.
endmenu # ESP32_SPIFLASH
menu "Ethernet configuration"
depends on ESP32_EMAC
config ESP32_ETH_NRXDESC
int "RX description number"
default 9
---help---
Descriptions of RX should be more than TX's.
config ESP32_ETH_NTXDESC
int "TX description number"
default 8
config ESP32_ETH_MDCPIN
int "MDC Pin"
default 23
range 0 39
config ESP32_ETH_MDIOPIN
int "MDIO Pin"
default 18
range 0 39
config ESP32_ETH_PHY_RSTPIN
int "Reset PHY Pin"
default 5
range 0 39
config ESP32_ETH_PHY_ADDR
int "PHY address"
default 1
endmenu # ESP32_EMAC
endif # ARCH_CHIP_ESP32
+4 -12
View File
@@ -81,18 +81,6 @@ ifeq ($(CONFIG_FS_HOSTFS),y)
CMN_CSRCS += xtensa_hostfs.c
endif
# Use of common/xtensa_etherstub.c is deprecated. The preferred mechanism
# is to use CONFIG_NETDEV_LATEINIT=y to suppress the call to
# up_netinitialize() in xtensa_initialize.c. Then this stub would not be
# needed.
ifneq ($(CONFIG_LX6_ETHERNET),y)
ifeq ($(CONFIG_NET),y)
CMN_CSRCS += xtensa_etherstub.c
endif
endif
# Required ESP32 files (arch/xtensa/src/lx6)
CHIP_CSRCS = esp32_allocateheap.c esp32_clockconfig.c esp32_cpuint.c
@@ -115,6 +103,10 @@ ifeq ($(CONFIG_ESP32_SPIFLASH),y)
CHIP_CSRCS += esp32_spiflash.c
endif
ifeq ($(CONFIG_ESP32_EMAC),y)
CHIP_CSRCS += esp32_emac.c
endif
# Configuration-dependent ESP32 files
ifeq ($(CONFIG_SMP),y)
File diff suppressed because it is too large Load Diff
+74
View File
@@ -0,0 +1,74 @@
/****************************************************************************
* arch/xtensa/src/esp32/esp32_emac.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#ifndef __ARCH_XTENSA_SRC_ESP32_ESP32_EMAC_H
#define __ARCH_XTENSA_SRC_ESP32_ESP32_EMAC_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#ifndef __ASSEMBLY__
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: esp32_emac_init
*
* Description:
* Initialize ESP32 ethernet device driver.
*
* Input Parameters:
* None
*
* Returned Value:
* 0 is returned on success. Otherwise, a negated errno value is
* returned indicating the nature of the failure:
*
* -ENOMEM is returned if no memory resource.
*
****************************************************************************/
int esp32_emac_init(void);
#ifdef __cplusplus
}
#endif
#undef EXTERN
#endif /* __ASSEMBLY__ */
#endif /* __ARCH_XTENSA_SRC_ESP32_ESP32_EMAC_H */
+3
View File
@@ -65,6 +65,7 @@
# define FUNCTION_2 (2 << FUNCTION_SHIFT)
# define FUNCTION_3 (3 << FUNCTION_SHIFT)
# define FUNCTION_4 (4 << FUNCTION_SHIFT)
# define FUNCTION_5 (5 << FUNCTION_SHIFT)
# define SPECIAL (7 << FUNCTION_SHIFT)
#define INPUT_PULLUP (INPUT | PULLUP)
@@ -76,12 +77,14 @@
# define INPUT_FUNCTION_2 (INPUT_FUNCTION | FUNCTION_2)
# define INPUT_FUNCTION_3 (INPUT_FUNCTION | FUNCTION_3)
# define INPUT_FUNCTION_4 (INPUT_FUNCTION | FUNCTION_4)
# define INPUT_FUNCTION_5 (INPUT_FUNCTION | FUNCTION_5)
#define OUTPUT_FUNCTION (OUTPUT | FUNCTION)
# define OUTPUT_FUNCTION_0 (OUTPUT_FUNCTION | FUNCTION_0)
# define OUTPUT_FUNCTION_1 (OUTPUT_FUNCTION | FUNCTION_1)
# define OUTPUT_FUNCTION_2 (OUTPUT_FUNCTION | FUNCTION_2)
# define OUTPUT_FUNCTION_3 (OUTPUT_FUNCTION | FUNCTION_3)
# define OUTPUT_FUNCTION_4 (OUTPUT_FUNCTION | FUNCTION_4)
# define OUTPUT_FUNCTION_5 (OUTPUT_FUNCTION | FUNCTION_5)
/* Interrupt type used with esp32_gpioirqenable() */
@@ -1181,6 +1181,8 @@
#define DPORT_WIFI_CLK_EN_REG (DR_REG_DPORT_BASE + 0x0CC)
#define DPORT_EMAC_CLK_EN (BIT(14))
/* DPORT_WIFI_CLK_EN : R/W ;bitpos:[31:0] ;default: 32'hfffce030 ; */
#define DPORT_WIFI_CLK_EN 0xFFFFFFFF
@@ -1192,6 +1194,8 @@
/* DPORT_WIFI_RST : R/W ;bitpos:[31:0] ;default: 32'h0 ; */
#define DPORT_EMAC_RST_EN (BIT(7))
#define DPORT_WIFI_RST 0xFFFFFFFF
#define DPORT_WIFI_RST_M ((DPORT_WIFI_RST_V)<<(DPORT_WIFI_RST_S))
#define DPORT_WIFI_RST_V 0xFFFFFFFF
File diff suppressed because it is too large Load Diff
+41
View File
@@ -21,6 +21,7 @@ Contents
o Memory Map
o Serial Console
o Buttons and LEDs
o Ethernet
o SMP
o OpenOCD for the ESP32
o Executing and Debugging from FLASH and IRAM
@@ -215,6 +216,46 @@ Buttons and LEDs
There are several on-board LEDs for that indicate the presence of power
and USB activity. None of these are available for use by software.
Ethernet
========
ESP32 has a 802.11 hardware MAC, so just connects to external PHY chip.
Due to ESP32's GPIOs are not enough, so recommanded users to use RMII
to connect ESP32 to PHY chip, current driver also only supports RMII option.
The RMII GPIO pins are fixed, but the SMI and functional GPIO pins are optional.
RMII GPIO pins are as following:
ESP32 GPIO PHY Chip GPIO
IO25 <--> RXD[0]
IO26 <--> RXD[1]
IO27 <--> CRS_DV
IO0 <--> REF_CLK
IO19 <--> TXD[0]
IO21 <--> TX_EN
IO22 <--> TXD[1]
SMI GPIO pins (default option) are as following:
ESP32 GPIO PHY Chip GPIO
IO18 <--> MDIO
IO23 <--> MDC
Functional GPIO pins(default option) are as following:
ESP32 GPIO PHY Chip GPIO
IO5 <--> Reset_N
Espressif has an offcial Ethernet development board:
https://docs.espressif.com/projects/esp-idf/en/latest/esp32/hw-reference/esp32/get-started-ethernet-kit.html
This driver has been tested according to this board and ESP32 core
board + LAN8720 module. If users have some issue about using this driver,
please refer the upper official document, specially the issue that GPIO0
causes failing to bring the ESP32 chip up.
SMP
===