Notes
GitHub ProfileHere are some notes on how to deal with these MCUs. If you got such a chip then I suppose you have bought BluePill on Aliexpress where some unfair sellers don’t claim clearly enough that the boards are based on a clone of STM32 MCUs.
Reference manual for this MCU available only on chiness. You can find an information that it is pin to pin compatible with STM32F103 but it is not clear if errata is the same. One note about flash size: there is a lot of information from community (e.g. here, here) that original STM32F103C8T6 actually has 128Kb of flash even though it’s marked as 64Kb. But the clone CS32 has only 64Kb.
While programming works well using STlink V2 clone and STM32 ST-LINK Utility
or STM32CubeProgrammer
there are problems with debugging. Fortunately this can be fixed.
You can debug these chips with OpenOCD. To do it you have to change idcode of the device in OpenOCD configuration. Original STM32F103 chip has 0x1ba01477
, but CS32 has 0x2ba01477
. So the simplest way is to find configuration file stm32f1x.cfg
in OpenOCD directory and replace idcode:
#set _CPUTAPID 0x1ba01477
set _CPUTAPID 0x2ba01477
Or create a new config for that case and replace a value. Also you should set reset mode to Software system reset. In STM32CubeIDE open [project_name]Debug.cfg
and set reset configuration as:
reset_config none
set CONNECT_UNDER_RESET 0
set CORE_RESET 0
Now debugging should work.
Stlink gdbserver that is shipped with TrueStudio or STMCubeIDE doesn’t work with these chips. When it tries to connect, there is an error in output stating that it can not verify the device. I suppose the problem is the same as with OpenOCD because of another idcode and maybe vendor.