Ethernet FeatherWing + Feather M0 (Ethernet Examples not Working

Hello,
I have been working on troubleshooting an issue that has recently popped up with my M0 Feathers using UDP write and endPacket. I have tried uploading using IDE Version 1.8.5 and 1.8.6 on multiple computers. Both of these sketches run successfully on 32U4 feathers.

The first sketch is a virtually unmodified example sketch ChatServer:

/*

#include <SPI.h>
#include <Ethernet2.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network.
// gateway and subnet are optional:
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(10, 99, 7, 177);
IPAddress gateway(0, 0, 0, 0 );
IPAddress subnet(255, 255, 255, 0);


// telnet defaults to port 23
EthernetServer server(23);
boolean alreadyConnected = false; // whether or not the client was connected previously

void setup() {
  // initialize the ethernet device
  Ethernet.begin(mac, ip, gateway, subnet);
  // start listening for clients
  server.begin();
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  Serial.print("Chat server address:");
  Serial.println(Ethernet.localIP());
}

unsigned long loopCount;
void loop() {
  // wait for a new client:
  EthernetClient client = server.available();
  Serial.print("LC: "); Serial.println(loopCount++);
  // when the client sends the first byte, say hello:
  if (client) {
    if (!alreadyConnected) {
      // clead out the input buffer:
      client.flush();
      Serial.println("We have a new client");
      client.println("Hello, client!");
      alreadyConnected = true;
    }

    if (client.available() > 0) {
      // read the bytes incoming from the client:
      char thisChar = client.read();
      // echo the bytes back to the client:
      server.write(thisChar);
      // echo the bytes to the server as well:
      Serial.write(thisChar);
    }
  }
}

The ChatServer code works with any of my 32U4 Feathers but does not seem to work with any M0 Feathers. With the M0, the code continues to run but does not read its IP correctly. I can ping the feather successfully. Output below:

Chat server address:0.0.0.0
LC: 0
LC: 1
LC: 2
LC: 3
...

/*

#include <SPI.h>
#include <Ethernet2.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network.
// gateway and subnet are optional:
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(10, 99, 7, 177);
IPAddress gateway(0, 0, 0, 0 );
IPAddress subnet(255, 255, 255, 0);


// telnet defaults to port 23
EthernetUDP udp;
boolean alreadyConnected = false; // whether or not the client was connected previously

void setup() {
  // initialize the ethernet device
  Ethernet.begin(mac, ip, gateway, subnet);
 udp.begin(4000);
  Serial.begin(9600);
  while (!Serial)     ; // wait for serial port to connect. Needed for Leonardo only

  Serial.print("IP address:");
  Serial.println(Ethernet.localIP());
}

unsigned long loopCount;
void loop() {
 if(Serial.read()=='t')
 {
  uint8_t emptyPack[] = {0, 0, 0, 0};
  Serial.print("BEGIN: "); Serial.println(udp.beginPacket(IPAddress(10, 99, 7, 9), 8888));
  Serial.print("WRITE: "); Serial.println(udp.write(emptyPack, 4));
  Serial.print("END: "); Serial.println(udp.endPacket());
 }else if(loopCount++ % 1000 == 0) 
    Serial.println(loopCount);
 delay(1);
}

On the 32U4s, i get the expected 4 returned from udp.write() and a 1 from udp.endPacket. On the M0, the sketch freezes after endPacket(). The output of this sketch is as follows:

IP address:0.0.0.0
1
1001
2001
3001
4001
5001
6001
BEGIN: 1
WRITE: 0
END:

I am able to ping the IP of the feather before and after the code stops on udp.endPacket() after sending a 't'.

I even had a coworker try a sketch that had been working, and we are seeing the same result where the Feather does not return its IP Address, returns a Zero for udp.write() and blocks code on endPacket.

The outputs posted are with the most up to date libraries (besides SAMD Boards by Adafruit which is at 1.2.2). They were tested on several M0 and 32U4 feathers/Ethernet featherWings. I briefly plugged in an oscilliscope and can confirm that MISO and MOSI are at least active and PIN 10 seems to be working as SS.

I am completely stumped and was very surprised that I couldn't find anyone else posting about the same issue! I would greatly appreciate it if anyone can help, please let me know if any more info is needed!

use Ethernet library. it is more then a month since a new version with support for all W5000 chips was published.

did you connect Ethernet cable to router or to computer? connect to router or switch

Juraj, thanks for responding!

I switched over to Ethernet.h, I did not realize it supports W5500.

The tests on my bench are being run through a switch. The output of the second code from a 32U4:

IP address:10.99.7.177
1
1001
2001
3001
BEGIN: 1
WRITE: 4
END: 1
4001
5001
...

The output of the same code on the M0:

IP address:0.0.0.0
1
1001
2001
3001
4001
BEGIN: 1
WRITE: 0
END:

Updated code:

#include <SPI.h>
#include <Ethernet.h>


byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip(10, 99, 7, 177);
IPAddress gateway(0, 0, 0, 0 );
IPAddress subnet(255, 255, 255, 0);


// telnet defaults to port 23
EthernetUDP udp;
boolean alreadyConnected = false; // whether or not the client was connected previously

void setup() {
  // initialize the ethernet device
  Ethernet.begin(mac, ip, gateway, subnet);
 udp.begin(4000);
  Serial.begin(9600);
  while (!Serial)     ; // wait for serial port to connect. Needed for Leonardo only

  Serial.print("IP address:");
  Serial.println(Ethernet.localIP());
}

unsigned long loopCount;
void loop() {
 if(Serial.read()=='t')
 {
  uint8_t emptyPack[] = {0, 0, 0, 0};
  Serial.print("BEGIN: "); Serial.println(udp.beginPacket(IPAddress(10, 99, 7, 9), 8888));
  Serial.print("WRITE: "); Serial.println(udp.write(emptyPack, 4));
  Serial.print("END: "); Serial.println(udp.endPacket());
 }else if(loopCount++ % 1000 == 0) 
    Serial.println(loopCount);
 delay(1);
}

Digging a little deeper, the code seems to be stopping in Socket.cpp:

bool EthernetClass::socketSendUDP(uint8_t s)
{
	SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
	W5100.execCmdSn(s, Sock_SEND);

	/* +2008.01 bj */
	while ( (W5100.readSnIR(s) & SnIR::SEND_OK) != SnIR::SEND_OK ) {
		Serial.println(W5100.readSnIR(s));
		if (W5100.readSnIR(s) & SnIR::TIMEOUT) {
			/* +2008.01 [bj]: clear interrupt */
			W5100.writeSnIR(s, (SnIR::SEND_OK|SnIR::TIMEOUT));
			SPI.endTransaction();
			//Serial.printf("sendUDP timeout\n");
			return false;
		}
		SPI.endTransaction();
		yield();
		SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
	}

	/* +2008.01 bj */
	W5100.writeSnIR(s, SnIR::SEND_OK);
	SPI.endTransaction();

	//Serial.printf("sendUDP ok\n");
	/* Sent ok */
	return true;
}

The call to readSnIR returns 0 and the code remains in the loop. This, and the IP address being configured correctly, but reading as 0.0.0.0, seems to point to SPI failing on MISO side? I have tried with 3 different feathers with the same result.

at which voltage are SPI pins of the Ethernet module?

Both types of feathers are running at 3.3V. I checked the logic pins and the CS with an oscilloscope and they all seem to be working.

Update: We have a custom PCB designed based off an M0 Feather/FeatherWing that is able to run this sketch successfully. I tried lowering the SPI speeds in case that was causing any issues and still the same result.

If anyone has an Ethernet FeatherWing and a M0 Feather lying around and can try torun this sketch that would be very helpful!

Sorry to bump, but any ideas?