Attached is the simple patch to make it work under Windows. The Windows binary built with MinGW and the libusb-win32 device driver are also included. Regards, Xiaofan --------------------------------------------------------------------------------------- The main difference between libusb-win32 and libusb is that libusb has a trick so that it does not care the direction bit of the endpoint but libusb-win32 cares. The following is a patch generated by "diff -u" under MinGW/MSys for the file usb_pickit.c and the file main.c to make it work under Windows. It also supresses some warning messages. I've never used diff before so in the zip attachment (remove the .any extension) I actually attach the update files). 1) patch to usb_pickit.c --- usb_pickit_org.c Wed Jan 11 16:08:48 2006 +++ usb_pickit.c Sun Jan 15 14:23:54 2006 @@ -16,9 +16,20 @@ const static int pickit_productID=0x0032; // PICkit 1 FLASH starter kit const static int pickit_configuration=2; /* 1: HID; 2: vendor specific */ const static int pickit_interface=0; -const static int pickit_endpoint=1; /* first endpoint for everything */ +/* change by Xiaofan: Windows cares the direction bit of endpoint */ +//const static int pickit_endpoint=1; /* first endpoint for everything */ +const static int pickit_endpoint_out=1; /* endpoint 1 address for OUT */ +const static int pickit_endpoint_in=0x81; /* endpoint 0x81 address for IN */ +/* end of changes by Xiaofan */ const static int pickit_timeout=1000; /* timeout in ms */ +#ifdef WIN32 +#include +#define sleep(x) Sleep(x/1000) +#endif + +extern void printUsage(const char *why); + /* PICkit always uses 8-byte transfers */ const static int reqLen=8; typedef unsigned char byte; @@ -59,7 +70,7 @@ /** Send this binary string command. */ static void send_usb(usb_pickit *d,const char *src) { - int r=PICKIT_USB(write)(d,pickit_endpoint, + int r=PICKIT_USB(write)(d,pickit_endpoint_out, (char *)src,reqLen,pickit_timeout); if (r!=reqLen) { perror("usb PICkit write"); bad("USB write failed"); } } @@ -88,9 +99,9 @@ /** Read this many bytes from this device */ /* JEB - added (char *) casting to dest to supress the signedness difference warning, during compilation */ static void recv_usb(usb_pickit *d,int len,byte *dest) { - int i; +// int i; - int r=PICKIT_USB(read)(d,pickit_endpoint,(char *)dest,len,pickit_timeout); + int r=PICKIT_USB(read)(d,pickit_endpoint_in,(char *)dest,len,pickit_timeout); if (r!=len) { perror("usb PICkit read"); bad("USB read failed"); } } @@ -129,8 +140,10 @@ struct usb_device *device; struct usb_bus* bus; +#ifndef WIN32 if (geteuid()!=0) bad("This program must be run as root, or made setuid root"); +#endif #ifdef USB_DEBUG usb_debug=4; @@ -222,7 +235,7 @@ a four byte boundary. So I simply increased the size of the program memory read by 1. this bug only seems to effect the 627,675,630,676 devices.*/ const char *usb_pickit_get_device(usb_pickit *d, pic14_state *s) { - char *deviceName; + char *deviceName=NULL; char *err=NULL; int rev; pic14_word id_word; @@ -614,7 +627,7 @@ void usb_pickit_merge_config(usb_pickit *d, pic14_config *oldconfig, pic14_config *newconfig) { - int i; +// int i; pic14_config merged=*newconfig; merged.osccal=oldconfig->osccal; #define BG_MASK 0x3000 /* mask to extract bandgap bits */ 2) patch to main.c --- main.c.bak Wed Jan 4 15:21:28 2006 +++ main.c Sun Jan 15 14:21:05 2006 @@ -4,6 +4,7 @@ #include #include #include "usb_pickit.h" +#include /* Write .hex file data into a chip */ const char *programMode(usb_pickit *d,const char *inFile,int keepOld) { 3) Sample running session E:\Coding\usb_pickit_1.5-jeb>usb_pickit --off Locating USB Microchip(tm) PICkit(tm) (vendor 0x04d8/product 0x0032) found 3 busses Found USB PICkit as device '\\.\libusb0-0001--0x04d8-0x0032' on USB bus bus-0 Communication established. Onboard firmware version is 2.0.2 E:\Coding\usb_pickit_1.5-jeb>usb_pickit --extract test636.hex Locating USB Microchip(tm) PICkit(tm) (vendor 0x04d8/product 0x0032) found 3 busses Found USB PICkit as device '\\.\libusb0-0001--0x04d8-0x0032' on USB bus bus-0 Communication established. Onboard firmware version is 2.0.2 PIC16F636 / 16F639 Rev 1 found E:\Coding\usb_pickit_1.5-jeb>usb_pickit --verify test636.hex Locating USB Microchip(tm) PICkit(tm) (vendor 0x04d8/product 0x0032) found 3 busses Found USB PICkit as device '\\.\libusb0-0001--0x04d8-0x0032' on USB bus bus-0 Communication established. Onboard firmware version is 2.0.2 PIC16F636 / 16F639 Rev 1 found .hex file contains a configuration word Program Memory verified with .hex file. Program Memory Checksum verified with .hex file. Config Word verified with .hex file. Config IDs verified with .hex file. EE Data Memory verified with .hex file. Device successfully verified with .hex file.