ee 472 – embedded microcomputer systems an example ...€¦ · ee 472 – embedded microcomputer...

15
EE 472 – Embedded Microcomputer Systems An Example Project Tutorial Part 3: Debugging via the JTAG University of Washington Daniel Schuler – August 2008 Ye Jian Li – December 2008 Modifying the Make File When we wish to debug a C file, we must tell the compiler to include the hooks in the executable to support the debugging process. We do this by modifying the make file, through a set of flags, to build the target code accordingly. For our system, we add, -O0 -g3 -Wall –c” to the compile flags in the make file. For Tiny: $(THUMB_OBJ) : %.o : %.c $(CC) -c $(THUMB_FLAGS) $(CFLAGS) -O0 -g3 -Wall -c $< -o $@ $(ARM_OBJ) : %.o : %.c $(CC) -c $(CFLAGS) -O0 -g3 -Wall -c $< -o $@ For Heavy: $(THUMB_OBJ) : %.o : %.c $(CC) -c $(THUMB_FLAGS) $(CFLAGS) -O0 -g3 -Wall -c "$<" >> '$(@:%.o=%.d)' $(ARM_OBJ) : %.o : %.c $(CC) -c $(CFLAGS) -O0 -g3 -Wall -c "$<" >> '$(@:%.o=%.d)' Be certain that you type these in, rather than cutting and pasting, when incorporating these changes into the make file. Incorporating the Make Controller Configuration file The first thing we need is an interface to support communication between the OpenOCD and the make controller. We accomplish this through the file: makeController-debug.cfg. We have two ways of doing this: Copy the file C:\”your path”\ firmware-v1.5.1\projects\heavy\openOCD\makeController- debug.cfg into your project output folder. Alternately, as in the part 1 tutorial, we can import the configuration file makeController-debug.cfg, into our workspace. This configuration file is located in: C:\”your path”\firmware-v1.5.0\projects\heavy\openOCD.

Upload: others

Post on 25-Oct-2020

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: EE 472 – Embedded Microcomputer Systems An Example ...€¦ · EE 472 – Embedded Microcomputer Systems An Example Project Tutorial Part 3: Debugging via the JTAG University of

EE 472 – Embedded Microcomputer Systems An Example Project Tutorial

Part 3: Debugging via the JTAG University of Washington

Daniel Schuler – August 2008

Ye Jian Li – December 2008

Modifying the Make File

When we wish to debug a C file, we must tell the compiler to include the hooks in the executable to support the debugging process. We do this by modifying the make file, through a set of flags, to build the target code accordingly. For our system, we add,

“-O0 -g3 -Wall –c” to the compile flags in the make file. For Tiny: $(THUMB_OBJ) : %.o : %.c $(CC) -c $(THUMB_FLAGS) $(CFLAGS) -O0 -g3 -Wall -c $< -o $@ $(ARM_OBJ) : %.o : %.c $(CC) -c $(CFLAGS) -O0 -g3 -Wall -c $< -o $@

For Heavy: $(THUMB_OBJ) : %.o : %.c $(CC) -c $(THUMB_FLAGS) $(CFLAGS) -O0 -g3 -Wall -c "$<" >> '$(@:%.o=%.d)' $(ARM_OBJ) : %.o : %.c $(CC) -c $(CFLAGS) -O0 -g3 -Wall -c "$<" >> '$(@:%.o=%.d)'

Be certain that you type these in, rather than cutting and pasting, when incorporating these changes into the make file.

Incorporating the Make Controller Configuration file

The first thing we need is an interface to support communication between the OpenOCD and the make controller. We accomplish this through the file: makeController-debug.cfg. We have two ways of doing this:

• Copy the file C:\”your path”\ firmware-v1.5.1\projects\heavy\openOCD\makeController-debug.cfg into your project output folder.

• Alternately, as in the part 1 tutorial, we can import the configuration file makeController-debug.cfg, into our workspace. This configuration file is located in:

C:\”your path”\firmware-v1.5.0\projects\heavy\openOCD.

