LAN8720 Can't work on esp32 with ETH_CLOCK_GPIO17_OUT
I read the source code from network_lan.c from ports/esp32
in line 143
eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG();
mac_config.smi_mdc_gpio_num = self->mdc_pin;
mac_config.smi_mdio_gpio_num = self->mdio_pin;
esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config);
it use default config but many boards' lan8720 are setted with other clock
like my board is GPIO17
In Arduino the code is write like this(https://github.com/espressif/arduino-esp32/blob/ba6e82c30d31a2ddc1276a045e0c42a29b38869f/libraries/Ethernet/src/ETH.cpp Line:257)
eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG();
mac_config.clock_config.rmii.clock_mode = (eth_clock_mode) ? EMAC_CLK_OUT : EMAC_CLK_EXT_IN;
mac_config.clock_config.rmii.clock_gpio = (1 == eth_clock_mode) ? EMAC_APPL_CLK_OUT_GPIO : (2 == eth_clock_mode) ? EMAC_CLK_OUT_GPIO : (3 == eth_clock_mode) ? EMAC_CLK_OUT_180_GPIO : EMAC_CLK_IN_GPIO;
mac_config.smi_mdc_gpio_num = mdc;
mac_config.smi_mdio_gpio_num = mdio;
mac_config.sw_reset_timeout_ms = 1000;
eth_mac = esp_eth_mac_new_esp32(&mac_config);
It enabled clock config with {gpio0:EMAC_TX_CLK,gpio0:CLK_OUT1,gpio16:EMAC_CLK_OUT,gpio17:EMAC_CLK_180}
without clock set lan8720 return OSError: esp_eth_driver_install failed,which can't work
Could micropython support clock config ? It really help a lot.Thanks
my mpy code is below:
import network
nic = network.LAN(0,mdc= Pin(23),mdio=Pin(18),
phy_addr=0,phy_type=network.PHY_LAN8720
)
'''
#define ETH_ADDR 0
#define ETH_POWER_PIN -1
#define ETH_MDC_PIN 23
#define ETH_MDIO_PIN 18
#define LED 2
#define ETH_TYPE ETH_PHY_LAN8720
#define ETH_CLK_MODE ETH_CLOCK_GPIO17_OUT
#define ETH_RESET 5
'''
Ethernet support on the Olimex ESP32-POE
I'm trying to get ethernet working on the ESP32-POE from Olimex. It's a ESP32 with a LAN8720A chip.
According to https://github.com/micropython/micropython-esp32/issues/172 the similar boards ESP32-GATEWAY and ESP32-EVB seem to work. I tried the same code on the ESP32-POE but without luck.
Here are the schematics of the 3 boards:
As you can see the GATEWAY and EVB are quite similar. The POE has a different power layout because of the power over ethernet capabilities but also GPIO00 is not connected to CLKIN anymore. Instead GPIO17 is used which was defined as the Power Pin in the other boards.
I'm not sure what to make out of this. I'm not an electrical engineer so I have no clue what to look for. I tried the ESP-IDF example demo and it worked. Micropython seems to do the same thing in the C code below so I'm not sure why it doesn't work.
rst:0x1 (POWERON_RESET),boot:0x1b (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:5060
load:0x40078000,len:8788
ho 0 tail 12 room 4
load:0x40080400,len:6772
entry 0x40081610
I (428) cpu_start: Pro cpu up.
I (428) cpu_start: Application information:
I (428) cpu_start: Compile time: 12:32:34
I (430) cpu_start: Compile date: Feb 14 2019
I (436) cpu_start: ESP-IDF: v3.3-beta1-268-g5c88c5996
I (442) cpu_start: Single core mode
I (447) heap_init: Initializing. RAM available for dynamic allocation:
I (453) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (460) heap_init: At 3FFB92B0 len 00026D50 (155 KiB): DRAM
I (466) heap_init: At 3FFE0440 len 0001FBC0 (126 KiB): D/IRAM
I (472) heap_init: At 40078000 len 00008000 (32 KiB): IRAM
I (478) heap_init: At 40092834 len 0000D7CC (53 KiB): IRAM
I (485) cpu_start: Pro cpu start user code
I (55) cpu_start: Starting scheduler on PRO CPU.
OSError: [Errno 2] ENOENT
MicroPython v1.10-98-g4daee3170 on 2019-02-14; ESP32 module with ESP32
Type "help()" for more information.
>>> import machine
>>> import network
>>> lan = network.LAN(mdc = machine.Pin(16), mdio = machine.Pin(17), power = None, phy_type = network.PHY_LAN8720, phy_addr=0)
I (22904) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
>>> print('ifconfig :', lan.ifconfig())
ifconfig : ('0.0.0.0', '0.0.0.0', '0.0.0.0', '0.0.0.0')
>>> print('status : ', lan.status())
status : None
>>> print('isconnected : ', lan.isconnected())
isconnected : False
>>> print('active : ', lan.active())
active : False
>>> lan.active(True)
E (55444) emac: Timed out waiting for PHY register 0x2 to have value 0x0007(mask 0xffff). Current value 0x0000
E (56444) emac: Timed out waiting for PHY register 0x3 to have value 0xc0f0(mask 0xfff0). Current value 0x0000
E (56444) emac: Initialise PHY device Timeout
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: ethernet enable failed
>>>
I hope someone with more knowledge about the underlying C code or the hardware can shine some light on this.