Minipro TL866CS Universal Programmer working with Arduino IDE

Hi,

yesterday I tried to add the Minipro TL688CS Universal Programmer to the Arduino IDE for programming.
I got it working now, but its still just a proof of concept. Till now I can upload to Atmega328P, Attiny45 and Attiny85. Tested on OSX with 1.6.7, but should work on Linux too, for Windows I’ve no clue.

Only Upload Using Programmer is working, Burn Bootloader and Fuses still missing but should not be that hard to add.

Requirements:
Minipro Software for Mac/Linux → GitHub - vdudouyt/minipro: An open source program for controlling the MiniPRO TL866xx series of chip programmers
Srec_cat for hex/binary conversation → get it via apt-get, homebrew or you favorite package manager

Few words on the implemenation. There are two entries in platform.txt and programmers.txt. This will add the TL688 as a programmer. Instead of avrdude a scrips is called, which translates a few exports for the Minipro and sets the filesizes of the targets.
The Minipro software will only upload bin files where the filesize equals the flashsize.

For the Atmega382P the script will also check if the fuses of the selected board and device are the same.
For Attiny45 and Attiny85, reading and writing of the fuses is broken on the latest version of Minipro. So the check can’t be done at the moment.

After this, the script invokes srec_cat to convert the hex to a binary with the right size and then minipro will upload the bin to the device.

Find the changes/script below.
Depending on where you install minipro/srec_cat and arduino_tl688cs, you have to check for correct paths in platform.txt and in the bash script.

Entry for platform.txt

tools.minipro.path=/usr/local/bin/
tools.minipro.cmd.path={path}arduino_tl688cs
tools.minipro.program.params.verbose=
tools.minipro.program.params.quiet=
tools.minipro.program.pattern="{cmd.path}" "{build.mcu}" "{build.path}/{build.project_name}" "{bootloader.low_fuses}" "{bootloader.high_fuses}" "{bootloader.extended_fuses}" "{bootloader.lock_bits}" "{build.path}"

Entry for programmers.txt

minipro.name=Minipro TL866
minipro.program.tool=minipro
minipro.program.extra_params=

arduino_tl688cs ->bash script which will be called from the IDE

#!/bin/bash

set -e

# translate mcu settings from Arduino to Minipro
# define size of bin file for srec_cat
# Minipro will only upload if filesize == flashsize
if [ "$1" == "attiny45" ]
then
 mcu="ATTINY45"
 size="0x1000"
fi
if [ "$1" == "attiny85" ]
then
 mcu="ATTINY85"
 size="0x2000"
fi
if [ "$1" == "atmega328p" ]
then
 mcu="ATMEGA328P"
 size="0x8000"
fi

#save fuse settings for comparison
fuses_lo=$(printf "fuses_lo = 0x00%x\n" $3)
fuses_hi=$(printf "fuses_hi = 0x00%x\n" $4)
fuses_ext=$(printf "fuses_ext = 0x00%x\n" $5)
lock_byte=$(printf "lock_byte = 0x00%x\n" $6)

#load fuse setings to tmp file
#if the device id does not match, the script exits here
/usr/local/bin/minipro -p $mcu -r $7/tmp.conf -c config

set +e

#read file and compare fuse settings
#if one of the fuses does not match, the script exits
#fuses for Attiny45 and Attiny85 are brocken in minipro
if [ "$1" == "atmega328p" ]
then
IFS=

\n’ read -d ‘’ -r -a fuse < $7/tmp.conf
if [ “${fuse[0]}” == “$fuses_lo” ]
then
echo “$fuses_lo… OK”
else
echo “Invalid Fuse: expected $fuses_lo, got ${fuse[0]}”
exit 1
fi
if [ “${fuse[1]}” == “$fuses_hi” ]
then
echo “$fuses_hi… OK”
else
echo “Invalid Fuse: expected $fuses_hi, got ${fuse[1]}”
exit 1
fi

if [ “${fuse[2]}” == “$fuses_ext” ]
then
echo “$fuses_ext… OK”
else
echo “Invalid Fuse: expected $fuses_ext, got ${fuse[2]}”
exit 127
fi
if [ “${fuse[3]}” == “$lock_byte” ]
then
echo “$lock_byte… OK”
else
echo “Invalid Fuse: expected $lock_byte, got ${fuse[3]}”
exit 1
fi
fi
 
set -e  
 
#generate bin files form hex with the right size  
/opt/local/bin/srec_cat $2.hex -intel -fill 0x00 0x000 $size -o $2.bin -binary    
#upload bin file
/usr/local/bin/minipro -p $mcu -w $2.bin

Adding information:

srec_cat is part of the srecord Ubuntu package. I don't know the name for the other distros but it should be close to that.

There is a typo in the script file name arduino_tl688cs should be named arduino_tl866cs and all reference to arduino_tl688cs in other configuration files should be updated as well.

Another issue in the bash script itself. The string comparison operator of the test program "[" should be a single '=' instead of '=='.