Content originally posted in LPCWare by accabog on Tue Sep 25 06:54:53 MST 2012
Hi,
I thought about posting about this since I haven't seen anything related to this on the net and there might be people who would like to take advantage of this.
The idea is to integrate the LPC-Link debugger inside Eclipse so that one could program and debug the projects without having to use the LPCXpresso.
Even though I will explain how to do this, an installation of the LPCXpresso is still required because we need the compiler toolchain and the debugger tool.
*This tutorial assumes the user already has some basic experience and understanding of compilers, microcontrollers and familiarity with Eclipse and LPCXpresso.
--- TOOL CHAIN SETUP ---
In my setup, I have used Eclipse Juno + CDT and as a target the LPC1112FD/102 uC. After making a new project, you should select the correct toolchain for it. You can go to the project properties, c/c++ build -> tool chain editor; there you can select the "Cross GCC" option from the Current toolchain dropdown list. Then go to "Settings", select the "Tool Settings" tab and then select "Cross GCC Compiler" from the list. In the "Command" textfield enter arm-none-eabi-gcc. Go to Symbols and add __NEWLIB__, DEBUG or NDEBUG, __USE_CMSIS=CMSISv2p00_LPC11xx (or other symbols, according to your needs and implementation).
In the Includes section add your include folders, as usual.
In the Miscellaneous enter the following in the Other flags textfield:
-c -fmessage-length=0 -fno-builtin -ffunction-sections -fdata-sections -mcpu=cortex-m0 -mthumb
(don't ask, I'm not an expert:P; I guess -mcpu= could be assigned cortex-m3 if your target is an M3 core).
In the "Cross GCC Linker" tab enter again as above, in the Command field: arm-none-eabi-gcc. Then in the General tab of this section, select No startup or default libs; Again in the miscellaneous tab, the Linker flags field, enter: -mcpu=cortex-m0 -mthumb -T "linker_script.ld", where linker_script is your project's linker script. In the same place, in the "Other options" section, add -Map="${BuildArtifactFileBaseName}.map" and --gc-sections. If you go back to the "Cross GCC Linker" tab, you should see now these settings in the All options textbox;
Go to the "Cross GCC Assembler" and enter again arm-none-eabi-gcc in the Command field; Then go to the General tab and enter in the Assembler flags field the following: -c -x assembler-with-cpp -D__NEWLIB__ -DDEBUG -D__CODE_RED -g3 -mcpu=cortex-m0 -mthumb
Click Apply to make sure your settings are saved.
Go to the Build Steps tab (up) and enter in the Post-build steps Command the following:
arm-none-eabi-size "${BuildArtifactFileName}"; arm-none-eabi-objcopy -O binary "${BuildArtifactFileName}" "${BuildArtifactFileBaseName}.bin" ; checksum -p LPC1112FD_102 -d ${BuildArtifactFileBaseName}.bin
This will display some size info about the created binary after build and will create a .bin file (will not be necessary here, but you never know when you'll need one); the -p LPC1112FD_102 specifies the target, so adjust according to your needs.
Go ti the Build Artifact tab, make sure the artifact type selected is Executable and the Artifact Extension is axf;
Go to the Environment tab in the C/C++ Build dropdown and add or append the PATH variable with C:\nxp\LPCXpresso_4.2.3_292\lpcxpresso\bin; and C:\nxp\LPCXpresso_4.2.3_292\lpcxpresso\Tools\bin; The first one is the path to the checksum.exe needed in the post build steps, and also to the debugger tool; the second one is the path to the toolchain; Also check the install path of the LPCXpresso, this one is the default; Apply and exit.
Given that you have a correct linker script in your Build(or Debug/Release) folder, you should be able to compile your software. If you don't have one, create a dummy project with LPCXpresso, targeting your particular uC and the steal it (copy paste).
--- DEBUGGER SETUP ---
First, you need to add C:\nxp\LPCXpresso_4.2.3_292\lpcxpresso\bin; to the path of your system. (Ctrl Panel -> Adv. sys. settings.-> env. variables on win.) [B](1)[/B]
Go to Debug Configurations, GDB Hardware Debugging tab and make a new config. Give it a nice name; In the Main tab, C/C++ Application field, enter your path to the .axf binary(or how it is called..);
On the bottom of the Main tab, the GDB Launcher is indicated. It should be the Standard GDB Hardware Debugging Launcher. If not, click Select other.. and tick the Use configuration specific settings and select the Standard GDB Hardware Debugging Launcher.
In the Debugger tab, enter as GDB Command the path to the gdb server: C:\nxp\LPCXpresso_4.2.3_292\lpcxpresso\Tools\bin\arm-none-eabi-gdb.exe. Command set can be left as Standard(Windows) and protocol version as "mi". Uncheck "Use remote target" if selected.
In the Startup tab, in the Initialization Commands textbox, enter the following:
[B]set remotetimeout 60000
target extended-remote | crt_emu_lpc11_13_nxp -wire=hid -g -mi -0 -pLPC1112FD/102 -vendor=NXP
info proc
info program
mon capabilities
set mem inaccessible-by-default off
mon ondisconnect cont
set arm force-mode thumb[/B]
Check the Load Image and select the Use project binary radiobutton; Also select the Load Symbols and select the Use project binary radiobutton.
Scroll down to the Run Commands textbox. There enter the following:
[B]mon info,all
-data-list-register-names
-break-insert -t main
-stack-info-depth
-stack-list-frames 0 1
-exec-continue[/B]
Click Apply and then Debug, to test the configuration.
I hope this will help some. It's not intended for beginners, and I'm also not an expert..there are multiple niches related to this (gdb, gcc, Eclipse IDE) so there is room for improvements. These configurations will differ a little from target to target, so a little understanding of this is required. The download limit for the debugger is still limited to the licence you have. This is usually located in C:\Users\Public\LPCXpresso\LPCXpresso.acc
[B](1)[/B] This is necessary for the gdb to be able to execute the crt_emu_lpc11_13_nxp command. On my machine, a logout login cycle is required so that the updated path to be seen.
If you have any questions or you need clarifications, or maybe suggestions for improvements, please let me know.
Alex
EDIT: I forgot to mention that every time the LPC-Link debugger is plugged in the USB port, the device must be initialized as a HID device through the script found at C:\nxp\LPCXpresso_4.2.3_292\lpcxpresso\bin\Scripts\bootLPCXpresso.cmd so you might add that config script as an external tool in eclipse