Running

Embedded boards have different ways to get your program onto them and get them running. This guide assumes your board has a JTAG connector, and you have a JTAG hardware debugger like a Segger J-Link. JTAG is a set of standards that let you attach a hardware device to your embedded board, and then remotely control the CPU. You can load code, start, stop, step through the program, and examine variables and memory.

  1. Attach the Debugger Cables

  2. Start the Debugger

    Refer to your JTAG debugger’s documentation for information on how to start a GDB Server process that gdb can communicate with to load code and start, stop, and step the embedded board’s CPU. Your command line may be different from this one.

    $ JLinkGDBServer -device ATSAMA5D27 -if JTAG -speed 1000 -JTAGConf -1,-1
    
  3. Launch the Gnu Debugger

    In another terminal window, launch the GDB for your platform. In the case of this guide, this came with the ARM Embedded Gnu Toolchain we downloaded in the Install step.

    $ arm-none-eabi-gdb
    
  4. Connect to the board’s serial console

    Usually you connect a USB-to-serial adapter to the board’s serial console so you can see debug logging or execute Apache NuttX Shell (nsh) commands. You can access the serial console from Linux with the picocom terminal program. From another terminal, do this:

    $ picocom -b 115200 /dev/ttyUSB0
    
  5. Set gdb to talk with the J-Link

    (gdb) target extended-remote :2331
    
  6. Reset the board

    (gdb) mon reset
    
  7. You may need to switch to the serial console to hit a key to stop the board from booting from its boot monitor (U-Boot, in the case of the SAMA5 boards from Microchip).

  8. Halt the board

    (gdb) mon halt
    
  9. Load nuttx

    (gdb) file nuttx
    (gdb) load nuttx
    `/home/adamf/src/nuttx-sama5d36-xplained/nuttx/nuttx' has changed; re-reading symbols.
    Loading section .text, size 0x9eae4 lma 0x20008000
    Loading section .ARM.exidx, size 0x8 lma 0x200a6ae4
    Loading section .data, size 0x125c lma 0x200a6aec
    Start address 0x20008040, load size 654664
    Transfer rate: 75 KB/sec, 15587 bytes/write.
    (gdb)
    
  10. Set a breakpoint

    (gdb) breakpoint nsh_main
    
  11. Start nuttx

    (gdb) continue
    Continuing.
    
    Breakpoint 1, nsh_main (argc=1, argv=0x200ddfac) at nsh_main.c:208
    208        sched_getparam(0, &param);
    (gdb) continue
    Continuing.
    

Debugging Shortcuts

Note that you can abbreviate gdb commands, info b is a shortcut for information breakpoints; c works the same as continue, etc.