tag:blogger.com,1999:blog-11779924928186859652024-03-06T09:07:30.752+01:00.Net Micro FrameworkInformation on development and porting for the Microsoft .NET Micro Framework (NETMF) 3.0Kevin Townsendhttp://www.blogger.com/profile/07530967701464128104noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-1177992492818685965.post-38007746089934720032009-03-13T12:51:00.004+01:002009-03-13T13:00:15.483+01:00Update on OpenOCD 0.10 SupportI realized when I started running into stability problems with the debugger that I am actually using an older version of OpenOCD in the tutorial below (build 717 which is quite old by now). I was pointing to the wrong folder, since I had two different versions installed. My bad. <br /><br />I am currently in the process of trying to get everything to work with the latest official release of OpenOCD, and once I can figure out how to properly configure Eclipse I'll post the configuration files here, and explain any particular hoops I had to jump through to get the debugging working. I'll try to make a full post on configuring OpenOCD again, just to avoid any confusion and having to switch between the two articles trying to figure out what's different, etc.Kevin Townsendhttp://www.blogger.com/profile/07530967701464128104noreply@blogger.com2tag:blogger.com,1999:blog-1177992492818685965.post-11651028861126475742009-02-20T10:14:00.042+01:002009-02-20T13:37:53.762+01:00Configuring Eclipse + OpenOCD + GCC to Debug NativeSampleStefan Schmidt already made an excellent (and gray-hair-reducing) <a href="http://discovertheexperience.blogspot.com/2008/11/how-to-use-eclipse-and-gdb-to-debug-net_09.html">blog entry</a> 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).<br /><br /><span style="font-size:130%;"><strong>Requirements</strong></span><br /><ul><li>An ARM Toolchain (Stefan recommended Raissonance's free toolchain, but I'm using the also free <a href="http://www.codesourcery.com/sgpp/lite/arm/portal/release316">CodeSourcery G++ Lite Q3 2007</a>, since this is the same GCC toolchain used by the PK Team)</li><br /><li><a href="http://openocd.berlios.de/web/">OpenOCD</a> (I'm using 0.1.0)</li><br /><li>Eclipse IDE (I'm using <a href="http://www.eclipse.org/downloads/">Eclipse IDE for C/C++ Developers</a>)</li><br /><li>Zylin-embedded CDT (installed from within Eclipse via Software Updates: <a href="http://www.zylin.com/zylincdt">http://www.zylin.com/zylincdt</a>)<br /></li><li>A JTAG debugging device compatible with OpenOCD (while I own many, in this case I'm using Olimex's <a href="http://www.olimex.com/dev/arm-usb-ocd.html">ARM-USB-OCD</a> since it's affordable, convenient, and easy to find online).</li><br /><li>Obviously some sort of ARM7/9 development board (I'm using an <a href="http://www.olimex.com/dev/lpc-2478stk.html">Olimex P2478 STK</a> in this case since I had one laying around, and it is a good fit for the NETMF)</li></ul><br /><p><span style="font-size:130%;"><strong>Installation</strong></span></p><p>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:</p><p><strong>CodeSourcery G++ Lite</strong>: C:\Program Files\CodeSourcery\Sourcery G++ Lite<br /><strong>Eclipse</strong>: C:\Program Files\Eclipse<br /><strong>OpenOCD</strong>: C:\Program Files\openocd-r717<br /><strong>Porting Kit</strong>: E:\MicroFrameworkPK_v3_0</p><p><span style="font-size:130%;"><strong>Install Zylin Embedded CDT</strong></span></p><p>To do any sort of debugging, you will need to install the freely available Zylin Embedded CDT.</p><ol><li>Load Eclipse</li><br /><li>Select <strong>Help -> Software Updates ...</strong>. </li><br /><li>Click on the <strong>Available Software</strong> tab</li><br /><li>Click the <strong>Add Site... </strong>button and enter the following url: <span style="font-family:courier new;font-size:85%;"><a href="http://www.zylin.com/zylincdt">http://www.zylin.com/zylincdt</a></span></li></ol><p>You should now be able to install <strong>Zylin Embedded CDT</strong> 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.</p><p><span style="font-size:130%;"><strong>Create a New Project in Eclipse</strong></span> </p><ol><li>Open a command prompt and go to the folder where the Porting Kit is installed:<br />ex.: "E:\MicroFrameworkPK_v3_0"</li><br /><li>Run "setenv_gcc.cmd" passing in the folder where your arm toolchain is located:<br />ex.: "setenv_gcc.cmd c:\progra~1\CodeSourcery\Source~1"</li><br /><li>Launch Eclipse from the command prompt:<br />ex.: "c:\progra~1\Eclipse\eclipse.exe"</li><br /><li>Create a new C++ Project in Eclipse</li><br /><li>Give the project the same name as the folder where the PK in installed:<br />ex.: "MicroFrameworkPK_v3_0"</li><br /><li>Set the working folder to be one level higher than the porting kit installation folder:<br />ex.: "E:\"</li></ol><p><span style="font-size:130%;"><strong>Configure the Build Settings</strong></span><br /></p><ol><li>Select the project in the "Project Explorer" window (on the left by default), and select <strong>Project -> Properties</strong> in the menu</li><br /><li>Click on the "<strong>C/C++ Build</strong>" item in the treeview</li><br /><li>Click the "<strong>Manage Configurations ...</strong>" button and create a new configuration named "LPC2478 Debug (Flash)" or something similar. Set it to active and click OK.</li><br /><li>In the "<strong>Builder Settings</strong>" tab, add the following settings:<br /><strong>Build Command: </strong>"msbuild.exe"<br /><strong>Build Directory</strong>: "${workspace_loc:/MicroFrameworkPK_v3_0/Solutions/LPC2478}"<br /><strong>Note</strong>: the folder name will change depending on what name you entered in the Solution Wizard</li><br /><li>In the "<strong>Behaviours</strong>" tab, check <strong>Build (Incremental Build)</strong> and add the following:<br />"dotNetMF.proj /t:build /p:flavor=debug;memory=flash;platform=LPC2478"<br /><strong>Note</strong>: This is different than Stefan's suggestions since I am using Flash and not RAM</li></ol><p><strong><span style="font-size:130%;">Configure OpenOCD as an External Tool</span></strong><br /></p><ol><li>Select the <strong>Run -> External Tools -> External Tool Configuration ... </strong>menu entry</li><br /><li>Select "Program" in the left-hand treeview and click the "<strong>New launch configuration</strong> icon in the top left corner", and name the new tool configuration "<strong>OpenOCD (ARM-USB-OCD)</strong>"</li><br /><li>On the <strong>Main</strong> tab add the following settings:<br /><strong>Location</strong>: C:\Program Files\openocd-r717\bin\openocd-ftd2xx.exe<br /><strong>Working Direction</strong>: C:\Program Files\openocd-r717\bin\<br /><strong>Arguments</strong>: -f scripts\lpc2294\lpc2xxx_armusbocd.cfg</li><br /><li>Go to the <strong>Common</strong> tab and in <strong>Display in favorites menu</strong> box, check "External Tools". This will add OpenOCD to your favorites menu where it can more easily be launched.</li><br /><li>If you want the project to build every time you launch OpenOCD go to the <strong>Build </strong>tab and check <strong>Build before launch</strong>.</li></ol><p><strong><span style="font-size:130%;">Configure GDB (GCC Debugger)</span></strong><br /></p><ol><li>Select the <strong>Run -> Debug Configurations </strong>menu</li><br /><li>Select <strong>"Zylin Embedded debug (Native)"</strong> in the left-hand treeview, and create a "<strong>New Launch Configuration"</strong> using the appropriate icon in the top left corner.</li><br /><li>Name it "<strong>LPC2478 NativeSample</strong>" or something similar</li><br /><li>In the <strong>Main </strong>tab, select the <strong>C/C++ Application</strong> textbox and enter:<br /><span style="font-family:courier new;font-size:85%;">E:\MicroFrameworkPK_v3_0\BuildOutput\ARM\GCC4.2\FLASH\debug\LPC2478\bin\NativeSample.axf</span><br /><strong>Note</strong>: This folder may change depending your how you have configured your build, and the name you gave your project in the Solution Wizard, etc.</li><br /><li>In the <strong>Debugger</strong> tab, set the GDB Debugger textbox to:<br /><span style="font-family:courier new;font-size:85%;">C:\Program Files\CodeSourcery\Sourcery G++ Lite\bin\arm-none-eabi-gdb.exe</span></li><br /><li>In the <strong>Commands</strong> tab, add the following the the <strong>'Initialize' commands</strong> box:<br /><span style="font-family:courier new;font-size:85%;">target remote 127.0.0.1:3333<br />monitor reset<br />monitor sleep 500<br />monitor poll<br />monitor soft_reset_halt<br />monitor arm7_9 force_hw_bkpts enable<br />break PreStackEntry<br />load<br />continue</span><br /><strong>NOTE:</strong> 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 <strong>force_hw_bkpts</strong> to <strong>sw_bkpts</strong>.</li></ol><strong><span style="font-size:130%;">Test it out</span></strong><br /><strong><span style="font-size:130%;"></span></strong><br />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).<br /><ol><li>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 <strong>Console</strong> 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.<br /><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSM5jEBMvMrGwIu1imq5g29nH_ybDive7yJQXE-2il3fcyM4D9Tw_nBwc1HNtkBYxBfD3DnsYJDpPE_pHAwIYg1ja_BZOMmqK0lO0LBeNX-eUBRjXM7XxKklKHnHvUDxMraJZIMhSbXYU/s1600-h/BuildIcon.jpg"><img id="BLOGGER_PHOTO_ID_5304825758095666354" style="WIDTH: 320px; CURSOR: hand; HEIGHT: 66px" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSM5jEBMvMrGwIu1imq5g29nH_ybDive7yJQXE-2il3fcyM4D9Tw_nBwc1HNtkBYxBfD3DnsYJDpPE_pHAwIYg1ja_BZOMmqK0lO0LBeNX-eUBRjXM7XxKklKHnHvUDxMraJZIMhSbXYU/s320/BuildIcon.jpg" border="0" /></a> </li><br /><br /><li>The the build above was succesful then ... pat yourself on the back, and Start OpenOCD using the External Tools Icon:<br /><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiq5AYlZdja2JI7yg98DAoVhAeOeTRwIc8IVk1P3MXEmRP5lbTND3k3jnKcEK-WqIh0iHtN_z4KFzMeH1QRnk2tp400pcl9lvUTEoMf40UBuMBEaiCnVmlmlCax0ItKMqRmWDQzo-_AI-U/s1600-h/OpenOCD.jpg"><img id="BLOGGER_PHOTO_ID_5304827441320105986" style="WIDTH: 320px; CURSOR: hand; HEIGHT: 129px" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiq5AYlZdja2JI7yg98DAoVhAeOeTRwIc8IVk1P3MXEmRP5lbTND3k3jnKcEK-WqIh0iHtN_z4KFzMeH1QRnk2tp400pcl9lvUTEoMf40UBuMBEaiCnVmlmlCax0ItKMqRmWDQzo-_AI-U/s320/OpenOCD.jpg" border="0" /></a></li><br /><br /><li>Finally, if OpenOCD is running, you can start debugging using the Debug Icon:<br /><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsLGrQp1wsUXRknnZ4yLkDdFy2JDy1JxVM9xH3j8-yhvWRdf0eWIFhF7SCFlQQFMF6svaMcgHKH3F0jGeENQSswnzbJSFl_WB-K7WyNGvtjgxRs0EifW_gowKh0ZLBEAvq0-_4Ehwdjh4/s1600-h/DebugIcon.jpg"><img id="BLOGGER_PHOTO_ID_5304827650105129426" style="WIDTH: 292px; CURSOR: hand; HEIGHT: 129px" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsLGrQp1wsUXRknnZ4yLkDdFy2JDy1JxVM9xH3j8-yhvWRdf0eWIFhF7SCFlQQFMF6svaMcgHKH3F0jGeENQSswnzbJSFl_WB-K7WyNGvtjgxRs0EifW_gowKh0ZLBEAvq0-_4Ehwdjh4/s320/DebugIcon.jpg" border="0" /></a></li><br /></ol><br /><p>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 ('<span style="font-family:courier new;font-size:85%;">scripts\lpc2294\lpc2xxx_armusbocd.cfg</span>' in this example) to adjust the <strong>jtag_speed</strong>, 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 <a href="http://discovertheexperience.blogspot.com/2008/11/how-to-use-eclipse-and-gdb-to-debug-net_09.html">Stefan's excellent blog entry</a>, should at least get you moving in the right direction, though.</p><p><span style="font-size:130%;"><strong>OpenOCD Config Script (Just in case)</strong></span></p><p>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): </p><pre><br /><span style="font-size:78%;">#daemon configuration<br /><br />telnet_port 4444<br /><br />gdb_port 3333<br /><br /><br /><br /># tell gdb our flash memory map<br /><br /># and enable flash programming<br /><br />gdb_memory_map enable<br /><br />gdb_flash_program enable<br /><br /><br /><br />#interface<br /><br />interface ft2232<br /><br />ft2232_device_desc "Olimex OpenOCD JTAG A"<br /><br />ft2232_layout "olimex-jtag"<br /><br />ft2232_vid_pid 0x15BA 0x0003<br /><br /><span style="color:#cc0000;">jtag_speed 9</span><br /><br /><span style="color:#cc0000;">jtag_nsrst_delay 200<br /><br />jtag_ntrst_delay 200</span><br /><br /><br /><br /><br /><br />#use combined on interfaces or targets that can't set TRST/SRST separately<br /><br />reset_config trst_and_srst srst_pulls_trst<br /><br /><br /><br />#jtag scan chain<br /><br />jtag_device 4 0x1 0xf 0xe<br /><br /><br /><br />#target configuration<br /><br />daemon_startup reset<br /><br /><br /><br />#target <type> <startup><br /><br />target arm7tdmi little run_and_halt 0 arm7tdmi-s_r4<br /><br />run_and_halt_time 0 30<br /><br /><br /><br />working_area 0 0x40000000 0x4000 nobackup<br /><br /><br /><br />#flash configuration<br /><br />#flash bank lpc2000 0x0 0x40000 0 0 0 lpc2000_v1 14765 calc_checksum<br /><br /><span style="color:#cc0000;">flash bank lpc2000 0x0 0x40000 0 0 0 lpc2000_v2 12000 calc_checksum</span><br /><br /><br /><br /># For more information about the configuration files, take a look at:<br /><br /># http://openfacts.berlios.de/index-en.phtml?title=Open+On-Chip+Debugger</span><br /><br /></pre><br />#<br/><br /><p><span style="font-size:130%;"><strong>And the Final Result ... </strong></span></p><p>Here is a screenshot of the debugging in action:</p><p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1IeQb8Ec9jJqn6nVtShRpBnO9taYdSBBv3IECMu3wVD1wxxGedyPek8GSZMc472NZNHG_yIN5hATR8DTUkgCS5FcqHH-SxsNPrKQ5kFXZJRXVz5h0rNsppl5r7A-yVGY8LlUsj2aQ9a0/s1600-h/DebugScreen.jpg"><img id="BLOGGER_PHOTO_ID_5304855651438720754" style="WIDTH: 320px; CURSOR: hand; HEIGHT: 195px" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1IeQb8Ec9jJqn6nVtShRpBnO9taYdSBBv3IECMu3wVD1wxxGedyPek8GSZMc472NZNHG_yIN5hATR8DTUkgCS5FcqHH-SxsNPrKQ5kFXZJRXVz5h0rNsppl5r7A-yVGY8LlUsj2aQ9a0/s320/DebugScreen.jpg" border="0" /></a><br /></p>Kevin Townsendhttp://www.blogger.com/profile/07530967701464128104noreply@blogger.com4tag:blogger.com,1999:blog-1177992492818685965.post-71451652552568009372009-02-07T11:59:00.001+01:002009-02-07T12:21:16.443+01:00Precompiled GCC Toolchains for the Porting KitI have been trying to get GCC to work with the .Net Micro Framework Porting Kit (PK), but unlike the commercial compilers that are supported for the PK (MDK, etc.), there are five dozen different ways to build a GCC/ARM toolchain.<br /><br />In <a href="http://discovertheexperience.blogspot.com/2008/11/net-micro-framework-porting-kit-v30.html">.NET Micro Framework Porting Kit V3.0 with GCC Support?</a>, Stefan Schmidt had suggested using <a href="http://www.raisonance.com/">Raisonance's</a> free ARM toolchain, since a none EABI compiler is required. I had downloaded it, and tried it out, but I also asked the NETMF support team which toolchain they are using internally, since it will likely make any support inquiries easier, and save me a headache as well. Apparently, they are using the (also free) <a href="http://www.codesourcery.com/gnu_toolchains/arm/portal/release316">Sourcery G++ Lite</a> toolchain from CodeSourcery. I opted to use the older Q3 2007 release (reference in the previous link), since the newer releases use GCC 4.3, whereas the porting kit was tested to work with 4.2.<br /><br />Once I can get the NativeSample project up and running, I'll post a tutorial on how to properly configure Sourcery G++ Lite with the PK.Kevin Townsendhttp://www.blogger.com/profile/07530967701464128104noreply@blogger.com2