Wednesday, March 16, 2016

Getting Minipro 866 working with Raspberry Pi

For some time, I've had a Minipro TL866CS eprom programmer that I got on Ebay. While it works very well, its software is windows only. I'd like to move it downstairs permanently where all the eproms and whatnot live. I'd also like to move my logic shrimp (a logic sump compatible open source logic sniffer) down there, as well as have a terminal and a browser and email and all that good stuff in my workshop.

The obvious answer would have been a PC. If I had a spare that worked. Since I don't, I turned to one of my stack of Raspberry Pis, in this case a model 2b, formerly my desktop Pi before the model 3s came out.

The upshot: my basement Pi now has minicom for terminal/rs232 stuff (I still need to test that with a USB rs232 dongle) OLS, the logic-sump compatible software I'm used to (which I also still need to test with the logic shrimp). I figured it would be a simple matter to download the minipro software from here: https://github.com/vdudouyt/minipro, compile, plug in the minipro and go.

Nothing worked. The minipro flashed its red LED continuously. It wasn't getting enough power. I'd stumbled over the solution to this before. Edit the Pi's /boot/config.txt file and add the lines:

# Increase max USB current
max_usb_current=1

to it. Now the Minipro's LED stayed on, but the minipro open source software still wouldn't talk to it.

lsusb showed the 866's USB ID, 04d8:e11c, properly, but listed it as a Microchip Technology device. Which tells us who made the USB chip. This was different from my x86-64 Linux machine's enumeration, which I suspected was why the software wouldn't see it. I'm not sure this step was necessary, but it didn't hurt anything. I coped /usr/share/misc/usb.ids file from my desktop linux machine to /usr/share/misc/usb.ids on the Pi. Now the 866 enumerated identically to how it did on my desktop PC. The software still didn't work.

My next attempt was installing the latest libusb-1.0.yadda. I'm fairly certain this step is unnecessary, but I downloaded libusb-1.0.20 from http://sourceforge.net/projects/libusb/files/libusb-1.0/libusb-1.0.20/ , built, and installed that. It worked fine, but the minipro software /still/ didn't work properly. So I dug into minipro's source.

The problem I was having turned out to be unrelated to USB (Or I'd solved all the USB problems already. It's hard to tell in retrospect.) the minipro software was built on an x86-64 system, where chars are all signed in C. On arm architectures like the Pi, chars are unsigned. In the parsing function of the minipro software, the author uses one variable, a char, to store the output of getopt() whether it's valid or -1, which getopt returns when it runs out of options. If you store -1 in an unsigned char, you get 255. It's not equal to -1, which the line tested for, so it tried to parse it. Finding no valid commands with that character value, the parser loop promptly decided I'd fed it garbage, gave me the instructions, and terminated the program.

Once I understood that, the fix was pretty simple. Edit main.c and change the char c into int8_t c. (Coding on Arduino has made me paranoid about making sure my data types really are what I think they are.) I've sent a pull request to the original author with these changes, or you can download my fixed source here: https://github.com/jrstrick/minipro  (Update: the Minipro  dev accepted my pull request, so the main trunk should now work properly.)

You might be aware there's a Qt GUI for the minipro software out there. You can get it here: https://github.com/wd5gnr/qtl866 , but I have not yet gotten it to work with the Pi. It gives exactly the same error the command line used to, even with the fixed version, so I'm suspicious of how its option string is being built before it calls minipro, but I don't know Qt at all. I may hack at it more later.

-JRS

No comments:

Blog Archive