使用gdb实时调式arduino

前言

arduino ide 功能过于简单,连最基本的断点调式功能都不提供。通过串口查看调式数据实在是很不便捷,通过某种方式远程调式arduino是很有必要的。

环境

这次尝试是在64位fedora 22下进行,使用的arduino板子类型为leonardo.需要python 2 支持.

bash$ uname -a
>Linux heymind-laptop 4.0.5-300.fc22.x86_64 #1 SMP Mon Jun 8 16:15:26 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

开始

配置PlatformIO

PlatformIO is a cross-platform code builder and the missing library manager.

以前我在linux开放arduino时候使用的是ino工具,PlatformIO 和它类似,只不过它功能更加强大,支持的芯片种类繁多,包括stm32,avr都有支持link.对于IDE 也有很好的配置教程link,甚至还提供库管理(没用过).

bash pip install platformio && pip install --egg scons

安装很简单。

bash platformio platforms install atmelavr
 platformio platforms show atmelavr

配置simulavr

这是一个类似于仿真器的程序,他可以通过usb串口与单片机通信,并模拟出一个gdb server ,可以通过avr-gdb 或者其他IDE进行debug.

下载源代码:http://ftp.yzu.edu.tw/nongnu//simulavr/simulavr-1.0.0.tar.gz

之后进入目录./configure,有可能报错

Could not locate libbfd.so/libbfd.a and/or bfd.h.

解决依赖。

bashdnf install binutils-devel

编译有可能报错,

systemclock.cpp:70:8: note: use ‘this->resize’ instead

只需要手动修改一下这个文件,按照提示修改即可。整体安装流程如下:

bash./configure
make
make install

配置工程

初始化工程

bashplatformio init --borad=leonardo

之后可以在src 里编辑代码,将库依赖放到lib 里。

platformio run 上传到板子。

进行调式

启动gdb server

bashsimulavr --gdbserver -p 4242 --device atmega16

使用gdb进行调式(也可以在 QT Creator , eclipse中进行,配置过程相似)

bash$ avr-gdb
>GNU gdb (GDB) 7.1
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-unknown-linux-gnu --target=avr".
For bug reporting instructions, please see:
><http://www.gnu.org/software/gdb/bugs/>.

(gdb) target remote localhost:4242
>Remote debugging using localhost:4242
>warning: Can not parse XML target description; XML support was disabled at compile time

(gdb) add-symbol-file /home/exodus/workspace/arduino/platformio-try/.pioenvs/leonardo/firmware.elf 0
>add symbol table from file "/home/exodus/workspace/arduino/platformio-try/.pioenvs/leonardo/firmware.elf" at
>   .text_addr = 0x0
(y or n) y
>Reading symbols from /home/exodus/workspace/arduino/platformio-try/.pioenvs/leonardo/firmware.elf...done.

(gdb) list
>23 int atexit(void (*func)()) { return 0; }
24  
25  // Weak empty variant initialization function.
26  // May be redefined by variant files.
27  void initVariant() __attribute__((weak));
28  void initVariant() { }
29  
30  int main(void)
>31 {

说完了

好了,就到这里了,arduino从现在起调式就很美好了~
日后有机会再写写如何在ide中进行调式,争取配置出一个完美的IDE~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值