Table of contents:
- Introduction
- Crosstoolchain
- Building
- Flashing
- Debugging
Previously in Flashing a led blinking application was recorded to FRDM-KL25Z board for execution. Here we use the GNU debugger for debugging this application during execution.
Build a cross debugger for ARM
localhost ~ # crossdev --ex-gdb -t arm-none-eabi ...
This should leave in your Gentoo system a cross gdb for the intended architecture:
localhost ~ # arm-none-eabi-gdb -ex quit Python Exception name 'os' is not defined: warning: Could not load the Python gdb module from `/usr/share/gdb/python'. Limited Python support is available from the _gdb module. Suggest passing --data-directory=/path/to/gdb/data-directory. GNU gdb (Gentoo 7.7 vanilla) 7.7 Copyright (C) 2014 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later 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-pc-linux-gnu --target=arm-none-eabi". Type "show configuration" for configuration details. For bug reporting instructions, please see: . Find the GDB manual and other documentation resources online at: . For help, type "help". Type "apropos word" to search for commands related to "word".
Use OpenOCD as a remote end for gdb
OpenOCD has the ability of serving as the remote end of a gdb session, allowing debug commands to be sent to the board’s on-chip debugger. The Makefile in frdm-kl25z-blink3 sources has a target for setting up a cross gdb session with openocd as the remote for debugging frdm_kl25z_blink3:
user@localhost /tmp/frdm-kl25z-blink3-1.0 $ make debug arm-none-eabi-gdb -ex "target remote | openocd -c \"gdb_port pipe; log_output debug.log; interface cmsis-dap\" -f ./support/openocd/kl25_init.cfg" -ex "monitor reset init" -ex "break main" -ex "continue" frdm_kl25z_blink3 Python Exception name 'os' is not defined: warning: Could not load the Python gdb module from `/usr/share/gdb/python'. Limited Python support is available from the _gdb module. Suggest passing --data-directory=/path/to/gdb/data-directory. GNU gdb (Gentoo 7.7 vanilla) 7.7 Copyright (C) 2014 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later 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-pc-linux-gnu --target=arm-none-eabi". Type "show configuration" for configuration details. For bug reporting instructions, please see: . Find the GDB manual and other documentation resources online at: . For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from frdm_kl25z_blink3...done. Remote debugging using | openocd -c "gdb_port pipe; log_output debug.log; interface cmsis-dap" -f ./support/openocd/kl25_init.cfg Open On-Chip Debugger 0.8.0-dev-00350-g6c74255 (2014-02-14-16:00) Licensed under GNU GPL v2 For bug reports, read http://openocd.sourceforge.net/doc/doxygen/bugs.html warning: Can not parse XML target description; XML support was disabled at compile time 0x00000000 in __vect_table () target state: halted target halted due to debug-request, current mode: Thread xPSR: 0x01000000 pc: 0x00002038 msp: 0x20003000 Breakpoint 1 at 0x2114: file Sources/ProcessorExpert.c, line 53. Continuing. Breakpoint 1, main () at Sources/ProcessorExpert.c:53 53 PE_low_level_init(); (gdb)
As currently written, the debug target should restart execution of the application and stop in function main() due to a breakpoint. So at this state the execution is stopped (RGB led ceases to blink) and gdb is awaiting for debug commands.
Debug 🙂
Well it’s gdb; feel free to poke around for insightful debugging. The following is an example of catching the timer interruption handler where led colors are cycled:
(gdb) clear Deleted breakpoint 1 (gdb) break LEDTimer_OnInterrupt Breakpoint 2 at 0x2078: file Sources/Events.c, line 80. (gdb) continue Continuing. Breakpoint 2, LEDTimer_OnInterrupt (UserDataPtr=0x0 ) at Sources/Events.c:80 80 switch (led_state++) { (gdb) list 75 /* ===================================================================*/ 76 void LEDTimer_OnInterrupt(LDD_TUserData *UserDataPtr) 77 { 78 /* Write your code here ... */ 79 static int led_state = 0; 80 switch (led_state++) { 81 case 0: 82 RedLED_SetVal(RedLED_DeviceData); 83 GreenLED_SetVal(GreenLED_DeviceData); 84 BlueLED_SetVal(BlueLED_DeviceData); (gdb) display led_state 1: led_state = 0 (gdb) continue Continuing. Breakpoint 2, LEDTimer_OnInterrupt (UserDataPtr=0x0 ) at Sources/Events.c:80 80 switch (led_state++) { 1: led_state = 1 (gdb) next 87 RedLED_ClrVal(RedLED_DeviceData); 1: led_state = 2 (gdb) next 88 break; 1: led_state = 2 (gdb) continue Continuing. Breakpoint 2, LEDTimer_OnInterrupt (UserDataPtr=0x0 ) at Sources/Events.c:80 80 switch (led_state++) { 1: led_state = 2 (gdb) continue Continuing. Breakpoint 2, LEDTimer_OnInterrupt (UserDataPtr=0x0 ) at Sources/Events.c:80 80 switch (led_state++) { 1: led_state = 3 (gdb) clear Deleted breakpoint 2 (gdb) continue Continuing. ^C Program received signal SIGINT, Interrupt. main () at Sources/ProcessorExpert.c:66 66 for(;;){} 1: led_state = 6 (gdb) quit A debugging session is active. Inferior 1 [Remote target] will be detached. Quit anyway? (y or n) y Detaching from program: /tmp/frdm-kl25z-blink3-1.0/frdm_kl25z_blink3, Remote target Ending remote debugging. user@localhost /tmp/frdm-kl25z-blink3-1.0 $