W5500 UDP Packets bigger than 1257 lost

HI There,

i was searching the whole internet but couldn’t find a solution for my problem…

I built a UDP broadcast receiver with an ESP32-Wroom and the W5500 using the SPI interface. So far so good, the Receiver works whilst receiving packages up to the size range of 1257 bytes. The langer ones fail to get recognized or are dumped by udp.parsePacket() using the Ethernet2.h library. I can see these packages in Wireshark but the receiver doesnt. The maximum size of the packages is 1464 which is below the threshold I believe. this package could be received via the ESP WLAN feature but that was way to slow for my puropses.

Here’s the part of the code… let me know what else you need to find my mistake…

#include <SPI.h>
#include <Ethernet2.h>
#include <EthernetUdp2.h>
#include "local_config.h"

#define PIN_CS 5
#define UDP_PACKET_SIZE 1500


byte packetBuffer[UDP_PACKET_SIZE];
 
//The IP address that this arduino has requested to be assigned to.
EthernetUDP Udp;
uint16_t packetSize = 0;
bool state = 0;
const uint16_t localPort = 22815; 


/*
 * Wiz W5500 reset function.  Change this for the specific reset
 * sequence required for your particular board or module.
 */
void WizReset() {
    Serial.print("Resetting Wiz W5500 Ethernet Board...  ");
    pinMode(RESET_P, OUTPUT);
    digitalWrite(RESET_P, HIGH);
    delay(250);
    digitalWrite(RESET_P, LOW);
    delay(50);
    digitalWrite(RESET_P, HIGH);
    delay(350);
    Serial.println("Done.");
}


/*
 * This is a crock. It's here in an effort
 * to help people debug hardware problems with
 * their W5100 ~ W5500 board setups.  It's 
 * a copy of the Ethernet library enums and
 * should, at the very least, be regenerated
 * from Ethernet.h automatically before the
 * compile starts (that's a TODO item).
 *
 */
/*
 * Print the result of the hardware status enum
 * as a string.
 * Ethernet.h currently contains these values:-
 *
 *  enum EthernetHardwareStatus {
 *  	EthernetNoHardware,
 *  	EthernetW5100,
 *  	EthernetW5200,
 *  	EthernetW5500
 *  };
 *
 */
void prt_hwval(uint8_t refval) {
    switch (refval) {
    case 0:
        Serial.println("No hardware detected.");
        break;
    case 1:
        Serial.println("WizNet W5100 detected.");
        break;
    case 2:
        Serial.println("WizNet W5200 detected.");
        break;
    case 3:
        Serial.println("WizNet W5500 detected.");
        break;
    default:
        Serial.println
            ("UNKNOWN - Update espnow_gw.ino to match Ethernet.h");
    }
}


/*
 * Print the result of the ethernet connection
 * status enum as a string.
 * Ethernet.h currently contains these values:-
 *
 *  enum EthernetLinkStatus {
 *     Unknown,
 *     LinkON,
 *     LinkOFF
 *  };
 *
 */
void prt_ethval(uint8_t refval) {
    switch (refval) {
    case 0:
        Serial.println("Uknown status.");
        break;
    case 1:
        Serial.println("Link flagged as UP.");
        break;
    case 2:
        Serial.println("Link flagged as DOWN. Check cable connection.");
        break;
    default:
        Serial.println
            ("UNKNOWN - Update espnow_gw.ino to match Ethernet.h");
    }
}

void sendNTPpacket(const char *address) {
    // Set all bytes in the buffer to 0.
    memset(packetBuffer, 0, 1500);

    // Initialize values needed to form NTP request
    // (see http://en.wikipedia.org/wiki/Network_Time_Protocol).
    packetBuffer[0] = 0b11100011;      // LI, Version, Mode
    packetBuffer[1] = 0;        // Stratum, or type of clock
    packetBuffer[2] = 6;        // Polling Interval
    packetBuffer[3] = 0xEC;     // Peer Clock Precision
    // 8 bytes of zero for Root Delay & Root Dispersion
    packetBuffer[12] = 49;
    packetBuffer[13] = 0x4E;
    packetBuffer[14] = 49;
    packetBuffer[15] = 52;

    // All NTP fields have been given values, now
    // send a packet requesting a timestamp.
    Udp.beginPacket(address, 123);      // NTP requests are to port 123
    Udp.write(packetBuffer, 1500);
    Udp.endPacket();
}

