You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to get some USB to Serial adapters to work, that are not the CDC ACM devices (would like to get those to work as well).
So I started hacking up my own object. Currently doing it all within an Arduino sketch, where I have the .cpp and .h for the new object contained within the sketch.
In this case the device is a GPS unit has an PL2303 chipset in it:
My connect code:
bool USBHostFTDI::connect() {
USB_INFO(" USBHostFTDI::connect() called\r\n");
if (dev) {
for (uint8_t i = 0; i < MAX_DEVICE_CONNECTED; i++) {
USBDeviceConnected* d = host->getDevice(i);
if (dev == d)
return true;
}
disconnect();
}
host = USBHost::getHostInst();
for (uint8_t i = 0; i < MAX_DEVICE_CONNECTED; i++) {
USBDeviceConnected* d = host->getDevice(i);
USB_DBG("\tDev: %p\r\n", d);
if (d != NULL) {
USB_INFO("Device:%p\r\n", d);
if (host->enumerate(d, this) != USB_TYPE_OK) {
USB_INFO("Enumerate returned status not OK");
continue; //break; what if multiple devices?
}
printf("\tconnect hser_device_found\n\r");
bulk_in = d->getEndpoint(intf_SerialDevice, BULK_ENDPOINT, IN);
USB_INFO("bulk in:%p", bulk_in);
bulk_out = d->getEndpoint(intf_SerialDevice, BULK_ENDPOINT, OUT);
USB_INFO(" out:%p\r\n", bulk_out);
printf("\tAfter get end points\n\r");
if (bulk_in && bulk_out) {
dev = d;
dev_connected = true;
// USB_INFO("New hser device: VID:%04x PID:%04x [dev: %p - intf: %d]", dev->getVid(), dev->getPid(), dev, intf_SerialDevice);
printf("New hser device: VID:%04x PID:%04x [dev: %p - intf: %d]", dev->getVid(), dev->getPid(), dev, intf_SerialDevice);
dev->setName("Serial", intf_SerialDevice);
host->registerDriver(dev, intf_SerialDevice, this, &USBHostFTDI::init);
size_bulk_in = bulk_in->getSize();
size_bulk_out = bulk_out->getSize();
bulk_in->attach(this, &USBHostFTDI::rxHandler);
bulk_out->attach(this, &USBHostFTDI::txHandler);
host->bulkRead(dev, bulk_in, buf, size_bulk_in, false);
printf("\n\r>>>>>>>>>>>>>> connected returning true <<<<<<<<<<<<<<<<<<<<\n\r");
return true;
}
}
}
init();
return false;
}
It is faulting on the call: bulk_in = d->getEndpoint(intf_SerialDevice, BULK_ENDPOINT, IN);
Note: the useEndpoints code could be simplified:
/*virtual*/ bool USBHostFTDI::useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir) //Must return true if the endpoint will be used
{
USB_INFO("USBHostFTDI::useEndpoint(%u, %u, %u\n\r", intf_nb, type, dir);
printf("USBHostFTDI::useEndpoint(%u, %u, %u\n\r", intf_nb, type, dir);
if (intf_nb == intf_SerialDevice) {
//if (type == INTERRUPT_ENDPOINT && dir == IN) return true; // see if we can ignore it later
if (type == BULK_ENDPOINT && dir == IN) {
hser_device_found = true;
return true;
}
if (type == BULK_ENDPOINT && dir == OUT) {
hser_device_found = true;
return true;
}
}
return false;
}
Note: these devices as well as some other USB to Serial adapters, the interface has 3 endpoints,
The first one typically being an Interrupt IN, which, I am saying NO to use. the second and third endpoints are BULK OUT and BULK IN which I am trying to use. This should work as it is how the devices are handled in some other code bases.
Here is debug output for a run I just did, which is now in the blinking red lights cycle...
Note the last two debug lines are from some debug information I added to the library code:
USBEndpoint * USBDeviceConnected::getEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint8_t index) {
USB_DBG("getEndpoint(%u %u %u %u %p", intf_nb, type, dir, index);
if (intf_nb >= MAX_INTF) {
return NULL;
}
for (int i = 0; i < MAX_ENDPOINT_PER_INTERFACE; i++) {
USB_DBG("index: %d %p", i, intf[intf_nb].ep[i]);
if ( intf[intf_nb].ep[i] == nullptr) continue; // don't walk through NULL
if ((intf[intf_nb].ep[i]->getType() == type) && (intf[intf_nb].ep[i]->getDir() == dir)) {
if(index) {
index--;
} else {
return intf[intf_nb].ep[i];
}
}
}
return NULL;
}
My first guess was the: intf[intf_nb].ep[i]
value was probably going to be NULL, so I added test for it, which did not help.
Looks like the value is: 0xffff
Which then trying to use that as an object pointer faulted. Not sure if that has special meaning here? Or
the code is not handling the case where there are more end points than the library is configured to allow per interface?
or?
The text was updated successfully, but these errors were encountered:
Like #32. There is a lot more information in the forum posts:
https://forum.arduino.cc/t/can-not-find-examples-for-usbhostserial/1182486/18?u=kurte
I am trying to get some USB to Serial adapters to work, that are not the CDC ACM devices (would like to get those to work as well).
So I started hacking up my own object. Currently doing it all within an Arduino sketch, where I have the .cpp and .h for the new object contained within the sketch.
In this case the device is a GPS unit has an PL2303 chipset in it:
My connect code:
It is faulting on the call:
bulk_in = d->getEndpoint(intf_SerialDevice, BULK_ENDPOINT, IN);
Note: the useEndpoints code could be simplified:
Note: these devices as well as some other USB to Serial adapters, the interface has 3 endpoints,
The first one typically being an Interrupt IN, which, I am saying NO to use. the second and third endpoints are BULK OUT and BULK IN which I am trying to use. This should work as it is how the devices are handled in some other code bases.
Here is debug output for a run I just did, which is now in the blinking red lights cycle...
Note the last two debug lines are from some debug information I added to the library code:
My first guess was the: intf[intf_nb].ep[i]
value was probably going to be NULL, so I added test for it, which did not help.
Looks like the value is: 0xffff
Which then trying to use that as an object pointer faulted. Not sure if that has special meaning here? Or
the code is not handling the case where there are more end points than the library is configured to allow per interface?
or?
The text was updated successfully, but these errors were encountered: