PlatformIO IDE 相关折腾

 · 2 分钟

前言

我对这个平台…又爱又恨

爱:

  • 资源丰富
  • 自动化
  • 便于调试 (画重点)

恨:

  • 构建环境时慢(国内下载速度慢)
  • Python有点鬼畜
  • 玄学bug

太长不看版

我做了下面的事:

  • 改用完全MIT协议的VSCodium, 而不是微软协议授权的Visual Studio Code
  • 安装PlatformIO IDE在VSCode系列上的插件
  • BlackMagic Probe进行调试

改用VSCodium

网上/几个项目官方主页上应该能显著地看到VSCodium项目的意义, 不再详叙

实际体验上, 少了很多微软的提示, 变清爽了, 我猜主要因为微软的配置(追踪/插件市场等)都消失的缘故

安装PlatformIO IDE插件

VSCodium想装的话, 需要装一个依赖

需要安装的全部插件如下:

  • vscode-cpptools
  • platformio-ide

依序安装哦~

接着挂好代理, 不然的话建议先把pip的镜像站配置好(忘了说, 这玩意儿需要Python)

安装后重启编辑器, 就会自动开始安装PlatformIO IDE

代理/镜像在这时起了作用, 加速是必须的, 不然可能会崩溃(人)

新建项目, 选择合适的板子(平台), 确认后会下载其它与平台相关的文件. 这一步更需要代理加速

疑难解决

想看调试信息可以在菜单栏Help -> Toggle Developer Tools看相关信息, 不过在执行完之间输出都会卡缓存里就是了

如果出了任何问题, 都可以将PlatformIO IDE的配置文件夹删除, 重来一遍, 具体位置可以参考官方文档

对于Linux发行版: 一般在/home/$USER/.platformio, 删掉这个文件夹即可, 下次再打开编辑器会自动重新安装

Black Magic Probe进行调试

我在STM32F103上写Arduino, 这是我的platformio.ini

[env:bluepill_f103c8_128k]
platform = ststm32
board = bluepill_f103c8_128k
framework = arduino

;; use BMP as debugger
debug_tool = blackmagic
upload_protocol = blackmagic
upload_port = /dev/ttyBmpGdb    ; change accordingly
monitor_port = /dev/ttyBmpTarg  ; change accordingly

;; customize debug init cmds
;; bug fixed: new BMPs use `monitor connect_srst enable` rather
;;            than `monitor reset halt`, the latter doesn't exist
debug_init_cmds =
    define pio_reset_halt_target
        set language c
        set *0xE000ED0C = 0x05FA0004
        set $busy = (*0xE000ED0C & 0x4)
        while ($busy)
            set $busy = (*0xE000ED0C & 0x4)
        end
        set language auto
    end
    define pio_reset_run_target
        pio_reset_halt_target
    end
    target extended-remote $DEBUG_PORT
    monitor connect_srst enable
    monitor swdp_scan
    attach 1
    set mem inaccessible-by-default off
    $LOAD_CMDS
    $INIT_BREAK
    set language c
    set *0xE000ED0C = 0x05FA0004
    set $busy = (*0xE000ED0C & 0x4)
    while ($busy)
        set $busy = (*0xE000ED0C & 0x4)
    end
    set language auto

;; init break, here we set it loop, which is equivalent
;; to main in arduino
debug_init_break =
    tbreak main.cpp:loop
    ; tbreak main ; the original setting

;; extra cmds
; debug_extra_cmds =
;     tbreak main.cpp:setup

;; load application only when it's modified
debug_load_mode = modified

具体如何修改可以参考官方文档

之后F5就能愉快地用BMP进行Arduino调试了

总结

安装问题不大, 下载资源文件很头疼, 配置好后用起来很开心

以上