(SOLVED) CH-340 USB to Serial Download issue

jbforrer
Posts: 16
Joined: Thu Oct 08, 2015 5:44 am

(SOLVED) CH-340 USB to Serial Download issue

Postby jbforrer » Mon Feb 22, 2016 7:04 am

Geetings,

UPDATE: --------------------------------------------------------------------------------
It appears to be Linux driver issue.
Serial download worked fine on my XP box, but failed on Linux.
There is discussion about these CH340-based Chinese Arduino boards having similar
issue. The solution is to install a different driver supplied by the manufacturer.
They supply drivers for Windows, Linux and OSX.
I downloaded the Linux driver, built the driver and installed it.
Serial download now works fine with the new driver.
------------------------------------------------------------------------------------------------

Hope someone can help. This regards serial download method that fails with the CH-340.

I have a STM32F103VET6 board that includes a handy, on-board CH-340 USB to serial chip.
For some reason the STM32DUINO serial downloader appears not to like this chip. Please see console output below.

On further investigation, the board has jumpers to disable the CH-340 chip's RX/TX and allow hardwiring in a substitute USB to serial convertor.
I substituted a PL-2302 based cable and found serial download is good and reliable.

Strange thing is, once good code loaded, one can change the jumpers back and the CH340 passes data back and forth over the serial interface just fine.

Does there appear to be a handshake issue at download time when the CH-340 chip is used? Or something with my IDE install?

Thanks in advance.
JBF.


---console debugging follows below------------

ST32MF103VET6 with CH-340 USB-to-serial
-----------------------------------------------------------------
Failed to read ACK byte <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Unexpected reply from device on command 0x01 <<<<<<<<<<<<<<<
stm32flash Arduino_STM32_0.9

http://github.com/rogerclarkmelbourne/arduino_stm32

Using Parser : Raw BINARY
Interface serial_posix: 230400 8E1

ST32MF103VET6 with PL-2302 USB-to-serial
------------------------------------------------------------------
Using Parser : Raw BINARY
Interface serial_posix: 230400 8E1
Version : 0x22
Option 1 : 0x00
Option 2 : 0x00
Device ID : 0x0414 (High-density)
- RAM : 64KiB (512b reserved by bootloader)
- Flash : 512KiB (sector size: 2x2048)
- Option RAM : 16b
- System RAM : 2KiB
Write to memory
Erasing memory
Wrote address 0x08002034 (100.00%) Done.

Starting execution at address 0x08000000... done.
Last edited by jbforrer on Tue Feb 23, 2016 11:28 pm, edited 1 time in total.

User avatar
RogerClark
Posts: 5466
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: CH-340 USB to Serial Download issue

Postby RogerClark » Mon Feb 22, 2016 9:20 am

Have you tried STM's Flash loader "Demonstrator" (i,e their serial flash loader) ?

You could also try reducing the speed, and if that fails there is a python version, but in both these cases you'd have to edit the serial uploader bat file (assuming you are running windows)

BTW. We have had various issues with the PC exe version, and I had to do several bug fixes, but not really any major code changes.
Unfortunately the source codes not seem to be supported by the original author either.

User avatar
mrburnette
Posts: 1769
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: CH-340 USB to Serial Download issue

Postby mrburnette » Mon Feb 22, 2016 1:31 pm

jbforrer wrote:<...>
Strange thing is, once good code loaded, one can change the jumpers back and the CH340 passes data back and forth over the serial interface just fine.

Does there appear to be a handshake issue at download time when the CH-340 chip is used? Or something with my IDE install?

Thanks in advance.
JBF.


So, when you are trying to download code, the bootloader is active. After a sketch is running, the serial I/O is managed by sketch libraries.

Unless you have a zillion of these things lying around, my take is to download using the working method (serial cable) and then to use the CH-340 for serial I/O to the running sketch. For development, the forum recommends the Maple Mini as it is completely supported or, supported the best 8-) Everything else is iffy and support comes only from other members with the identical board.

