如何调试在 Arduino 硬件上运行的 Arduino 代码?
有没有办法设置源代码级断点,在实际硬件上运行代码,并能够检查变量并继续?
Is there a way to set source-level breakpoints, run the code on actual hardware, and be able to inspect variables and continue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Visual Micro Microsoft Visual Studio 2015 Community Edition(免费)插件为 Arduino 提供了 USB 调试器。它允许您完全按照您所描述的方式进行操作。 (在IDE安装过程中不要忘记单击安装C++)
调试器支持串行、RF、蓝牙和一些Wi-Fi。它可以在 Arduino 运行时监视或更新变量的值。包括图表和数据/引脚可视化以及观察、跟踪、中断。
新闻:2016 年 1 月还发布了适用于 Arduino Zero 的 GDB 调试器。与串行/蓝牙调试器一样,GDB 版本支持 ino/cpp 源代码,但还支持 Arduino 核心和库的调试。它支持许多功能,例如:步过、步出、单步指令或源代码行、内存、寄存器、局部变量、监视、实时表达式和堆栈跟踪。
The Visual Micro plugin for Microsoft Visual Studio 2015 Community Edition (free) provides a USB debugger for Arduino. It allows you to do exactly as you describe. (Don't forget to click to install C++ during IDE install)
The debugger supports serial, RF, Bluetooth and some Wi-Fi. It enables the values of variables to be watched or update while the Arduino runs. Chart and data/pin visualizations along with watch, trace, break are included.
News: January 2016 also includes release of a GDB debugger for the Arduino Zero. As with the Serial/Bluetooth debugger, the GDB version supports ino/cpp source code, but additionally supports debug of Arduino core and libraries. It supports many features such as: step over, step out, step instruction or source line, memory, registers, locals, watch, live expressions, and stack trace.
在 Arduino 上设置“源断点”的方法是添加一个串行输出,将您想要查看的值发送到串行监视器。
当您准备好后,下一步就是转向 WinAVR、AVR Studio 和 Atmel JTAG Mark II 或 Atmel Dragon。
这些程序和设备将允许您创建 C 代码并单步执行代码并监视变量和寄存器。 JTAG 设备可以单步执行您的 C 代码或编译器创建的汇编代码。
预先警告,高级嵌入式 C 编程仍然非常接近机器,您必须小心单步中断例程、定时器例程和其他低级例程,因为很多时候它会阻止代码正确运行。
The way to set "source breakpoints" on the Arduino is to add a serial output to send the value the you want to see to the Serial Monitor.
When you are ready the next step is to move to WinAVR, AVR Studio and a Atmel JTAG Mark II or a Atmel Dragon.
These programs and devices will allow you to create C code and single step through the code and monitor variables and registers. The JTAG devices can single step through your C code or the assembly code created by the compiler.
Be forewarned that high level embedded C programming is still very close to the machine and you have to be careful single stepping interrupt routines, timer routines and other low level routines because many times it will prevent the code from operating correctly.
为了检查变量,我只需将它们打印到串行监视器。
这是我目前正在研究的一个例子:
For inspecting variables I just print them to the serial monitor.
Here's an example I'm working on at the moment: