CH341A Programmer

27,823

8

22

Introduction: CH341A Programmer

I recently have purchased a CH341A mini programmer. The mini programmer is OK and can by used to program 24 and 24 series chips. It is very low cost but quite useful as I can use it to flash my computer BIOS and router firmware.

WCH has kindly released its API and C library for developers to utilise the chip. So I have decided to build my own programming software for the mini programmer.

The programming software I have utilise the CH341DLL.dll library provoided by WCH. It can utilise I2C and SPI protocol via USB.

All codes are written in C# and all C++ function calls have been wrapped to be used by C#.

The driver and C library can be downloaded from WCH's website. http://www.wch-ic.com/

Step 1: The Main Window

The main windows provides all the functions we need to read and program these Flash NOR / EEPROM chips. You can also use the menu to perform the same function.

It has in-built HEX editor to edit the file or content read fromt the chip. For example, we can add the MAC code in the router firmware before program it to the chip.

All related functions (Copy / Paste / Search etc) are provided for editing the binary file.

Step 2: Chip Selection

You need to select the chip you want to work on first.

Just click on the "Search" button to search the chip in the chip database. Just type the keywords of your chip and all matching chips will be displayed in the grid.

For 24 series chips (I2C), you will have to select it manually as they don't have any id / signature for us to identify them.

For 25 series chips (SPI), you can use the "Auto Detect" button to read the id / signature of the chip. If an id is found, a chip selection window will pop up for you to select it.

Step 3: Read Chip

Use "Read" button to read the chip you have selected. The content of the chip will be displayed on the HEX editor.

You can use the "Save" button to save the chip content.

Step 4: Program Chip

You can open an existing file by click on the "Open" button.

Once a file has been selected, its content will be loaded to the HEX editor.

You can apply changes to the content before program it to the chip.

Once you are satisfied with the loaded content, click on "Program" button to program it to the chip.

You can also use "Auto" button to program the chip which will verify the data after it was programed.

The SPI chip will be erased automatically before the programming starts. However, you can manually erase the chip as well.

Step 5: Verify Chip

Once you have read or written the chip, It is highly recommanded to verify the read / write content against the content loaded in the HEX editor.

You can verify the content by click on the "Verify" button.

Step 6: File Slicer

The program has in-built file slicer function to slice a certain part of the fiile / loaded content and save it to a file.

This function is very useful when working on router firmwares. For example, extract the last 64KB of the file to save your router's ART information.

Step 7: File Merger

You can also use the file merger to merge two files into one.

Some laptop BIOS utilise multiple chips to store BIOS and EC information. You will need to combine them before you can work on it.

By utilising the merge function, you can combine two files into one for further process.

Step 8: Program Download

Please download the program and source code from my Google Drive below.

https://drive.google.com/drive/folders/17xf3EKIPe2Nhx2obE235PBRnkSKaU4uv?usp=sharing

The source code has not been well commented yet. I will upload a well commented version once I have added these comments for better reading and unstanding.

