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

ethernet library issue with W5500 #7654

Closed
1 task
infrafast opened this issue Oct 15, 2020 · 8 comments
Closed
1 task

ethernet library issue with W5500 #7654

infrafast opened this issue Oct 15, 2020 · 8 comments

Comments

@infrafast
Copy link

Basic Infos

  • [ x] This issue complies with the issue POLICY doc.
  • [ x] I have read the documentation at readthedocs and the issue is not addressed there.
  • [ x] I have tested that the issue is present in current master branch (aka latest git).
  • [x ] I have searched the issue tracker for a similar issue.
  • If there is a stack dump, I have decoded it.
  • [x ] I have filled out all fields below.

Platform

  • Hardware: ESP-12
  • Core Version: 2.6.3 and also 2.7
  • Development Env: Arduino IDE 1.5
  • Operating System: Windows

Settings in IDE

  • Module: Wemos D1 mini r2
  • Flash Mode:
  • Flash Size: 4MB
  • lwip Variant: v2 Lower Memory
  • Reset Method:
  • Flash Frequency: [40Mhz]
  • CPU Frequency: 80Mhz
  • Upload Using: both OTA and SERIAL
  • Upload Speed: 115200

Problem Description

I am facing an issue with trying to implement a WP5500 an ESP12 module
The business case is that I need a very small scale device having both WIFI and ethernet connectity because of mechanical and other constraints.

As far as I know I should use the the Ethernet library from Arduinom which I tried.
However looks like the implementation of this library for the ESP8266 is a bit behind other board as it does't allow to for instance use CS pin (using init method) and lacks a few other method like EthernetLinkStatus

