Qinheng CH32F103C8T6: PlatformIO DAPLink and WCHLink download configuration

catalogue

Burning with DAP link

DAP link is an open-source debugging simulator of ARM, also known as CMSIS-DAP. It supports almost all MCU with Cortex-M core, and does not choose brand manufacturers Its function is equivalent to ST link of ST
The Win10 Keil5 MDK can be plug and play without driver and configuration In platform io of Linux, some configuration is required to work normally

1. First locate the configuration directory of PlatformIO

The default directory is / home / [your user name] / Platform IO /, you can see the directories of packages, penv and platforms below. This step is very important because you need to add new files to the configuration directory

2. Add CH32F103C8 to the development board configuration

Add a bluepill in the platforms / STM32 / boards directory_ ch32f103c8. JSON file. The contents of the file are as follows:,

{
  "build": {
    "arduino": {
      "variant_h": "variant_PILL_F103Cx.h"
    },
    "core": "stm32",
    "cpu": "cortex-m3",
    "extra_flags": "-DSTM32F1 -DSTM32F103xB",
    "f_cpu": "72000000L",
    "hwids": [
      [
        "0x1EAF",
        "0x0003"
      ],
      [
        "0x1EAF",
        "0x0004"
      ]
    ],
    "mcu": "stm32f103c8t6",
    "product_line": "STM32F103xB",
    "variant": "STM32F1xx/F103C8T_F103CB(T-U)",
    "zephyr": {
       "variant": "stm32_min_dev_blue"
    }
  },
  "debug": {
    "default_tools": [
      "stlink"
    ],
    "jlink_device": "STM32F103C8",
    "openocd_extra_args": [
      "-c",
      "reset_config none"
    ],
    "openocd_target": "ch32f1x",
    "svd_path": "STM32F103xx.svd"
  },
  "frameworks": [
    "arduino",
    "mbed",
    "cmsis",
    "libopencm3",
    "stm32cube",
    "zephyr"
  ],
  "name": "BluePill CH32F103C8",
  "upload": {
    "maximum_ram_size": 20480,
    "maximum_size": 65536,
    "protocol": "stlink",
    "protocols": [
      "jlink",
      "cmsis-dap",
      "stlink",
      "blackmagic",
      "mbed",
      "dfu"
    ]
  },
  "url": "http://www.wch.cn/products/CH32F103.html",
  "vendor": "Generic"
}

This file is based on bluepill_f103c8.json mainly modifies "openocd_target": "ch32f1x" and changes the configuration file of openocd

After adding, you can search the development board named "BluePill CH32F103C8" in the Boards of PlatformIO

3. Modify platform ini

Modify the board to a custom bluepill_ch32f103c8, the modified configuration is similar to

[env:bluepill_ch32f103c8_dap]
platform = ststm32
board = bluepill_ch32f103c8
framework = cmsis
upload_protocol = cmsis-dap
debug_tool = cmsis-dap

4. Add CH32F1X in the OpenOCD configuration

Under packages / tool openocd / scripts / target directory, add a ch32f1x Cfg file, the content is

# CH32F103x

set CPUTAPID 0x2ba01477

source [find target/stm32f1x.cfg]

The configuration content is in stm32f1x CFG based on this configuration, the chip ID is defined as 0x2ba01477, so there is no need to use platform Ini is additionally configured

5. Burning

In most cases, you can burn by connecting DAP link, and the output is

openocd -d2 -s /home/milton/.platformio/packages/tool-openocd/scripts -f interface/cmsis-dap.cfg -c "transport select swd" -f target/ch32f1x.cfg -c "reset_config none" -c "program {.pio/build/bluepill_ch32f103c8_dap/firmware.elf}  verify reset; shutdown;"
xPack OpenOCD x86_64 Open On-Chip Debugger 0.11.0+dev (2021-10-16-21:15)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
debug_level: 2

swd
Info : DEPRECATED target event trace-config; use TPIU events {pre,post}-{enable,disable}
none separate

Info : CMSIS-DAP: SWD  supported
Info : CMSIS-DAP: Atomic commands supported
Info : CMSIS-DAP: FW Version = 2.0.0
Info : CMSIS-DAP: Serial# = 205544643577
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 0 TDO = 0 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 1000 kHz
Info : SWD DPIDR 0x2ba01477
Info : stm32f1x.cpu: Cortex-M3 r2p1 processor detected
Info : stm32f1x.cpu: target has 6 breakpoints, 4 watchpoints
Info : starting gdb server for stm32f1x.cpu on 3333
Info : Listening on port 3333 for gdb connections
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0xfffffffe msp: 0xfffffffc
** Programming Started **
Info : device id = 0x20000410
Info : flash size = 64kbytes
** Programming Finished **
** Verify Started **
** Verified OK **
** Resetting Target **
shutdown command invoked

6. Adjust the frequency

If such an error occurs

