diff --git a/README b/README deleted file mode 100644 index 389b017..0000000 --- a/README +++ /dev/null @@ -1,26 +0,0 @@ -fxload-libusb -============= - -Copyright (c) 2007 claudio.favi@epfl.ch - -This code was modified from linux-hotplug project. -http://linux-hotplug.sourceforge.net/ - -Copying: read the copying coming with the code. - -Usage is very similar to the original code expect that the device -selection/link/mode functions have been removed and replace with -interactive selection. - -To load into RAM: -./fxload-libusb.exe -t fx2 -I ../fx2fw-sdcc/usbjtag.hex -To flash the EEPROM use the Vend_Ax.hex stage2 loader from Cypress. -./fxload-libusb.exe -s Vend_Ax.hex -c 0xC2 -t fx2 -I ../fx2fw-sdcc/usbjtag.hex - -Dependencies: libusb: I used libusb-win32-filter-bin-0.1.12.0.exe . If -you use a different version and it does work. copy from libusb -installation tree the usb.h and libusb.a files. Then recompile. - - -Compilation: I use mingw32-gcc to create a standalone exe but you -could also use cygwin gcc. Edit the makefile and then type: make diff --git a/README.md b/README.md index bc059a5..9c27022 100644 --- a/README.md +++ b/README.md @@ -148,4 +148,45 @@ Now, you should be able to work with EZ-USB micros without root access! Just re ## Using FXLoad -A Win32 + libusb-1.0 API port of fxload, programming tool for Cypress EZ-USB series. +### Specifying the Device To Load +This version of fxload allows you to specify the device to connect to in three different ways. + +1. You may not specify the `--device` argument at all, in which case fxload will present a menu of all the available USB devices connected to the machine. You can select the one to load from the menu. This mode is ideal for command line usage. +2. You may specify `--device :` to select a device by its vendor ID and hardware ID (in hexadecimal). For example, to flash an unconfigured FX2LP, you would pass `--device 04b4:8613`. By default, this will select the first such device found, but you can change that by adding `@N` after the vid and pid to use the Nth device found (where N is the 0-indexed index of the device to use). +3. You may specify `--device .` to select a device by its bus and device number, specified as decimal numbers. You can get the bus and device numbers from `lsusb` on Linux, though I'm not aware of a utility to list them on Linux. + +### Loading a Hex File to RAM +To just load a firmware file into RAM, use a command like: +```sh +$ fxload --ihex-path -t FX2LP +``` + +(the -t argument may be changed to "FX2", "FX", or "AN21" as appropriate) + +Sinc you are loading to RAM, this method of loading firmware will only last until the device is reset, which is useful for testing firmware builds! + +### Loading a Hex File to EEPROM + +**Warning: This process can soft-brick your device if you load invalid firmware. See the "unbricking" section below for more details.** + +To load a hex file into EEPROM, use a command line: +```sh +$ fxload --ihex-path -t FX2LP --eeprom -c 0xC2 +``` + +The `-c` argument gives the value for the command byte (the first byte of the device EEPROM). The value to use here changes based on the device. For FX2LP, 0xC2 causes the device to boot from EEPROM, and 0xC0 causes the device to load the VID, PID, and DID from EEPROM. + +### Loading Only VID, PID, and DID values to EEPROM + +Unlike loading an entire firmware file, doing this will cause the EZ-USB chip to enumerate in its default bootup state with no code, but with custom VID, PID, and DID values for your application. For this mode, use the same command as above but change the command byte for your device to 0xC0, then pass a hex file containing the VID, PID, and DID values in the correct binary format. + +TODO need to create an example for how to do this... + +### Unbricking +If you load firmware onto the EEPROM which does not properly boot up, your device may be soft-bricked -- you might be unable to flash firmware onto it normally. In this situation, the easiest way to recover is to use a jumper wire to short the EEPROM's SCL or SDA pin to GND, then turn on the power. This will force the I2C bus into the low state, preventing the EZ-USB from reading its firmware and making it boot up as an unconfigured device. Then, remove the jumper and flash the code again. + +This shouldn't hurt the device because I2C is an open drain bus, where chips only write 0 to the bus lines or leave them high impedance, so nothing will be writing 1 to the bus and causing a short. + +Some dev boards also provide jumpers which can be used to disconnect the EEPROM from the FX2LP. These will also work for unbricking it -- just remove them and turn on the power, then plug them back in and reflash new firmware. + +More info about unbricking can be found [here](https://www.triplespark.net/elec/periph/USB-FX2/eeprom/). \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index ba3fef9..2dff794 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -32,39 +32,6 @@ struct device_spec { int index; uint16_t vid, pid; int bus, port; }; -//void usage(const char *argv0) { -// char *p = strrchr(argv0, '/'); -// char *q = strrchr(argv0, '\\'); -// -// // basename of argv0 -// p = (p > q) ? p+1 : q+1; -// -// fprintf(stderr, "Usage: %s [options] -I file [-c 0xC[02] -s loader]\n", p); -// fprintf(stderr, -// "Options:\n" -// " -D : select device by vid:pid or bus.port\n" -// " -t : select type from (an21|fx|fx2|fx2lp)\n" -// " -I : program hex file\n" -// " -s : program stage1 loader to write a file into EEPROM\n" -// " -c : program first byte of EEPROM with either 0xC0 or 0xC2\n" -// " -V : show version\n" -// " -v : show verbose message\n"); -// fprintf(stderr, -// "Examples:\n" -// " // program fw.hex to the FIRST device with given vid\n" -// " $ %s -d 04b4:@0 -I fw.hex\n" -// "\n" -// " // program fw.hex to the SECOND device at given bus\n" -// " $ %s -d 004.@1 -I fw.hex\n" -// "\n" -// " // program vid:pid info to EEPROM\n" -// " $ %s -I vidpid.hex -c 0xC0 -s Vend_Ax.hex\n" -// "\n" -// " // program whole firmware to EEPROM\n" -// " $ %s -I fwfile.hex -c 0xC2 -s Vend_Ax.hex\n", p, p, p, p); -// exit(1); -//} - /* * Finds the correct USB device to open based on the provided device spec. * If wanted is nullptr, all USB devices are printed to the console and the user