Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reusing net.en.start() #424

Open
progerstar opened this issue Aug 16, 2023 · 4 comments
Open

Reusing net.en.start() #424

progerstar opened this issue Aug 16, 2023 · 4 comments

Comments

@progerstar
Copy link

progerstar commented Aug 16, 2023

Network driver (tested on lan8720) works only once.
2 different scenarios:

1. DHCP after DHCP

/ > net.en.setup()
/ > net.en.start(false)
[..IP is ok..]
/ > net.en.stop()
/ > net.en.setup()
/ > net.en.start(false)
stdin:1: 503316483:can't connect check cable
stack traceback:
[C]: in field 'start'
stdin:1: in main chunk
[C]: in ?

2. Static IP if DHCP failed

/ > net.en.setup()
[..DHCP server is unpulgged..]
/ > net.en.start(false)
stdin:1: 503316483:can't connect check cable
stack traceback:
[C]: in field 'start'
stdin:1: in main chunk
[C]: in ?
/ > net.en.setup( net.packip(192,168,1,200), net.packip(255,255,255,0), net.packip(192,168,1,1), net.packip(8,8,8,8), net.packip(8,8,4,4) )
/ > net.en.start(false)
/ > net.stat()
...
ip address 0.0.0.0 netmask 0.0.0.0
gw address 0.0.0.0

@the0ne
Copy link
Collaborator

the0ne commented Sep 19, 2023

Confirmed.
Did you look into the code to find the root cause?

For a possible quick-fix I added esp_eth_deinit() at the end of function eth_stop but the root-cause seems to be the lan8720 chip not being properly re-initialized:

/ > net.en.setup()
/ > net.en.start(false)
/ > net.stat()
wf: mac address 00:00:00:00:00:00
   ip address 0.0.0.0 / netmask 0.0.0.0
   gw address 0.0.0.0

en: mac address 94:b9:7e:d3:f3:5b
   ip address 192.168.1.122 netmask 255.255.255.0
   gw address 192.168.1.200

ns:
   dns-server 1 ip address 192.168.1.200
   dns-server 2 is unset
   dns-server 3 is unset
/ > net.en.stop()
/ > net.en.setup()
/ > net.en.start(false)
E (32230) emac: Timed out waiting for PHY register 0x2 to have value 0x0007(mask 0xffff). Current value 0x0000
E (33231) emac: Timed out waiting for PHY register 0x3 to have value 0xc111(mask 0xfff0). Current value 0x0000
E (34238) emac: Timed out waiting for PHY register 0x3 to have value 0xc0f0(mask 0xfff0). Current value 0x0000
E (34239) emac: Initialise PHY device Timeout
stdin:1: 503316483:can't connect check cable
stack traceback:
	[C]: in field 'start'
	stdin:1: in main chunk
	[C]: in ?

@progerstar
Copy link
Author

progerstar commented Sep 22, 2023

Yep, net.en.setup() doesn't run twise, because status_get(STATUS_ETH_SETUP) still true after deinit.
The fix is an additional command status_set(0x00000000, STATUS_ETH_SETUP) in a *eth_stop().

@the0ne
Copy link
Collaborator

the0ne commented Sep 22, 2023

Sure that's really enough? I think I had tested that before and it wasn't sufficient.

@progerstar
Copy link
Author

progerstar commented Sep 22, 2023

Yes, there is no way to avoid the following code from the net.en.setup() otherwise:
if (!status_get(STATUS_ETH_SETUP)) { if ((error = net_init())) { return error; } status_set(STATUS_ETH_SETUP, 0x00000000); } else { return NULL; }
I've tried with CONFIG_PHY_POWER_PIN (i.e. with hw ic reset) and without it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants