Skip to content

Add support clock mode for ESP32 ethernet module#4515

Closed
petrkr wants to merge 5 commits intomicropython:masterfrom
petrkr:ethernetesp32
Closed

Add support clock mode for ESP32 ethernet module#4515
petrkr wants to merge 5 commits intomicropython:masterfrom
petrkr:ethernetesp32

Conversation

@petrkr
Copy link
Copy Markdown
Contributor

@petrkr petrkr commented Feb 17, 2019

I've added optional parameter support for network.LAN clock_mode and implemented new enum string for network module class to support Clock mode for ESP32.

Can be used for some cases when especially LAN8720 modules uses clock source from ESP's pin GPIO17.

usage:

import machine
import network

lan = network.LAN(mdc = machine.Pin(23), mdio = machine.Pin(18), power=None, phy_type = network.PHY_LAN8720, phy_addr=1, clock_mode=network.ETH_CLOCK_GPIO17_OUT)
lan.active(1)

new enum at network module:

>>> for i in dir(network): print(i)
... 
ETH_CLOCK_GPIO0_IN
ETH_CLOCK_GPIO16_OUT
ETH_CLOCK_GPIO17_OUT
...

Also added catch events for ethernet module:

I (44868) ethernet: start
True
>>> I (48868) ethernet: LAN cable connected
I (49798) event: eth ip: 10.0.0.137, mask: 255.255.255.0, gw: 10.0.0.1
I (49798) ethernet: Got IP
I (64868) ethernet: LAN cable disconnected
I (72868) ethernet: LAN cable connected
I (73798) event: eth ip: 10.0.0.137, mask: 255.255.255.0, gw: 10.0.0.1
I (73798) ethernet: Got IP

should fix #4502

Later I think about do some events like wifi has. But for fix work with different clock modes should be this enough.

@petrkr
Copy link
Copy Markdown
Contributor Author

petrkr commented Feb 19, 2019

Rebase to latest master

@dpgeorge
Copy link
Copy Markdown
Member

Thanks, it looks really good!

One point: don't you think it's better to use the ESP-IDF default clock_mode rather than ETH_CLOCK_GPIO0_IN? In case the IDF changes it from GPIO0. So the default value of the clock_mode keyword arg would be "-1", which indicates to use the IDF's value. Then the code is something like:

if (args[ARG_clock_mode].u_int != -1) {
    // validate value
    config.clock_mode = args[ARG_clock_mode].u_int;
}

@petrkr
Copy link
Copy Markdown
Contributor Author

petrkr commented Feb 21, 2019

Thanks, it looks really good!

One point: don't you think it's better to use the ESP-IDF default clock_mode rather than ETH_CLOCK_GPIO0_IN? In case the IDF changes it from GPIO0. So the default value of the clock_mode keyword arg would be "-1", which indicates to use the IDF's value. Then the code is something like:

if (args[ARG_clock_mode].u_int != -1) {
    // validate value
    config.clock_mode = args[ARG_clock_mode].u_int;
}

Hi,
yeah, you are right, I supposed default value from SDK was GPIO0_IN, so I used it, but yes, it's better to do not set it at all and let SDK to use default from phy_lan8720_default_ethernet_config call. I will commit change later today.

@petrkr
Copy link
Copy Markdown
Contributor Author

petrkr commented Feb 21, 2019

One more question before I will test it on HW later... u_int does not stands for unsigned int so what about -1 value ?

@dpgeorge
Copy link
Copy Markdown
Member

u_int does not stands for unsigned int so what about -1 value ?

The "u" stands for union, so it is a signed int. -1 is a good value to indicate default.

@petrkr
Copy link
Copy Markdown
Contributor Author

petrkr commented Feb 21, 2019

u_int does not stands for unsigned int so what about -1 value ?

The "u" stands for union, so it is a signed int. -1 is a good value to indicate default.

I see. In that case, pushed change (with rebase to actual master)

@dpgeorge
Copy link
Copy Markdown
Member

Thanks for updating. Merged in 7d8c71c through 5801a00 (the 3 commits related to adding clock_mode were squashed together).

@dpgeorge dpgeorge closed this Feb 21, 2019
@petrkr petrkr deleted the ethernetesp32 branch February 21, 2019 12:41
tannewt pushed a commit to tannewt/circuitpython that referenced this pull request Mar 31, 2021
This allows more options to be overridden to 0 in an mpconfigboard.mk.

Improved:
 * FRAMEBUFFERIO, FULL_BUILD, BITOPS, PWMIO, RGBMATRIX, OTARYIO, PULSEIO, WATCHDOG

Still problematic (pull requests welcome):
 * RP2PIO & NEOPIXEL_WRITE, possibly only if a status neopixel is defined
 * BITBANGIO, possibly only if BUSIO is enabled
 * RTC

Incidentally, with RP2PIO & NEOPIXEL_WRITE, BITBANGIO, and RTC re-enabled I get
```
323956 bytes used, 720524 bytes free in flash firmware space out of 1044480 bytes (1020.0kB).
12072 bytes used, 250072 bytes free in ram for stack and heap out of 262144 bytes (256.0kB).
```

Closes micropython#4515
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ethernet support on the Olimex ESP32-POE

2 participants