赞
踩
在windows上,搭建嵌入式 RUST开发环境,基于STM32L475芯片,使用 VS Code + Cortex-debug + STlink实现单步调试。
这一部分将安装RUST开发环境到windows上。由于不想安装vs的全家桶,所以安装x86_64-pc-windows-gnu版本的。
https://www.rust-lang.org/zh-CN/tools/install
然后双击安装。
输入2,回车进入自定义安装
x86_64-pc-windows-gnu
其他选择默认即可
设定完自定义的选项之后,直接回车即可安装。
Current installation options:
default host triple: x86_64-pc-windows-gnu
default toolchain: stable
profile: default
modify PATH variable: yes
1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
>
安装完成,按任意键关闭当前终端。
工程搭建我是使用自己基于潘多拉L475开发板搭建的工程。其他芯片或开发板也可以参考这个模板。
git clone https://github.com/Guozhanxin/rust-stm32l4-pandora.git
rustup target add thumbv7em-none-eabihf
以闪灯程序为例,直接进入对应的示例工程,运行cargo命令执行编译即可。
cd blinky
cargo build --release
编译好的elf文件为 target\thumbv7em-none-eabihf\release\blinky
使用相应的下载工具,将elf文件下载到开发板即可运行。或者将其转化为bin文件,拖入ST-Link虚拟出来的U盘中,也可以完成下载。
调试部分,主要介绍 vscode+cortex-debug+stlink 的方式下载/调试 RUST 代码。
其实和调试 c 代码的方式是一样的。
在 vscode 的插件市场搜索 cortex-debug,安装对应的插件。
添加基于 cortex-debug 的调试配置,主要就是几个字段的修改:
我这里由于之前安装了 RT-Thread Studio,因此一些调试工具都是直接用的 RT-Thread Studio里下载好的,没有额外安装。如果是纯净的环境可能需要自己安装相应的软件。
网上基于openocd的教程较多,也可以按照其他的教程搭建openocd的调试环境。
{ // 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。 // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "cwd": "${workspaceFolder}", "executable": "E:\\workspace\\rust-stm32l4-pandora\\blinky\\target\\thumbv7em-none-eabihf\\release\\blinky", "name": "Debug with ST-Link", "request": "launch", "type": "cortex-debug", "runToEntryPoint": "main", "showDevDebugOutput": "none", "servertype": "stlink", "armToolchainPath": "D:\\Progm\\RT-ThreadStudio\\repo\\Extract\\ToolChain_Support_Packages\\ARM\\GNU_Tools_for_ARM_Embedded_Processors\\10.2.1\\bin", "gdbPath": "D:\\Progm\\RT-ThreadStudio\\repo\\Extract\\ToolChain_Support_Packages\\ARM\\GNU_Tools_for_ARM_Embedded_Processors\\10.2.1\\bin\\arm-none-eabi-gdb.exe", "stlinkPath": "D:\\Progm\\RT-ThreadStudio\\repo\\Extract\\Debugger_Support_Packages\\STMicroelectronics\\ST-LINK_Debugger\\1.6.0\\ST-LINK_gdbserver.exe", "stm32cubeprogrammer": "D:\\Progm\\RT-ThreadStudio\\repo\\Extract\\Debugger_Support_Packages\\STMicroelectronics\\ST-LINK_Debugger\\1.6.0\\tools\\bin", "svdFile": "D:\\Progm\\RT-ThreadStudio\\repo\\Extract\\Chip_Support_Packages\\RealThread\\STM32L4\\0.2.2\\debug\\svd\\STM32L4x5.svd" } ] }
点击调试按钮,就可以自动下载调试了,还能在rust里单步代码。Enjoy!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。