Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Patch for avrdude-6.0.1 and AVR-ISP-MKII
Index: stk500v2.c
===================================================================
--- stk500v2.c (6.0.1)
+++ stk500v2.c (working copy)
@@ -1618,9 +1618,9 @@
baud = USB_DEVICE_AVRISPMKII;
PDATA(pgm)->pgmtype = PGMTYPE_AVRISP_MKII;
pgm->set_sck_period = stk500v2_set_sck_period_mk2;
- pgm->fd.usb.max_xfer = USBDEV_MAX_XFER_MKII;
- pgm->fd.usb.rep = USBDEV_BULK_EP_READ_MKII;
- pgm->fd.usb.wep = USBDEV_BULK_EP_WRITE_MKII;
+ pgm->fd.usb.max_xfer = 0;
+ pgm->fd.usb.rep = -1;
+ pgm->fd.usb.wep = -1;
pgm->fd.usb.eep = 0; /* no seperate EP for events */
#else
fprintf(stderr, "avrdude was compiled without usb support.\n");
@@ -1674,7 +1674,7 @@
baud = USB_DEVICE_STK600;
PDATA(pgm)->pgmtype = PGMTYPE_STK600;
pgm->set_sck_period = stk600_set_sck_period;
- pgm->fd.usb.max_xfer = USBDEV_MAX_XFER_MKII;
+ pgm->fd.usb.max_xfer = 0;
pgm->fd.usb.rep = USBDEV_BULK_EP_READ_STK600;
pgm->fd.usb.wep = USBDEV_BULK_EP_WRITE_STK600;
pgm->fd.usb.eep = 0; /* no seperate EP for events */
@@ -3410,9 +3410,9 @@
#if defined(HAVE_LIBUSB)
serdev = &usb_serdev;
baud = USB_DEVICE_JTAGICEMKII;
- pgm->fd.usb.max_xfer = USBDEV_MAX_XFER_MKII;
- pgm->fd.usb.rep = USBDEV_BULK_EP_READ_MKII;
- pgm->fd.usb.wep = USBDEV_BULK_EP_WRITE_MKII;
+ pgm->fd.usb.max_xfer = 0;
+ pgm->fd.usb.rep = -1;
+ pgm->fd.usb.wep = -1;
pgm->fd.usb.eep = 0; /* no seperate EP for events */
#else
fprintf(stderr, "avrdude was compiled without usb support.\n");
@@ -3523,9 +3523,9 @@
#if defined(HAVE_LIBUSB)
serdev = &usb_serdev;
baud = USB_DEVICE_AVRDRAGON;
- pgm->fd.usb.max_xfer = USBDEV_MAX_XFER_MKII;
- pgm->fd.usb.rep = USBDEV_BULK_EP_READ_MKII;
- pgm->fd.usb.wep = USBDEV_BULK_EP_WRITE_MKII;
+ pgm->fd.usb.max_xfer = 0;
+ pgm->fd.usb.rep = -1;
+ pgm->fd.usb.wep = -1;
pgm->fd.usb.eep = 0; /* no seperate EP for events */
#else
fprintf(stderr, "avrdude was compiled without usb support.\n");
Index: usb_libusb.c
===================================================================
--- usb_libusb.c (6.0.1)
+++ usb_libusb.c (working copy)
@@ -103,9 +103,7 @@
}
}
- if (fd->usb.max_xfer == 0)
- fd->usb.max_xfer = USBDEV_MAX_XFER_MKII;
-
+
usb_init();
usb_find_busses();
@@ -202,16 +200,19 @@
}
fd->usb.handle = udev;
- if (fd->usb.rep == 0)
+ if (fd->usb.rep < 0)
{
/* Try finding out what our read endpoint is. */
for (i = 0; i < dev->config[0].interface[0].altsetting[0].bNumEndpoints; i++)
{
- int possible_ep = dev->config[0].interface[0].altsetting[0].
- endpoint[i].bEndpointAddress;
-
+ int possible_ep = dev->config[0].interface[0].altsetting[0].endpoint[i].bEndpointAddress;
+ int possible_ep_size = dev->config[0].interface[0].altsetting[0].endpoint[i].wMaxPacketSize;
+
if ((possible_ep & USB_ENDPOINT_DIR_MASK) != 0)
{
+ fprintf(stderr,
+ "%s: usbdev_open(): using read endpoint 0x%02x\n",
+ progname, possible_ep);
if (verbose > 1)
{
fprintf(stderr,
@@ -219,33 +220,49 @@
progname, possible_ep);
}
fd->usb.rep = possible_ep;
+ //Take smaller endpoint size as max
+ if ((fd->usb.max_xfer == 0) || (possible_ep_size < fd->usb.max_xfer))
+ {
+ fd->usb.max_xfer = possible_ep_size;
+ }
break;
}
}
- if (fd->usb.rep == 0)
+ if (fd->usb.rep < 0)
{
fprintf(stderr,
- "%s: usbdev_open(): cannot find a read endpoint, using 0x%02x\n",
- progname, USBDEV_BULK_EP_READ_MKII);
- fd->usb.rep = USBDEV_BULK_EP_READ_MKII;
+ "%s: usbdev_open(): ERROR: cannot find a read endpoint\n",
+ progname);
+
}
}
- for (i = 0; i < dev->config[0].interface[0].altsetting[0].bNumEndpoints; i++)
+ if (fd->usb.wep < 0)
{
- if ((dev->config[0].interface[0].altsetting[0].endpoint[i].bEndpointAddress == fd->usb.rep ||
- dev->config[0].interface[0].altsetting[0].endpoint[i].bEndpointAddress == fd->usb.wep) &&
- dev->config[0].interface[0].altsetting[0].endpoint[i].wMaxPacketSize < fd->usb.max_xfer)
+ /* Try finding out what our write endpoint is. */
+ for (i = 0; i < dev->config[0].interface[0].altsetting[0].bNumEndpoints; i++)
{
- if (verbose != 0)
- fprintf(stderr,
- "%s: max packet size expected %d, but found %d due to EP 0x%02x's wMaxPacketSize\n",
- progname,
- fd->usb.max_xfer,
- dev->config[0].interface[0].altsetting[0].endpoint[i].wMaxPacketSize,
- dev->config[0].interface[0].altsetting[0].endpoint[i].bEndpointAddress);
- fd->usb.max_xfer = dev->config[0].interface[0].altsetting[0].endpoint[i].wMaxPacketSize;
+ int possible_ep = dev->config[0].interface[0].altsetting[0].endpoint[i].bEndpointAddress;
+ int possible_ep_size = dev->config[0].interface[0].altsetting[0].endpoint[i].wMaxPacketSize;
+
+ if ((possible_ep & USB_ENDPOINT_DIR_MASK) == 0)
+ {
+ fprintf(stderr, "%s: usbdev_open(): using write endpoint 0x%02x\n",
+ progname, possible_ep);
+ fd->usb.wep = possible_ep;
+ //Take smaller endpoint size as max
+ if ((fd->usb.max_xfer == 0) || (possible_ep_size < fd->usb.max_xfer))
+ {
+ fd->usb.max_xfer = possible_ep_size;
+ }
+ break;
+ }
+ }
+ if (fd->usb.wep < 0)
+ {
+ fprintf(stderr, "%s: usbdev_open(): ERROR: cannot find a write endpoint",
+ progname);
+ }
}
- }
return 0;
trynext:
usb_close(udev);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.