Close

Flashing the CH552 dev board from the command line

ken-yapKen Yap wrote 05/17/2024 at 13:25 • 3 min read • Like

This is a follow up to https://hackaday.io/page/13802-a-quick-foray-into-the-ch552-mcu

I finally got around to having a use for these cheap and tiny MCU boards.

Instead of using the Arduino CH55x framework by Deqing Sun in my initial exploration, I'm developing using command line tools. Editing and compiling using SDCC is no problem, I've done this for other 8051 projects such as #Adventures with a STC89C52 development board The issue is how to flash the embedded code to the board. The tool I chose is vnproch55x which is maintained by Deqing Sun also. So I just made a link to the binary provided by the Arduino CH55x framework.

However I ended up looking at the code on GitHub also to work out how to invoke it. From observing the output of the Sketch > Upload action, it's called with two additional command line parameters. The full invocation looks like this:

vnproch55x -r 16 -t CH552 blink.hex

The -r parameter sets the number of seconds to retry, the -t parameter chooses the target MCU type, and finally note that utility accepts hex files also, all enhancements to the original vnproch551 by NgoHungCuong. So if you don't have the Arduino CH55x framework installed, Deqing Sun's utility is the one to clone and compile to get an executable utility.

Also confusing the situation was that any sketch uploaded by the Arduino CH55x framework contains a bootloader which makes it appear as /dev/ttyACM0 which is a CDC with USB VID 1209:C550. This confused me because I was expecting the USB VID to be 4348:55E0. When such a CDC bootloader is in place you need to set the serial speed to 1200 baud and drop DTR to make it ready for receiving a sketch. The Arduino IDE does this but to do it from the CLI you can use a short Python script reset.py from the repo Arduino_Loader in GitHub. I made one small change to upgrade it to Python3 since that's the current Python on my Linux system.

However once you have loaded a bare metal sketch, i.e. one that doesn't use a CDC bootloader, it will appear at USB VID 4348:55E0. But I could not get the attention of the board to receive a new sketch. Remembering how similar boards work, I found the sequence.

  1. First start vnproch55x to read the hex file and start attempting to connect to the board. You now see why I used a generous retry period of 16 seconds.
  2. Connect the USB cable to the port while holding down the BOOT button (the other one is the RESET) button.
  3. Release the BOOT button. It will accept a USB connection and receive the code and execute it.

Incidentally the udev rule supplied for the CH55x sets the device mode to 0666. It's better to set it to mode 0660 and owned by the group used for downloads which you should make yourself a member of, in my Linux system it's dialout (I know, not much to do with embedded development, it's historical).

Great! Now I can finish the development of the embedded program and put the board to use.

Like

Discussions