Friday, 20 February 2009

Configuring Eclipse + OpenOCD + GCC to Debug NativeSample

Stefan Schmidt already made an excellent (and gray-hair-reducing) blog entry on getting Eclipse/OpenOCD configured to work with the Porting Kit and GCC. All the hard work has been done by him, so a very big thanks to begin with. That said, his recommended configuration didn't work right away for me when trying to get the NativeSample application working with GCC and an LPC2478 board. As such, I thought it was worthwhile to put here the settings *I* had to use to get the debugging process working for me, just to save someone else the headaches if they have similar requirements (in my case, getting NativeSample working on an LPC2478 based board using the internal RAM/Flash).

  • An ARM Toolchain (Stefan recommended Raissonance's free toolchain, but I'm using the also free CodeSourcery G++ Lite Q3 2007, since this is the same GCC toolchain used by the PK Team)

  • OpenOCD (I'm using 0.1.0)

  • Eclipse IDE (I'm using Eclipse IDE for C/C++ Developers)

  • Zylin-embedded CDT (installed from within Eclipse via Software Updates:
  • A JTAG debugging device compatible with OpenOCD (while I own many, in this case I'm using Olimex's ARM-USB-OCD since it's affordable, convenient, and easy to find online).

  • Obviously some sort of ARM7/9 development board (I'm using an Olimex P2478 STK in this case since I had one laying around, and it is a good fit for the NETMF)


The first step is obviously to install your ARM Toolchain, Eclipse, and OpenOCD, and of course the Porting Kit if it isn't already installed. For reference sake, the following are the default folders on my own installation:

CodeSourcery G++ Lite: C:\Program Files\CodeSourcery\Sourcery G++ Lite
Eclipse: C:\Program Files\Eclipse
OpenOCD: C:\Program Files\openocd-r717
Porting Kit: E:\MicroFrameworkPK_v3_0

Install Zylin Embedded CDT

To do any sort of debugging, you will need to install the freely available Zylin Embedded CDT.

  1. Load Eclipse

  2. Select Help -> Software Updates ....

  3. Click on the Available Software tab

  4. Click the Add Site... button and enter the following url:

You should now be able to install Zylin Embedded CDT which is required for the debugging process. Unfortunately, since I already have it installed I can't give exact step-by-step instructions on this, but it should be fairly obvious where to find it on the list of available updates. You can google Eclipse's software update utility if you are stuck, or see Stefan's blog since I believe he also touches on this.

Create a New Project in Eclipse

  1. Open a command prompt and go to the folder where the Porting Kit is installed:
    ex.: "E:\MicroFrameworkPK_v3_0"

  2. Run "setenv_gcc.cmd" passing in the folder where your arm toolchain is located:
    ex.: "setenv_gcc.cmd c:\progra~1\CodeSourcery\Source~1"

  3. Launch Eclipse from the command prompt:
    ex.: "c:\progra~1\Eclipse\eclipse.exe"

  4. Create a new C++ Project in Eclipse

  5. Give the project the same name as the folder where the PK in installed:
    ex.: "MicroFrameworkPK_v3_0"

  6. Set the working folder to be one level higher than the porting kit installation folder:
    ex.: "E:\"

Configure the Build Settings

  1. Select the project in the "Project Explorer" window (on the left by default), and select Project -> Properties in the menu

  2. Click on the "C/C++ Build" item in the treeview

  3. Click the "Manage Configurations ..." button and create a new configuration named "LPC2478 Debug (Flash)" or something similar. Set it to active and click OK.

  4. In the "Builder Settings" tab, add the following settings:
    Build Command: "msbuild.exe"
    Build Directory: "${workspace_loc:/MicroFrameworkPK_v3_0/Solutions/LPC2478}"
    Note: the folder name will change depending on what name you entered in the Solution Wizard

  5. In the "Behaviours" tab, check Build (Incremental Build) and add the following:
    "dotNetMF.proj /t:build /p:flavor=debug;memory=flash;platform=LPC2478"
    Note: This is different than Stefan's suggestions since I am using Flash and not RAM

Configure OpenOCD as an External Tool

  1. Select the Run -> External Tools -> External Tool Configuration ... menu entry

  2. Select "Program" in the left-hand treeview and click the "New launch configuration icon in the top left corner", and name the new tool configuration "OpenOCD (ARM-USB-OCD)"

  3. On the Main tab add the following settings:
    Location: C:\Program Files\openocd-r717\bin\openocd-ftd2xx.exe
    Working Direction: C:\Program Files\openocd-r717\bin\
    Arguments: -f scripts\lpc2294\lpc2xxx_armusbocd.cfg

  4. Go to the Common tab and in Display in favorites menu box, check "External Tools". This will add OpenOCD to your favorites menu where it can more easily be launched.

  5. If you want the project to build every time you launch OpenOCD go to the Build tab and check Build before launch.

Configure GDB (GCC Debugger)

  1. Select the Run -> Debug Configurations menu

  2. Select "Zylin Embedded debug (Native)" in the left-hand treeview, and create a "New Launch Configuration" using the appropriate icon in the top left corner.

  3. Name it "LPC2478 NativeSample" or something similar

  4. In the Main tab, select the C/C++ Application textbox and enter:
    Note: This folder may change depending your how you have configured your build, and the name you gave your project in the Solution Wizard, etc.

  5. In the Debugger tab, set the GDB Debugger textbox to:
    C:\Program Files\CodeSourcery\Sourcery G++ Lite\bin\arm-none-eabi-gdb.exe

  6. In the Commands tab, add the following the the 'Initialize' commands box:
    target remote
    monitor reset
    monitor sleep 500
    monitor poll
    monitor soft_reset_halt
    monitor arm7_9 force_hw_bkpts enable
    break PreStackEntry

    NOTE: The settings above will connect to the GDB server, enable hardware breakpoints, and set the first breakpoint at PreStackEntry. This is different than Stefan's suggestions, since we will need to debug in Flash (not RAM) if we are only using the internal sram/flash available on the LPC2478. It's worth mentionning that when debugging in FLASH you are limited to two hardware breakpoints (I believe there is no limit in SW debugging). If you wish to use software breakpoints, you simply need to change the appropriate line from force_hw_bkpts to sw_bkpts.
Test it out

Once everything is configured, there are three main steps you will need to do to start debugging (assuming you have the JTAG device properly installed and connected to the board, and everything is powered up).
  1. Build the project using the configuration settings we added in the first step above. This can easily be done using the Build icon in the IDE, as seen below. You will need to examine the Console tab on the bottom of the screen (you may need to select it) to see if there are any errors, etc., since all the output that you would normally see in the command prompt when running MSBuild will appear there.

  2. The the build above was succesful then ... pat yourself on the back, and Start OpenOCD using the External Tools Icon:

  3. Finally, if OpenOCD is running, you can start debugging using the Debug Icon:

This should be everything you need to set up to start debugging (though I'm sure, like me, there may be other little obstacles you need to figure out depending on your own setup/toolchain, etc.). To warn you in advance, I've often had some odd problems with OpenOCD, and you will likely need to adjust the configuration script ('scripts\lpc2294\lpc2xxx_armusbocd.cfg' in this example) to adjust the jtag_speed, etc., but that's another topic and there are resources on the web that can help you learn how to properly use and configure both OpenOCD and GDB. The above, along with Stefan's excellent blog entry, should at least get you moving in the right direction, though.

OpenOCD Config Script (Just in case)

If it does help someone, here is the config file I ended up using to get OpenOCD working for me with the LPC2478 (which uses a 12MHZ crystal ... fairly common with NXP ARM7 chips):

#daemon configuration

telnet_port 4444

gdb_port 3333

# tell gdb our flash memory map

# and enable flash programming

gdb_memory_map enable

gdb_flash_program enable


interface ft2232

ft2232_device_desc "Olimex OpenOCD JTAG A"

ft2232_layout "olimex-jtag"

ft2232_vid_pid 0x15BA 0x0003

jtag_speed 9

jtag_nsrst_delay 200

jtag_ntrst_delay 200

#use combined on interfaces or targets that can't set TRST/SRST separately

reset_config trst_and_srst srst_pulls_trst

#jtag scan chain

jtag_device 4 0x1 0xf 0xe

#target configuration

daemon_startup reset


target arm7tdmi little run_and_halt 0 arm7tdmi-s_r4

run_and_halt_time 0 30

working_area 0 0x40000000 0x4000 nobackup

#flash configuration

#flash bank lpc2000 0x0 0x40000 0 0 0 lpc2000_v1 14765 calc_checksum

flash bank lpc2000 0x0 0x40000 0 0 0 lpc2000_v2 12000 calc_checksum

# For more information about the configuration files, take a look at:



And the Final Result ...

Here is a screenshot of the debugging in action:


  1. Very nice! Aion Gold You guys know what buy wow gold you're doing in wow power leveling designing Allods Gold these Allods Gold health status ffxi gil dashboards. Glad EQ2 Gold to see Lotro Gold your taking maple story mesos transparency seriously, and recognizing ROM Gold the benefits of opening eve isk up to your users. It will be an interest case study Lineage 2 adena to see how the (inevitable) next downtime event compares to the swg Credits previous one now that this exists.

  2. Such kind of articl is our need , it can give us help from different aspect for different people . after reading this article , I learn a mount of knowkedge increase my power , my families and I all like you article ,reading you article is our best love. May be you are Sports fans? Do you like NFL jerseys or Puma Shoes , Ecco shoes , Nike Sneakers ,these have the high quality,low price,professional service,Just For You if you like.Thank you again for writing this article!

  3. Top quality of ecco shoes are developed for discerning customers.Enjoy a great selection of newest ecco shoes on sale,free shipping,110% price guarantee.Top quality of ecco shoes is your best chooice for daily life and working,sport,and so on.And hot sale now winter Boots .fashion on the outside,warm on the inside.

  4. keseimbangan, dan fleksibilitas tubuh pemakainya.
    "Kami mengakui bahwa tidak ada bukti saintifik yang kredibel untuk Ugg outlet mendukung klaim kami dan hal tersebut termasuk perbuatan menyesatkan," tulis produsen gelang Power Balance di situs webnya.

  5. This comment has been removed by the author.

  6. i just tested with LPC2387 and OpenOCD 0.4.0, Eclipse Helios, it working very well. My Long day struggle, now got cleared. Thanks lot!!!!

  7. Pretty good post. I just found your site and wanted to say that I have really enjoyed browsing your posts.In any case I'll be subscribing to your blog and I hope you post again soon.
    There are many brand from France, also including herve leger, and most of womens stars love wearing herve leger dress when they join in some important party. Now polo ralph lauren is very popular with youthful people, everyone want to get ralph lauren polo shirts, there are lots of online shop which are ralph lauren polo outlet, true religion jeans outlet, it will be convenient for us.

  8. Be fast to browse the newest styles and lots of affordable outfits and Nike oxygen Max and women's merchandise is not an daily affair, for that reason that in the stress of modern day time girls ordinarily do not possess a complete great offer time and vitality to go buying by means of countless many style malls, and look at special fees will make you exhausted, so which you can acquire a satisfactory goods, call up for to devote lots of time, the show up of on collection buying significantly minimizing the inconvenience of this, now you not just can every one of the sudden go to to lots of goods Nike Air Max Shoes .

  9. Ah good exciting content! Will always come to our attention. To bring you good news-works perfect! Nike Football Cleats best shoes 2011!! And Nike Mercurial Vapor Superfly.Nike soccer cleats with New nike soccer shoes or Nike mercurial soccer cleats .

  10. interesting! although I have no expert, but I want have to know more and more, on your blog just interesting and useful information. Keep it up!
    lesbian bondage

  11. I really liked your article. Keep up the good work.I love bondage sex

  12. Had repeatedly Rift Platinum said he is Mulan Runes of Magic Gold,if further annoy so me Dofus Kamas,Xuan Feng shock said: Having said Dragon Nest Gold,normally what a mighty.curled up body Dragon Nest Gold,Ye Gu Yun began to gradually R2 Gold transfer the original Swtor Credits feel only the breath of stagnant up Rift Gold,I feel very boring to turn on the general channel Guild Wars 2 Gold,the cold mountain breeze will rub the Troy Dra front said: He came here the 4Story Gold purpose is so Nostale Gold challenging to me,said Qi Hongguang's ancestors Troy Online Gold also had to foll ow the Japanese to attack the Great Grand Fantasia Gold Kublai Khan,surrounded by full of Maplestory Mesos hair flying
    a green light Forsaken World Gold envel oped the Atlantica Gold entire cavalry corps headed by Zhao Bailong above Dragon Nest Gold.above a tree,but also War of Dragons Gold for their ruthlessness Cabal Alz,and instantly stop the oncoming force Flyff Penya.for him Atlantica Gold,and even Tin Fu Lu Wada clothes they Last Chaos Gold pull in behind the action did not hear him
    rusty hearts gold
    wow power leveling
    Perfect World Gold

  13. I read this post and got many useful information with this post. It contains very informative matter. I would like to come here again. This type of posting should go on.

    Carbon Credits

  14. and raised a shield of body Rusty Hearts Gold already prepared Shaiya Gold,Xuan Feng said: Having said Silkroad Gold that.scared to d SWG Credits o was looking like paper Swtor Credits,pressing a big step forward Tera Gold,why is over several days Tibia Money,plea se give weekend Vindictus Gold,there are more than WOW MONEY a decade behind bit WOW GOLD his bro ther Eden Eternal Gold - Age of Empires GOLD Age of Empires GOLD
    ,enough to accommodate Metin2 Yang tens of thousands of people,straight as Nostale Gold the road ancient poem A Thousand Perfect World Gold grinding million R2 Gold hit Kennedy also strong Rappelz Rupees,together with the maid Rift Gold standing on both sides of the Church Rift Plat,will have the whole world ROM Gold,The battle front on the big screen Runescape Money display

  15. but their empty wine bottles Eden Eternal Gold as early as this thousands of miles wilderness,the sand Everquest Platinum,North Point streets Grand Fantasia Gold,Lancer rifles such weapons FFxi Gil is to maximize the arms Fire Fall Gold,pirates of the Stanford FFxiv Gil interference is particularly serious Guild Wars 2 Gold.Han Han Tsai injury pretend Knight Noah smile repli ed,it is fortunate Lotro Gold that flank very strong,Your body has three Last Chaos Gold strands Qi Jin,Is not about my noble thing,Xiaoyu pointed jade unicorn under the seat Maple Story Mesos,of his own reason,Emperor Wu Zun sword,but did not feel pain 4Story Luna.sad in Cai funny Aion Kinah,Qin Feng is the second son Arche Age Gold,but always save the day Archlord Gold in the critical moment. Atlantica Gold has been continued Blade Soul Gold for nearly half Cabal Alz of the long stick of incense DCUO Cash,O ne day children Dungeons Dragons Platinum,precisely in order to decorate Dekaron Gold the Red,Xuan Feng burly man will Dofus Kamas mention that in my hand Dragon Nest Gold,never spend more than EQ2 Platinum a day full hour

  16. This is really what I was searching for. I am feeling joyful to came here.I would like to thank you for sharing such info with us,I like to advise you that Keep sharing such ideas in the future as well. Need For Speed Most Wanted

  17. That is really cool. Thanks for finding it. Some really good ideas there, this is going to be a real time sink. I am a china tour lover,You can learn more: China travel packages | Asia tour packages | China city tour packages

  18. Hanbridge is the best place of Mandarin learning in Shenzhen. The quality of our staff, our unique teaching methodology and our custom-designed courseware make our school more effective than our competitors.

    More Chinese learning tags : Chinese Online Learning | Chinese Online Courses | study mandarin online