Monday, September 13, 2021

Arduino ID and CH32F103C8T6

(if you are catching up, start here: initial Arduino w/STM post)

OK, so I was looking to get a second STM32F103C8T6 board and a second STM32F411CEU6 board as well. I wanted to have two each so I could keep the latest circuit and code build on one board while the other was used to work on the next part of the project. Once tested, it would be rolled into the primary and then on to the next bit. Well, when my F103 order arrived, it was actually a CH32F103C8T6. I can not tell if I made a mistake and ordered the wrong board or if I was shipped the wrong board. The vendor was able to produce a invoice copy (of course) that showed the order was for the CH32F103C8T6, so I am stuck with it, which I expected as it would no way be worth shipping it back for a replacement. Figured I would keep it to see "how bad it could be" and just place another order for the STM.

Did some searching and it seems these boards can be actually fairly good and compatible with the STM boards or total crap. The one I wound up with is a blue/black-pill. It has the F103C8T6 chip by WCH and is on a blue circuit board but has the black pill push buttons for boot0 and NRST. It also has a USB-C connector.

I tried just hooking it up like the STM F103 and no luck.It came up as a universal serial bus unknown device. Then I figued what do I have to lose and connected it to the PC just like I connected the real Black-Pill. Used the ST-Link with the power disconnected and plugged in the USB-C connector. In Arduino, I selected the "Generic STM32F1 Series", "BluePill F103C8", set the rest up as normal and picked the upload method as "STM32CubeProgrammer (SWD)" (I also tried selecting "STLink" and think that worked better). This is the Cube results (the STLink results are lower down).


Sketch uses 23936 bytes (36%) of program storage space. Maximum is 65536 bytes.

Global variables use 3556 bytes (17%) of dynamic memory, leaving 16924 bytes for local variables. Maximum is 20480 bytes.

      -------------------------------------------------------------------

                       STM32CubeProgrammer v2.8.0                  

      -------------------------------------------------------------------


ST-LINK SN  : 36FF6C06344E393734192457
ST-LINK FW  : V2J29S7
Board       : --
Voltage     : 3.18V
SWD freq    : 4000 KHz
Connect mode: Under Reset
Reset mode  : Hardware reset
Device ID   : 0x410
Revision ID : Rev B
Device name : STM32F101/F102/F103 Medium-density
Flash size  : 64 KBytes
Device type : MCU
Device CPU  : Cortex-M3
BL Version  : 0x__


Memory Programming ...

Opening and parsing file: STM32_Blink.ino.bin
  File          : STM32_Blink.ino.bin
  Size          : 24232 Bytes
  Address       : 0x08000000 


Erasing memory corresponding to segment 0:
Erasing internal memory sectors [0 23]
Download in Progress:


File download complete
Time elapsed during download operation: 00:00:34.850

RUNNING Program ... 
  Address:      : 0x8000000
Application is running, Please Hold on...
Start operation achieved successfully

Using STLink, got these results:

Sketch uses 14804 bytes (22%) of program storage space. Maximum is 65536 bytes.
Global variables use 2072 bytes (10%) of dynamic memory, leaving 18408 bytes for local variables. Maximum is 20480 bytes.
STM32 ST-LINK CLI v3.3.0.0
STM32 ST-LINK Command Line Interface

ST-LINK SN: 36FF6C06344E393734192457
ST-LINK Firmware version: V2J29S7 (Need Update)
Connected via SWD.
SWD Frequency = 4000K.
Target voltage = 3.2 V
Connection mode: Normal
Reset mode: Software reset
Device ID: 0x410 
Device flash Size: 64 Kbytes
Device family: STM32F10xx Medium-density

Loading file...
Flash Programming:
  File : c:\TEMPFI~1\arduino_build_155575\STM32_Blink.ino.bin
  Address : 0x08000000
Memory programming...
 0%������������������������� 51%������������������������� 100%
Memory programmed in 21s and 500ms.
Programming Complete.

MCU Reset.

Application started.

In addition, if you are having issues getting the program loaded via Arduino BUT you can connect successfully to the board using the ST-Link, you can load your Arduino sketch that way. Verify your sketch to make sure it is error free. Then select "Sketch", "Export compiled Binary". You will find the BIN file in the sketch directory. In my case that is "C:\Users\{login}\Documents\Arduino\STM32_Blink" and the binary was called "STM32_Blink.ino.BLUEPILL_F103C8.bin". Just launch ST-LINK, connect to the board, open the BIN and do the "program & verify". When I initially connect to the CH32F103C8T6, ST-Link displays:

21:26:14 : ST-LINK SN : 36FF6C06344E393734192457
21:26:14 : V2J29S7
21:26:14 : Connected via SWD.
21:26:14 : SWD Frequency = 4,0 MHz.
21:26:14 : Connection mode : Normal.
21:26:14 : Debug in Low Power mode enabled.
21:26:14 : Device ID:0x410 
21:26:14 : Device flash Size : 64KBytes
21:26:14 : Device family :STM32F10xx Medium-density

When the BIN file is opened, it shows:

21:27:46 : [STM32_Blink.ino.BLUEPILL_F103C8.bin] opened successfully.
21:27:46 : [STM32_Blink.ino.BLUEPILL_F103C8.bin] checksum : 0x0024D8A5 

After uploading the BIN, it shows:

21:28:33 : Memory programmed in 35s and 328ms.
21:28:33 : Verification...OK
21:28:33 : Programmed memory Checksum: 0x0024D8A5

Am still "playing" with the process/sequence but it looks to be working/workable. I will finish connecting the IC pins and likely use this as the second board until the "real" one comes in but so far it is "compatible" enough for what I am doing and the specs for memory and speed match so we shall see.

Update 21/09/15:

Did some simple interfacing and programming to this board using 2 sets of status light LED boards (each board has 6 LEDs that you can drive from the board pins). I first wired it all up using the STM32F411. It works completely and as expected. I then swapped out the F411 for the CH32F103C8T6 board. The sketch did need some minor tweaking on the pin assignments (as it would have if I were to swap in an F103) but other than that it compiled, loaded, and ran just as the BlackPill did. When I get a chance I will do an STM-F103 to the CH-F103 compare but it will need to wait for now as I don't have a free STM-F103 at the moment.

It does "appear" to be circuit board compatible as the various pins are labeled the same as the STM32F103 I have but I would like to test/verify some to be sure.

No comments:

Post a Comment