Double buffered USB endpoints
Posted: Fri May 06, 2011 9:00 am
Hi,
I've been having some trouble getting double buffered endpoints working. I'm trying to put together a simple test program to demonstrate, but in the mean time what I am doing is this:
Defining the endpoint config:
Initialising the endpoint in the usb event handler:
UART1_EPNUM = 1.
The USB descriptors are set correctly and include the endpoint twice at addresses 0x81 and 0x01. The device enumerates fine and that is not a problem.
But I am finding that whilst the device responds fine to a bulk write, the bulk read call back is never used. I put together a very simple libusb-0.1 based test program to connect to the device. The write succeeds but the read fails due to timeout. I tried to upload this as an attachment but the board wont allow .c files...
In the end, after digging through the ChibiOS USB code I managed to get it working by changing usb_lld_init_endpoint() slightly from:
To:
Which leads me to my question: does the current usb stack handle double buffered endpoints?
Thanks!
I've been having some trouble getting double buffered endpoints working. I'm trying to put together a simple test program to demonstrate, but in the mean time what I am doing is this:
Defining the endpoint config:
Code: Select all
static const USBEndpointConfig uart1_ep_c = {
.ep_mode = USB_EP_MODE_TYPE_BULK | USB_EP_MODE_PACKET,
.setup_cb = NULL,
.in_cb = uart_tx,
.out_cb = uart_rx,
.in_maxsize = 0x0040,
.out_maxsize = 0x0040,
.in_state = NULL,
.out_state = NULL
};Initialising the endpoint in the usb event handler:
Code: Select all
usbInitEndpointI(usbp, UART1_EPNUM, &uart1_ep_c);UART1_EPNUM = 1.
The USB descriptors are set correctly and include the endpoint twice at addresses 0x81 and 0x01. The device enumerates fine and that is not a problem.
But I am finding that whilst the device responds fine to a bulk write, the bulk read call back is never used. I put together a very simple libusb-0.1 based test program to connect to the device. The write succeeds but the read fails due to timeout. I tried to upload this as an attachment but the board wont allow .c files...
Code: Select all
#include <stdio.h>
#include <sys/types.h>
#include <usb.h>
int main(void)
{
struct usb_bus *bus;
struct usb_device *dev;
struct usb_dev_handle *device = NULL;
int vendor = 0x1403;
int product = 0x6010;
char buf[64];
int ret;
int timeout = 1000;
char iface;
char out, in;
int d = 0;
if(d == 1) {
iface = 1;
out = 0x03;
in = 0x81;
} else {
iface = 0;
out = 0x01;
in = 0x01;
}
usb_init();
if (usb_find_busses() < 0)
printf("usb_find_busses() failed\n");
if (usb_find_devices() < 0)
printf("usb_find_devices() failed\n");
printf("Looking for usb device..\n");
for (bus = usb_get_busses(); bus; bus = bus->next) {
for (dev = bus->devices; dev; dev = dev->next) {
if (dev->descriptor.idVendor == vendor && dev->descriptor.idProduct == product) {
printf("Found it!\n");
device = usb_open(dev);
bus = NULL;
break;
}
}
if(bus == NULL)
break;
}
if(device == NULL) {
printf("Couldn't find device\n");
return -1;
}
usb_claim_interface(device, iface);
ret = usb_bulk_write (device, out, buf, 64, timeout);
if(ret < 0) {
fprintf(stderr, "usb error: %d (%s)\n", ret, usb_strerror());
} else {
printf("wrote some data\n");
}
ret = usb_bulk_read (device, in, buf, 64, timeout);
if(ret < 0) {
fprintf(stderr, "usb error: %d (%s)\n", ret, usb_strerror());
} else {
printf("read some data\n");
}
return 0;
}In the end, after digging through the ChibiOS USB code I managed to get it working by changing usb_lld_init_endpoint() slightly from:
Code: Select all
/* IN endpoint settings, always in NAK mode initially.*/
if (epcp->in_cb != NULL)
epr |= EPR_STAT_TX_NAK;To:
Code: Select all
/* IN endpoint settings, always in NAK mode initially.*/
if (epcp->in_cb != NULL)
epr |= EPR_STAT_TX_VALID;Which leads me to my question: does the current usb stack handle double buffered endpoints?
Thanks!