Flash the AVR Atmel ATtiny Chips with a Modified CH341A ISP Programmer
Содержание
- Hardware requirements:
- 1) Map the CH341A 16 pin-outs to the ATtiny 8 pin-outs
- 2) Install libusb-1.0 (version 1.0.22+)
- 3) Build the CH341A programmer tool
- 4) Connect the CH341A connector pins to the SOIC test clip
- 5) Flash the ATtiny85 Digistump board
- 6) Make a permanent AVR PCI programmer rig
- 7) Test the PCB rig
- 8) Flash an ATtiny85 Digistump using the new PCB
- 9) Make a unique connector
- 10) Tips and troubleshooting
The problem is that the CH341A is not designed for ATtiny chips, but for flashing motherboard BIOS chips. I bought one just for the included SOIC test clip, but I wanted to see if I could repurpose it for flashing an ATtiny85 chip. This post is a reference for myself about the commands and hardware hacks I had to do for when I have to do this again in half a year or later.
Hardware requirements:
- An inexpensive CH341A EEPROM/BIOS programmer from AliExpress
- A SOIC 8-pin test clip
- A Linux machine running Debian/Ubuntu
Not having a dedicated AVR SPI programmer, I want to make a permanent AVR programmer rig instead of using the Arduino UNO ISP sketch trick (I have over 30 ATtiny85 chips and growing). Here’s how I accomplished this.
1) Map the CH341A 16 pin-outs to the ATtiny 8 pin-outs
With an ohmmeter, I mapped the pins with side labels to the socket pins. Now I know which socket pins correspond to the ATTiny function pins (e.g. MOSI, MISO, CS, etc.). Here is my sketch.
CH341A ISP programmer pin map to ATtiny chips
This jibes with the one schematic I found online for this common-yet-obscure ISP BIOS/EEPROM programmer.
CH341A MiniProgrammer ISP programmer schematic Credit: onetransistor.eu
2) Install libusb-1.0 (version 1.0.22+)
I’m running Linux Mint Bionic (18.04 LTS) which has only libusb 1.0.21. This is insufficient. The programming tool (next section) requires version 1.0.22+ because the API changed slightly. Disco has this version, so here is how I installed it from the Disco repo but stayed on Bionic (credits to George Shuklin).
3) Build the CH341A programmer tool
Trel725 wrote a small programming tool to make the CH341A flash ATtiny chips of all varieties. The only requirement is that libusb 1.0.22+ is installed. Simply clone the repo and run make in Linux. There will be a new file called chavrprog. Make sure it has execute permissions with chmod +x chavrprog . What it does is send bytes to the ATtiny and reads the responses in a way that enables flashing ATtiny chips. I’m so glad he made this tool.
Those steps again are:
4) Connect the CH341A connector pins to the SOIC test clip
I just used a breadboard and come colored wires to map the CH341A socket to the SOIC8 test clip given my sketch from above.
Map the CH341A socket to the SOIC test clip for ATtiny chips Closeup of breadboard wires in the SOIC8 test clip connector
The colors are mapped to the CH341A as follows:
Notice the notch on the ribbon cable when inserting the colored wires into the ribbon cable connector.
5) Flash the ATtiny85 Digistump board
The red wire of test clip should line up with the little circle of the ATtiny chip both denote pin 1. I tried a few times to get the clip to attach perfectly because the pins are so small. Notice the orientation of the Digistump in relation to the red wire of the SOIC8 test clip.
SOIC test clip on the ATtiny85 Digistump
I could now flash the t85_default.hex from the micronucleus firmware repo located in https://github.com/micronucleus/micronucleus/tree/master/firmware/releases. I’ve actually forked this repo and made a special bootloader for the APA106 RGB LED. Either way, to flash the micronucleus bootloader all that is required is:
It worked great from the very first flash attempt. The on-board run light on the Digistump is lit awaiting a program for the bootloader. The Digistump is now unbricked.
6) Make a permanent AVR PCI programmer rig
The ISP programmer came with a little PCB to make custom expansion projects I suppose. I use that to permanently map the CH341A pins to the SOIC8 ribbon cable for use with ATtiny chips.
CH341A accessories
The plan is to use the empty PCB and create a hardware pin map between the CH341A socket and the ribbon cable connecting the SOIC8 test clip to the ATtiny chips. Only one cut needs to be made at pin 6 to isolate those two holes. The rest is straightforward soldering. The purple circles denote pins going down. The blue circles denote pins going up. I’ll only add a total of 12 pins, not 16 pins, to this PCB board.
Hardware pin mapping between the CH341A ISP programmer and the SOIC8 test clip for ATtiny chips
Here I cut the connection between the holes at location 6 with an X-acto knife and added the wire jumpers like in the diagram above. I used the legs from a spare resistor I had lying around. They are thin so they leave enough room for the through-hole pins to fit.
Add wire jumpers from a spare resistor
The finished jumper board looks like this. Please forgive that there is still flux on the terminal base.
Completed CH341A PCB pin board
When the PCB is trimmed and clean, it looks like this.
CH341A PCB board trimmed and clean
7) Test the PCB rig
It’s good to test the wiring one more time to check for shorts. All the top pins should map to the top pins of the ATtiny chip and match the function pins on the side of the CH341A.
Confirm the wiring and function pins of the PCB board
8) Flash an ATtiny85 Digistump using the new PCB
In the moment of truth, everything works fine. The new PCB is doing its job well and the first ATtiny85 was flashed successfully.
Successful flashing of an ATtiny85 with the CH341A and custom PCB
9) Make a unique connector
I know me and one day I’ll put the ribbon connector in the wrong way and burnout a chip. I took a pair of pins and trimmed down the leads. Then I put epoxy on the top, let it harden, and inserted it into the empty contacts of the ribbon connector. They are removable, but now the connector has only one way to connect to the modified PCB board for safety.
Make a unique ribbon connector with pins and epoxy
10) Tips and troubleshooting
If the ATtiny starts malfunctioning, the EEPROM may have been corrupted. I’ve noticed this happens sometimes when cycling the power supply if there is a power ripple. I run this command to compare the EEPROM contents with the original hex file used to flash the bootloader:
If there is corruption then the tool will display the address at the first discrepancy, or else it will state the signature is correct.
Another trick is to flash the bootloader, then upload the user program via micronucleus, then dump the combined contents of the EEPROM to disk. Then I can flash both the bootloader and user program in one step. Here is how I do it for an ATtiny85 Digistump:
Источник: