USB Host conflict with Ethernet

Hello! I am wondering if someone else can replicate this bug. I seem to be getting a conflict when using USB host to read a HID device (testing with FS) and ethernet. The ethernet seems to still work, but the USB never reads any data.


#include "USBHost.h"
#include <PortentaEthernet.h>
#include <Ethernet.h>
#include <EthernetUdp.h>

USBHost usb;

// The IP address will be dependent on your local network:
IPAddress ip(192, 168, 0, 177);

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

// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE];  // buffer to hold incoming packet,
char ReplyBuffer[] = "acknowledged";        // a string to send back

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


static int process_hid_recv(tusbh_ep_info_t* ep, const uint8_t* data, uint32_t len) {
  //Serial.println("test");
  for (int i = 0; i < len; i++) {
    if (data[i] != 0) {
      Serial.println(data[i]);
    }
  }
}


static const tusbh_hid_class_t cls_hid = {
  .backend = &tusbh_hid_backend,
  .on_recv_data = process_hid_recv,
  //.on_send_done = process_hid_sent,
};


static const tusbh_class_reg_t class_table[] = {
  (tusbh_class_reg_t)&cls_hid,
  0,
};

void setup()
{
  Serial.begin(115200);
  Serial.println("Booted");
  //usb.Init(USB_CORE_ID_HS, class_table);
  usb.supplyPowerOnVBUS(true);

  usb.Init(USB_CORE_ID_FS, class_table);
  /* //Works if the following line is uncommented
  // start the Ethernet
  Ethernet.begin(ip);

  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // Check for Ethernet hardware present
  if (Ethernet.hardwareStatus() == EthernetNoHardware) {
    Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
    while (true) {
      delay(1); // do nothing, no point running without Ethernet hardware
    }
  }
  if (Ethernet.linkStatus() == LinkOFF) {
    Serial.println("Ethernet cable is not connected.");
  }

  // start UDP
  Udp.begin(localPort);
*/
}

void loop() {
  usb.Task();
}

Is the ethernet shield on the bottom, under the USB Host?
Did you reassign the SS for the USB Host to another pin, like D7?
Did you bend D10 on the USBHost shield so it doesn't go into the ethernet shield?
Did you jumper D10 to D7 on the USB Host shield?
Just checking.

Hi, it's not a shield, it's the built-in USB on the Portenta.

Not sure how much help I can be there.
Which Portenta do you have? H7?
Did you look at the examples? IDE - > File -> Examples
I looked at the H7, and the USB Host setup looks different than yours.

Yes, it's the H7.
This is code basically directly from the USB Keyboard reader example project, just added the functions to read HID devices. I see the HID data if ethernet is not enabled.

If you uncomment the ethernet code, you are changing the Serial baud rate.
If you are watching the native serial port at 115200, then change the baud rate to 9600, the output will apparently stop due to baud rate mismatch.
Just a thought...

Yes, unfortunately it doesn't make a differnence.
I tried to make a separate sketch with WiFi rather than Ethernet, and it does work for a couple seconds but stops.

Have you tried the DhcpAddressPrinter sketch in examples?
Maybe your IP is incorrect?
I presume your localnet has a dhcp server.

Edit: Ethernet.begin() returns a value. Last I checked returning zero indicated a fail.

Edit2: Did you figure out Ethernet.begin() requires a mac address?

Ethernet.begin(mac,ip);`