void InitEthernet()
{
    Serial.println("\n\tUDP NTP Client v3.0\r\n");
    
    // Use Ethernet.init(pin) to configure the CS pin.
    Ethernet.init(PIN_CS);           // GPIO5 on the ESP32.
    WizReset();

    /* 
     * Network configuration - all except the MAC are optional.
     *
     * IMPORTANT NOTE - The mass-produced W5500 boards do -not-
     *                  have a built-in MAC address (depite 
     *                  comments to the contrary elsewhere). You
     *                  -must- supply a MAC address here.
     */
    Serial.println("Starting ETHERNET connection...");
    Ethernet.begin(eth_MAC, eth_IP, eth_DNS, eth_GW, eth_MASK);

    delay(200);

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

    /*
     * Sanity checks for W5500 and cable connection.
     
    Serial.print("Checking connection.");
    bool rdy_flag = false;
    for (uint8_t i = 0; i <= 20; i++) {
        if ((Ethernet.hardwareStatus() == EthernetNoHardware)
            || (Ethernet.linkStatus() == LinkOFF)) {
            Serial.print(".");
            rdy_flag = false;
            delay(80);
        } else {
            rdy_flag = true;
            break;
        }
    }
    if (rdy_flag == false) {
        Serial.println
            ("\n\r\tHardware fault, or cable problem... cannot continue.");
        Serial.print("Hardware Status: ");
        prt_hwval(Ethernet.hardwareStatus());
        Serial.print("   Cable Status: ");
        prt_ethval(Ethernet.linkStatus());
        while (true) {
            delay(10);          // Halt.
        }
    } else {
        Serial.println(" OK");
    }*/

    while (!Udp.begin(localPort));
    Serial.print("UDP Started! Listening on Port ");
    Serial.println(localPort);
}

void setup() 
{
  Serial.begin(115200);
  delay(1000);
  InitEthernet();

  Serial.println("Startup process finished!\n\n");
}

void loop(){
  uint16_t packetSize = Udp.parsePacket();
  //If we received something.
  if(packetSize){
    Serial.println(packetSize);                                    
  }
}


Not familiar with the library, found this, I would start looking into the library and putting diagnostic output after each operation or register access to identify what is going on.

Thanks Eugeny,

I think i’ll have to do that… yet I don’t know how to do it… you mean put a serial output in the library parts that are of interest?

I did some further research and found a very strange behaviour and another issue that I’ll have to attend to and seek help.

Last one is that the controller only recognises broadcast packets that are send to 255.255.255.255 in IP (Multicast!?), dedicated messages to the specific IP do not get through. Are there any options in the code that I have to attend to, to get the direct messaging to work? In the datasheet it seems that this issue shouldn’t be there because i use standard udp.begin() which semas to set the registers correctly.

The other strange thing I noticed is that the controller is “picky” from which tools/programms/games the large messages come from. A packet sent from the Microsoft UDP sender/receiver tool with size of 1472 can be seen in Wireshark AND is recognised by the controller! BUT a package of the same Size commming from the game F1 22 (EA) is not recognised? How’s that possible? I’ll attach the Wireshark readings below…

Regards!
S.

WIreshark output from Microsoft UDP Tool Package with 1472byte of Data:

