PlatformIO Community

Debugging of STM32F103 clone "BluePill" board, wrong idcode

Hi,
I have a problem debugging my STM32 clone. How can I fix the issue with the idcode?

Warn : UNEXPECTED idcode: 0x2ba01477
Error: expected 1 of 1: 0x1ba01477

.pioinit:13: Error in sourced command file:

Your BluePill board contains a CS32F103C8T6 chip, a Chinese clone instead of a real STM32F103C8T6.

In order to upload the code, add the below line to platformio.ini:

upload_flags = -c set CPUTAPID 0x2ba01477
1 Like

I have already made these changes since I encountered problems with uploading.
But somehow this is not applied to the debugger.

Try and use the debug_init_cmds.

debug_init_cmds =
  set CPUTAPID 0x2ba01477
  target extended-remote $DEBUG_PORT
  $INIT_BREAK
  monitor reset halt
  $LOAD_CMDS
  monitor init
  monitor reset halt
1 Like

I have tried so far with these commands. But somehow the debugger still not accepts the new CPU ID.

Here is my platformio.ini and the error code of the debugger while uploading:

[env:bluepill_f103c8]
platform = ststm32
board = bluepill_f103c8
framework = arduino
upload_flags = -c set CPUTAPID 0x2ba01477
[env:debug]
platform = ststm32
board = bluepill_f103c8
framework = arduino
debug_init_cmds =
set CPUTAPID 0x2ba01477
target extended-remote $DEBUG_PORT
$INIT_BREAK
monitor reset halt
$LOAD_CMDS
monitor init
monitor reset halt

xPack OpenOCD, 64-bit Open On-Chip Debugger 0.10.0+dev (2019-07-17-11:28)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
debug_level: 1

hla_swd
none separate

Warn : UNEXPECTED idcode: 0x2ba01477
Error: expected 1 of 1: 0x1ba01477
in procedure ‘program’
** OpenOCD init failed **
shutdown command invoked

*** [upload] Error 1

Oh right, because the init cmds still go to GDB and not openOCD before it. There still multiple ways to do it.

  1. By using a custom board JSON file with an expanded openocd_extra_args. Copy-paste the bluepill JSON file into the boards/ folder of the project as a new name (e.g. cs32_bluepill.json), extend the openocd_extra_args by two entries for the CPUTAPID and use board = cs32_bluepill.
  2. Directly modify the openOCD debug server invocation in the platformio.ini to have the right flags. E.g.
debug_server =
  C:\Users\Maxi\.platformio\packages\tool-openocd\bin\openocd.exe
  -s C:\Users\Maxi\.platformio\packages\tool-openocd\scripts
  -f interface\stlink.cfg
  -c "transport select hla_swd"
  -c "set CPUTAPID 0x2ba01477"
  -f target\stm32f1x.cfg
  -c "reset_config none"

(use adapted path information)
3. Permanently modify C:\Users\Maxi\.platformio\packages\tool-openocd\scripts\target\stm32f1x.cfg line 42 to have the “corrected” ID for the chinese clone.

1 Like

Thanks a lot! Its working now.

I am also trying the debugger on my STM32F407VGT6 board with genuine chip.
Somehow the debugger wont execute:

Error: Please specify debug_port for environment

Do you have any idea how to fix this? I am using STLINK V2 programmer.

Separate topic with full platformio.ini please.