{"id":167,"date":"2011-05-19T13:24:57","date_gmt":"2011-05-19T20:24:57","guid":{"rendered":"http:\/\/..\/?p=167"},"modified":"2011-05-19T13:24:57","modified_gmt":"2011-05-19T20:24:57","slug":"msp430-launchpad-and-c","status":"publish","type":"post","link":"https:\/\/blog.engine12.com\/?p=167","title":{"rendered":"MSP430 Launchpad and C++"},"content":{"rendered":"<p><a href=\"..\/wp-content\/uploads\/2011\/05\/IMG_8355.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignright size-medium wp-image-214\" src=\"..\/wp-content\/uploads\/2011\/05\/IMG_8355-300x180.jpg\" alt=\"\" width=\"300\" height=\"180\" srcset=\"https:\/\/blog.engine12.com\/wp-content\/uploads\/2011\/05\/IMG_8355-300x180.jpg 300w, https:\/\/blog.engine12.com\/wp-content\/uploads\/2011\/05\/IMG_8355-768x461.jpg 768w, https:\/\/blog.engine12.com\/wp-content\/uploads\/2011\/05\/IMG_8355.jpg 800w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a>I transformed a simple <a href=\"https:\/\/github.com\/Hack-a-Day\/had_launchpad-blink\/blob\/30c9b4c926ec2dbcca923e75b1345ceb7f16498b\/main.c\">helloworld<\/a> C program into <a href=\"http:\/\/engine12.com\/files\/hellomsp430\/main.cpp\">C++ classes<\/a>.\u00a0 I was able to match up one-to-one the C generated assembly to a C++ equivalent.\u00a0 In this example, the benefit of using C++ code is limited to namespaces.\u00a0 Hopefully you can see how the usage of C++ namespaces improves readability and assists in minimizing coding errors.\u00a0 Most of the C code projects end up becoming so sloppy and full of pitfalls.\u00a0 Using C++ allows your code base to be small and manageable across the spectrum of projects.\u00a0 The code and makefile for the project are located <a href=\"http:\/\/engine12.com\/files\/hellomsp430\/MSP430_CPP.tar.bz2\">here<\/a>.\u00a0 The project was compiled with the <a href=\"http:\/\/mspgcc4.sourceforge.net\/\">msp430gcc<\/a> toolchain on a Ubuntu host.<\/p>\n<h2>Setting Up<\/h2>\n<p>Instructions for building the msp430 gnu toolchain are at <a href=\"http:\/\/hackaday.com\/2010\/08\/11\/how-to-launchpad-programming-with-linux\/\">hackaday.com<\/a>.\u00a0 Many sites claimed to setup the <a href=\"http:\/\/www.ti.com\/launchpad\">Launchpad<\/a> for debugging with gdb and eclipse, but none worked for me.  I was able to set up debugging in eclipse as follows.\u00a0 If you don&#8217;t already have it, install the <a href=\"http:\/\/opensource.zylin.com\/embeddedcdt.html\">Zylin Embedded CDT<\/a> plugin.\u00a0 I have v14.15.1 installed in Galileo (Eclipse).\u00a0 It&#8217;s assumed that you have the drivers properly configured for mspdebug and that you can communicate with the Launchpad using the <a href=\"http:\/\/mspdebug.sourceforge.net\/download.html\">mspdebug<\/a> command line.<\/p>\n<p>Run-&gt; External Tools&#8211;&gt; External Tools Configuration<a href=\"..\/wp-content\/uploads\/2011\/05\/msp430_eclipse1.png\"><img decoding=\"async\" loading=\"lazy\" class=\"size-medium wp-image-188 alignleft\" src=\"..\/wp-content\/uploads\/2011\/05\/msp430_eclipse1-300x270.png\" alt=\"\" width=\"300\" height=\"270\" srcset=\"https:\/\/blog.engine12.com\/wp-content\/uploads\/2011\/05\/msp430_eclipse1-300x270.png 300w, https:\/\/blog.engine12.com\/wp-content\/uploads\/2011\/05\/msp430_eclipse1.png 719w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Select the &#8220;Program&#8221; in the tree control of the left pane and then click the icon for &#8220;New Launch Configuration&#8221;<\/p>\n<p>Fill in the dialog as shown.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"..\/wp-content\/uploads\/2011\/05\/msp430_eclipse_dbg.png\"><img decoding=\"async\" loading=\"lazy\" class=\"size-medium wp-image-187 alignright\" src=\"..\/wp-content\/uploads\/2011\/05\/msp430_eclipse_dbg-300x288.png\" alt=\"\" width=\"300\" height=\"288\" \/><\/a>Run-&gt;Debug Configurations<\/p>\n<p>Create a new configuration under the tree heading &#8211;&gt; Zylin Embedded Debug (Native)<\/p>\n<p>Fill in the &#8216;main&#8217; tab with the project name and point to the .elf of the application that you are going to debug.<\/p>\n<p>Fill in the &#8216;debugger&#8217; tab with the location of msp430-gdb.\u00a0 For me this was &#8220;\/opt\/msp430-gcc-4.4.5\/bin\/msp430-gdb&#8221;.\u00a0 The command line is empty.<\/p>\n<p>Fill in the &#8216;commands&#8217; tab with the following in the &#8216;initial&#8217; section and a &#8220;continue&#8221; in the &#8216;run&#8217; section:<\/p>\n<p style=\"padding-left: 30px\"><span style=\"color: #ff9900\">set remoteaddresssize 64<\/span><br \/>\n<span style=\"color: #ff9900\"> set remotetimeout 999999<\/span><br \/>\n<span style=\"color: #ff9900\"> target remote localhost:2000<\/span><\/p>\n<h2>Code Differences<\/h2>\n<p>So now you have a makefile for C++ projects and a couple of basic MSP430 objects.<\/p>\n<p>Notice the destructors are not virtual functions in the example code.\u00a0 It&#8217;s unlikely you&#8217;ll be deleting static objects, so you can eliminate a bunch of unneeded code by declaring them this way. Since they will never be called, more code space is saved by removing them entirely.\u00a0 My preferred solution would be editing the linker script and discarding the destructors section.<\/p>\n<p>I tried to get as close to the original C generated assembly as I could.\u00a0 This required some reworking of the <a href=\"http:\/\/engine12.com\/files\/hellomsp430\/CTimer.h\">timer header<\/a>.\u00a0 The functionality of the object is changed, but it&#8217;s a closer match to the original C code with only an 8 word difference.\u00a0 The startup assembly script would need modification to make the code match up entirely.\u00a0 Here are the listings for the generated assembly, <a href=\"http:\/\/engine12.com\/files\/hellomsp430\/C_version.lst\">C version<\/a> and <a href=\"http:\/\/engine12.com\/files\/hellomsp430\/C++_version.lst\">C++ version<\/a>.<\/p>\n<p>There is a great series on using the gnu tools for bare metal programming and C++ at <a href=\"http:\/\/www.eetimes.com\/design\/embedded\/4007119\/Building-Bare-Metal-ARM-Systems-with-GNU-Part-1--Getting-Started\">www.eetimes.com<\/a>.<\/p>\n<p>&nbsp;<\/p>\n<p>Links:<\/p>\n<p><a href=\"http:\/\/hackaday.com\/2010\/08\/11\/how-to-launchpad-programming-with-linux\/\">http:\/\/hackaday.com\/2010\/08\/11\/how-to-launchpad-programming-with-linux\/<\/a><\/p>\n<p><a href=\"https:\/\/github.com\/Hack-a-Day\/had_launchpad-blink\/blob\/30c9b4c926ec2dbcca923e75b1345ceb7f16498b\/main.c\">https:\/\/github.com\/Hack-a-Day\/had_launchpad-blink\/blob\/30c9b4c926ec2dbcca923e75b1345ceb7f16498b\/main.c<\/a><\/p>\n<p><a href=\"http:\/\/engine12.com\/files\/hellomsp430\/\">http:\/\/engine12.com\/files\/hellomsp430\/<\/a><\/p>\n<p><a href=\"http:\/\/mspgcc4.sourceforge.net\/\">http:\/\/mspgcc4.sourceforge.net\/<\/a><\/p>\n<p><a href=\"http:\/\/www.ti.com\/launchpad\">http:\/\/www.ti.com\/launchpad<\/a><\/p>\n<p><a href=\"http:\/\/www.eetimes.com\/design\/embedded\/4007119\/Building-Bare-Metal-ARM-Systems-with-GNU-Part-1--Getting-Started\">http:\/\/www.eetimes.com\/design\/embedded\/4007119\/Building-Bare-Metal-ARM-Systems-with-GNU-Part-1&#8211;Getting-Started<\/a><\/p>\n<p><a href=\"http:\/\/opensource.zylin.com\/embeddedcdt.html\">http:\/\/opensource.zylin.com\/embeddedcdt.html<\/a><\/p>\n<p><a href=\"http:\/\/mspdebug.sourceforge.net\/download.html\">http:\/\/mspdebug.sourceforge.net\/download.html<\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I transformed a simple helloworld C program into C++ classes.\u00a0 I was able to match up one-to-one the C generated assembly to a C++ equivalent.\u00a0 In this example, the benefit of using C++ code is limited to namespaces.\u00a0 Hopefully you can see how the usage of C++ namespaces improves readability and assists in minimizing coding <a href='https:\/\/blog.engine12.com\/?p=167'>[&#8230;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[10],"_links":{"self":[{"href":"https:\/\/blog.engine12.com\/index.php?rest_route=\/wp\/v2\/posts\/167"}],"collection":[{"href":"https:\/\/blog.engine12.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.engine12.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.engine12.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.engine12.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=167"}],"version-history":[{"count":0,"href":"https:\/\/blog.engine12.com\/index.php?rest_route=\/wp\/v2\/posts\/167\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.engine12.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=167"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.engine12.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=167"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.engine12.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=167"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}