0000   ff ff ff ff ff ff 70 5a b6 91 9f 8b 08 00 45 00   ......pZ......E.
0010   05 d4 94 c4 00 00 80 11 00 00 c0 a8 b2 14 ff ff   ................
0020   ff ff fa bf 51 29 05 c0 a1 5e 61 62 63 64 65 66   ....Q)...^abcdef
0030   67 68 69 6a 61 62 63 64 65 66 67 68 69 6a 61 62   ghijabcdefghijab
0040   63 64 65 66 67 68 69 6a 61 62 63 64 65 66 67 68   cdefghijabcdefgh
0050   69 6a 61 62 63 64 65 66 67 68 69 6a 61 62 63 64   ijabcdefghijabcd
0060   65 66 67 68 69 6a 61 62 63 64 65 66 67 68 69 6a   efghijabcdefghij
0070   61 62 63 64 65 66 67 68 69 6a 61 62 63 64 65 66   abcdefghijabcdef
0080   67 68 69 6a 61 62 63 64 65 66 67 68 69 6a 61 62   ghijabcdefghijab
0090   63 64 65 66 67 68 69 6a 61 62 63 64 65 66 67 68   cdefghijabcdefgh
00a0   69 6a 61 62 63 64 65 66 67 68 69 6a 61 62 63 64   ijabcdefghijabcd
00b0   65 66 67 68 69 6a 61 62 63 64 65 66 67 68 69 6a   efghijabcdefghij
00c0   61 62 63 64 65 66 67 68 69 6a 61 62 63 64 65 66   abcdefghijabcdef
00d0   67 68 69 6a 61 62 63 64 65 66 67 68 69 6a 61 62   ghijabcdefghijab
00e0   63 64 65 66 67 68 69 6a 61 62 63 64 65 66 67 68   cdefghijabcdefgh
00f0   69 6a 61 62 63 64 65 66 67 68 69 6a 61 62 63 64   ijabcdefghijabcd
0100   65 66 67 68 69 6a 61 62 63 64 65 66 67 68 69 6a   efghijabcdefghij
0110   61 62 63 64 65 66 67 68 69 6a 61 62 63 64 65 66   abcdefghijabcdef
0120   67 68 69 6a 61 62 63 64 65 66 67 68 69 6a 61 62   ghijabcdefghijab
0130   63 64 65 66 67 68 69 6a 61 62 63 64 65 66 67 68   cdefghijabcdefgh
0140   69 6a 61 62 63 64 65 66 67 68 69 6a 61 62 63 64   ijabcdefghijabcd
0150   65 66 67 68 69 6a 61 62 63 64 65 66 67 68 69 6a   efghijabcdefghij
0160   61 62 63 64 65 66 67 68 69 6a 61 62 63 64 65 66   abcdefghijabcdef
0170   67 68 69 6a 61 62 63 64 65 66 67 68 69 6a 61 62   ghijabcdefghijab
0180   63 64 65 66 67 68 69 6a 61 62 63 64 65 66 67 68   cdefghijabcdefgh
0190   69 6a 61 62 63 64 65 66 67 68 69 6a 61 62 63 64   ijabcdefghijabcd
01a0   65 66 67 68 69 6a 61 62 63 64 65 66 67 68 69 6a   efghijabcdefghij
01b0   61 62 63 64 65 66 67 68 69 6a 61 62 63 64 65 66   abcdefghijabcdef
01c0   67 68 69 6a 61 62 63 64 65 66 67 68 69 6a 61 62   ghijabcdefghijab
01d0   63 64 65 66 67 68 69 6a 61 62 63 64 65 66 67 68   cdefghijabcdefgh
01e0   69 6a 61 62 63 64 65 66 67 68 69 6a 61 62 63 64   ijabcdefghijabcd
01f0   65 66 67 68 69 6a 61 62 63 64 65 66 67 68 69 6a   efghijabcdefghij
0200   61 62 63 64 65 66 67 68 69 6a 61 62 63 64 65 66   abcdefghijabcdef
0210   67 68 69 6a 61 62 63 64 65 66 67 68 69 6a 61 62   ghijabcdefghijab
0220   63 64 65 66 67 68 69 6a 61 62 63 64 65 66 67 68   cdefghijabcdefgh
0230   69 6a 61 62 63 64 65 66 67 68 69 6a 61 62 63 64   ijabcdefghijabcd
0240   65 66 67 68 69 6a 61 62 63 64 65 66 67 68 69 6a   efghijabcdefghij
0250   61 62 63 64 65 66 67 68 69 6a 61 62 63 64 65 66   abcdefghijabcdef
0260   67 68 69 6a 61 62 63 64 65 66 67 68 69 6a 61 62   ghijabcdefghijab
0270   63 64 65 66 67 68 69 6a 61 62 63 64 65 66 67 68   cdefghijabcdefgh
0280   69 6a 61 62 63 64 65 66 67 68 69 6a 61 62 63 64   ijabcdefghijabcd
0290   65 66 67 68 69 6a 61 62 63 64 65 66 67 68 69 6a   efghijabcdefghij
02a0   61 62 63 64 65 66 67 68 69 6a 61 62 63 64 65 66   abcdefghijabcdef
02b0   67 68 69 6a 61 62 63 64 65 66 67 68 69 6a 61 62   ghijabcdefghijab
02c0   63 64 65 66 67 68 69 6a 61 62 63 64 65 66 67 68   cdefghijabcdefgh
02d0   69 6a 61 62 63 64 65 66 67 68 69 6a 61 62 63 64   ijabcdefghijabcd
02e0   65 66 67 68 69 6a 61 62 63 64 65 66 67 68 69 6a   efghijabcdefghij
02f0   61 62 63 64 65 66 67 68 69 6a 61 62 63 64 65 66   abcdefghijabcdef
0300   67 68 69 6a 61 62 63 64 65 66 67 68 69 6a 61 62   ghijabcdefghijab
0310   63 64 65 66 67 68 69 6a 61 62 63 64 65 66 67 68   cdefghijabcdefgh
0320   69 6a 61 62 63 64 65 66 67 68 69 6a 61 62 63 64   ijabcdefghijabcd
0330   65 66 67 68 69 6a 61 62 63 64 65 66 67 68 69 6a   efghijabcdefghij
0340   61 62 63 64 65 66 67 68 69 6a 61 62 63 64 65 66   abcdefghijabcdef
0350   67 68 69 6a 61 62 63 64 65 66 67 68 69 6a 61 62   ghijabcdefghijab
0360   63 64 65 66 67 68 69 6a 61 62 63 64 65 66 67 68   cdefghijabcdefgh
0370   69 6a 61 62 63 64 65 66 67 68 69 6a 61 62 63 64   ijabcdefghijabcd
0380   65 66 67 68 69 6a 61 62 63 64 65 66 67 68 69 6a   efghijabcdefghij
0390   61 62 63 64 65 66 67 68 69 6a 61 62 63 64 65 66   abcdefghijabcdef
03a0   67 68 69 6a 61 62 63 64 65 66 67 68 69 6a 61 62   ghijabcdefghijab
03b0   63 64 65 66 67 68 69 6a 61 62 63 64 65 66 67 68   cdefghijabcdefgh
03c0   69 6a 61 62 63 64 65 66 67 68 69 6a 61 62 63 64   ijabcdefghijabcd
03d0   65 66 67 68 69 6a 61 62 63 64 65 66 67 68 69 6a   efghijabcdefghij
03e0   61 62 63 64 65 66 67 68 69 6a 61 62 63 64 65 66   abcdefghijabcdef
03f0   67 68 69 6a 61 62 63 64 65 66 67 68 69 6a 61 62   ghijabcdefghijab
0400   63 64 65 66 67 68 69 6a 61 62 63 64 65 66 67 68   cdefghijabcdefgh
0410   69 6a 61 62 63 64 65 66 67 68 69 6a 61 62 63 64   ijabcdefghijabcd
0420   65 66 67 68 69 6a 61 62 63 64 65 66 67 68 69 6a   efghijabcdefghij
0430   61 62 63 64 65 66 67 68 69 6a 61 62 63 64 65 66   abcdefghijabcdef
0440   67 68 69 6a 61 62 63 64 65 66 67 68 69 6a 61 62   ghijabcdefghijab
0450   63 64 65 66 67 68 69 6a 61 62 63 64 65 66 67 68   cdefghijabcdefgh
0460   69 6a 61 62 63 64 65 66 67 68 69 6a 61 62 63 64   ijabcdefghijabcd
0470   65 66 67 68 69 6a 61 62 63 64 65 66 67 68 69 6a   efghijabcdefghij
0480   61 62 63 64 65 66 67 68 69 6a 61 62 63 64 65 66   abcdefghijabcdef
0490   67 68 69 6a 61 62 63 64 65 66 67 68 69 6a 61 62   ghijabcdefghijab
04a0   63 64 65 66 67 68 69 6a 61 62 63 64 65 66 67 68   cdefghijabcdefgh
04b0   69 6a 61 62 63 64 65 66 67 68 69 6a 61 62 63 64   ijabcdefghijabcd
04c0   65 66 67 68 69 6a 61 62 63 64 65 66 67 68 69 6a   efghijabcdefghij
04d0   61 62 63 64 65 66 67 68 69 6a 61 62 63 64 65 66   abcdefghijabcdef
04e0   67 68 69 6a 61 62 63 64 65 66 67 68 69 6a 61 62   ghijabcdefghijab
04f0   63 64 65 66 67 68 69 6a 61 62 63 64 65 66 67 68   cdefghijabcdefgh
0500   69 6a 61 62 63 64 65 66 67 68 69 6a 61 62 63 64   ijabcdefghijabcd
0510   65 66 67 68 69 6a 61 62 63 64 65 66 67 68 69 6a   efghijabcdefghij
0520   61 62 63 64 65 66 67 68 69 6a 61 62 63 64 65 66   abcdefghijabcdef
0530   67 68 69 6a 61 62 63 64 65 66 67 68 69 6a 61 62   ghijabcdefghijab
0540   63 64 65 66 67 68 69 6a 61 62 63 64 65 66 67 68   cdefghijabcdefgh
0550   69 6a 61 62 63 64 65 66 67 68 69 6a 61 62 63 64   ijabcdefghijabcd
0560   65 66 67 68 69 6a 61 62 63 64 65 66 67 68 69 6a   efghijabcdefghij
0570   61 62 63 64 65 66 67 68 69 6a 61 62 63 64 65 66   abcdefghijabcdef
0580   67 68 69 6a 61 62 63 64 65 66 67 68 69 6a 61 62   ghijabcdefghijab
0590   63 64 65 66 67 68 69 6a 61 62 63 64 65 66 67 68   cdefghijabcdefgh
05a0   69 6a 61 62 63 64 65 66 67 68 69 6a 61 62 63 64   ijabcdefghijabcd
05b0   65 66 67 68 69 6a 61 62 63 64 65 66 67 68 69 6a   efghijabcdefghij
05c0   61 62 63 64 65 66 67 68 69 6a 61 62 63 64 65 66   abcdefghijabcdef
05d0   67 68 69 6a 61 62 63 64 65 66 67 68 69 6a 61 62   ghijabcdefghijab
05e0   0d 0a                                             ..

