Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@

About
About
=====

Beta libusb code for EEPROM programmers based on the WinChipHead CH341a IC
Beta libusb code for EEPROM programmers based on the WinChipHead CH341a IC

Author
======

Written by asbokid and released under the terms of the GNU GPL, version 3, or later.
Copyright Dec 2011, asbokid <ballymunboy@gmail.com>
Written by asbokid and released under the terms of the GNU GPL, version 3, or later.

Copyright Dec 2011, asbokid <ballymunboy@gmail.com>

Licence
=======

This is free software: you can redistribute it and/or modify it under the terms of
the latest GNU General Public License as published by the Free Software Foundation.
This is free software: you can redistribute it and/or modify it under the terms of
the latest GNU General Public License as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program.
If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU General Public License along with this program.
If not, see <http://www.gnu.org/licenses/>.

Requires
========

gcc
GNU make
libusb-1.0 and the libusb library development files. See http://libusb.wiki.sourceforge.net/
gcc
GNU make
libusb-1.0 and the libusb library development files. See http://libusb.wiki.sourceforge.net/
libusb-1.0-dev (on debian-based distros)

Compiling
=========

gcc -o ch341eeprom ch341eeprom.c ch341funcs.c -lusb-1.0
gcc -o ch341eeprom ch341eeprom.c ch341funcs.c -lusb-1.0

Running
=======

Expand All @@ -45,7 +45,7 @@ Running
ch341eeprom - an i2c EEPROM programming tool for the WCH CH341a IC
Version 0.5 copyright (c) 2011 asbokid <ballymunboy@gmail.com>

This program comes with asbolutely no warranty; This is free software,
This program comes with absolutely no warranty; This is free software,
and you are welcome to redistribute it under certain conditions:
GNU GPL v3 License: http://www.gnu.org/licenses/gpl.html

Expand Down Expand Up @@ -109,7 +109,7 @@ Running
0000060: 6666 6666 6666 6666 6666 6666 6666 6666 ffffffffffffffff
0000070: 7777 7777 7777 7777 7777 7777 7777 7777 wwwwwwwwwwwwwwww

asbokid@u50si1:$ sudo ./ch341eeprom -v -s 24c64 -w testimg24c64.bin
asbokid@u50si1:$ sudo ./ch341eeprom -v -s 24c64 -w testimg24c64.bin

Searching USB buses for WCH CH341a i2c EEPROM programmer [1a86:5512]
Found [1a86:5512] as device [7] on USB bus [2]
Expand Down Expand Up @@ -147,12 +147,12 @@ Running
0000070: 7777 7777 7777 7777 7777 7777 7777 7777 wwwwwwwwwwwwwwww


Concluding Notes
Concluding Notes
================

The code handles the 3 byte addressing used by EEPROMS of 32kbit and greater (24c32-)
It uses asynchronous USB transfers but should be portable to Microsoft Windows.

All comments and contributions welcomed!
asbokid <ballymunboy@gmail.com> - Dec 2011
All comments and contributions welcomed!

asbokid <ballymunboy@gmail.com> - Dec 2011
10 changes: 5 additions & 5 deletions ch341eeprom.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "ch341eeprom.h"

FILE *debugout, *verbout;
uint8_t *readbuf = NULL;
static uint8_t *readbuf = NULL;

int main(int argc, char **argv) {
int i, ret = 0, eepromsize = 0, bytesread = 0;
Expand All @@ -41,7 +41,7 @@ int main(int argc, char **argv) {
static char version_msg[] =
"ch341eeprom - an i2c EEPROM programming tool for the WCH CH341a IC\n" \
"Version " CH341TOOLVERSION " copyright (c) 2011 asbokid <ballymunboy@gmail.com>\n\n" \
"This program comes with asbolutely no warranty; This is free software,\n" \
"This program comes with absolutely no warranty; This is free software,\n" \
"and you are welcome to redistribute it under certain conditions:\n" \
"GNU GPL v3 License: http://www.gnu.org/licenses/gpl.html\n";

Expand Down Expand Up @@ -136,13 +136,13 @@ int main(int argc, char **argv) {
}

if(!(devHandle = ch341configure(USB_LOCK_VENDOR, USB_LOCK_PRODUCT))) {
fprintf(stderr, "Couldnt configure USB device\n", USB_LOCK_VENDOR, USB_LOCK_PRODUCT);
fprintf(stderr, "Couldn't configure USB device %x:%x\n", USB_LOCK_VENDOR, USB_LOCK_PRODUCT);
goto shutdown;
}
fprintf(verbout, "Configured USB device\n", USB_LOCK_VENDOR, USB_LOCK_PRODUCT);
fprintf(verbout, "Configured USB device %x:%x\n", USB_LOCK_VENDOR, USB_LOCK_PRODUCT);

if(ch341setstream(devHandle, CH341_I2C_STANDARD_SPEED) < 0) {
fprintf(stderr, "Couldnt set i2c bus speed\n");
fprintf(stderr, "Couldn't set i2c bus speed\n");
goto shutdown;
}
fprintf(verbout, "Set i2c bus speed to [100kHz]\n");
Expand Down
6 changes: 5 additions & 1 deletion ch341funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ struct libusb_device_handle *ch341configure(uint16_t vid, uint16_t pid) {
return NULL;
}

libusb_set_debug(NULL, 3); // maximum debug logging level
#if LIBUSB_API_VERSION <= 0x01000106
libusb_set_debug(NULL, 3); // maximum debug logging level
#else
libusb_set_option(NULL, LIBUSB_OPTION_LOG_LEVEL, 3); // maximum debug logging level
#endif

fprintf(verbout, "Searching USB buses for WCH CH341a i2c EEPROM programmer [%04x:%04x]\n",
USB_LOCK_VENDOR, USB_LOCK_PRODUCT);
Expand Down