Hi all,

I've been testing the ethernet capabilities of the Teensy 4.1 for receiving large UDP packets, and I've run up against a limit which I'm not learned enough to understand or solve.

I've got a minimal sketch which, after establishing the ethernet connection, just checks the size of the packet coming in and spits that out the USB serial.
At first I ran into the issue of packets being dropped entirely when they were larger than 2048 bytes, which I figured out was due to the SocketSize being set to precisely that. In testing of increasing this value, there seems to be a hard limit at 10212 bytes, even though I've seen samples floating around which have Ethernet.setSocketSize(1024 * 16); i.e. 16k, well larger than the 10 and a bit k I can actually achieve. I've pasted the arduino sketch below, and am using Max to send UDP packets of given sizes to test what comes back with "Received packet of size ". I've tried increasing StackHeap size, and reducing the SocketNum, but neither (and no combinations) seem to increase the acceptable max size of an incoming packet.

Does anyone have ideas why this might be happening, and whether it's possible to increase beyond this point? Or is there a hardware limitation of some sort at play here?
My ideal target for a project I'm working on is 36225 bytes, so there's a long gap to bridge!

Any help is much appreciated!

Code:
#include <NativeEthernet.h>
#include <NativeEthernetUdp.h>

// Any group of digital pins may be used
// Enter an IP address for your controller below.
// The IP address will be dependent on your local network:
IPAddress ip(192, 168, 2, 177);

unsigned int localPort = 3333;      // local port to listen on

// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;

void setup() {
  Serial.begin(9600);
  uint8_t mac[6];
  teensyMAC(mac);
  Ethernet.setStackHeap(1024 * 64);
  Ethernet.setSocketSize(1024 * 16);
  Ethernet.setSocketNum(1);
  Ethernet.begin(mac, ip);
  Serial.println("Ethernet started");
  if (Ethernet.hardwareStatus() == EthernetNoHardware) {
    while (true) {
      Serial.println("Ethernet hardware not found?!");
      delay(1000);
    }
  }
  if (Ethernet.linkStatus() == LinkOFF) {
    while (true) {
      Serial.println("Waiting for Ethernet cable to be connected.");
      delay(1000);
    }
  }
  Serial.println("Ethernet OK");
  Serial.print("IP address: ");
  Serial.println(Ethernet.localIP());
  Udp.begin(localPort);
  Serial.println("Started UDP sevice");
}

void loop() {
  int packetSize = Udp.parsePacket();
  if(packetSize) {
    Serial.print("Received packet of size ");
    Serial.println(packetSize);
    while(Udp.available()){
      Udp.read();
    }
  }
}

void teensyMAC(uint8_t *mac) {

  static char teensyMac[23];
  
  #if defined(HW_OCOTP_MAC1) && defined(HW_OCOTP_MAC0)
    Serial.println("using HW_OCOTP_MAC* - see https://forum.pjrc.com/threads/57595-Serial-amp-MAC-Address-Teensy-4-0");
    for(uint8_t by=0; by<2; by++) mac[by]=(HW_OCOTP_MAC1 >> ((1-by)*8)) & 0xFF;
    for(uint8_t by=0; by<4; by++) mac[by+2]=(HW_OCOTP_MAC0 >> ((3-by)*8)) & 0xFF;

    #define MAC_OK

  #else
    
    mac[0] = 0x04;
    mac[1] = 0xE9;
    mac[2] = 0xE5;

    uint32_t SN=0;
    __disable_irq();
    
    #if defined(HAS_KINETIS_FLASH_FTFA) || defined(HAS_KINETIS_FLASH_FTFL)
      Serial.println("using FTFL_FSTAT_FTFA - vis teensyID.h - see https://github.com/sstaub/TeensyID/blob/master/TeensyID.h");
      
      FTFL_FSTAT = FTFL_FSTAT_RDCOLERR | FTFL_FSTAT_ACCERR | FTFL_FSTAT_FPVIOL;
      FTFL_FCCOB0 = 0x41;
      FTFL_FCCOB1 = 15;
      FTFL_FSTAT = FTFL_FSTAT_CCIF;
      while (!(FTFL_FSTAT & FTFL_FSTAT_CCIF)) ; // wait
      SN = *(uint32_t *)&FTFL_FCCOB7;

      #define MAC_OK
      
    #elif defined(HAS_KINETIS_FLASH_FTFE)
      Serial.println("using FTFL_FSTAT_FTFE - vis teensyID.h - see https://github.com/sstaub/TeensyID/blob/master/TeensyID.h");
      
      kinetis_hsrun_disable();
      FTFL_FSTAT = FTFL_FSTAT_RDCOLERR | FTFL_FSTAT_ACCERR | FTFL_FSTAT_FPVIOL;
      *(uint32_t *)&FTFL_FCCOB3 = 0x41070000;
      FTFL_FSTAT = FTFL_FSTAT_CCIF;
      while (!(FTFL_FSTAT & FTFL_FSTAT_CCIF)) ; // wait
      SN = *(uint32_t *)&FTFL_FCCOBB;
      kinetis_hsrun_enable();

      #define MAC_OK
      
    #endif
    
    __enable_irq();

    for(uint8_t by=0; by<3; by++) mac[by+3]=(SN >> ((2-by)*8)) & 0xFF;

  #endif

  #ifdef MAC_OK
    sprintf(teensyMac, "MAC: %02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
    Serial.println(teensyMac);
  #else
    Serial.println("ERROR: could not get MAC");
  #endif
}