I find little comfort in calling the issue a "hand-shaking" problem since we hardly can classify the failure. Likely, you are not getting the 'reset' signal generated to put the uC into the bootloader. You can try and press the reset button a few milliseconds before the sketch start to download. Others on the forum have come up with reset circuits for various boards.

Ray

jbforrer
Posts: 16
Joined: Thu Oct 08, 2015 5:44 am

Re: CH-340 USB to Serial Download issue

Postby jbforrer » Mon Feb 22, 2016 5:31 pm

Thanks for the suggestions.

Incidentally, the board as described by @Madias in this post:
viewtopic.php?f=28&t=490
I need almost all those extra I/O pins for my project, more than the low-end Leaf clones offer.

1) I tried the "push reset" trick before download (am familiar with the procedure on my home-made Atmel Arduino projects). Did not help.

2) "STM Flashloader Demo" program does recognise the CH-340 and allows one to flash. I flashed the bootloader as example. Works fine.

3) Bootloader downloads via USB works fine, so does ST-link, also BMP works fine.

This is not really a showstopper for me as there are several working download methods, am just curious why there is this issue with the CH340 and not with some others, like for example, the PL-2303 USB to Serial interface. I can do as Ray suggest and use the on-board CH340 for serial I/O for my application, just not for serial downloading.

Appreciate the issues with the download code as mentioned by Roger... probably not worth wasting time on that.

Thanks much for all the efforts.
JBF.

User avatar
RogerClark
Posts: 5466
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: CH-340 USB to Serial Download issue

Postby RogerClark » Mon Feb 22, 2016 8:07 pm

I think that STMs Flash loader also has a CLI version, so you could also just modify the serial upload bat file to use the CLI instead.

The reason I didnt use the CLI was that I was trying to keep things as Open Source as possible.

If you have more than one STM32 board, you could flash the Black Magic Probe onto another board and use that for SWD uploads.

zmemw16
Posts: 978
Joined: Wed Jul 08, 2015 2:09 pm
Location: St Annes, Lancs,UK

Re: CH-340 USB to Serial Download issue

Postby zmemw16 » Mon Feb 22, 2016 8:52 pm

jbforrer wrote:Incidentally, the board as described by @Madias in this post:
viewtopic.php?f=28&t=490

oh great :cry:
no doubt its variants as well

jbforrer
Posts: 16
Joined: Thu Oct 08, 2015 5:44 am

Re: (SOLVED) CH-340 USB to Serial Download issue

Postby jbforrer » Tue Feb 23, 2016 11:30 pm

Please see the update on the first post regarding a solution.

Thanks,
JBF.

User avatar
RogerClark
Posts: 5466
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: (SOLVED) CH-340 USB to Serial Download issue

Postby RogerClark » Tue Feb 23, 2016 11:51 pm

Thanks

User avatar
ahull
Posts: 1401
Joined: Mon Apr 27, 2015 11:04 pm
Location: Sunny Scotland
Contact:

Re: (SOLVED) CH-340 USB to Serial Download issue

Postby ahull » Wed Feb 24, 2016 4:14 pm

jbforrer wrote:Please see the update on the first post regarding a solution.

Thanks,
JBF.


Do you have a link to the updated linux driver?
- Andy Hull -

User avatar
mrburnette
Posts: 1769
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: (SOLVED) CH-340 USB to Serial Download issue

Postby mrburnette » Wed Feb 24, 2016 4:58 pm

ahull wrote:Do you have a link to the updated linux driver?



Maybe from the link in this post? https://forum.arduino.cc/index.php?PHPSESSID=4khm4dc3e3h9jmr1fioq38eqj5&topic=289518.msg2024878#msg2024878

Ray


Return to “USB to Serial adaptors”

Who is online

Users browsing this forum: No registered users and 1 guest