NuttX的应用记录 4 (小记录)

好久没看过NuttX了,做个移植试一试。
板子是STM32F407ZE,有两块屏幕,蜂鸣器,FLASH,E2PROM,LED。
先找个类似的,复制一个副本。
stm32f4discovery就是407的,复制一下。
include/board.h中修改一下接口,这个很简单。对应的io可以在nuttx/arch/arm/src/stm32/hardware/stm32f40xxx_pinmap.h中查找。将所有的IO都列出来就行了。顺便一提,可以用cubemx来设置外设,然后就会有一个更方便观察的图形界面方便编写这部分。
编写完这些文件后,还需要到nuttx/boards/Kconfig里添加板子。不然板子的相关文件不会被识别。
编写完成后,处理一点BUG,就可以编译出来了,但是跑出去后终端没有相应。下面是DEBUG时间。
Using OpenOCD and gdb to debug my NuttX port to LPC11xx

参考这篇文章,用apt安装openocd

sudo apt install openocd

然后,我的调试器是st-link V2-1,所以就是:

openocd -f interface/stlink-v2-1.cfg -f target/stm32f4x.cfg

现在放着不管这个窗口,新开一个。安装arm的gdb:

sudo apt install arm-none-eabi-gdb

完成后,我调试代码的时候发现不能调试函数内的语句。于是,尝试开启了:

make menuconfig
> Build Setup > Debug Options > [*] Stack coloration
> Build Setup > Debug Options > [*] Heap coloration
> Build Setup > Debug Options > [*] Generate Debug Symbols 

然后就可以愉快的调试了:

$ arm-none-eabi-gdb nuttx
GNU gdb (7.10-1ubuntu3+9) 7.10
Copyright (C) 2015 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-linux-gnu --target=arm-none-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from nuttx...done.
(gdb) load
You can't do that when your target is `exec'
(gdb) target remote localhost:3333
Remote debugging using localhost:3333
__start () at chip/stm32_start.c:271
271	{
(gdb) halt
Undefined command: "halt".  Try "help".
(gdb) monitor halt
(gdb) load
Loading section .text, size 0xfd67 lma 0x8000000
Loading section .ARM.extab, size 0x228 lma 0x800fd68
Loading section .ARM.exidx, size 0x1148 lma 0x800ff90
Loading section .data, size 0x68 lma 0x80110d8
Start address 0x80001ae, load size 69951
Transfer rate: 12 KB/sec, 6995 bytes/write.
(gdb) b stm32_clockconfig
Breakpoint 1 at 0x8000210: file chip/stm32_rcc.c, line 179.
(gdb) c
Continuing.
Note: automatically using hardware breakpoints for read-only addresses.

Breakpoint 1, stm32_clockconfig () at chip/stm32_rcc.c:179
179	{
(gdb) 
Continuing.
^C
Program received signal SIGINT, Interrupt.
0x080043e6 in up_idle () at chip/stm32_idle.c:207
207	  asm("WFI");
(gdb) monitor reset
(gdb) c
Continuing.
WARNING! The target is already running. All changes GDB did to registers will be discarded! Waiting for target to halt.
^C
Program received signal SIGINT, Interrupt.
0x080043e6 in up_idle () at chip/stm32_idle.c:207
207	  asm("WFI");
(gdb) load
Loading section .text, size 0xfd67 lma 0x8000000
Loading section .ARM.extab, size 0x228 lma 0x800fd68
Loading section .ARM.exidx, size 0x1148 lma 0x800ff90
Loading section .data, size 0x68 lma 0x80110d8
Start address 0x80001ae, load size 69951
Transfer rate: 12 KB/sec, 6995 bytes/write.
(gdb) b up_setup
Breakpoint 2 at 0x8000780: file chip/stm32_serial.c, line 1467.
(gdb) c
Continuing.

Breakpoint 1, stm32_clockconfig () at chip/stm32_rcc.c:179
179	{
(gdb) c
Continuing.

Breakpoint 2, up_setup (dev=dev@entry=0x20000000 <g_usart1priv>)
    at chip/stm32_serial.c:1467
1467	{
(gdb) step
1468	  struct up_dev_s *priv = (struct up_dev_s *)dev->priv;
(gdb) 

最后调试出来是LED忘记改IO了。改了后还是不能工作,最后是把st-link重新插了一下串口就正常了。

NuttShell (NSH)
nsh> 

移植还是比较简单的。剩下的就是其余外设的驱动了。


补充一下,使用ui选项可以更好的调试:

$ arm-none-eabi-gdb -tui nuttx

在这里插入图片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章