Skip Navigation LinksProjects > LPC1343 Reference Design > Tutorial: Debugging LPC1343 CodeBase with LPCXpresso

Debugging the LPC1343 CodeBase with LPCXpresso

How to build firmware, flash the device and debug using the free LPCXpresso IDE.

While LPCXpresso and the related LPC-Link SWD debugger are both closed-source projects, they're probably the cheapest professional solution out there at the moment for development and debugging on ARM Cortex M devices from NXP. A 128KB code-limited version of the IDE is available free for use with NXP microcontrollers, and the 20EUR/30USD development boards include a complete SWD HW-debugger that can be seperated from the MCU half and used independently. Which means for 20 EUR, you have a full professionally maintained development suite, and a debugger that allows you to conveniently flash your device, and debug using step-through debugging. Until a comparable fully open-source alternative comes out with the same level of maturity, it's hard to argue with the price.

The LPC1343 Code Base already includes project files for Rowley Associate's Crossworks for ARM IDE, and the free cross-platform CodeLite IDE with very basic debugging via GDB and a Segger J-Link for ARM, but the latter still isn't terribly reliable. By following the tutorial below, you can take an inexpensive LPCXpresso dev board -- or, the J-Link debugger half of it to be precise -- and start debugging right away.

What Do I Need?
  • The LPCXpresso IDE (freely available but requires registration and email activation for full 128KB support)
  • Any LPCXpresso dev board with the J-Link section seperated from the MCU part if you want to use the code based with anything other than the attached MCU.
  • The latest copy of the LPC1343 Code Base from Github (LPCXpresso project files are only included in v1.0.0 and higher).  Click 'Downloads' in the top-right, and then click the 'Download as Zip' button.

Step One: Import the LPC1343 CodeBase into your workspace

Once you have installed and activate your copy of LPCXpresso, open up the IDE and click the "Import existing project" option in the Import and Export task window:

Step Two: Select the path where the LPC1343 CodeBase was saved

In the dialogue box that appears, select the folder where the LPC1343 CodeBase was downloaded and unzipped:

Step Three: Update the Makefile for Debug or Release

Unlike traditional LPCXpresso project where the Makefile, linker script, startup code, etc., are all generated dynamically, the LPC1343 CodeBase is based on a Makefile and custom startup files, etc. This was an intentional choice to have something totally platform independent, and to be able to fully control the license restrictions on the code, but it means that you need to manually change the Makefile when you want to add new files to the project, and to state whether you want to build in debug mode or release mode.

Debug mode takes about 2x the flash space as release mode, and on a small part like the LPC1343 (32KB flash) this is only possible on some project. If your project is small enough, and you want full debugging support including stepping through the C-code line by line, you need to open the Makefile and find the line where DEBUGBUILD is set.

For debug builds, including full step-through debugging of your original C source code, set DEBUGBUILD to TRUE. For much smaller, and heavily optimised code, and for project release, set this value to FALSE. For complex projects, you will likely be forced to set this to FALSE because of size restrictions.

Step Four: Build the project

Once the Makefile has been set to the appropriate debug mode, right-click on the project and select 'Build Project'. This will cause the Makefile to execute, and the build process will commence:

Step Five: Wait for the build to complete

Because of the size of the LPC1343 CodeBase it can take a while to complete, but you can see the progress as follows:

Step Six: Build Complete

Once the build is complete and if everything worked out, you should see the size of the compiled binary, and additional .hex and .bin files will be created (to allow programming the device using FlashMagic over UART or with the USB bootloader):

Step Seven: Start Debugging and Flash Device

If everything build correctly, you can click on 'Debug (Debug)' in the highlighted task window:

Step Eight: Select firmware.elf from the steps above

Because the build system is based on a Makefile, LPCXpresso will ask you which file you want to debug. Select firmware.elf, which was generated in step six above:

Step Nine: Wait for the LPC-Link SW to launch

LPCXpresso will (unfortunately) go through another build process, and then it will try to execute the firmware loader for the LPC-Link (it uses a USB DFU class). Make sure you have your LPC-Link connected to the board you want to debug, and you should see the build process stall around 57% while the LPC-Link loads for the first time:

Step Ten: Debug!

. Once loaded, it will program the flash on the MCU with your firmware, and start executing. At this point, you're device is executing the firmware, and depending on the build mode you selected, you have varying options for debugging. The screenshot below shows a debug build where you can fully step-through the original source code, set breakpoint, etc.:

  • Facebook
  • DZone It!
  • Digg It!
  • StumbleUpon
  • Technorati
  • Del.icio.us
  • NewsVine
  • Reddit
  • Blinklist
  • Furl it!

Comments