WIreshark output from F1 22 Package with 1472byte of Data:

0000   ff ff ff ff ff ff d8 5e d3 a3 24 45 08 00 45 00   .......^..$E..E.
0010   05 d4 5d 97 00 00 80 11 64 7c c0 a8 b2 5d ff ff   ..].....d|...]..
0020   ff ff d7 cf 51 29 05 c0 0d 86 e6 07 01 0b 01 00   ....Q)..........
0030   a9 7e 81 ea 9a b0 34 e2 10 08 28 44 a8 77 00 00   .~....4...(D.w..
0040   00 ff ca 7a af c3 a7 88 bb 42 9b e8 0e c4 78 72   ...z.....B....xr
0050   89 3a 2a 0f b3 b8 a6 96 6a 3c 89 08 a7 00 4b 80   .:*.....j<....K.
0060   a6 7f fe fb 83 08 a6 ae 94 b9 d9 cd 8c bb d6 3b   ...............;
0070   34 3a 30 ca 44 40 00 18 a7 bb cc 51 00 3d eb 74   4:0.D@.....Q.=.t
0080   c5 c3 b0 ec b5 42 ab 01 0a 43 00 00 00 00 00 00   .....B...C......
0090   00 00 00 00 00 00 dc 05 4f 00 27 80 d3 7f 8e 02   ........O.'.....
00a0   de 05 00 00 00 00 00 00 00 00 00 00 00 00 12 21   ...............!
00b0   46 40 00 0a 1e bb 37 98 a3 bc 7b 1f bf c3 d4 1f   F@....7...{.....
00c0   b6 42 01 48 b4 c2 00 00 00 00 00 00 00 00 00 00   .B.H............
00d0   00 00 16 05 fc ff 1b 80 e1 7f f8 01 15 05 00 00   ................
00e0   00 00 00 00 00 00 00 00 00 00 a4 84 46 40 00 40   ............F@.@
00f0   08 39 20 2e 7c bc 2d ad c5 c3 05 e9 b5 42 46 c4   .9 .|.-......BF.
0100   09 43 00 00 00 00 00 00 00 00 00 00 00 00 d7 05   .C..............
0110   30 00 27 80 d3 7f 8f 02 d7 05 00 00 00 00 00 00   0.'.............
0120   00 00 00 00 00 00 eb 23 46 40 00 e0 c3 ba 5a c4   .......#F@....Z.
0130   a3 bc 5a 71 bf c3 1b 24 b6 42 96 3d 94 c2 00 00   ..Zq...$.B.=....
0140   00 00 00 00 00 00 00 00 00 00 b2 06 02 00 2e 80   ................
0150   cd 7f 0d 02 b1 06 00 00 00 00 00 00 00 00 00 00   ................
0160   00 00 65 b6 45 40 00 c0 8e b8 a1 54 83 bc 97 0d   ..e.E@.....T....
0170   bd c3 37 4b b6 42 d2 dc 83 c2 00 00 00 00 00 00   ..7K.B..........
0180   00 00 00 00 00 00 c5 04 12 00 18 80 e4 7f f3 01   ................
0190   c5 04 00 00 00 00 00 00 00 00 00 00 00 00 1d ad   ................
01a0   46 40 00 58 10 ba 01 86 79 bc 74 a6 bf c3 6e 24   F@.X....y.t...n$
01b0   b6 42 0d 87 68 c2 00 00 00 00 00 00 00 00 00 00   .B..h...........
01c0   00 00 3f 05 0f 00 1d 80 df 7f e0 01 3f 05 00 00   ..?.........?...
01d0   00 00 00 00 00 00 00 00 00 00 ff 6f 46 40 00 30   ...........oF@.0
01e0   fd b9 00 44 70 bc 29 53 bd c3 5a 48 b6 42 30 b6   ...Dp.)S..ZH.B0.
01f0   47 c2 00 00 00 00 00 00 00 00 00 00 00 00 91 03   G...............
0200   fd ff 0e 80 ee 7f f1 01 91 03 00 00 00 00 00 00   ................
0210   00 00 00 00 00 00 07 47 47 40 00 40 ff 38 1d eb   .......GG@.@.8..
0220   78 bc 79 03 c0 c3 8d 24 b6 42 5f bd 28 c2 00 00   x.y....$.B_.(...
0230   00 00 00 00 00 00 00 00 00 00 7a 03 bd ff 0e 80   ..........z.....
0240   ef 7f ed 01 79 03 00 00 00 00 00 00 00 00 00 00   ....y...........
0250   00 00 98 52 47 40 00 62 07 3b 44 04 77 bc 26 8c   ...RG@.b.;D.w.&.
0260   bd c3 ce 4f b6 42 00 e0 07 c2 00 00 00 00 00 00   ...O.B..........
0270   00 00 00 00 00 00 7e 03 f7 ff 0e 80 ef 7f d5 01   ......~.........
0280   7d 03 00 00 00 00 00 00 00 00 00 00 00 00 b5 50   }..............P
0290   47 40 00 e0 9e 39 dd a4 6a bc 95 67 c0 c3 46 25   G@...9..j..g..F%
02a0   b6 42 da 76 d1 c1 00 00 00 00 00 00 00 00 00 00   .B.v............
02b0   00 00 0c 06 22 00 26 80 d6 7f e7 01 0c 06 00 00   ....".&.........
02c0   00 00 00 00 00 00 00 00 00 00 89 09 46 40 00 18   ............F@..
02d0   88 ba ac ad 73 bc ec f8 bd c3 6f 4b b6 42 1b 17   ....s.....oK.B..
02e0   90 c1 00 00 00 00 00 00 00 00 00 00 00 00 b2 04   ................
02f0   09 00 18 80 e4 7f 01 02 b2 04 00 00 00 00 00 00   ................
0300   00 00 00 00 00 00 90 b6 46 40 00 90 99 b9 98 54   ........F@.....T
0310   80 bc de d5 c0 c3 d3 20 b6 42 22 d5 22 c1 00 00   ....... .B"."...
0320   00 00 00 00 00 00 00 00 00 00 9d 05 e1 ff 21 80   ..............!.
0330   db 7f 06 02 9c 05 00 00 00 00 00 00 00 00 00 00   ................
0340   00 00 0b 41 46 40 00 18 7b 3a 50 9f 81 bc e8 4d   ...AF@..{:P....M
0350   be c3 04 4e b6 42 2e fa fb bf 00 00 00 00 00 00   ...N.B..........
0360   00 00 00 00 00 00 c3 05 f2 ff 23 80 da 7f e8 01   ..........#.....
0370   c3 05 00 00 00 00 00 00 00 00 00 00 00 00 9f 2d   ...............-
0380   46 40 00 b0 ed 39 54 36 74 bc 00 00 00 00 00 00   F@...9T6t.......
0390   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
03a0   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
03b0   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
03c0   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
03d0   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
03e0   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
03f0   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
0400   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
0410   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
0420   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
0430   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
0440   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
0450   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
0460   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
0470   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
0480   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
0490   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
04a0   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
04b0   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
04c0   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
04d0   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
04e0   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
04f0   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
0500   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
0510   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
0520   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
0530   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
0540   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
0550   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
0560   00 00 00 00 00 00 00 00 00 00 f5 ea 05 42 ad 0a   .............B..
0570   05 42 2b 05 0f 42 70 7f 10 42 99 92 84 bf 64 1c   .B+..Bp..B....d.
0580   3b 3f fd 17 94 bf 3f 9a 9a 3f 5f 4c c3 c1 3a 25   ;?....?..?_L..:%
0590   0c c1 53 cf fe c1 97 ed bc 41 00 00 00 00 00 00   ..S......A......
05a0   00 00 00 00 00 00 00 00 00 00 d1 16 95 3b 7e 73   .............;~s
05b0   8c 3b d7 90 95 3b 1e fa 8b 3b 90 1f 03 bb 08 e7   .;...;...;......
05c0   50 38 92 ec 68 bc 4e 9c a5 39 5e 25 36 bb 8c 04   P8..h.N..9^%6...
05d0   f2 b9 28 b2 2c bb c1 7b d3 bd 0c 94 49 3d d5 39   ..(.,..{....I=.9
05e0   0a 39                                             .9

Can you please attach data in Wireshark format.

What is the RX buffer size? If W5500 receives packet, and next packet arrives which has data larger than remaining RX buffer space, then this next packet will be discarded - you will not get it into the buffer because there’s simply no space. How does your code free the RX buffer? I do not see parsePacket() getting data out of there.

Hi Eugeny,

What do you mean by Wireshark format? *.pcapng?

I didn’t change the size right now but already expermiented with that - no effect. As far as I know the basic size is 2kb per socket, 8 sockets, 16kb altogether.

found this in the code:


public:
  static const uint16_t SSIZE = 2048; // Max Tx buffer size
private:
  static const uint16_t RSIZE = 2048; // Max Rx buffer size

It seems tha even not all of the packages that i send manually are recognised by the controller, yet Wireshark sees them.

What can I do to give you a better insight? Want the code?

The Data itself is processed by udp.read() but only if there is something in it. But all of this is standard Ethernet2 library:

int EthernetUDP::read(unsigned char* buffer, size_t len)
{

  if (_remaining > 0)
  {

    int got;

    if (_remaining <= len)
    {
      // data should fit in the buffer
      got = recv(_sock, buffer, _remaining);
    }
    else
    {
      // too much data for the buffer, 
      // grab as much as will fit
      got = recv(_sock, buffer, len);
    }

    if (got > 0)
    {
      _remaining -= got;
      return got;
    }

  }

  // If we get here, there's no data available or recv failed
  return -1;

}

int16_t recv(SOCKET s, uint8_t *buf, int16_t len)
{
  // Check how much data is available
  int16_t ret = w5500.getRXReceivedSize(s);
  if ( ret == 0 )
  {
    // No data available.
    uint8_t status = w5500.readSnSR(s);
    if ( status == SnSR::LISTEN || status == SnSR::CLOSED || status == SnSR::CLOSE_WAIT )
    {
      // The remote end has closed its side of the connection, so this is the eof state
      ret = 0;
    }
    else
    {
      // The connection is still up, but there's no data waiting to be read
      ret = -1;
    }
  }
  else if (ret > len)
  {
    ret = len;
  }

  if ( ret > 0 )
  {
    w5500.recv_data_processing(s, buf, ret);
    w5500.execCmdSn(s, Sock_RECV);
  }
  return ret;
}

uint16_t W5500Class::getRXReceivedSize(SOCKET s)
{
    uint16_t val=0,val1=0;
    do {
        val1 = readSnRX_RSR(s);
        if (val1 != 0)
            val = readSnRX_RSR(s);
    } 
    while (val != val1);
    return val;
}

void W5500Class::recv_data_processing(SOCKET s, uint8_t *data, uint16_t len, uint8_t peek)
{
    uint16_t ptr;
    ptr = readSnRX_RD(s);

    read_data(s, ptr, data, len);
    if (!peek)
    {
        ptr += len;
        writeSnRX_RD(s, ptr);
    }
}

void W5500Class::read_data(SOCKET s, volatile uint16_t src, volatile uint8_t *dst, uint16_t len)
{
    uint8_t cntl_byte = (0x18+(s<<5));
    read((uint16_t)src , cntl_byte, (uint8_t *)dst, len);
}

void W5500Class::execCmdSn(SOCKET s, SockCMD _cmd) {
    // Send command to socket
    writeSnCR(s, _cmd);
    // Wait for command to complete
    while (readSnCR(s))
    ;
}

uint16_t W5500Class::read(uint16_t _addr, uint8_t _cb, uint8_t *_buf, uint16_t _len)
{ 
    SPI.beginTransaction(wiznet_SPI_settings);
    setSS();
    SPI.transfer(_addr >> 8);
    SPI.transfer(_addr & 0xFF);
    SPI.transfer(_cb);
    for (uint16_t i=0; i<_len; i++){
        _buf[i] = SPI.transfer(0);
    }
    resetSS();
    SPI.endTransaction();

    return _len;
}

Does your compilator allow omitting arguments? What is the value of peek when recv_data_processing() is called?

You are right, the nr. of parameters from call and function don’t add up. Yet there’s no warning concerning that. Should I worry?

The peek output just before the if statement is and always stays “0”. Which means the pointer+length is calculated and written in the register, right? Btw. peek is initialized in the header file as “0”.

If it is normal under programming language specification then someone changing default value will make application inoperable.

This was my question - is it always calculated and target register updated? Can you please ensure everything is defined explicitly (e.g. value of this peek).

Hey Eugeny,

as far as I kept on reading I found out, that it may be possible that I can’t pickup the contents of the buffer fast enough to ensure to get every packet. Despite the ESP32 ist pretty fast compared to e.g. an AtMega32U4. But what i’m still wondering about is the fact that only these big packages seem to be the problem yet they are sent at the same rate!?

So still struggling with this issue. The rest works really well for my purposes I think, if could sort out that size matter even If I didn’t catch every single packet it would still be great. therefore I was experimenting with the sending frequency of the data… (can be set to 10/20/30/60Hz). Sending only in 10Hz didn’t help either - the big ones are still gone.

“peek” as i said is defined as “uint8_t peek = 0” in the header. I found no other operation that is altering peek whatsoever.

Concering the parameters given for recv_data_processing function I investigated if there’s any other function to call with the right ammount of arguments… couldn’t find anything else but the already shown funtionality.

If what you say is the case (must prove!) then the speed of buffer pointer advancement matters. And this speed may depend on many factors - your algorithm, time for ISR etc. How to prove? Speed up the communication by NOT reading data from the buffer. Just advance pointer, logging that you have got a packet. This way you will not spend time on reading packet data.

This `peek is an argument to the function. Can you explicitly set to pass 0 every time you call function, or remove the condition to always advance the pointer?

Try increasing socket 0 RX buffer size to max 16KB.

Hi Eugeny,

I just solved my problem… But not by fixing the Ethernet2 lib. I did a fast test with the ethernet_generic lib an it worked instantly. At 30Hz send rate i receive 28.4Hz which ist far more than i expected!

Thanks for all the effort you put Info this for me!

@everyone else having Problems with receiving bigger packets… Switch to ethernet_generic lib! :wink:

Regards!
S.

1 Like