Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
vscode
教程:ubuntu 下 vscode 编译 下载 调试 rt-thread stm32 程序
发布于 2019-08-07 00:25:35 浏览:7782
订阅该版
[tocm] 先上结果:  ## 步骤一:rt-thread 源码下载及编译 步骤一可跳过,参考下面官方文档链接里更详细的说明 [官网教程链接](https://www.rt-thread.org/document/site/application-note/setup/qemu/ubuntu/an0005-qemu-ubuntu/) #### 下载 rt-thread 国内镜像源码 ``` git clone https://gitee.com/rtthread/rt-thread.git ``` ``` sudo apt install scons ``` ``` sudo apt install libncurses5-dev ``` 解压 gcc-arm-none-eabi 工具链到指定目录:  进入 `rt-thread/bsp/stm32/stm32f429-atk-apollo` 目录,执行命令 `scons --dist` ,生成一个干净单一的 stm32f429 工程。 将 `rt-thread/bsp/stm32/stm32f429-atk-apollo/dist` 目录下的 stm32 工程拷贝到你喜欢的地方。 进入刚刚拷贝的 stm32 工程里,编辑 rtconfig.py 文件。  将 gcc-arm-none-eabi 工具链的路径填入如下图相应的位置。  在拷贝的工程目录下输入 `scons` 命令即可编译 rt-thread 源码。   ## 步骤二: openOCD 最新源码下载编译及安装 #### 下载 openocd 在 github 上的最新镜像源码 ```c git clone https://github.com/ntfreak/openocd.git ```  #### 安装编译 openocd 需要的相关库 ```c sudo apt-get install build-essential pkg-config autoconf automake libtool libusb-dev libusb-1.0-0-dev libhidapi-dev ``` ```c sudo apt-get install libtool libsysfs-dev ```   #### 编译安装 ```c sudo ./bootstrap ```  ```c sudo ./configure ```  ```c sudo make ```  ```c sudo make install ```  #### 使用测试 ```c openocd --version ```  ```c sudo openocd -f /usr/local/share/openocd/scripts/interface/cmsis-dap.cfg -f /usr/local/share/openocd/scripts/target/stm32f4x.cfg ``` 我使用的仿真器是 DAP ,目标开发板芯片是 STM32F429 。如果你使用的是其他仿真器以及目标芯片,只需将 ```cmsis-dap.cfg``` , ``` stm32f4x.cfg``` 替换即可。  上述步骤开启了 GDB 服务器,此时我们需要使用 telnet 登录到这个服务器,进行一些测试操作。 ```c telnet localhost 4444 ``` 输入 halt 命令,芯片停止运行。 ```c halt ``` 输入 reset 命令,芯片复位重启。 ```c reset ```  如果要烧录 bin 文件到目标芯片,先输入 ```halt``` 停止芯片,然后输入 ``` flash write_image erase /home/tang/Desktop/stm32f429-atk-apollo/rtthread.bin 0x8000000 ``` 烧录 bin 文件到目标芯片,地址为 0x8000000。如下图所示: ```c flash write_image erase /home/tang/Desktop/stm32f429-atk-apollo/rtthread.bin 0x8000000 ```  以上步骤是 rt-thread 源码的编译与下载,后面等我整理完接下来的步骤截图,将介绍如何使用 `vscode + openocd + gcc-arm-none-eabi-gdb` 调试代码。 ## 步骤三: ubuntu 下 vscode 单步调试 rt-thread 程序 #### 效果预览 未完待续。。。。。。 
查看更多
36
个回答
默认排序
按发布时间排序
来一颗糖
2019-08-07
这家伙很懒,什么也没写!
## 步骤三: ubuntu 下 vscode 单步调试 rt-thread 程序 进入用户主目录,编辑该目录下的 .profile 文件,将 gcc-arm-none-eabi 工具链 的路径添加到环境变量中。  在 .profile 文件末尾加上 ``` export PATH=/home/tang/toolchain/gcc-arm-none-eabi-8-2019-q3-update/bin:$PATH ```  输入命令 ``` soruce ~/.profile ``` 使刚刚配置的环境变量生效。  进入我们先前拷贝的 stm32 工程目录,输入 scons --target=vsc 命令生成,vscode 的文件索引。 ``` scons --target=vsc -s ```  输入 code ./ 命令打开 vscode 。 ``` code ./ ```  给 vscode 添加任务  编辑 task.json 文件,添加如下三个任务: - 1. openocd server:用于开启 openocd GDB 服务器。 - 2. rebuild:用于重新编译工程。 - 3. build:用于编译工程。  task.json 文件内容如下: ```json { // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "label": "openocd", "type": "shell", "command": "sudo openocd -f /usr/local/share/openocd/scripts/interface/cmsis-dap.cfg -f /usr/local/share/openocd/scripts/target/stm32f4x.cfg && exit" }, { "label": "scons", "type": "shell", "command": "scons -c && scons -j4 && exit", "problemMatcher": [] }, { "label": "telnet localhost 4444", "type": "shell", "command": "telnet localhost 4444 && exit" } ], } ``` 为 vscode 添加 Debug 配置  编辑 launch.json 文件, 需要注意修改的地方如下图红框框所示:  launch.json 文件内容如下: ```json { // 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。 // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "debug Launch", "type": "cppdbg", "request": "launch", "targetArchitecture": "arm", "program": "stm32", "args": [""], "stopAtEntry": true, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "MIMode": "gdb", "miDebuggerPath": "/home/tang/toolchain/gcc-arm-none-eabi-8-2019-q3-update/bin/arm-none-eabi-gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "launchCompleteCommand": "None", "miDebuggerServerAddress": "localhost:3333", "customLaunchSetupCommands": [ { "text": "target remote :3333", "description": "connect to server", "ignoreFailures": false }, { "text": "file /home/tang/workspace/stm32f429-atk-apollo/rt-thread.elf", "description": "load file to gdb", "ignoreFailures": false }, { "text": "load", "description": "download file to MCU", "ignoreFailures": false }, { "text": "monitor reset", "description": "reset MCU", "ignoreFailures": false }, { "text": "b main", "description": "set breakpoints at main", "ignoreFailures": false }, ] } ] } ``` ### 最后一步 在 vscode 界面下,按 F1 键,输入 ```Tasks: Run Task``` 回车。  上下键选择 build 编译工程。   上下键选择 openocd server 启动 openocd 服务器。   ### 输入 sudo 密码  按 F5 键 或如下图所示,启动调试。  ### 开启调试  
greedyhao
2019-08-07
这家伙很懒,什么也没写!
**niubility**
MurphyZhao
认证专家
2019-08-07
这家伙很懒,什么也没写!
很强势
我夏了夏天
认证专家
2019-08-07
Life isn't about finding yourself, life is about creating yourself.
沙发板凳地板都没了,还是要说这很强,另外一种调试方式
Ernest
2019-08-08
这家伙很懒,什么也没写!
new balance
pkokoc
2019-09-10
这家伙很懒,什么也没写!
强,喜欢这种折腾
deepsky2018
2019-09-15
这家伙很懒,什么也没写!
厉害!!
921742079
2019-09-20
这家伙很懒,什么也没写!
默认的项目debug一次,以后会再也连不上,cubemx里面需要选择sys,wire debug模式,楼主你可以重复断点么?我这边用stm32f103c8t6是这样
来一颗糖
2019-09-20
这家伙很懒,什么也没写!
>默认的项目debug一次,以后会再也连不上,cubemx里面需要选择sys,wire debug模式,楼主你可以重复断点么? ... --- 第一次能调试,断开连接后就再也不能调试了吗?
来日方长
2019-09-20
这家伙很懒,什么也没写!
666
撰写答案
登录
注册新账号
关注者
0
被浏览
7.8k
关于作者
来一颗糖
这家伙很懒,什么也没写!
提问
7
回答
231
被采纳
1
关注TA
发私信
相关问题
1
潘多拉开发板在VSCODE无法执行micropython
2
vscode qemu debug 遇到的问题
3
rtthread使用makefile开启动态方式创建线程失败
4
VScode调试qemu-vexpress-a9工程,GDB出错,求助~
5
使用Vscode+qemu调试RT-Thread,F5调试时报错
6
在VScode适用studio插件项目里面的环境变量问题
7
vscode插件编译报错
8
如何vs code中新建rt-thread在项目?
9
GD32VF103 VSCODE开发环境移植问题
10
在bsp目录下打开vscode,没办法通过vscode查看src目录下的源文件
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
最新文章
1
使用官方BOOT升级,看这一篇就够了?(以STM32F407VGT6为例)
2
可以使用MQTT连接AI大模型吗
3
RT-Thread离线包制作
4
RT-Thread 屏蔽在线软件包的方法
5
RT-Thread OS应用开发实战线上师资培训通知
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
DMA
USB
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
rt-smart
FAL
I2C_IIC
cubemx
ESP8266
WIZnet_W5500
UART
ota在线升级
PWM
BSP
flash
freemodbus
packages_软件包
潘多拉开发板_Pandora
GD32
定时器
ADC
flashDB
编译报错
socket
keil_MDK
中断
rt_mq_消息队列_msg_queue
Debug
SFUD
msh
ulog
C++_cpp
at_device
本月问答贡献
聚散无由
5
个答案
5
次被采纳
RTT_逍遥
6
个答案
2
次被采纳
踩姑娘的小蘑菇
6
个答案
1
次被采纳
a1012112796
4
个答案
1
次被采纳
YZRD
3
个答案
1
次被采纳
本月文章贡献
wake_mirco
2
篇文章
7
次点赞
mushroom
1
篇文章
8
次点赞
张世争
1
篇文章
7
次点赞
rv666
1
篇文章
4
次点赞
alight
1
篇文章
3
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部