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

在這裏插入圖片描述

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