Skip to content
AVR programmer based on Chinese ch341a
C Makefile
Branch: master
Clone or download
Trel725 Merge pull request #5 from l0ud/master
Refactored flash write function. Fix programming mcu with page size 128
Latest commit 0da864e Oct 19, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE
Makefile Eeprom read/write added Jul 11, 2016
README.md update README Jun 14, 2017
ch341a.c Fix compilation warnings, added mega88p mcu Sep 3, 2018
ch341a.h Cleanup, reading improvement Jul 1, 2016
chavrprog.c Refactored flash write function. Fix programming mcu with page size 128 Sep 6, 2018
chavrprog.exe Added windows binary Aug 6, 2016
chavrprog.h Refactored flash write function. Fix programming mcu with page size 128 Sep 6, 2018
cintelhex.h Build fix Jul 10, 2016
config.c Refactored flash write function. Fix programming mcu with page size 128 Sep 6, 2018
config.h
config_ihex.h Cleanup, reading improvement Jul 1, 2016
ihex_copy.c Cleanup, reading improvement Jul 1, 2016
ihex_parse.c initial version Jun 29, 2016
ihex_record.c initial version Jun 29, 2016
main.c Eeprom read/write added Jul 11, 2016
schematics.jpg added schematics Jun 14, 2017

README.md

chavrprog

AVR programmer using Chinese ch341a chip

There is a lot of strange things from China, and ch341a is one of the them. Cheap USB-Serial, USB-SPI, USB-I2C, USB-Parralel, etc makes it seems to be the real thing. However, lack of documentation make that device almost useless, except for couple of open-source projects. This project adds support for AVR microcotrollers programming using CH341a chip.

Project is based on ch341prog by Setarcos (https://github.com/setarcos/ch341prog), and technically is a brief implementation of ATMEL serial programming protocol using low-level functions from ch341prog project. Also, to parse Intel HEX source files from libcintelhex (https://github.com/martin-helmich/libcintelhex) are used.

Building

I've tried to iclude all necessary dependencies into the package, so it's necessary just run make. The only lib you should have installed in your system is libusb-1.0

Also to run chavrprog without root privileges you can create file 99-ch341.rules file into your rules.d directory (usually /etc/udev/rules.d) with following content: SUBSYSTEM=="usb", ATTR{idVendor}=="1a86", ATTR{idProduct}=="5512", GROUP="plugdev"

Usage

Connect ch341 programmer by scheme: AVR ch341a
MISO-----MISO
MOSI-----MOSI
SCK------SCK
Reset----CS
GND------GND

Or the same using popular chineese programmer, connect to socket for spi flash:
socket AVR
1-------Reset
2-------MISO
4-------GND
5-------MOSI
6-------SCK

alt text

Commads

-d DEVICE - specifies AVR chip
-r ADDR - read flash memory from start to ADDR in bytes, or
-r f FILE read whole flash memory to specified file
-w HEX - write flash memory from intel HEX file
-e - erase device
-c HEX - read and compare HEX with flash memory (strictly)
-a HEX - automatically erase, write and check data in chip, or
-a s HEX - same with strict verification instead of fast default
use if you're flashing complex HEX, like Arduino bootloader or if default fails
-p r - read content of on-chip EEPROM, print in terminal, or
-p r FILE - read EEPROM to FILE
-p w HEX - write eeprom from intel hex file -f - read fuse bits
-l BYTE - write low fuse
-H BYTE - write high fuse
-x BYTE - write extended fuse
-L read lock bits

There is 2 verification functions implemented - fast and strict. By default with -a command fast one is used. This is good for writing homogenous HEX files - like most of programms, and works much faster because verifies only written part. Another one verifies whole memory, what makes it applicable for complex HEX with gaps, but works slower due to whole chip reading.

The most typical command set looks like:
chavrprog -d mega328p -a ./firmware.hex

Disklaimer

Project is under development and may contain mistakes.

To add another MCU's it's necessary to add it discription (name, pagesize, number of pages, eeprom size) to file config.c Most popular AVRs (which is used in Arduino) are already added. Theoretically, current version should work with any Atmega chip, if Atmel commad set is same for all chips, but was tested only with on Atmega32u4. Devices with more then 64K memory not supported now. Initial implementation for Attiny is done, most popular devices added to config. Hopefully, it should work for any attiny, nevertheless tested inly with attiny13.

Windows version

chavrprog.exe is pre-compiled binary for cygwin64. To use it you should have cygwin installed with libusb-1.0 and libusb-win32 driver for ch341a installed through Zadig (http://zadig.akeo.ie/).

License

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.

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 can’t perform that action at this time.