Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
RT-Thread发布
vscode
开发环境
一文教你如何在VSCODE中搭建RT-Thread开发环境
发布于 2024-08-30 10:44:59 浏览:1011
订阅该版
# Spark-1 星火一号开发板环境搭建 [TOC] ## 一 . 下载rt-thread源码 git clone https://github.com/RT-Thread/rt-thread.git ## 二. 安装env脚本环境 **在Powershell执行以下命令** ```tex wget https://gitee.com/RT-Thread-Mirror/env/raw/master/install_windows.ps1 -O install_windows.ps1 set-executionpolicy remotesigned .\install_windows.ps1 --gitee ``` 1. Powershell要以管理员身份运行。 2. 将其设置为 remotesigned 后,您可以作为普通用户运行 PowerShell。( After setting it to remotesigned, you can run PowerShell as a normal user.) 3. 一定要关闭杀毒软件,否则安装过程可能会被杀毒软件强退 ## 三 . 配置工具链 ### 3.1 使用 SDK方式下载工具链arm-none-eabi-gcc **使用 ~/.env/env.psl 激活env环境,第一次需要加载.** ![screenshot_image-20240829195417008.png](https://oss-club.rt-thread.org/uploads/20240830/b45f287b1a77adc8abf1f234de9227a9.png) #### 3.1.1 下载工具链 ![screenshot_image-20240829204009387.png](https://oss-club.rt-thread.org/uploads/20240830/eda1aaeacff627da1a4a5ed6e805f726.png) **输入 命令 sdk,会弹出如下界面,使用回车选中我们下载的工具链:arm-none-eabi-gcc toolchain** ![screenshot_image-20240829202825926.png](https://oss-club.rt-thread.org/uploads/20240830/a288698786bb246f70895fa6e50251d7.png) **保存后退出,开始自动下载工具链。** **如下:下载成功** ```tex Using default symbol values (no '.config') Configuration saved to '.config' [Use Gitee server - auto decision based on timezone] Package was NOT found on mirror server. Using a non-mirrored address to download. downloading arm-gnu-toolchain-13.2.rel1-mingw-w64-i686-arm-none-eabi.zip ... 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 364M/364M [29:48<00:00, 204kB/s] 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 8563/8563 [01:21<00:00, 104.94it/s] ==============================> ARM_NONE_EABI_GCC v13.2.rel1 is downloaded successfully. Operation completed successfully. (.venv) PS C:\Users\RTT\Desktop\rt\rt-thread-master> (.venv) PS C:\Users\RTT\Desktop\rt\rt-thread-master> ``` #### 3.1.2 测试工具链 **原理:scons在sdk中自动探测工具链并进行使用下载的工具链** **进入rt-thread-master\bsp\stm32\stm32f407-rt-spark 目录 使用 scons 进行编译** ```tex (.venv) PS C:\Users\RTT\Desktop\rt\rt-thread-master\bsp\stm32\stm32f407-rt-spark> scons scons: Reading SConscript files ... C:\Users\RTT\Desktop\rt\rt-thread-master\bsp\stm32\stm32f407-rt-spark\rtconfig.py:80: SyntaxWarning: invalid escape sequence '\l' LFLAGS = DEVICE + ' --scatter "board\linker_scripts\link.sct" --info sizes --info totals --info unused --info veneers --list rt-thread.map --strict' set CC to C:\Users\RTT\.env\tools\scripts\packages\arm-none-eabi-gcc-v13.2.rel1\bin Newlib version: 4.3.0 scons: done reading SConscript files. scons: Building targets ... scons: building associated VariantDir targets: build CC build\applications\main.o CC build\board\board.o CC build\board\CubeMX_Config\Src\stm32f4xx_hal_msp.o CC build\kernel\components\drivers\core\device.o CC build\kernel\components\drivers\i2c\dev_i2c_bit_ops.o CC build\kernel\components\drivers\i2c\dev_i2c_core.o CC build\kernel\components\drivers\i2c\dev_i2c_dev.o CC build\kernel\components\drivers\ipc\completion_comm.o CC build\kernel\components\drivers\ipc\completion_up.o CC build\kernel\components\drivers\ipc\condvar.o CC build\kernel\components\drivers\ipc\dataqueue.o CC build\kernel\components\drivers\ipc\pipe.o CC build\kernel\components\drivers\ipc\ringblk_buf.o CC build\kernel\components\drivers\ipc\ringbuffer.o CC build\kernel\components\drivers\ipc\waitqueue.o CC build\kernel\components\drivers\ipc\workqueue.o CC build\kernel\components\drivers\misc\rt_drv_pwm.o CC build\kernel\components\drivers\pin\dev_pin.o ``` ```tex CC C:\Users\RTT\Desktop\rt\rt-thread-master\bsp\stm32\libraries\HAL_Drivers\drivers\drv_gpio.o CC C:\Users\RTT\Desktop\rt\rt-thread-master\bsp\stm32\libraries\HAL_Drivers\drivers\drv_usart.o AS C:\Users\RTT\Desktop\rt\rt-thread-master\bsp\stm32\libraries\STM32F4xx_HAL\CMSIS\Device\ST\STM32F4xx\Source\Templates\gcc\startup_stm32f407xx.o LINK rt-thread.elf Memory region Used Size Region Size %age Used CODE: 69876 B 1 MB 6.66% RAM1: 5372 B 128 KB 4.10% RAM2: 0 GB 64 KB 0.00% MCUlcdgrambysram: 0 GB 1 MB 0.00% arm-none-eabi-objcopy -O ihex rt-thread.elf rtthread.hex arm-none-eabi-size rt-thread.elf text data bss dec hex filename 69876 1196 4172 75244 125ec rt-thread.elf arm-none-eabi-objcopy -O binary rt-thread.elf rtthread.bin arm-none-eabi-size rt-thread.elf text data bss dec hex filename 69876 1196 4172 75244 125ec rt-thread.elf scons: done building targets. ``` ### 3.2 使用Keil MDK的编译器ARMCLANG #### 3.2.1 修改rtconfig.py **修改rt-thread/bsp/stm32/stm32f407-rt-spark/rtconfig.py** 1.修改为CROSS_TOOL = 'keil' 如图所示 ![screenshot_image-20240828115853076.png](https://oss-club.rt-thread.org/uploads/20240830/6ece7985539870613a7cb0f73fca4a31.png) 2.修改PLATFORM = 'armclang' ,修改 EXEC_PATH 为你keil安装的目录 ![screenshot_image-20240828130445901.png](https://oss-club.rt-thread.org/uploads/20240830/5c2ed4422bd82cfc8b95c322ab51e97a.png) #### 3.2.2 修改building.py **修改rt-thread/tools/building.py** 将 env['ASCOM']= env['ASPPCOM'] 注释掉 ![screenshot_image-20240828131055403.png](https://oss-club.rt-thread.org/uploads/20240830/c3793efd61b61c05080e2b40b10b0ea3.png) ## 四 . 测试环境 **每次打开终端需要执行 ~/.env/env.ps1 以激活环境变量。** ### 4.1 Powershell 中测试环境 #### 4.1.1 在Powershell中编译工程 **使用 scons 命令进行编译** ![screenshot_image-20240828101141899.png](https://oss-club.rt-thread.org/uploads/20240830/c0ba6b5c8a0b5e3b504a751073eb07fe.png) ![screenshot_image-20240828101250908.png](https://oss-club.rt-thread.org/uploads/20240830/abcb4a58f292769d10f81047ec592c15.png) #### 4.1.2 在Powershell中生成Keil MDK的工程 **使用 scons --target=mdk5 生成Keil MDK 工程** ![screenshot_image-20240828101708390.png](https://oss-club.rt-thread.org/uploads/20240830/2ea5d93a214cf9e86c4d7daececc2d57.png) ### 4.2 在vscode中测试环境 #### 4.2.1 使用gcc-arm-none-eabi在vscode中编译工程 **如何配置使用gcc-arm-none-eabi工具链在上一章已经介绍了,不懂的话可以看上一章。** **使用 scons 命令进行编译** 输出部分结果如下: ```tex PS C:\Users\RTT\Desktop\rt\rt-thread-master\bsp\stm32\stm32f407-rt-spark> scons scons: Reading SConscript files ... set CC to C:\Users\RTT\.env\tools\scripts\packages\arm-none-eabi-gcc-v13.2.rel1\bin Newlib version: 4.3.0 scons: done reading SConscript files. scons: Building targets ... scons: building associated VariantDir targets: build CC build\applications\main.o CC build\board\board.o CC build\board\CubeMX_Config\Src\stm32f4xx_hal_msp.o CC build\kernel\components\drivers\core\device.o CC build\kernel\components\drivers\i2c\dev_i2c_bit_ops.o CC build\kernel\components\drivers\i2c\dev_i2c_core.o CC build\kernel\components\drivers\i2c\dev_i2c_dev.o CC build\kernel\components\drivers\ipc\completion_comm.o CC build\kernel\components\drivers\ipc\completion_up.o CC build\kernel\components\drivers\ipc\condvar.o CC build\kernel\components\drivers\ipc\dataqueue.o CC build\kernel\components\drivers\ipc\pipe.o CC build\kernel\components\drivers\ipc\ringblk_buf.o CC build\kernel\components\drivers\ipc\ringbuffer.o CC build\kernel\components\drivers\ipc\waitqueue.o CC build\kernel\components\drivers\ipc\workqueue.o ``` ```tex CC build\applications\main.o LINK rt-thread.elf Memory region Used Size Region Size %age Used CODE: 81524 B 1 MB 7.77% RAM1: 5444 B 128 KB 4.15% RAM2: 0 GB 64 KB 0.00% MCUlcdgrambysram: 0 GB 1 MB 0.00% arm-none-eabi-objcopy -O ihex rt-thread.elf rtthread.hex arm-none-eabi-size rt-thread.elf text data bss dec hex filename 81524 1972 3468 86964 153b4 rt-thread.elf arm-none-eabi-objcopy -O binary rt-thread.elf rtthread.bin arm-none-eabi-size rt-thread.elf text data bss dec hex filename 81524 1972 3468 86964 153b4 rt-thread.elf scons: done building targets. ``` #### 4.2.2 使用ARMCLANG在vscode中编译工程 **如何配置使用 ARMCLANG 在上一章已经介绍了,不懂的话可以看上一章。** 使用 scons 进行编译 部分输出信息如下: ```tex (.venv) PS C:\Users\RTT\Desktop\1\rt-thread\bsp\stm32\stm32f407-rt-spark> scons scons: Reading SConscript files ... scons: done reading SConscript files. scons: Building targets ... scons: building associated VariantDir targets: build CC build\applications\main.o CC build\board\board.o CC build\board\CubeMX_Config\Src\stm32f4xx_hal_msp.o CC build\kernel\components\drivers\core\device.o CC build\kernel\components\drivers\i2c\dev_i2c_bit_ops.o CC build\kernel\components\drivers\i2c\dev_i2c_core.o CC build\kernel\components\drivers\i2c\dev_i2c_dev.o ``` ```tex AS C:\Users\RTT\Desktop\1\rt-thread\bsp\stm32\libraries\STM32F4xx_HAL\CMSIS\Device\ST\STM32F4xx\Source\Templates\arm\startup_stm32f407xx.o Warning: A1950W: The legacy armasm assembler is deprecated. Consider using the armclang integrated assembler instead. 0 Errors, 1 Warning LINK rt-thread.axf fromelf --bin rt-thread.axf --output rtthread.bin fromelf -z rt-thread.axf ======================================================================== ** Object/Image Component Sizes Code (inc. data) RO Data RW Data ZI Data Debug Object Name 50150 5652 9386 776 3536 416033 rt-thread.axf (uncompressed) 50150 5652 9386 264 3536 416033 rt-thread.axf (compressed) 0 0 4 0 0 0 (incl. padding) 50150 5652 9386 264 0 0 ROM Totals for rt-thread.axf scons: done building targets. ``` #### 4.2.3 在vscode中生成 Keil MDK 工程 **使用 scons --target=mdk5 生成Keil MDK 工程** 输出信息如下: ```tex (.venv) PS C:\Users\RTT\Desktop\1\rt-thread\bsp\stm32\stm32f407-rt-spark> scons --target=mdk5 scons: Reading SConscript files ... Keil5 project is generating... Keil Version: MDK Plus 5.39/Arm Compiler for Embedded 6.21/armlink [5ec1fa00] Keil-MDK project has generated successfully! ``` ## 五. vscode中调试程序 ### 5.1 安装Cortex-Debug ![screenshot_image-20240828145504007.png](https://oss-club.rt-thread.org/uploads/20240830/ed9f9e9e521ce7020c29bde976553b24.png.webp) ### 5.2 配置launch.json文件 ```json { // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "Cortex Debug", "cwd": "${workspaceFolder}", "executable": "./rt-thread.elf", //调试文件 "request": "launch", "type": "cortex-debug", //调试方式 "runToEntryPoint": "Reset_Handler", "servertype": "jlink", //类型 "serverpath": "D:/jlink/JLink_V798e/JLinkGDBServerCL.exe", //jink 路径 "device": "STM32F407ZG", //设备类型 "gdbPath": "D:/gcc-arm-none/10 2021.10/bin/arm-none-eabi-gdb.exe", //gdb 路径 "armToolchainPath": "D:/gcc-arm-none/10 2021.10/bin" //工具链路径 } ] } ``` ### 5.3 调试开始 使用**F5快捷键**即可启动调试 ![screenshot_image-20240829160412512.png](https://oss-club.rt-thread.org/uploads/20240830/91cfa20643bc35264c9a02e7cf8c8dbf.png) ## 六. vscode中下载程序 ### 6.1 添加jlink到环境变量 将Jlink安装路径添加进环境变量(使vscode中能找到jlink路径) ![screenshot_image-20240829152729436.png](https://oss-club.rt-thread.org/uploads/20240830/e8c7de0d7feda0c78a886fbf08be6218.png) ![screenshot_image-20240829152827048.png](https://oss-club.rt-thread.org/uploads/20240830/f7764e60ceddb8c87d75fa170f60aeb0.png) ### 6.2 安装pylink库 python调用jlink时需要用到 使用命令 : pip install pylink-square 安装pylink库 ![screenshot_image-20240829095409959.png](https://oss-club.rt-thread.org/uploads/20240830/5cd9402887ca808b15e83f62b974a9e4.png) ### 6.3 增加download_flash.py **在目录下新建download_flash.py文件,该文件是下载程序的脚本** ![screenshot_image-20240830092421547.png](https://oss-club.rt-thread.org/uploads/20240830/f99947bfa397ea5156caa2ffa54422d5.png) **download_flash.py脚本内容如下:** ```python import os import pylink def download_program(): link = pylink.JLink() try: #连接JLlink设备 link.open() #选择芯片和下载方式 link.set_tif(pylink.enums.JLinkInterfaces.SWD) link.connect('STM32F407ZG') #擦除程序 #link.erase() #下载并烧入程序 link.flash_file("./rtthread.hex",0) finally: #关闭与JLink的连接 link.close() download_program() ``` ### 6.4 下载程序 **执行指令下载程序** ``` python python download_flash.py ``` 结果如下图: ![screenshot_image-20240830092926266.png](https://oss-club.rt-thread.org/uploads/20240830/94e64ec5856c458388542e9d4513a304.png)
3
条评论
默认排序
按发布时间排序
登录
注册新账号
关于作者
rtt_dmx
这家伙很懒,什么也没写!
文章
2
回答
0
被采纳
0
关注TA
发私信
相关文章
1
RT-Thread单内核v0.2.2正式版
2
[发布] RT-Thread RTOS v0.2.3版本
3
RT-Thread 0.3.0 beta
4
RT-Thread/STM32 0.3.0 RC1发布
5
RT-Thread/LM3S 0.3.0 RC1版发布
6
建议弄个MIPS版本的。龙芯上用。
7
开源实时操作系统RT-Thread 0.3.0正式版发布
8
关于RT-THREAD的UDP讨论
9
这里是BUG回报板块!
10
rt-thread stm32 0.3.0 rc1 网络问题
推荐文章
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组件
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
USB
DMA
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
FAL
rt-smart
ESP8266
I2C_IIC
WIZnet_W5500
UART
ota在线升级
PWM
cubemx
freemodbus
flash
packages_软件包
BSP
潘多拉开发板_Pandora
定时器
ADC
GD32
flashDB
socket
中断
Debug
编译报错
msh
SFUD
rt_mq_消息队列_msg_queue
keil_MDK
ulog
MicroPython
C++_cpp
本月问答贡献
踩姑娘的小蘑菇
7
个答案
3
次被采纳
a1012112796
19
个答案
2
次被采纳
张世争
9
个答案
2
次被采纳
rv666
6
个答案
2
次被采纳
用户名由3_15位
13
个答案
1
次被采纳
本月文章贡献
程序员阿伟
9
篇文章
2
次点赞
hhart
3
篇文章
4
次点赞
RTT_逍遥
1
篇文章
6
次点赞
大龄码农
1
篇文章
5
次点赞
ThinkCode
1
篇文章
1
次点赞
回到
顶部
发布
问题
投诉
建议
回到
底部