Be the First to Share

    Recommendations

    • First Time Author Contest

      First Time Author Contest
    • Fruit and Veggies Speed Challenge

      Fruit and Veggies Speed Challenge
    • Backyard Contest

      Backyard Contest

    22 Comments

    0
    francis.doukhan
    francis.doukhan

    Question 6 weeks ago on Introduction

    Hello. It look like the driver delivered by WCH donnot cover all CH341 PIDs. I bought two different programmers one black similar to yours and one blue and both are using CH341A from WCH but their VID/PID is VID_1A86&PID_5512 which is not listed in the driver.inf file => not recognized by your software. Any idea?
    THX
    one add'l comment. V1.0 works and recognize the programmer while the v1.0.1 doesn't => my above interpretation was wrong

    0
    zsccat
    zsccat

    Answer 5 weeks ago

    Hi Francis,

    I think you have not get your driver installed correctly. There are 2 drivers for CH341A, one is the SER mode which you can use it as a USB-TTL adaptor; the other one is EPP mode which is the programmer use. You may had download the SER driver instead of the EPP one.

    V1.0 does not include programmer detection and it may not report correctly.

    Mine is having the same VID/PID as yours, once you have got the correct driver installed, you will see it from the device manager as the screenshot below.

    004.png
    0
    francis.doukhan
    francis.doukhan

    Reply 5 weeks ago

    Hello
    THX for your answer. As you said I initially made the mistake of installing the SER driver instead of the PAR one. Once the paralel driver installed as I told You I was abble to run the v1.0 (auto chip detect works, chip read works). However the V1.0.1 allways reports a non connected CH341 programmer. I am running under XP SP3 is that a possible reason of the issue?
    On both versions I have an exception which occurs when starting but it is not blocking for the application to open (both V1.0 and V1.01)
    .

    0
    zsccat
    zsccat

    Reply 5 weeks ago

    Hi Francis,

    I think that is the issue. I don't have a computer running XP now and all the programming and testing are done on a Windows 10 PC. The program was built in C# with .NET framework 4.0. You may try to install / re-install .NET 4.0 package and try again. That may fix your issue. (You can download the offline installation package at Microsoft's website https://www.microsoft.com/en-au/download/details.aspx?id=17718)

    0
    francis.doukhan
    francis.doukhan

    Reply 5 weeks ago

    Hello
    I switch to a W10 computer. But the behavior is still the same: V1.0 works, V1.01 doesn't and still the same exception when starting both applications.
    Any Idea?

    0
    zsccat
    zsccat

    Reply 5 weeks ago

    Hi Francis,

    Would you mind post a screenshot of the exception you have got?

    0
    francis.doukhan
    francis.doukhan

    Reply 5 weeks ago

    Here it is.
    Same as previously using XPSP3. It is not a critical XCeption (sorry in French).
    A quick translation follows:
    Unmanaged exception occurs in your application. Click on Continue and the application will ignore this error and try to continue. Click on Quit, the application will stop immediatelly.
    The format of the input string is not correct

    Are you starting the application using a configuration string? Could it be a problem with installed languages?

    XCeption.jpg
    0
    francis.doukhan
    francis.doukhan

    Reply 5 weeks ago

    Hi,
    Look like I already have the most recent .NET (I use a recent W10 20H2 19042)
    Anyway the updater dont do anything (nothing to update)
    But regardless the exception which is not blocking I dont understand why V1.0 works while v1.01 doesn't

    ControlPanel2.jpg
    0
    zsccat
    zsccat

    Reply 5 weeks ago

    Hi Francis,

    I have run out of ideas. I have never got this error before. I think you may need to download the source code, run it in debug mode and see what is the actual exception.

    0
    francis.doukhan
    francis.doukhan

    Reply 5 weeks ago

    OK
    I've downloaded visual studio community 2019
    Here is the errormessage deliverd during execution
    Une exception non gérée du type 'System.FormatException' s'est produite dans mscorlib.dll
    Le format de la chaîne d'entrée est incorrect.

    Look like teh error is still the same
    Not familiar in using MS tools
    Any guidance?

    0
    zsccat
    zsccat

    Reply 4 weeks ago

    Hi Francis,

    It is so good to hear that you have got it working properly now. Unfortunately, I don't have much time to do so many translations at the moment. (Maybe in the future once I can have some time) Moreover, USBIOX.dll is just a wrapper for native DLLs and does not have any logic inside. (The comments comes from the WCH C library) It should not impact your understanding of the code logics.

    0
    francis.doukhan
    francis.doukhan

    Reply 5 weeks ago

    Configured in French: I made the following change in fmMain.cs line 58 (original line in comment). I dont understand the usage of the added part (float.Parse("2.0")
    // hbx_Edit.Font = new Font(SystemFonts.MessageBoxFont.FontFamily, SystemFonts.MessageBoxFont.Size + float.Parse("2.0"), SystemFonts.MessageBoxFont.Style);
    hbx_Edit.Font = new Font(SystemFonts.MessageBoxFont.FontFamily, SystemFonts.MessageBoxFont.Size, SystemFonts.MessageBoxFont.Style);

    This change removes the exception and make the code operationg V1;01 (I suppose) with the detection of the board programmer working as well.

    Configured in English (some messages still in French after multiple reboot, Visual studio menu still in French, really Windows is a mess, nothing working properlly)
    Nevertheless the code execute without exception.
    I really dont understand why windows doesn't behave the same whatever the language is.
    Can you clarify the usage of the code: + float.Parse("2.0")?

    Could you please translate the file USBIOXdll.cs from Chinese to English?
    THX a lot

    0
    francis.doukhan
    francis.doukhan

    Reply 4 weeks ago

    Hi,
    I finaly catch the usage of your code and suggest to make the following changes using a standard C cast instead of a "sophisticated" Windows function.

    You write: SystemFonts.MessageBoxFont.Size + float.Parse("2.0")
    I suggest: SystemFonts.MessageBoxFont.Size + (float)2.0

    I have made the change in the InitialSetup() procedure as well as in btn_FontSizePlus_Click() and btn_FontSizeMinus_Click() procedures.

    The application works fine using French and English languages in W10 and works also well using my old XPSP3.

    Could you please translate the file USBIOXdll.cs from Chinese to English?
    THX a lot

    0
    zsccat
    zsccat

    Reply 5 weeks ago

    Hi Francis,

    I have never got that Exception before. However, you may try the following and test again. Change your windows default language to English instead of French and try again. You can change it back once you have tested. This can help to test whether it is related to the charset you are using or not.

    0
    Microrusty
    Microrusty

    Question 8 weeks ago on Step 8

    Writing to a Microchip 24LC256. Just doing the alphabet into the first 2 rows. Writing in Hex 41 to 5F. I save the program then write to the chip. When I do a read .it repeats the hex number every 20 hex lines. When it writes to the chip it duplicates the data. Any help would be great. Please see attached image.

    Screenshot.PNG
    0
    zsccat
    zsccat

    Answer 8 weeks ago

    You may also try this version (with 24LC256 in its name) which will write byte by byte instead of by page. Make sure choose 24C256_1 and this option will force the programmer to write byte by byte rather than page by page.

    01.PNG02.PNG
    0
    zsccat
    zsccat

    Answer 8 weeks ago

    Hi Microrusfy,

    I don't have any 24C256 chips and the code is programmed based on the datasheet. I had not test the code on a 24C256. The only 24 series chip I have is 24C02 and that one is tested. I have checked the source code and the the 2 byte address chip's address may not get calculated correctly. The version 1.01 has been updated with a fix. Please have a try and let me know how it goes as I cannot test it. I will order some 24C256 from Aliexpress to test out but it will take some time to arrive. Good luck mate.

    0
    Amirdelta
    Amirdelta

    5 months ago

    And a suggestion
    For your free probable hobby time
    You may add AVR ISP protocol to the app for wider usage and popularity as the protocols source code is available online.

    0
    zsccat
    zsccat

    Reply 5 months ago

    Thanks for your suggestion. I will look into it when I have time.