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
2 Likes

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
2 Likes

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
OpenOCD: Bug Reporting
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.

6 Likes

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.

Hi @maxgerhardt, I’ve tried your suggestion and worked for the second option:

[env:bluepill_f103c8_128k]
platform = ststm32
board = bluepill_f103c8_128k
framework = arduino
upload_flags = -c set CPUTAPID 0x2ba01477
debug_server =
  /home/user/.platformio/packages/tool-openocd/bin/openocd
  -s /home/user/.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" 

However, did not for the first option:

"debug": {
    "default_tools": [
      "stlink"
    ],
    "jlink_device": "STM32F103C8",
    "openocd_extra_args": [
      "-c",
      "reset_config none",
      "set",
      "CPUTAPID",
      "0x2ba01477"
    ],
    "openocd_target": "stm32f1x",
    "svd_path": "STM32F103xx.svd"
  },

I can’t see what I’m missing.

Did not what?

Are you using the wrong array of string arguments there. Should be

    "openocd_extra_args": [
      "-c",
      "reset_config none",
      "-c",
      "set CPUTAPID 0x2ba01477"
    ],

Sorry,
Did not work for the first option.

$ cat ~/.platformio/platforms/ststm32/boards/cs32_bluepill.json 
{
  "build": {
    "core": "stm32",
    "cpu": "cortex-m3",
    "extra_flags": "-DSTM32F1 -DSTM32F103xB -DARDUINO_BLUEPILL_F103C8",
    "f_cpu": "72000000L",
    "hwids": [
      [
        "0x1EAF",
        "0x0003"
      ],
      [
        "0x1EAF",
        "0x0004"
      ]
    ],
    "mcu": "stm32f103c8t6",
    "product_line": "STM32F103xB",
    "variant": "PILL_F103XX",
    "zephyr": {
       "variant": "stm32_min_dev_blue"
    }
  },
  "debug": {
    "default_tools": [
      "stlink"
    ],
    "jlink_device": "STM32F103C8",
    "openocd_extra_args": [
      "-c",
      "reset_config none",
      "-c",
      "set CPUTAPID 0x2ba01477"
    ],
    "openocd_target": "stm32f1x",
    "svd_path": "STM32F103xx.svd"
  },
  "frameworks": [
    "arduino",
    "mbed",
    "cmsis",
    "libopencm3",
    "stm32cube",
    "zephyr"
  ],
  "name": "BluePill F103C8",
  "upload": {
    "maximum_ram_size": 20480,
    "maximum_size": 65536,
    "protocol": "stlink",
    "protocols": [
      "jlink",
      "cmsis-dap",
      "stlink",
      "blackmagic",
      "mbed",
      "dfu"
    ]
  },
  "url": "http://www.st.com/content/st_com/en/products/microcontrollers/stm32-32-bit-arm-cortex-mcus/stm32f1-series/stm32f103/stm32f103c8.html",
  "vendor": "Generic"
}

Still getting the same result.

[env:bluepill_f103c8_128k]
platform = ststm32
board = cs32_bluepill
framework = arduino
upload_flags = -c set CPUTAPID 0x2ba01477

I had the same issue I fixed it by doing the following,
open the file specified below and make the changes
specified, do remember to keep a backup of the file if
things get messed up.
File: [openocd dir]/scripts/target/stm32f1x.cfg
Change: ‘set _CPUTAPID 0x1ba01477’ to ‘set _CPUTAPID 0x2ba01477’

note: in GNU/Llinux the openocd used by platformio is located at ‘/home/user/.platformio/packages/tool-openocd’