沁恒CH32F103C8T6(三): PlatformIO DAPLink和WCHLink下载配置

您所在的位置:网站首页 沁恒开发板好用吗安全吗 沁恒CH32F103C8T6(三): PlatformIO DAPLink和WCHLink下载配置

沁恒CH32F103C8T6(三): PlatformIO DAPLink和WCHLink下载配置

2024-07-11 18:51| 来源: 网络整理| 查看: 265

目录 沁恒CH32F103C8T6(一): Keil5环境配置,示例运行和烧录沁恒CH32F103C8T6(二): Linux PlatformIO环境配置, 示例运行和烧录沁恒CH32F103C8T6(三): PlatformIO DAPLink和WCHLink下载配置 使用 DAP-Link 烧录

DAP-Link 是ARM官方的一款开源的调试仿真器,也叫CMSIS-DAP, 几乎支持所有Cortex-M内核的MCU,不挑品牌厂家. 其功能等价于ST的ST-Link. 在Win10 Keil5 MDK中可以不需驱动, 不需配置, 即插即用. 在 Linux 的 PlatformIO 中, 需要做一些配置才能正常使用.

1. 首先定位到 PlatformIO 的配置目录

默认的目录是 /home/[你的用户名]/.platformio/ , 下面能看到 packages, penv, platforms 这几个目录, 这一步很重要, 因为需要往配置目录中添加新文件

2. 在开发板配置中添加 CH32F103C8

在 platforms/ststm32/boards 目录下, 新增一个 bluepill_ch32f103c8.json 文件, 文件内容如下,

{ "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" }

这个文件是基于 bluepill_f103c8.json 修改的, 主要就是修改了 "openocd_target": "ch32f1x",, 更换了 openocd 的配置文件.

添加之后, 在 PlatformIO 的 Boards 中, 就能搜索到名为"BluePill CH32F103C8"的开发板

3. 修改 platformio.ini

将 board 修改为自定义的 bluepill_ch32f103c8, 修改之后配置类似于

[env:bluepill_ch32f103c8_dap] platform = ststm32 board = bluepill_ch32f103c8 framework = cmsis upload_protocol = cmsis-dap debug_tool = cmsis-dap 4. 在OpenOCD配置中添加 CH32F1X

在 packages/tool-openocd/scripts/target 目录下, 新增一个 ch32f1x.cfg 文件, 内容为

# CH32F103x set CPUTAPID 0x2ba01477 source [find target/stm32f1x.cfg]

配置的内容, 是在 stm32f1x.cfg 这个配置的基础上定义芯片ID是 0x2ba01477, 这样就不需要在 platformio.ini 中额外配置了

5. 烧录

大部分情况下, 这时候连上DAP-Link就可以烧录了, 输出为

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. 调节频率

如果出现这样的错误

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

说明DAP-Link已经正常识别芯片, 但是在写入时出错, 可以将频率降低后再试. 频率的设置在 packages/tool-openocd/scripts/target/stm32f1x.cfg 修改其中的

# JTAG speed should be


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3