-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CH341A programmer support. #1215
Conversation
@am-ar |
Thanks for submitting the PR. I highly doubt it will make it into Avrdude v7.1, but it may be a nice addition if we're able to adress some of the issues pointed out below. A few things:
|
Add `prog_mode` configuration in `avrdude.conf`; Replace message functions;
Hello @mcuee, here is my test log: test.log
C:\Users\Dados\Environment\eclipse-cpp\avrdude>build\src\avrdude.exe -vvvvv -p attiny25 -C build\src\avrdude.conf -c ch341a -e -D -F -U flash:w:firmware_teste.hex:i
sys_config = build\src\avrdude.conf
sys_config_found = false
avrdude: Version 7.0-20221212 (0ae63b0)
Copyright the AVRDUDE authors;
see https://github.com/avrdudes/avrdude/blob/main/AUTHORS
System wide configuration file is C:\Users\Dados\Environment\eclipse-cpp\avrdude\build\src\avrdude.conf
Using Port : usb
Using Programmer : ch341a
avrdude: ch341a_open("usb")
AVR Part : ATtiny25
Chip Erase delay : 4500 us
RESET disposition : possible i/o
RETRY pulse : SCK
Serial program mode : yes
Parallel program mode : yes
Timeout : 200
StabDelay : 100
CmdexeDelay : 25
SyncLoops : 32
PollIndex : 3
PollValue : 0x53
Memory Detail :
Block Poll Page Polled
Memory Type Alias Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
----------- -------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
eeprom 65 6 4 0 no 128 4 0 4000 4500 0xff 0xff
Memory Ops:
Oeration Inst Bit Bit Type Bitno Value
----------- -------- -------- ----- -----
READ 31 VALUE 7 1
30 VALUE 6 0
29 VALUE 5 1
28 VALUE 4 0
27 VALUE 3 0
26 VALUE 2 0
25 VALUE 1 0
24 VALUE 0 0
23 VALUE 7 0
22 VALUE 6 0
21 VALUE 5 0
20 IGNORE 4 0
19 IGNORE 3 0
18 IGNORE 2 0
17 IGNORE 1 0
16 IGNORE 0 0
15 IGNORE 7 0
14 ADDRESS 6 0
13 ADDRESS 5 0
12 ADDRESS 4 0
11 ADDRESS 3 0
10 ADDRESS 2 0
9 ADDRESS 1 0
8 ADDRESS 0 0
7 OUTPUT 7 0
6 OUTPUT 6 0
5 OUTPUT 5 0
4 OUTPUT 4 0
3 OUTPUT 3 0
2 OUTPUT 2 0
1 OUTPUT 1 0
0 OUTPUT 0 0
WRITE 31 VALUE 7 1
30 VALUE 6 1
29 VALUE 5 0
28 VALUE 4 0
27 VALUE 3 0
26 VALUE 2 0
25 VALUE 1 0
24 VALUE 0 0
23 VALUE 7 0
22 VALUE 6 0
21 VALUE 5 0
20 IGNORE 4 0
19 IGNORE 3 0
18 IGNORE 2 0
17 IGNORE 1 0
16 IGNORE 0 0
15 IGNORE 7 0
14 ADDRESS 6 0
13 ADDRESS 5 0
12 ADDRESS 4 0
11 ADDRESS 3 0
10 ADDRESS 2 0
9 ADDRESS 1 0
8 ADDRESS 0 0
7 INPUT 7 0
6 INPUT 6 0
5 INPUT 5 0
4 INPUT 4 0
3 INPUT 3 0
2 INPUT 2 0
1 INPUT 1 0
0 INPUT 0 0
LOADPAGE_LO 31 VALUE 7 1
30 VALUE 6 1
29 VALUE 5 0
28 VALUE 4 0
27 VALUE 3 0
26 VALUE 2 0
25 VALUE 1 0
24 VALUE 0 1
23 VALUE 7 0
22 VALUE 6 0
21 VALUE 5 0
20 VALUE 4 0
19 VALUE 3 0
18 VALUE 2 0
17 VALUE 1 0
16 VALUE 0 0
15 VALUE 7 0
14 VALUE 6 0
13 VALUE 5 0
12 VALUE 4 0
11 VALUE 3 0
10 VALUE 2 0
9 ADDRESS 1 0
8 ADDRESS 0 0
7 INPUT 7 0
6 INPUT 6 0
5 INPUT 5 0
4 INPUT 4 0
3 INPUT 3 0
2 INPUT 2 0
1 INPUT 1 0
0 INPUT 0 0
WRITEPAGE 31 VALUE 7 1
30 VALUE 6 1
29 VALUE 5 0
28 VALUE 4 0
27 VALUE 3 0
26 VALUE 2 0
25 VALUE 1 1
24 VALUE 0 0
23 VALUE 7 0
22 VALUE 6 0
21 IGNORE 5 0
20 IGNORE 4 0
19 IGNORE 3 0
18 IGNORE 2 0
17 IGNORE 1 0
16 IGNORE 0 0
15 IGNORE 7 0
14 ADDRESS 6 0
13 ADDRESS 5 0
12 ADDRESS 4 0
11 ADDRESS 3 0
10 ADDRESS 2 0
9 VALUE 1 0
8 VALUE 0 0
7 IGNORE 7 0
6 IGNORE 6 0
5 IGNORE 5 0
4 IGNORE 4 0
3 IGNORE 3 0
2 IGNORE 2 0
1 IGNORE 1 0
0 IGNORE 0 0
Block Poll Page Polled
Memory Type Alias Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
----------- -------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
flash 65 6 32 0 yes 2048 32 64 4500 4500 0xff 0xff
Memory Ops:
Oeration Inst Bit Bit Type Bitno Value
----------- -------- -------- ----- -----
READ_LO 31 VALUE 7 0
30 VALUE 6 0
29 VALUE 5 1
28 VALUE 4 0
27 VALUE 3 0
26 VALUE 2 0
25 VALUE 1 0
24 VALUE 0 0
23 VALUE 7 0
22 VALUE 6 0
21 VALUE 5 0
20 VALUE 4 0
19 VALUE 3 0
18 VALUE 2 0
17 ADDRESS 9 0
16 ADDRESS 8 0
15 ADDRESS 7 0
14 ADDRESS 6 0
13 ADDRESS 5 0
12 ADDRESS 4 0
11 ADDRESS 3 0
10 ADDRESS 2 0
9 ADDRESS 1 0
8 ADDRESS 0 0
7 OUTPUT 7 0
6 OUTPUT 6 0
5 OUTPUT 5 0
4 OUTPUT 4 0
3 OUTPUT 3 0
2 OUTPUT 2 0
1 OUTPUT 1 0
0 OUTPUT 0 0
READ_HI 31 VALUE 7 0
30 VALUE 6 0
29 VALUE 5 1
28 VALUE 4 0
27 VALUE 3 1
26 VALUE 2 0
25 VALUE 1 0
24 VALUE 0 0
23 VALUE 7 0
22 VALUE 6 0
21 VALUE 5 0
20 VALUE 4 0
19 VALUE 3 0
18 VALUE 2 0
17 ADDRESS 9 0
16 ADDRESS 8 0
15 ADDRESS 7 0
14 ADDRESS 6 0
13 ADDRESS 5 0
12 ADDRESS 4 0
11 ADDRESS 3 0
10 ADDRESS 2 0
9 ADDRESS 1 0
8 ADDRESS 0 0
7 OUTPUT 7 0
6 OUTPUT 6 0
5 OUTPUT 5 0
4 OUTPUT 4 0
3 OUTPUT 3 0
2 OUTPUT 2 0
1 OUTPUT 1 0
0 OUTPUT 0 0
LOADPAGE_LO 31 VALUE 7 0
30 VALUE 6 1
29 VALUE 5 0
28 VALUE 4 0
27 VALUE 3 0
26 VALUE 2 0
25 VALUE 1 0
24 VALUE 0 0
23 VALUE 7 0
22 VALUE 6 0
21 VALUE 5 0
20 IGNORE 4 0
19 IGNORE 3 0
18 IGNORE 2 0
17 IGNORE 1 0
16 IGNORE 0 0
15 IGNORE 7 0
14 IGNORE 6 0
13 IGNORE 5 0
12 IGNORE 4 0
11 ADDRESS 3 0
10 ADDRESS 2 0
9 ADDRESS 1 0
8 ADDRESS 0 0
7 INPUT 7 0
6 INPUT 6 0
5 INPUT 5 0
4 INPUT 4 0
3 INPUT 3 0
2 INPUT 2 0
1 INPUT 1 0
0 INPUT 0 0
LOADPAGE_HI 31 VALUE 7 0
30 VALUE 6 1
29 VALUE 5 0
28 VALUE 4 0
27 VALUE 3 1
26 VALUE 2 0
25 VALUE 1 0
24 VALUE 0 0
23 VALUE 7 0
22 VALUE 6 0
21 VALUE 5 0
20 IGNORE 4 0
19 IGNORE 3 0
18 IGNORE 2 0
17 IGNORE 1 0
16 IGNORE 0 0
15 IGNORE 7 0
14 IGNORE 6 0
13 IGNORE 5 0
12 IGNORE 4 0
11 ADDRESS 3 0
10 ADDRESS 2 0
9 ADDRESS 1 0
8 ADDRESS 0 0
7 INPUT 7 0
6 INPUT 6 0
5 INPUT 5 0
4 INPUT 4 0
3 INPUT 3 0
2 INPUT 2 0
1 INPUT 1 0
0 INPUT 0 0
WRITEPAGE 31 VALUE 7 0
30 VALUE 6 1
29 VALUE 5 0
28 VALUE 4 0
27 VALUE 3 1
26 VALUE 2 1
25 VALUE 1 0
24 VALUE 0 0
23 VALUE 7 0
22 VALUE 6 0
21 VALUE 5 0
20 VALUE 4 0
19 VALUE 3 0
18 VALUE 2 0
17 ADDRESS 9 0
16 ADDRESS 8 0
15 ADDRESS 7 0
14 ADDRESS 6 0
13 ADDRESS 5 0
12 ADDRESS 4 0
11 IGNORE 3 0
10 IGNORE 2 0
9 IGNORE 1 0
8 IGNORE 0 0
7 IGNORE 7 0
6 IGNORE 6 0
5 IGNORE 5 0
4 IGNORE 4 0
3 IGNORE 3 0
2 IGNORE 2 0
1 IGNORE 1 0
0 IGNORE 0 0
Block Poll Page Polled
Memory Type Alias Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
----------- -------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
lfuse 0 0 0 0 no 1 1 0 9000 9000 0x00 0x00
Memory Ops:
Oeration Inst Bit Bit Type Bitno Value
----------- -------- -------- ----- -----
READ 31 VALUE 7 0
30 VALUE 6 1
29 VALUE 5 0
28 VALUE 4 1
27 VALUE 3 0
26 VALUE 2 0
25 VALUE 1 0
24 VALUE 0 0
23 VALUE 7 0
22 VALUE 6 0
21 VALUE 5 0
20 VALUE 4 0
19 VALUE 3 0
18 VALUE 2 0
17 VALUE 1 0
16 VALUE 0 0
15 IGNORE 7 0
14 IGNORE 6 0
13 IGNORE 5 0
12 IGNORE 4 0
11 IGNORE 3 0
10 IGNORE 2 0
9 IGNORE 1 0
8 IGNORE 0 0
7 OUTPUT 7 0
6 OUTPUT 6 0
5 OUTPUT 5 0
4 OUTPUT 4 0
3 OUTPUT 3 0
2 OUTPUT 2 0
1 OUTPUT 1 0
0 OUTPUT 0 0
WRITE 31 VALUE 7 1
30 VALUE 6 0
29 VALUE 5 1
28 VALUE 4 0
27 VALUE 3 1
26 VALUE 2 1
25 VALUE 1 0
24 VALUE 0 0
23 VALUE 7 1
22 VALUE 6 0
21 VALUE 5 1
20 VALUE 4 0
19 VALUE 3 0
18 VALUE 2 0
17 VALUE 1 0
16 VALUE 0 0
15 IGNORE 7 0
14 IGNORE 6 0
13 IGNORE 5 0
12 IGNORE 4 0
11 IGNORE 3 0
10 IGNORE 2 0
9 IGNORE 1 0
8 IGNORE 0 0
7 INPUT 7 0
6 INPUT 6 0
5 INPUT 5 0
4 INPUT 4 0
3 INPUT 3 0
2 INPUT 2 0
1 INPUT 1 0
0 INPUT 0 0
Block Poll Page Polled
Memory Type Alias Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
----------- -------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
hfuse 0 0 0 0 no 1 1 0 9000 9000 0x00 0x00
Memory Ops:
Oeration Inst Bit Bit Type Bitno Value
----------- -------- -------- ----- -----
READ 31 VALUE 7 0
30 VALUE 6 1
29 VALUE 5 0
28 VALUE 4 1
27 VALUE 3 1
26 VALUE 2 0
25 VALUE 1 0
24 VALUE 0 0
23 VALUE 7 0
22 VALUE 6 0
21 VALUE 5 0
20 VALUE 4 0
19 VALUE 3 1
18 VALUE 2 0
17 VALUE 1 0
16 VALUE 0 0
15 IGNORE 7 0
14 IGNORE 6 0
13 IGNORE 5 0
12 IGNORE 4 0
11 IGNORE 3 0
10 IGNORE 2 0
9 IGNORE 1 0
8 IGNORE 0 0
7 OUTPUT 7 0
6 OUTPUT 6 0
5 OUTPUT 5 0
4 OUTPUT 4 0
3 OUTPUT 3 0
2 OUTPUT 2 0
1 OUTPUT 1 0
0 OUTPUT 0 0
WRITE 31 VALUE 7 1
30 VALUE 6 0
29 VALUE 5 1
28 VALUE 4 0
27 VALUE 3 1
26 VALUE 2 1
25 VALUE 1 0
24 VALUE 0 0
23 VALUE 7 1
22 VALUE 6 0
21 VALUE 5 1
20 VALUE 4 0
19 VALUE 3 1
18 VALUE 2 0
17 VALUE 1 0
16 VALUE 0 0
15 IGNORE 7 0
14 IGNORE 6 0
13 IGNORE 5 0
12 IGNORE 4 0
11 IGNORE 3 0
10 IGNORE 2 0
9 IGNORE 1 0
8 IGNORE 0 0
7 INPUT 7 0
6 INPUT 6 0
5 INPUT 5 0
4 INPUT 4 0
3 INPUT 3 0
2 INPUT 2 0
1 INPUT 1 0
0 INPUT 0 0
Block Poll Page Polled
Memory Type Alias Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
----------- -------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
efuse 0 0 0 0 no 1 1 0 9000 9000 0x00 0x00
Memory Ops:
Oeration Inst Bit Bit Type Bitno Value
----------- -------- -------- ----- -----
READ 31 VALUE 7 0
30 VALUE 6 1
29 VALUE 5 0
28 VALUE 4 1
27 VALUE 3 0
26 VALUE 2 0
25 VALUE 1 0
24 VALUE 0 0
23 VALUE 7 0
22 VALUE 6 0
21 VALUE 5 0
20 VALUE 4 0
19 VALUE 3 1
18 VALUE 2 0
17 VALUE 1 0
16 VALUE 0 0
15 IGNORE 7 0
14 IGNORE 6 0
13 IGNORE 5 0
12 IGNORE 4 0
11 IGNORE 3 0
10 IGNORE 2 0
9 IGNORE 1 0
8 IGNORE 0 0
7 OUTPUT 7 0
6 OUTPUT 6 0
5 OUTPUT 5 0
4 OUTPUT 4 0
3 OUTPUT 3 0
2 OUTPUT 2 0
1 OUTPUT 1 0
0 OUTPUT 0 0
WRITE 31 VALUE 7 1
30 VALUE 6 0
29 VALUE 5 1
28 VALUE 4 0
27 VALUE 3 1
26 VALUE 2 1
25 VALUE 1 0
24 VALUE 0 0
23 VALUE 7 1
22 VALUE 6 0
21 VALUE 5 1
20 VALUE 4 0
19 VALUE 3 0
18 VALUE 2 1
17 VALUE 1 0
16 VALUE 0 0
15 IGNORE 7 0
14 IGNORE 6 0
13 IGNORE 5 0
12 IGNORE 4 0
11 IGNORE 3 0
10 IGNORE 2 0
9 IGNORE 1 0
8 IGNORE 0 0
7 IGNORE 7 0
6 IGNORE 6 0
5 IGNORE 5 0
4 IGNORE 4 0
3 IGNORE 3 0
2 IGNORE 2 0
1 IGNORE 1 0
0 INPUT 0 0
Block Poll Page Polled
Memory Type Alias Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
----------- -------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
lock 0 0 0 0 no 1 1 0 9000 9000 0x00 0x00
Memory Ops:
Oeration Inst Bit Bit Type Bitno Value
----------- -------- -------- ----- -----
READ 31 VALUE 7 0
30 VALUE 6 1
29 VALUE 5 0
28 VALUE 4 1
27 VALUE 3 1
26 VALUE 2 0
25 VALUE 1 0
24 VALUE 0 0
23 VALUE 7 0
22 VALUE 6 0
21 VALUE 5 0
20 VALUE 4 0
19 VALUE 3 0
18 VALUE 2 0
17 VALUE 1 0
16 VALUE 0 0
15 VALUE 7 0
14 VALUE 6 0
13 VALUE 5 0
12 VALUE 4 0
11 VALUE 3 0
10 VALUE 2 0
9 VALUE 1 0
8 VALUE 0 0
7 OUTPUT 7 0
6 OUTPUT 6 0
5 OUTPUT 5 0
4 OUTPUT 4 0
3 OUTPUT 3 0
2 OUTPUT 2 0
1 OUTPUT 1 0
0 OUTPUT 0 0
WRITE 31 VALUE 7 1
30 VALUE 6 0
29 VALUE 5 1
28 VALUE 4 0
27 VALUE 3 1
26 VALUE 2 1
25 VALUE 1 0
24 VALUE 0 0
23 VALUE 7 1
22 VALUE 6 1
21 VALUE 5 1
20 IGNORE 4 0
19 IGNORE 3 0
18 IGNORE 2 0
17 IGNORE 1 0
16 IGNORE 0 0
15 IGNORE 7 0
14 IGNORE 6 0
13 IGNORE 5 0
12 IGNORE 4 0
11 IGNORE 3 0
10 IGNORE 2 0
9 IGNORE 1 0
8 IGNORE 0 0
7 VALUE 7 1
6 VALUE 6 1
5 INPUT 5 0
4 INPUT 4 0
3 INPUT 3 0
2 INPUT 2 0
1 INPUT 1 0
0 INPUT 0 0
Block Poll Page Polled
Memory Type Alias Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
----------- -------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
signature 0 0 0 0 no 3 1 0 0 0 0x00 0x00
Memory Ops:
Oeration Inst Bit Bit Type Bitno Value
----------- -------- -------- ----- -----
READ 31 VALUE 7 0
30 VALUE 6 0
29 VALUE 5 1
28 VALUE 4 1
27 VALUE 3 0
26 VALUE 2 0
25 VALUE 1 0
24 VALUE 0 0
23 VALUE 7 0
22 VALUE 6 0
21 VALUE 5 0
20 IGNORE 4 0
19 IGNORE 3 0
18 IGNORE 2 0
17 IGNORE 1 0
16 IGNORE 0 0
15 IGNORE 7 0
14 IGNORE 6 0
13 IGNORE 5 0
12 IGNORE 4 0
11 IGNORE 3 0
10 IGNORE 2 0
9 ADDRESS 1 0
8 ADDRESS 0 0
7 OUTPUT 7 0
6 OUTPUT 6 0
5 OUTPUT 5 0
4 OUTPUT 4 0
3 OUTPUT 3 0
2 OUTPUT 2 0
1 OUTPUT 1 0
0 OUTPUT 0 0
Block Poll Page Polled
Memory Type Alias Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
----------- -------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
calibration 0 0 0 0 no 1 1 0 0 0 0x00 0x00
Memory Ops:
Oeration Inst Bit Bit Type Bitno Value
----------- -------- -------- ----- -----
READ 31 VALUE 7 0
30 VALUE 6 0
29 VALUE 5 1
28 VALUE 4 1
27 VALUE 3 1
26 VALUE 2 0
25 VALUE 1 0
24 VALUE 0 0
23 VALUE 7 0
22 VALUE 6 0
21 VALUE 5 0
20 IGNORE 4 0
19 IGNORE 3 0
18 IGNORE 2 0
17 IGNORE 1 0
16 IGNORE 0 0
15 VALUE 7 0
14 VALUE 6 0
13 VALUE 5 0
12 VALUE 4 0
11 VALUE 3 0
10 VALUE 2 0
9 VALUE 1 0
8 ADDRESS 0 0
7 OUTPUT 7 0
6 OUTPUT 6 0
5 OUTPUT 5 0
4 OUTPUT 4 0
3 OUTPUT 3 0
2 OUTPUT 2 0
1 OUTPUT 1 0
0 OUTPUT 0 0
Programmer Type : ch341a
Description : ch341a programmer
avrdude: ch341a_initialize()
avrdude: ch341a_ChipSelect()
avrdude: ch341a_ChipSelect()
avrdude: ch341a_program_enable()
avrdude: program_enable(): sending command. Resp = ff ff 53 0
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.00s
avrdude: device signature = 0x1e9108 (probably t25)
avrdude: erasing chip
avrdude: ch341a_initialize()
avrdude: ch341a_ChipSelect()
avrdude: ch341a_ChipSelect()
avrdude: ch341a_program_enable()
avrdude: program_enable(): sending command. Resp = ff ff 53 0
avrdude: reading input file firmware_teste.hex for flash
with 1944 bytes in 1 section within [0, 0x797]
using 61 pages and 8 pad bytes
avrdude: writing 1944 bytes flash ...
Writing | ################################################## | 100% 1.46s
avrdude: 1944 bytes of flash written
avrdude: verifying flash memory against firmware_teste.hex
avrdude: reading on-chip flash data ...
Reading | ################################################## | 100% 0.54s
avrdude: verifying ...
avrdude: 1944 bytes of flash verified
avrdude: ch341a_close()
avrdude: ch341a_ChipSelect()
avrdude done. Thank you.
|
Hello @MCUdude,
Because I'm using a CH341A based programmer, all my tests were done with it and I didn't study the datasheet in depth to see if it's compatible with other variants of the chip. It is likely to be compatible with other variants.
I refactored the code. Check if you agree now, please.
@KaeLL, when you have time. Can you help me with this? |
What is the state of this PR? @MCUdude Has the revision addressed your concerns? | I didn't study the datasheet in depth to see if it's compatible with other variants of the chip. It is likely to be compatible with other variants @am-ar We normally like to add code that generalises over the class of chips it deals with, just to ensure the code base does not become too fragmented. It would be great if the PR could address CH341 variants in different packages with different pin configurations. |
I've just ordered a CH341A programmer to test this PR. It will probably arrive within a few weeks, so I was hoping I could give it a test before merging this PR. However, it appears that all CH341 variants share the same USB VID/PID, so maybe we should rename the programmer to It would be neat if the CH341 could run at a lower clock speed in order to program AVRs that are running slow. However, this would have to be done by implementing a dedicated bit-banging option, perhaps |
Not necessarily. But I'm sure if and when I'll be able to work on this. |
I'm still waiting for the CH341A hardware I ordered a few weeks ago. I'll like to give it a try myself before we merge this PR. |
I do not have the programmer for now. I should have something in about a month. |
Hmm, I actually found a CH341A programmer like what @am-ar has. And I can now test this PR. |
Initial test seems to be a success. Verified with USBASP. Tested on a Uno clone with ATmega328PB, and using a hex file from MiniCore blink hex file.
|
A few notes.
Edit: this is not correct, there is another driver called CH341PAR which is the right driver for this programmer with VID/PID of 0x1A86:0x5512). It will appear under Windows Device Manager as
CH341A -- AVR ISP Connector Note: MOSI is called SDO in avrdude; MISO is called SDI. |
I found some info about the programmer here, including the schematics. From the inf file inside CH341PAR driver, it seems to me there are two VID/PIDs, 1A86:5512 is for CH341A, 4348:5512 is for the older CH341.
As for the Serial port configuration, different VID/PID combinations are used. 1A86:5523 is for CH341 and 4348:5523 is for the older CH341.
|
WCH product info page is a bit confusing though. They mention CH341B and CH341A which may work in all modes. CH341H may work in SPI mode but it is not recommended for new design, CH341C and CH341T can only used in UART mode so they can not be used for SPI. So in then end only CH341A/B/F can be used. CH341B/F have built-in internal clock whreas CH341A does not have. Datasheet: http://www.wch-ic.com/downloads/CH341DS1_PDF.html I will still suggest that we call this programmer |
Under Linux, WCH provides SER and PAR driver but we need to detach the driver in order to use libusb. Once we detach the driver, I can see this PR is good.
@stefanrueger |
No issues under macOS as well. Take note I did not install the vendor driver under macOS. The worry is that it may interfere with libusb.
|
But what if I have installed WCH macOS driver? (Note: there is not CH341PAR driver for macOS)
|
Edit: this is incorrect. I did not connect the target properly. Update:
|
I just received the CH341-based programmer, and the initial test looks good. I'm currently on vacation, so I've only brought a few chips. I've only tested this on an ATmega16 It looks like there is no support for caching in terminal mode. I'm also not able to write to flash, probably because of the missing cache support. Occasionally, it also failed to write data to EEPROM in terminal mode. See the output below.
|
Thanks for testing @MCUdude.
The programmer must provide |
I suggest we merge this PR as it is, and address the oter things paged r/w, clock speed and documentation. The fact that ~1.6MHz is the slowest clock it can provide should be documented. the CH341 chip selects pin (connected to the AVR reset pin) is also hard-coded to 0. This could be overridden using |
I think your proposal is good one and I will agree with you here. |
This reminds me: the ch341a programmer has only
|
I think CH341A should physically be capable of programming parts using TPI, but a resistor between SDI and SDO may be necessary. But it will require some additional code I'm sure. |
#include "ch341a.h" | ||
#include "usbdevs.h" | ||
|
||
#if defined(HAVE_LIBUSB_1_0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does that line read #if defined(HAVE_LIBUSB_1_0)
instead of #if defined(HAVE_LIBUSB) || defined(HAVE_LIBUSB_1_0)
?
Does it have to be libusb1.0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, as of now the codes only support libusb-1.0.
@@ -62,6 +62,8 @@ | |||
# endif | |||
#endif | |||
|
|||
#include <sys/time.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was it needed to move #include <sys/time.h>
from line 34 to here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's probably no good reason to move this. That's my guess...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not related to this PR but rather related to MSVC build. So yes it is out of scope for this PR but it is nice to have.
This commit - Updates and moves the avrdude.conf entry for the ch341a programmer - Provides paged access functions so terminal cache works - Reformats ch341a.[ch] as these are new additions Also - Removes unused function ch341a_spi_transfer() - Changes several fprintf(stderr, ...) to msg_error()
You are right @MCUdude! The current codebase cannot deal with |
Made the changes addressing the review:
Also
Only two things to clarify re libusb/libusb-1.0 and why the include was moved Other than that, I'd be happy to merge. |
I'm not sure how I can build Avrdude without libusb 1.0 without completely uninstalling libusb on my computer. Maybe @mcuee can give it a try. For reference, I found a trace that tells us that the CH341A may not work with libusb 0.1: From https://patchwork.coreboot.org/patch/4364/
|
That's fair enough and I'd be happy to go with I am thinking of undoing the change in |
It is not related to this PR but rather related to MSVC build. So yes it is out of scope for this PR but it is nice to have. |
OK, good. I'll leave it then. Just needed a reason for the change. |
The code as of now only works with libusb-1.0. This should not be an issue for majority of the platform except Windows. For majority of the Linux distros, macOS (Homebrew or macPorts), OpenBSD, NetBSD, Windows MinGW, libusb-compat-0.1 is dependant on libusb-1.0 (just a wrapper) and provide libusb-0.1 API for the platform. FreeBSD provides wrapper for both libusb-1.0 and libusb-0.1 API by using a system library. The only real issue is with avrdude MSVC build which uses avrdude specific avrdude-libusb library, which only provides libusb-0.1 API.
|
Yes I agree. |
Any objection for this PR as it is not supporting MSVC build now (it only supports libusb-1.0 API and not avrdude-libusb)? Is it okay to merge this first and then to address the issue for MSVC build later? |
- Return error in ch431a_open() when unable to claim usb interface - Fix return value of CH341ChipSelect() - Return error in ch431a_initialize() when CH341ChipSelect() fails - Minor fixes in error messages - Remove redundant #ifdef HAVE_LIBUSB_1_0 - Silence compiler for integer/unsigned warnings
I for one am happy to merge unless there is an imminent fix to the MSVC libusb issue. My final sweep through the ch341a programmer uncovered a few omissions error handling:
That warrants a final sanity test of the programmer. Other than that it would be good to go. |
@stefanrueger while you're at it, could you mention in the docs that The CH341A ISP bit clock is approx. 1.7 MHz (0.714us), and cannot be increased or decreased. This means that the CH341A can't program "stock" AVRs ? (Some sources say 1.4 MHz, while other states 1.6 or 1.7 MHz. I haven't measured mine yet) |
Should we address this in this PR, or should we deal with this later? |
Looks good.
|
Indeed. Just a quick test to enable CLKDIV8 for my ATmega2560 with external 16Mhz crystal (running at 2MHz) and it will fail to connect.
Restore the clock to 16MHz and then there will be no issue.
|
Excellent work @stefanrueger! It's a good idea to set the reset pin in avrdude.conf. |
Closes #714 |
Add CH341A programmer support.
Based on the issue: [patch #9127] Support for CH341A programmer.
Using the patch sent by @avrs-admin