Using OpenOCD and gdb to debug my NuttX port to LPC11xx

I’m porting NuttX to LPC11xx (using the LPCXpresso LPC1115 board) and these are the steps I used to get OpenOCD and GDB working to debug my firmware:

The openocd.cfg to use with STLink-v2 SWD programmer:

# LPC1115 LPCXpresso Target

# Using stlink as SWD programmer
source [find interface/stlink-v2.cfg]

# SWD as transport
transport select hla_swd

# Use LPC1115 target
set WORKAREASIZE 0x4000
source [find target/lpc11xx.cfg]

You need to execute “reset halt” from OpenOCD telnet server to get “monitor reset halt” working on gdb:


$ telnet 127.0.0.1 4444
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Open On-Chip Debugger

> reset halt
target state: halted
target halted due to debug-request, current mode: Thread 
xPSR: 0xc1000000 pc: 0x1fff0040 msp: 0x10000ffc

> exit

Now execute the command arm-none-eabi-gdb (from Debian/Ubuntu package “gdb-arm-none-eabi”) passing the nuttx ELF file:

$ arm-none-eabi-gdb nuttx
GNU gdb (7.7.1+dfsg-1+6) 7.7.1
Reading symbols from nuttx...done.

(gdb) target remote localhost:3333
Remote debugging using localhost:3333
0x1fff0040 in ?? ()

(gdb) monitor reset halt
target state: halted
target halted due to debug-request, current mode: Thread 
xPSR: 0xc1000000 pc: 0x1fff0040 msp: 0x10000ffc

(gdb) load
Loading section .vectors, size 0xc0 lma 0x0
Loading section .text, size 0x9197 lma 0x410
Loading section .ARM.exidx, size 0x8 lma 0x95a8
Loading section .data, size 0x48 lma 0x95b0
Start address 0x410, load size 37543
Transfer rate: 9 KB/sec, 6257 bytes/write.

(gdb) b __start
Breakpoint 1 at 0x410: file chip/lpc11_start.c, line 109.

(gdb) step
Note: automatically using hardware breakpoints for read-only addresses.

Breakpoint 1, __start () at chip/lpc11_start.c:109
109	{

(gdb) 
115	  lpc11_clockconfig();

(gdb) 
lpc11_clockconfig () at chip/lpc11_clockconfig.c:93
93	  putreg32(SYSCON_SYSPLLCLKSEL_IRCOSC, LPC11_SYSCON_SYSPLLCLKSEL);

(gdb) 
96	  putreg32((SYSCON_SYSPLLCTRL_MSEL_DIV(4) | SYSCON_SYSPLLCTRL_PSEL_DIV2), LPC11_SYSCON_SYSPLLCTRL);

(gdb) p /x *0x40048008      <--- this is the LPC11_SYSCON_SYSPLLCTRL register address
$2 = 0x23
(gdb) 

You can use breakpoints, steps and many other GDB features.

That is it!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s