Commit | Line | Data |
---|---|---|
3c132bd0 AW |
1 | =Monitor for Remote Inspection (MRI) Notes |
2 | ==Updates | |
3 | * **1/9/2012:** Added semihost support for stdin/stdout/stderr. This allows functions like printf() and scanf() to function. Their I/O gets redirected over the serial port to the gdb console. | |
6c79da43 AG |
4 | * **2/22/2012:** Switched to low level UART support to work with any of the 4 serial ports on the mbed. It also uses auto baud detection so that user just selects their desired baud rate in gdb at runtime. Also default interrupt priorities to 1 instead of 0, increasing the chance that MRI can debug ISRs. |
5 | * **2/29/2012:** Added notes about GCC4MBED_TYPE environment variable in Usage section. | |
6 | * **3/3/2012:** Added support for LocalFileSystem I/O redirection to the current directory on the gdb host computer. | |
7 | * **3/12/2012:** Added notes about imprecise nature of data watchpoints. | |
caea2d69 | 8 | * **4/29/12012:** Updated stack and double fault notes since MRI has been updated to lessen these concerns. |
3c132bd0 AW |
9 | |
10 | ==Installation | |
11 | There are a few things that you need to download and install for MRI: | |
12 | * Download [[http://mbed.org/media/uploads/simon/mbedmicrocontroller_21164.if]]. Copy this file to your mbed device and then reset it. This will update the firmware on the interface chip so that the JTAG portion can be disabled. | |
13 | * Install the MRI repository version of gcc4mbed on your local machine. There are two ways to do this: | |
14 | ** **Recommended:** Clone the repository so that you can pull down updates easily. {{{git clone git@github.com:adamgreen/mri.git}}} | |
15 | ** Go to [[https://github.com/adamgreen/mri/downloads]] and download an archive of the project and decompress it to your local machine. | |
caea2d69 | 16 | * Follow the instructions at [[https://github.com/adamgreen/mri#readme]] to allow the MRI project to pull down and install its dependencies. |
3c132bd0 AW |
17 | |
18 | ==Usage | |
6c79da43 AG |
19 | By default the gcc4mbed project builds binaries of a **Release** type which don't include any debugging support. This will need to be changed to a **Debug** build type to enable the MRI debugger in the binaries. The GCC4MBED_TYPE environment variable is used to set the build type. |
20 | ||
21 | On Windows: | |
22 | {{{ | |
23 | set GCC4MBED_TYPE=Debug | |
24 | }}} | |
25 | ||
26 | On OS X and Linux: | |
27 | {{{ | |
28 | export GCC4MBED_TYPE=Debug | |
29 | }}} | |
30 | ||
31 | Run the BuildShell script found in the root of the MRI project directory. This script configures your PATH to make sure that the correct version of gdb is used for debugging. | |
3c132bd0 AW |
32 | |
33 | The following is an example of running the HelloWorld sample under gdb on OS X. | |
34 | {{{ | |
6c79da43 | 35 | bash-3.2$ export GCC4MBED_TYPE=Debug |
3c132bd0 AW |
36 | bash-3.2$ cd samples/HelloWorld/ |
37 | bash-3.2$ make clean all deploy | |
38 | rm -f ../../src/gcc4mbed.o ../../src/syscalls.o ./main.o | |
39 | rm -f HelloWorld.hex | |
40 | rm -f HelloWorld.elf | |
41 | rm -f HelloWorld.map | |
42 | rm -f HelloWorld.bin | |
43 | rm -f HelloWorld.disasm | |
44 | arm-none-eabi-g++ -O0 -gstabs+3 -mcpu=cortex-m3 -mthumb -mthumb-interwork -fshort-wchar -ffunction-sections -fdata-sections -fpromote-loop-indices -Wall -Wextra -Wimplicit -Wcast-align -Wpointer-arith -Wredundant-decls -Wshadow -Wcast-qual -Wcast-align -fno-exceptions -I./ -I../../external/mbed -I../../external/mbed/LPC1768 -I../../external/FATFileSystem -I../../mri -DTARGET_LPC1768 -DGCC4MBED_DELAYED_STDIO_INIT=1 -c ../../src/gcc4mbed.c -o ../../src/gcc4mbed.o | |
45 | arm-none-eabi-g++ -O0 -gstabs+3 -mcpu=cortex-m3 -mthumb -mthumb-interwork -fshort-wchar -ffunction-sections -fdata-sections -fpromote-loop-indices -Wall -Wextra -Wimplicit -Wcast-align -Wpointer-arith -Wredundant-decls -Wshadow -Wcast-qual -Wcast-align -fno-exceptions -I./ -I../../external/mbed -I../../external/mbed/LPC1768 -I../../external/FATFileSystem -I../../mri -DTARGET_LPC1768 -DGCC4MBED_DELAYED_STDIO_INIT=1 -c ../../src/syscalls.c -o ../../src/syscalls.o | |
46 | arm-none-eabi-g++ -O0 -gstabs+3 -mcpu=cortex-m3 -mthumb -mthumb-interwork -fshort-wchar -ffunction-sections -fdata-sections -fpromote-loop-indices -Wall -Wextra -Wimplicit -Wcast-align -Wpointer-arith -Wredundant-decls -Wshadow -Wcast-qual -Wcast-align -fno-exceptions -I./ -I../../external/mbed -I../../external/mbed/LPC1768 -I../../external/FATFileSystem -I../../mri -DTARGET_LPC1768 -DGCC4MBED_DELAYED_STDIO_INIT=1 -c main.cpp -o main.o | |
47 | arm-none-eabi-g++ -mcpu=cortex-m3 -mthumb -O0 -Wl,-Map=HelloWorld.map,--cref,--gc-sections,--no-wchar-size-warning -T../../build/mbed.ld -L ../../external/gcc/LPC1768 ../../src/gcc4mbed.o ../../src/syscalls.o ./main.o ../../mri/mri.ar ../../external/mbed/LPC1768/mbed.ar ../../external/mbed/LPC1768/capi.ar -o HelloWorld.elf | |
48 | arm-none-eabi-size HelloWorld.elf | |
49 | text data bss dec hex filename | |
50 | 73335 1500 1084 75919 1288f HelloWorld.elf | |
51 | arm-none-eabi-objcopy -R .stack -O ihex HelloWorld.elf HelloWorld.hex | |
52 | arm-none-eabi-objcopy -O binary HelloWorld.elf HelloWorld.bin | |
53 | arm-none-eabi-objdump -d HelloWorld.elf >HelloWorld.disasm | |
54 | cp HelloWorld.bin /Volumes/MBED/ | |
55 | ||
56 | ***RESET MBED DEVICE*** | |
57 | ||
58 | bash-3.2$ arm-none-eabi-gdb HelloWorld.elf --baud 115200 -ex "set target-charset ASCII" | |
59 | GNU gdb (Sourcery G++ Lite 2011.03-42) 7.2.50.20100908-cvs | |
60 | Copyright (C) 2010 Free Software Foundation, Inc. | |
61 | License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> | |
62 | This is free software: you are free to change and redistribute it. | |
63 | There is NO WARRANTY, to the extent permitted by law. Type "show copying" | |
64 | and "show warranty" for details. | |
65 | This GDB was configured as "--host=x86_64-apple-darwin10.8.0 --target=arm-none-eabi". | |
66 | For bug reporting instructions, please see: | |
67 | <https://support.codesourcery.com/GNUToolchain/>... | |
68 | Reading symbols from /depots/mri/samples/HelloWorld/HelloWorld.elf...done. | |
69 | (gdb) target remote /dev/tty.usbmodem412 | |
70 | Remote debugging using /dev/tty.usbmodem412 | |
71 | __main () at ../../src/gcc4mbed.c:96 | |
72 | 96 __debugbreak(); | |
73 | (gdb) break main | |
74 | Breakpoint 1 at 0x73c: file main.cpp, line 26. | |
75 | (gdb) c | |
76 | Continuing. | |
77 | Note: automatically using hardware breakpoints for read-only addresses. | |
78 | ||
79 | Breakpoint 1, main () at main.cpp:26 | |
80 | 26 myled = 1; | |
81 | (gdb) bt | |
82 | #0 main () at main.cpp:26 | |
83 | (gdb) | |
84 | }}} | |
85 | ||
86 | ==Important Notes | |
6c79da43 AG |
87 | There are a few things to note about the MRI debug monitor functionality: |
88 | * LocalFileSystem I/O is redirected to the current directory on the gdb host computer when using MRI. This introduces a few limitations: | |
89 | ** Slower performance since I/O is being redirected over the serial port to the gdb host computer. | |
90 | ** No directory enumeration support (opendir,readdir,closedir). Calling such functions for the LocalFileSystem while running under MRI will result in stops like. | |
91 | \\{{{Program received signal SIGTRAP, Trace/breakpoint trap.}}}\\{{{0x00011a00 in mbed::LocalDirHandle::readdir() ()}}}\\ | |
92 | * The monitor and associated UART exception handler run at priority level 0. This means that the debugger can't preempt another interrupt service routine that is also running at priority level 0. By default, the mbed SDK allows its ISRs to use the default priority level of 0. MRI switches this default priority level to 1. If you have an ISR that must be run at priority level 0 then you will need to increase its priority level manually.\\ \\{{{NVIC_SetPriority(SysTick_IRQn, 0);}}}\\ \\ | |
93 | * The monitor requires the use of a UART to communicate with gdb and it defaults to using the USB based serial connection. This means you will end up with a conflict if your firmware also sends data to the PC over the default USB based serial port on the mbed. Your makefile can be used to override the mbed serial pins used by MRI. For example to switch to the UART on pins 9 and 10 of the mbed, you could add this line to your makefile:\\ \\{{{MRI_UART=MRI_UART_MBED_P9_P10}}}\\ \\ | |
94 | You can find all of the supported MRI_UART_* selections in the public mri/mri.h source file. | |
95 | * Data watchpoints on the LPC1768 are imprecise. This means that the line of code on which the debugger stops may be a line or two after the actual line of code which accessed the watched variable. | |
3c132bd0 AW |
96 | |
97 | ==Known Issues | |
98 | Known issues that will be investigated for future fixes include: | |
99 | * On Mac OS X, I see a hang in gdb when issuing the {{{target remote}}} command. The workaround is to disconnect the mbed device from the Mac by unplugging the USB cable and then reconnecting it to force reenumeration. | |
caea2d69 | 100 | ** It may be possible to workaround this issue in the gdb source code as well and I am currently dogfooding such a build of arm-none-eabi-gdb on my Mac. Please contact me if you would like to help test this fix on your Mac. |
3c132bd0 | 101 | * Can't dump objects from the mbed SDK. This includes objects of class types such as DigitialIn, InterruptIn, AnalogOut, etc. and even user created classes which derive from these classes. |
3c132bd0 | 102 | * User must be careful when debugging hard faults. Attempting to read/write from/to invalid memory locations could cause a double fault hang. |
caea2d69 AG |
103 | ** MRI does tell gdb which address ranges are invalid but it is still possible to attempt a write to a read-only peripheral memory mapped register and this could lead to a double fault. |
104 | * While MRI has been shown to work on some other LPC17xx based development systems, this isn't currently a supported scenario. However, as long as the device doesn't have a JTAG debugger attached and you can connect the PC to one of the UARTs on the device, it should work. | |
3c132bd0 AW |
105 | |
106 | ||
107 | ==Hit a Problem! | |
108 | GDB allows for all of the data sent between your PC and the remote MRI target to be captured to a log file. If you enter the following command in GDB before issuing the "target remote" command then everything for your session will be logged to a file called mri.log in the current directory where GDB was launched: | |
109 | {{{ | |
110 | set remotelogfile mri.log | |
111 | }}} | |
112 | ||
113 | Describe as clearly as possible what you were doing when you encountered the problem and then e-mail me this description along with a log file captured as described above. I have an electronic mail account at yahoo.com. The alias I use there is adamgrym. |