VSCode + Renode:构建现代嵌入式仿真工作流
发布: (2025年12月10日 GMT+8 13:47)
4 min read
原文: Dev.to
Source: Dev.to
为什么选择 Renode + VSCode?
现代嵌入式开发正逐步摆脱:
- IAR + 实体板卡 + 硬件编程器 + 串口线
- 只能在实体设备上进行断点和单步调试
- 切换 MCU 系列时需要重新安装工具链
转向:
- VSCode + GCC – 轻量、现代、跨平台
- Renode – 完整模拟 STM32 / ESP32 设备(UART、SPI、I2C、GPIO、DMA)
- GDB 远程调试 – 与平台无关,可通过网络调试
- 自动化友好 – 适用于 CI/CD 与可复现的测试
在众多国际公司中观察到的收益
- 大幅提升开发效率
- 支持自动化测试
- 让 CI 流水线能够运行 MCU 仿真
- 减少对实体硬件的依赖
安装 Renode
Renode 提供多种二进制发行版。请选择与您平台匹配的版本。
- Repository:
- 示例选择:
renode-latest.linux-portable-dotnet.tar.gz
为什么选择此版本?
- 自带 .NET 运行时
- 无需系统预装
dotnet/mono - 可直接在 Orange Pi / Raspberry Pi 上运行
安装步骤
# Download the tarball, then extract
tar -xzf renode-latest.linux-portable-dotnet.tar.gz
cd renode
# Launch Renode
./renode
Renode 配置
创建一个最小的 .resc 脚本,描述您想要仿真的 MCU 和外设。
下面的示例针对 STM32F103。
using sysbus
mach create "stm32f103"
machine LoadPlatformDescription @platforms/cpus/stm32f103.repl
# Load the ELF firmware (adjust the path for your setup)
machine LoadELF @/home/orangepi/object/renode_portable/firmware.elf
# Enable UART2 analyzer
showAnalyzer sysbus.usart2
# Start GDB server on port 3333 (accessible from VSCode)
machine StartGdbServer 3333 true
start
将此文件保存为 run_stm32.resc。
VSCode 调试配置
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug STM32F103 on Renode Remote",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/firmware.elf",
"cwd": "${workspaceFolder}",
"miDebuggerPath": "arm-none-eabi-gdb",
"miDebuggerServerAddress": "xxx.xxx.xxx.xxx:3333",
"preLaunchTask": "Run Renode Remote",
"stopAtEntry": true,
"setupCommands": [
{ "text": "set pagination off" },
{ "text": "set confirm off" },
{ "text": "set print pretty on" }
],
"postRemoteConnectCommands": [
{ "text": "monitor machine Pause" },
{ "text": "monitor sysbus LoadELF @/home/orangepi/object/renode_portable/firmware.elf" },
{ "text": "monitor cpu Reset" }
],
"externalConsole": false,
"targetArchitecture": "arm"
}
]
}
关键参数
miDebuggerPath– 本地 GDB 可执行文件的路径。miDebuggerServerAddress– 远程 Renode 的 GDB 端点。preLaunchTask– 在调试前启动远程机器上的 Renode。postRemoteConnectCommands– 暂停仿真、重新加载 ELF 并复位 CPU,以同步状态。
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "CMake Configure",
"type": "shell",
"command": "cmake",
"args": [
"-S", "${workspaceFolder}",
"-B", "${workspaceFolder}/build",
"-DCMAKE_BUILD_TYPE=Debug"
]
},
{
"label": "CMake Build",
"type": "shell",
"command": "cmake",
"args": [
"--build", "${workspaceFolder}/build",
"--config", "Debug"
],
"dependsOn": ["CMake Configure"]
},
{
"label": "Run Renode Remote",
"type": "shell",
"command": "ssh",
"args": [
"orangepi@xxx.xxx.xxx.xxx",
"\"cd /home/orangepi/object/renode_portable && ./renode run_stm32.resc\""
],
"dependsOn": ["CMake Build"]
}
]
}
该任务流水线会构建固件、将 ELF 与 .resc 脚本复制到远程机器、启动 Renode,最后附加 GDB 调试器。
测试
- 在 VSCode 中按 F5。
- Renode 在远程板上启动。
- 固件自动加载。
- UART 输出出现在 VSCode 终端,断点如预期工作。
现在,您已经拥有一个使用 VSCode、Renode 和 GDB 的完整、现代化嵌入式仿真工作流。