Page 2: EE 472 – Embedded Microcomputer Systems An Example ...€¦ · EE 472 – Embedded Microcomputer Systems An Example Project Tutorial Part 3: Debugging via the JTAG University of

In this tutorial, the full path is C:\projects\firmware-v1.5.0\projects\heavy\openOCD. This file should be placed in the same workspace folder in which the (executable) binary file was saved by the complier.

This tutorial is running the debug configuration so, this folder is bob/debug. This could also be the folder output as in the first alternative give above.

The workspace should now look something like:

Page 3: EE 472 – Embedded Microcomputer Systems An Example ...€¦ · EE 472 – Embedded Microcomputer Systems An Example Project Tutorial Part 3: Debugging via the JTAG University of

Configure the OpenOCD Daemon Open

Run → External Tools →External Tools Configurations.

At the next window, create a New Configuration by pressing the New icon.

Page 4: EE 472 – Embedded Microcomputer Systems An Example ...€¦ · EE 472 – Embedded Microcomputer Systems An Example Project Tutorial Part 3: Debugging via the JTAG University of

Name the configuration. Here we use OpenOCD-debug.

In the main tab, in Location, click on Browse File System.

Specify the path to openocd-ftd2xx.exe. This is C:\”your path”\openocd-r717\bin\openocd-ftd2xx.exe.

The path used here is

C:\openocd-r717\bin\openocd-ftd2xx.exe.

In the working directory, click on Browse Workspace. Browse to the folder where you imported the makeController-debug.cfg file.

Here, this is bob/debug. Finally, in Arguments, specify that OpenOCD should use the makeController-debug.cfg configuration script. This is accomplished by typing the command:

-f makeController-debug.cfg Click Apply.

Page 5: EE 472 – Embedded Microcomputer Systems An Example ...€¦ · EE 472 – Embedded Microcomputer Systems An Example Project Tutorial Part 3: Debugging via the JTAG University of

Click the Common tab. Check the box in Display in Favorites Menu

This will add the debug configuration to the menu bar for easy access. Click Apply, then click Close. (We will Run later.)

Page 6: EE 472 – Embedded Microcomputer Systems An Example ...€¦ · EE 472 – Embedded Microcomputer Systems An Example Project Tutorial Part 3: Debugging via the JTAG University of

Set Up the Debug Session Go to Run→Debug Configurations.

Highlight Zylin Embedded debug (Native) Click the New configuration icon.

Name the configuration whatever you like. Here it is named bob-debug. In Project, click Browse and select your current project (bob here).

Page 7: EE 472 – Embedded Microcomputer Systems An Example ...€¦ · EE 472 – Embedded Microcomputer Systems An Example Project Tutorial Part 3: Debugging via the JTAG University of

In C/C++ Application, click Search Project... and select the pertinent binary. For this example, this is the bob.elf file located in the Debug folder. Yours may be something like tiny.bin .

Click Apply:

Click on the Debugger tab.

In GDB debugger browse to the YAGARTO arm-elf-gdb executable.

Page 8: EE 472 – Embedded Microcomputer Systems An Example ...€¦ · EE 472 – Embedded Microcomputer Systems An Example Project Tutorial Part 3: Debugging via the JTAG University of

This should be at C:\”Your Path”\yagarto\bin\arm-elf-gdb.exe. Here, this is located at C:\yagarto\bin\arm-elf-gdb.exe.

Clear out the GDB command file.

Click Apply:

Click the Commands tab.

Copy and paste or type the following commands into the Initialize Commands text field:

target remote localhost:3333 monitor reset monitor wait 500 monitor soft_reset_halt monitor arm7_9 force_hw_bkpts enable

Leave the “Run Commands” field blank. Click Apply.

Page 9: EE 472 – Embedded Microcomputer Systems An Example ...€¦ · EE 472 – Embedded Microcomputer Systems An Example Project Tutorial Part 3: Debugging via the JTAG University of

Finally, select the Common tab, and check the Debug checkbox within Display in favorites menu.

Click Apply, then Close.

Workflow