target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x0800014c msp: 0x20005000
** Programming Started **
Info : device id = 0x20000410
Info : flash size = 64kbytes
Info : SWD DPIDR 0x2ba01477
Error: Failed to write memory at 0x2000003c
Error: error writing to flash at address 0x08000000 at offset 0x00000000
embedded:startup.tcl:1070: Error: ** Programming Failed **
in procedure 'program' 
in procedure 'program_error' called at file "embedded:startup.tcl", line 1135
at file "embedded:startup.tcl", line 1070
*** [upload] Error 1

It indicates that DAP link has recognized the chip normally, but there is an error in writing. You can reduce the frequency and try again The frequency is set at
packages/tool-openocd/scripts/target/stm32f1x.cfg
Modify one of them

# JTAG speed should be <= F_CPU/6. F_CPU after reset is 8MHz, so use F_JTAG = 1MHz
adapter speed 1000

You can set it to 500 or 800 and try again

Burn using WCH Link

WCH link is a download and debugging module based on WCH549 chip. It supports 3.3V/5V dual power output, supports USB to TTL serial port, and uses LED indicator to identify the working state. There are two working modes:

  1. CMSIS-DAP mode: it can be used for debugging and downloading ARM kernel MCU with SWD interface
  2. RISC-V mode: it can be used for debugging and downloading qinheng Series MCU of RISC-V architecture,

Data viewing

WCH link uses an 8-bit MCU with USB and serial port functions as the main control. The price is very competitive. The current cost is estimated to be less than seven yuan,
St link and DAP link are basically unable to achieve this price, and the cost of the main control chip is more than that

1. Add CH32F103 to the development board configuration

The configuration is the same as that of DAP link

2. Modify platform ini

The configuration is the same as that of DAP link

3. Add CH32F1X in the OpenOCD configuration

In packages / tool openocd / scripts / target directory, add ch32f1x Cfg file, the content is

# CH32F103x

set CPUTAPID 0x2ba01477

cmsis_dap_vid_pid 0x1a86 0x8011

source [find target/stm32f1x.cfg]

Compared with the configuration of DAP link, one line of CMSIS is added_ dap_ vid_ PID 0x1a86 0x8011, so that openocd can recognize WCH link as CMSIS DAP device

4. Modify 99 platform udev rules

When installing platform IO, it should be in / etc / udev / rules 99 platform udev has been added in the D / directory Rules this file is used to add 0666 permissions to USB devices
WCH link is a new device for PlatformIO, which is available in 99 platform udev Rules is not added to it. If it is not set, a permission error will occur

Error: could not open device 0x1a86:0x8011: Access denied (insufficient permissions)
Error: unable to open CMSIS-DAP device 0x1a86:0x8011
Error: unable to find a matching CMSIS-DAP device
Error: No Valid JTAG Interface Configured.
*** [upload] Error 255

At 99 platform udev The configuration of WCH Link needs to be added in the rules. Add two lines at the bottom

# WCH Link (CMSIS-DAP compatible adapter)
ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="8011", MODE="0666", ENV{ID_MM_DEVICE_IGNORE}="1", ENV{ID_MM_PORT_IGNORE}="1"

Execute after saving

sudo udevadm control --reload-rules

Then reseat WCHLink to make the permission take effect

5. Burning

If the above configuration is correct, the burning output is

CURRENT: upload_protocol = cmsis-dap
openocd -d2 -s /home/milton/.platformio/packages/tool-openocd/scripts -f interface/cmsis-dap.cfg -c "transport select swd" -f target/ch32f1x.cfg -c "reset_config none" -c "program {.pio/build/bluepill_f103c8_ch32/firmware.elf}  verify reset; shutdown;"
xPack OpenOCD x86_64 Open On-Chip Debugger 0.11.0+dev (2021-10-16-21:15)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
debug_level: 2

swd
Info : DEPRECATED target event trace-config; use TPIU events {pre,post}-{enable,disable}
none separate

Info : CMSIS-DAP: SWD  supported
Info : CMSIS-DAP: FW Version = 2.0.0
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 0 TDO = 0 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 1000 kHz
Info : SWD DPIDR 0x2ba01477
Info : stm32f1x.cpu: Cortex-M3 r2p1 processor detected
Info : stm32f1x.cpu: target has 6 breakpoints, 4 watchpoints
Info : starting gdb server for stm32f1x.cpu on 3333
Info : Listening on port 3333 for gdb connections
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x0800014c msp: 0x20005000
** Programming Started **
Info : device id = 0x20000410
Info : flash size = 64kbytes
** Programming Finished **
** Verify Started **
** Verified OK **
** Resetting Target **
shutdown command invoked

end

If you need two burning debugging tools to coexist, you can create two board configurations in platform Create two env s in ini and use different boards respectively. When using, use [platform IO] default_ Envs = XXXX for switching

reference resources

Keywords: Linux OpenOCD

Added by High_-_Tek on Wed, 26 Jan 2022 22:35:58 +0200