Configuration as following:

  • ESP8266 IDE package: 2.6.3 (also tested with latest 2.7.x)
  • ESP8266 model: D1 mini pro noname (wemos like)
  • pinout as following:
    D0 GPIO16 4
    D1 GPIO5 20
    D2 GPIO4 19 CS
    D3 GPIO0 18
    D4 DGPIO2 19
    D5 GPIO14 5 SCLK
    D6 CPIO12 6 MISO
    D7 GPIO13 7 MOSI
    D8 GPIO15 16
    I kept D5,D6,D7 as the standard SPI config (https://arduino-esp8266.readthedocs.io/en/latest/libraries.html#spi) and only use D2 as CS

Header of ethernet.h from last github repo: https://github.com/arduino-libraries/Ethernet
static int maintain();
static EthernetLinkStatus linkStatus();
static EthernetHardwareStatus hardwareStatus();

static void begin(...);
static void init(uint8_t sspin = 10);

static void MACAddress(uint8_t *mac_address);
static IPAddress localIP();
static IPAddress subnetMask();
static IPAddress gatewayIP();
static IPAddress dnsServerIP() { return _dnsServerAddress; }

void setMACAddress(const uint8_t *mac_address);
void setLocalIP(const IPAddress local_ip);
void setSubnetMask(const IPAddress subnet);
void setGatewayIP(const IPAddress gateway);
void setDnsServerIP(const IPAddress dns_server) { _dnsServerAddress = dns_server; }
void setRetransmissionTimeout(uint16_t milliseconds);
void setRetransmissionCount(uint8_t num);

etc...

Header of ethernet.h from ESP8266 board (for arduino IDE 1.5):

only:

void begin(...);
int maintain();
IPAddress localIP();
IPAddress subnetMask();
IPAddress gatewayIP();
IPAddress dnsServerIP();

I tried to :

  • use the ESP8266 native library from the package "as is" but the program is just pending at
    if (Ethernet.begin(mac) == 0)
    and never continues...(no reset no errors)

  • force usage of the most recent library but when compiling I get followinging error message. I could try to but I am a bit afraid that by doing that I will pull a things that will never end:
    W5100.setSubnetMask(subnet._address.bytes);

MCVE Sketch

#include <Arduino.h>
#include <Ethernet.h>

byte mac[] = {
  0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02
};

void setup() {
if (Ethernet.begin(mac) == 0)
}

void loop() {
 // void
}

Debug Messages

no messages
Debug messages go here



@d-a-v
Copy link
Collaborator

d-a-v commented Oct 15, 2020

Could you try git version of this core ?
Or installable beta (0.0.1) version ?

Both include https://github.com/arduino-libraries/Ethernet version.
Alternatively, you could try #6680

@infrafast
Copy link
Author

infrafast commented Oct 15, 2020

thanks a lot for your fast reply dav and all the work!

Here is now my full feedback :

  • I was able to integrate the new library easily (0.0.2)

  • when I recompile my application, I observed that ESPhttpUpdate.update protoype has changed...and my code don't compile anymore: it require now a WifiClient as input. I'd suggest to keep retro-compatility or ensure doc is made available to adapt

  • the rest of my code could compile and my current application remain compatible (with the exception above)

  • Concerning my target implementation:
    I have a TFT screen (use TFT_eSPI) that I have touse together with the Ethernet module
    Both are on SPI, TFT uses CS(D1) and Ethernet uses CS(D2), they share
    D5 GPIO14 5 SCLK
    D7 GPIO13 7 MOSI
    and only Ethernet uses D6 MISO

I wrote the following piece of code that include the ethernet usage:

MCVE Sketch

	#include <SPI.h>
	#include <Ethernet.h>
	#include <TFT_eSPI.h> // Graphics and font library for ST7735 driver chip

	byte mac[] = {0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02};

	long loopElapsedTime = 0;

	TFT_eSPI tft = TFT_eSPI();  // Invoke library, pins defined in User_Setup.h

	void setup() {
	  Serial.begin(115200);
	  while (!Serial);
	  tft.init(); tft.fillScreen(TFT_BLACK); tft.setTextColor(TFT_WHITE,TFT_BLACK);
	  
	  loopElapsedTime = millis();
	  
	  Ethernet.init(D2);  // ESP8266 with Adafruit Featherwing Ethernet

	  Serial.print("\nCode before TFT call. Initialize Ethernet with DHCP: ");
	  if (Ethernet.begin(mac) == 0) {
		Serial.println("Failed to configure Ethernet using DHCP");
		while (1); // do not continue
	  }
	  Serial.println(Ethernet.localIP());      // at that point in time we have an IP address and linkstatus is LinkON
	  Serial.printf(" link: %i",Ethernet.linkStatus()); 
	}

	void loop() {  
	  if ((millis() - loopElapsedTime) > 1000){
		loopElapsedTime = millis();
		
		Ethernet.maintain();    // maintain does no change anything to the issue
		
		tft.setCursor(0, 0, 2);
		tft.print(loopElapsedTime); // as soon as we call a tft  function that activate the SPI device, the Ethernet driver turn to LinkOFF and unset IP address
									// if you comment this call, then all works fine
		

		Serial.printf("\nCode after TFT call. link: %i",Ethernet.linkStatus()); 
		Serial.print("\nIP: ");
		Serial.print(Ethernet.localIP());    
	  }
	}

### Debug Messages

Here is what you get on serial line: 

12:45:54.326 -> Code before TFT call. Initialize Ethernet with DHCP: 192.168.0.211
12:45:55.017 ->  link: 1
12:45:55.345 -> Code after TFT call. link: 2
12:45:55.345 -> IP: (IP unset)


and here is the TFT user test config:

12:25:51.784 -> [code]
12:25:51.784 -> TFT_eSPI ver = 2.2.14
12:25:51.784 -> Processor    = ESP8266
12:25:51.784 -> Frequency    = 80MHz
12:25:51.784 -> Voltage      = 3.32V
12:25:51.784 -> Transactions = No
12:25:51.784 -> Interface    = SPI
12:25:51.784 -> SPI overlap  = No
12:25:51.784 -> 
12:25:51.784 -> Display driver = 7735
12:25:51.784 -> Display width  = 128
12:25:51.784 -> Display height = 160
12:25:51.784 -> 
12:25:51.784 -> TFT_CS   = PIN_D1
12:25:51.784 -> TFT_DC   = PIN_D8
12:25:51.784 -> 
12:25:51.784 -> Display SPI frequency = 27.00
12:25:51.784 -> [/code]




### Problem Description

The setup works good, the TFT is properly initiated and the W5500 module is assigned an IP address correctly
However as soon as we call a function that engage the SPI bus (in my case the TFT screen), looks like the Ethernet module loose its IP address and the link turn to OFF
It continues to work as you can still call HardwarStatus and check Link function and the TFT is also displaying properly

I suspect an implementation issue in the w5500 or ethernet code regarding switching from one device to another on the SPI bus
 

@d-a-v
Copy link
Collaborator

d-a-v commented Oct 29, 2020

I can see in your code that you use D2 as SlaveSelect/ChipSelect gpio.
Although there is no mention of SS/CS pin for the TFT screen in your code, it says D1 in logs.
It also says "27"(MHz?) as SPI frequency.

In Ethernet code, we have:

// Safe for all chips
#define SPI_ETHERNET_SETTINGS SPISettings(14000000, MSBFIRST, SPI_MODE0)`

Frequency in ethernet is initialized once. Maybe you should try and lower your TFT SPI frequency initialization (27->14?).

Anyway

  • This is not the place to ask about external drivers or libraries (TFT)
  • Ethernet was historically copied and locally adapted, and is now replaced by a submodule to have up-to-date drivers (more boards, debugged code). It is not our code anymore. As submodule, we can't update their sources without submitting a pull-request on their repository.
  • You may also try with more lwIP physical interfaces #6680, that we control, in which SPI is externally configured, and which offers better integration with libraries involving network.

@JAndrassy
Copy link
Contributor

JAndrassy commented Oct 29, 2020

@d-a-v , Ethernet library uses SPI transactions and applies the settings before every use of the bus

@d-a-v
Copy link
Collaborator

d-a-v commented Oct 29, 2020

@JAndrassy ah right !
I was looking only in w5100.cpp in which mainly setSS() .. resetSS() is used.
Then @infrafast I personally have no idea about what can be wrong between TFT lib and Arduino's Ethernet lib...
... wait, you have this in your logs:

12:25:51.784 -> Transactions = No  <-- must be yes
12:25:51.784 -> SPI overlap  = No  <-- what is it ?

@infrafast
Copy link
Author

infrafast commented Oct 29, 2020

Thank you both, the author of TFT-espi provided good feedback here: Bodmer/TFT_eSPI#811
@d-a-v : indded; Transactions = No should be Transactions = Yes in the TFT library, this improve the situation as TFT and Ethernet can work together, but then for some reason it seems to impact WIFI.
I will perform additionnal test with 6680 and keep you posted here

@d-a-v
Copy link
Collaborator

d-a-v commented Oct 29, 2020

You may add some yield() in your code, that should help FW internals including WiFi processing.

@earlephilhower
Copy link
Collaborator

#6680 is merged and Ethernet is now a submodule. Closing this as I believe all is fixed and 2 months w/o updates.

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

4 participants