We finally get to actually stepping through our code. The workflow is going to be as follows:

Compile and upload new code. Fire up the OpenOCD daemon Debug the new program

This tutorial is going to assume that you have accomplished the previous example project tutorials and have an executable file. Turn power to the Make Controller OFF; attach the

Page 10: EE 472 – Embedded Microcomputer Systems An Example ...€¦ · EE 472 – Embedded Microcomputer Systems An Example Project Tutorial Part 3: Debugging via the JTAG University of

JTAG connector to the Make Controller. Turn power to the Make Controller ON and download your executable. Plug the USB connector on the Olimex OCD tool into computer USB port.

Comment from Daniel: I have had trouble with drivers installed previously, and you may be asked to install the drivers again. Follow the Open On-Chip debugger tutorial in this case. This should not occur, but when it has, re-installing the drivers works.

Run the OpenOCD Daemon

Go to Run → External Tools → External Tools Name, Here, this is OpenOCD-debug.

The console window should display the following if you are successful.

Congratulations, the OpenOCD Daemon is running, now we just need to start a debug session.

Page 11: EE 472 – Embedded Microcomputer Systems An Example ...€¦ · EE 472 – Embedded Microcomputer Systems An Example Project Tutorial Part 3: Debugging via the JTAG University of

Run the Debug Session

Go to Run → Debug Configurations. At the next window, highlight the debug session you created above (bob-debug here), Hit Debug in the lower right corner.

In the workspace the console will now display something like:

Page 12: EE 472 – Embedded Microcomputer Systems An Example ...€¦ · EE 472 – Embedded Microcomputer Systems An Example Project Tutorial Part 3: Debugging via the JTAG University of

Now, in the workspace, we want to change from the development view to the debug view. In the upper right corner, click on the little debug icon.

If this graphic does not show up, in the development view, select

Window → Open Perspective → Debug on the toolbar. The workspace should change to something similar to the following graphic. The Expressions pane may or may not be open.

Page 13: EE 472 – Embedded Microcomputer Systems An Example ...€¦ · EE 472 – Embedded Microcomputer Systems An Example Project Tutorial Part 3: Debugging via the JTAG University of

In the Debug Tab, one will notice that Embedded GDB is suspended, and there are icons above for “play” “stop” “pause” and the like:

We will not go through all of the icons and possibilities, as the best way to learn them is to play around.

Breakpoints and Watches

Let’s first add a watch. If the Expressions pane is open, click on the icon at its upper right corner. If it is not, then go to the code pane. Press the right mouse button. This will open a menu; select Add Watch Expression. Doing so will bring up a window similar to the following figure. Type in “i” (or the variable you wish to watch) and hit OK:

Page 14: EE 472 – Embedded Microcomputer Systems An Example ...€¦ · EE 472 – Embedded Microcomputer Systems An Example Project Tutorial Part 3: Debugging via the JTAG University of

In the Expressions pane you will now see watched variable:

Now, let’s add a breakpoint. In the desired code (main.c for our example), double-click on the left-hand bar next to the desired line of code at which the breakpoint is to be set. In the following figure, this bar is a light blue, but before you add the breakpoint it is gray. Successful addition of a breakpoint is indicated by the icon next to “Led_SetState(0);” in this example.

Page 15: EE 472 – Embedded Microcomputer Systems An Example ...€¦ · EE 472 – Embedded Microcomputer Systems An Example Project Tutorial Part 3: Debugging via the JTAG University of

Also note the addition of a breakpoint under the Breakpoints tab:

Now, resume the gdb by clicking the resume icon . The watched variable will show the value that is stored at its memory location, and there is also a disassembly tab. Note that, at this moment in time, you can only set two breakpoints at a time. Three will error out. However, when the debugger is suspended, you can delete and add breakpoints as desired.

When you are finished, Go to Run→Terminate, or Click the stop icon for both the debugger and the OpenOCD Daemon.

This is the conclusion of the Example Project Tutorials. “Here endith the lesson.” “Now what are you prepared to do about it?”

…Daniel Schuler