A Step by Step Guide To MSP430 Programming under Linux

This is a guest post by one of our members, [A]lvaro. He’s been kind enough to offer step by step tutorial to setup a MSP430 toolchain. Although his work environment is Ubuntu, the described steps should make it easier for you to get going on other platforms. You can also download the pdf version of this tutorial.

[A]lvaro Aguilar is currently an undergraduate student at St. Mary’s University in San Antonio, TX, where he is  pursuing a double Bachelor’s in Physics and Electrical Engineering. His final year project is a robot based around the MSP430; this robot will be used by other students to explore the endless applications of microprocessors.

I put together this guide from various sources I found on the internet. It is meant to help a beginner set-up the Eclipse IDE to work with MSPGCC and be able to use it to debug and program MSP430 devices. This guide is just a compilation, so you may fi nd further insight into some of the steps by visiting the following sites:

1. MSPGCC Wiki
2. MSPGCC4 and MSPDEBUG
3. MSP430 Eclipse MSPGCC Ubuntu Tutorial
4. Eclipse IDE with MSPGCC

Before beginning with the installation, you have to make sure you have the following packages:
subversion,texinfo, patch, libncurses5-dev,zlibc,zlib1g-dev,libx11-dev,libusb-dev,libreadline6-dev

Now that the basics are covered, we will fi rst install and set up mspgcc. We will later tell Eclipse to use these tools in order to compile our C programs and output a code that the MSP430s can understand.
Keep in mind during the process the Eclipse is a general working environment, and we must tell it what to do with the files: what compiler to feed them to, and with what parameters.

MSPGCC
There are two option for this package. The older version is more robust, but needs additional installation of certain packages. Basically, you will need to install an older version of gcc because Ubuntu ships with v.4.x but you need v.3.x for the original MSPGCC. Additional information can be found at MPGCC Wiki The newer version, mspgcc4, is available for download as a pre-built package. I installed mspgcc version 4 by visiting the following website:

[sourcecode language="plain" light="1"]http://sourceforge.net/projects/mspgcc4/files/c[/sourcecode]

Extract its contents onto /opt/mspgcc and change its permissions using the following command:

[sourcecode language="bash" light="1"]sudo chown -R $USER.$USER /opt/mspgcc[/sourcecode]

In order to debug your device, you will additionally need “msp430-gdbproxy“. Run the following set of commands to get it along with its libraries:

[sourcecode language="bash" light="1"]cd /opt/mspgcc/bin
wget http://www.soft-switch.org/downloads/mspgcc/msp430-gdbproxy
chmod 777 msp430-gdbproxy
cd /usr/lib
sudo wget http://www.soft-switch.org/downloads/mspgcc/libHIL.so
sudo wget http://www.soft-switch.org/downloads/mspgcc/libMSP430.so[/sourcecode]

Now that we have mspgcc installed we must add the /opt/mspgcc/bin path to our environment so that we may call these functions from the command line. Edit the fi le /etc/environment and add the path at the end of the line. A reboot is needed in order for the change to take e ffect.

Finally, there is a small tweak needed in order to recognize the newer MSP430 devices. Running the command dmesg | tail after plugging in your device should reveal what is needed. If you see an error saying ti_download_ firmware – firmware not found, then you must perform the following step. You will need the firmware called ti_3410.fw, which can be found under /lib/firmware/ti 3410.fw. Run the following command in order to make it accessible:

[sourcecode language="bash" light="1"]ln -s /lib/firmware/ti_3410.fw /lib/firmware/ti_usb-3410.bin[/sourcecode]

Reconnecting the device and running dmesg | tail again should generate an output in which you see a line saying:

[sourcecode language="bash" light="1"]TI USB 3410 1 port adapter converter now attached to ttyUSB0[/sourcecode]

If you don’t see this, then you should change the confi guration value of the USB device. Attention: The USB device that you change will depend on your dmesg | tail output, and the device that is recognized (in my example it was 5-1). Become root before attempting to do this:

[sourcecode language="bash" light="1"]echo 2 > /sys/bus/usb/devices/5-1/bConfigurationValue[/sourcecode]

Since /dev/ttyUSB0 is owned by root.uucp, you should add your $USER to the uucp group. Replace $USER in the following command in order to add a di erent user to the group. Also, be sure to use the -a
flag in order to append the file to the group rather than overwriting its contents:

[sourcecode language="bash" light="1"]usermod -a -G uucp $USER[/sourcecode]

You may now start msp430-gdbproxy by trying the following command:

[sourcecode language="bash" light="1"]msp430-gdbproxy msp430 /dev/ttyUSB0[/sourcecode]

If all goes well the proxy should be initialized and ready to receive commands through port 2000. By the way, this is not the only way to communicate with your device. You may also download a tool called mspdebug. This one supports newer devices that might not be supported by the usual msp430-gdb (like the eZRF-2500). Check out this tutorial for info on how to set it up.
Now that MSPGCC is set-up, we can set up Eclipse in order to work with it.

Eclipse
You will need to install Eclipse and a few add-ons. Begin by installing eclipse from the command line:

[sourcecode language="bash" light="1"]sudo apt-get install eclipse[/sourcecode]

After the installation is done, fi re up eclipse. Go to Help : Install New Software. . .

You will want to install two software packages from the following locations:
1. CDT add-on (Choose the one for your version of Eclipse):
http://www.eclipse.org/cdt/downloads.php
2. Zylin Embedded CDT:
http://opensource.zylin.com/embeddedcdt.html

On those sites, you will nd the correct link to plug into the “Work with:” box in Eclipse Install New Software. When the installation is done, Eclipse will need to reboot for the changes to take eff ect.
After the restart, you will have to make a new C project. I created a regular project like this:

Click next and create a new project (I called mine led) as an Empty Executable:

Click fi nish and you will be greeted by the default C/C++ perspective under Eclipse. On the left side you will see the Project Explorer, where you will be able to visualize everything under your source code. For now, you can drag and drop the fash LED example in there. I got mine from the IAR Embedded Workbench installation on a Windows Machine, but you can download sample code from the TI website. This is what the screen should look like after opening up the source fi le:


Now that we have a project made, we need to specify the settings so that Eclipse may build this project using the MSPGCC compiler. Right-click on the project name and select Properties from the menu. Go to C/C++ Build and expand its contents to select Settings. Under the Tool Settings tab, you will nd settings for the Compiler, Linker and Assembler. First of all, open up a terminal and type the following command:

[sourcecode language="bash" light="1"]msp430-gcc –target-help[/sourcecode]

The output will show all the supported MCU names; keep the correct one for your device in mind. For example, my device is the MSP430F2013, and the correct MCU name was msp430x2013.
Back on the GCC C Compiler option inside Eclipse, specify the following command:

[sourcecode language="bash" light="1"]msp430-gcc -mmcu=msp430x2013[/sourcecode]

Of course, change to your specfi c MCU name from before.

In order to include header fi les, the compiler must know where to find them. Go to the Directories option under GCC C Compiler and specify the directories where you keep the header fi les for mspgcc. The default directory is /opt/mspgcc/msp430/include. In the end, I included the following directories.

[sourcecode language="bash" light="1"]/opt/mspgcc/msp430/include
/opt/mspgcc/include
/usr/include[/sourcecode]

Now we need to set up the GCC C Linker part in a similar manner. The command needs to be the same, so just copy and paste the same information into that fi eld. However, we must tell the linker where the libraries are, so under GCC C Linker, go to Libraries and include the following under “\Library search path (-L)“:

[sourcecode language="bash" light="1"]/opt/mspgcc/msp430/lib
/opt/mspgcc/lib
/usr/local/lib[/sourcecode]

Finally, the Assembler must be set-up correctly, so navigate down to it. This time, the command is di erent, so in the \Command” fi eld, enter the following: msp430-as. As usual, we must also tell this assembler where to fi nd the include files. Click on General and add the following paths to the “Include paths (-I)” box:

[sourcecode language="bash" light="1"]/opt/mspgcc/msp430/include
/opt/mspgcc/include[/sourcecode]

Now that our compiling tools are ready to be used, we need to tell Eclipse what type of fi le to create. Head over to the “Build Artifact” tab and type in “elf” under “Artifact Extension“. On the next tab over “Binary Parsers“, make sure that the Elf Parser is selected.

Compiling set-up is now fi nally done, so clicking OK should bring you to the main page. Try building the project by selecting Project : Build Project. If everything went well, you should have a succesful build. Otherwise, check the console and correct the issues presented.

Now that we have a working executable, we want to debug it. I used msp430-gdbproxy along with msp430-gdb in order to achieve this. You can also use mspdebug by itself to do this step, and the set-up is similar so you may use this guide to set it up under Eclipse as well. The proxy part is just a proxy that forwards the commands from msp430-gdb to the actual MSP430 device connected to your computer. Therefore the fi rst thing we will do is set-up Eclipse to run the proxy before anything else. Head over to Run : External Tools : External Tools Confi gurations. . . . Create a new con figuration and set it up like this. You should take a quick read at the man page of msp430-gdbproxy before con guring the parameters in order to ensure you got the right device. The arguments I passed where msp430 (type of device) and then the port at which it was attached (this should be known from the previously issued command dmesg | tail).

As you can see, I also other tools available. Namely, msp430-gdbproxy running under wine. Find a great tutorial for this here. Additionally, I also have a tool for running mspdebug. The following is a screenshot with the parameters that worked for me. However, you should read the man page for that command in order to make sure everything is set-up for your device.

Now that the proxy is set-up, try running it and observe the console output. It should include certain information about your device and end with the line “Listening on port 2000” or so. Once that is ready to go, we can set up msp430-gdb to work as the debugger from inside Eclipse. In order to do this, we need to open the Project Properties again. Therefore right-click on the project name, and select Properties from the drop-down menu. Under Run/Debug Settings, select New. . . and then click OK. Under the “Main” tab ensured that the correct names are given for the Project and for the Executable created during compilation. Now head to the “Debugger” tab and select remote gdb/mi from the “Debugger” drop-down list. Type in msp430-gdb on the “GDB Debugger” line. Go to the “Gdbserver Settings
tab and select the port that msp430-gdbproxy is listening on; the default is 2000 along with 127.0.0.1 for the server name.

Finally, create a le in your home directory called .gdbinit. Inside of this fi le, place the following lines:

[sourcecode language="bash"]set remoteaddresssize 64
set remotetimeout 999999
target remote localhost:2000[/sourcecode]

Conclusion
Once again, this guide is merely a compilation of di erent articles found online. If you have questions regarding the procedures, or errors along the way, be sure to check out the following websites:
1. MSPGCC Wiki
2. MSPGCC4 and MSPDEBUG
3. MSP430 Eclipse MSPGCC Ubuntu Tutorial
4. Eclipse IDE with MSPGCC

Please feel free to ask any questions in the comments below.

31 Comments

  1. very nicely done. although i am not an eclipse fan, i can see one can benefit a lot working in an IDE environment.

    Reply
  2. I _am_ an Eclipse fan, and I have been wanting a tutorial like this for a long time! Where do I find it? On my favorite site!

    I’m trying to use Linux more in all I do, so this is a great step. Thank you Alvaro!

    Reply
    • I’m glad you guys find benefit in it! If you got any questions along the way don’t hesitate to ask, I know I got lost when trying to do it the first time.
      Good luck and I hope this is of good use for all of you (could be somewhat followed, at least to set up Eclipse, under Windows as well)

      Reply
      • thanks for the tutorial, but I have a little problem I am using a virtual machine and it will not let me extract mspgcc4 documents to the folder opt achievement nor copy the extracted folder you could assist me with this problem
        thanks

        Reply
  3. echo 2 > /sys/bus/usb/devices/5-1/bConfigurationValue

    On that line (when you are setting up the TI3410 USB driver), make sure it looks like this rather:

    echo 2 > /sys/bus/usb/devices/5-1/bConfigurationValue

    NOTE: this step might not be necessary if the driver is already recognized on your computer…

    Reply
    • Is there a difference between the two lines… let me know if I need to correct it.

      Reply
      • My bad, on the online version it looks like

        echo 2 & gt; /sys/bus/usb/devices/5-1/bConfigurationValue

        ( without the space between & gt; ) When I copied that into this box it got correctly interpreted as the ‘>’ sign.

        Reply
        • Fixed.

          Reply
  4. Hi Alvaro,

    First off, I would like to thank you for compiling this up-to-date tutorial on setting up an MSP430 programming and debugging interface on Linux using Eclipse as an IDE. A few months ago I attempted to install everything but sort of gave up as I couldn’t find a centralized source of information that would tell you everything from beginning to end.

    In any case, I am attempting to set up an interface to program the msp-fet430uif using mspdebug. I got through a lot of your tutorial with success. I can build the project, and run the mspdebug proxy (both in Eclipse and on the terminal).

    ——————————–
    MSPDebug version 0.13 – debugging tool for MSP430 MCUs
    Copyright (C) 2009, 2010 Daniel Beer
    This is free software; see the source for copying conditions. There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

    Trying to open UIF on /dev/ttyUSB0…
    Initializing FET…
    FET protocol version is 20404000
    Configured for JTAG (2)
    Set Vcc: 3000 mV
    fet: FET returned error code 4 (Could not find device (or device not supported))
    fet: command C_IDENT1 failed
    fet: identify failed
    Trying again…
    Initializing FET…
    FET protocol version is 20404000
    Configured for JTAG (2)
    Sending reset…
    Set Vcc: 3000 mV
    Device ID: 0xf16c
    Device: MSP430F1611
    Code memory starts at 0×4000
    Number of breakpoints: 8

    Available commands:
    = dis help locka prog run sym
    break erase hexout md read set
    cgraph exit isearch mw regs setbreak
    delbreak gdb load opt reset step

    Available options:
    color gdb_loop iradix quiet

    Type “help ” for more information.
    Press Ctrl+D to quit.

    (mspdebug)
    ——————————–

    However, I run into problems when trying to go to debug mode (you know where I can single step, set breakpoints, etc). I combined your tutorial with the FAQ from the mspdebug website: http://mspdebug.sourceforge.net/faq.html#eclipse

    I run into errors in connecting to the device. Below, notice the “Connection timed out” and “no symbol ‘download’”:

    ——————————–
    set remoteaddresssize 64
    set remotetimeout 999999
    target remote localhost:2000
    localhost:2000: Connection timed out.
    set download-write-size 2000
    No symbol “download” in current context.
    set remote memory-write-packet-size 2000
    set remote memory-write-packet-size fixed
    set remote memory-read-packet-size 2000
    set remote memory-read-packet-size fixed
    ——————————–

    I would appreciate any help you can provide.

    Thanks,

    Mehdi

    Reply
      • Hello,

        Thanks for the quick reply. I did not see this post before, so I just tried it. Still no success, but here are my results:

        command: mspdebug uif -j -d /dev/ttyUSB0 gdb

        —————————
        MSPDebug version 0.13 – debugging tool for MSP430 MCUs
        Copyright (C) 2009, 2010 Daniel Beer
        This is free software; see the source for copying conditions. There is NO
        warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

        Trying to open UIF on /dev/ttyUSB0…
        Initializing FET…
        FET protocol version is 20404000
        Configured for JTAG (2)
        Set Vcc: 3000 mV
        fet: FET returned error code 4 (Could not find device (or device not supported))
        fet: command C_IDENT1 failed
        fet: identify failed
        Trying again…
        Initializing FET…
        FET protocol version is 20404000
        Configured for JTAG (2)
        Sending reset…
        Set Vcc: 3000 mV
        Device ID: 0xf16c
        Device: MSP430F1611
        Code memory starts at 0×4000
        Number of breakpoints: 8
        Bound to port 2000. Now waiting for connection…
        —————————

        Then I run the debug config from within eclipse, and the terminal updates to:
        —————-
        Client connected from 127.0.0.1:52225
        Clearing all breakpoints…
        Reading 2 bytes from 0xffff
        Connection closed
        —————-

        On eclipse, I get the same thing as before:

        —————-
        set remoteaddresssize 64
        set remotetimeout 999999
        target remote localhost:2000
        localhost:2000: Connection timed out.
        set download-write-size 2000
        No symbol “download” in current context.
        set remote memory-write-packet-size 2000
        set remote memory-write-packet-size fixed
        set remote memory-read-packet-size 2000
        set remote memory-read-packet-size fixed
        —————-

        Any ideas?

        Thanks,

        Mehdi

        Reply
        • Hello Medhi,

          This _is_ a late reply and you may have solved it by now. But reading the output from mspdebug I believe the problem sits in the hardware circuit between the FET and the target. The target JTAG does not come up properly. You _are_ using the MSP430FET USB module? And the target is in full JTAG, not spy-bi-wire?

          Reply
    • Hi Mehdi,
      Are you compiling with the -g flag on.

      Looks like you got no symbols:
      “No symbol “download” in current context.”

      Also, I would suggest moving this to the forums, as it gets a bit cramped.

      Reply
  5. is there some way that I can save this page to my PC ?
    Thanks

    Reply
  6. Hi Alvaro, thank you very much because it has been a really interesting post and has helped a lot.

    I have one question: I am using the cc430f5137 and apparently it is not supported by the msp430-gdbproxy, it appears:

    debug: MSP430_Initialize()
    error: msp430: Could not initialize device interface (1)
    debug: MSP430_Initialize()
    error: msp430: The FET tool version does not match this program. Update required.

    Do you know how could I update the tool?

    Really appreciate any help.

    Reply
    • Hey Juan,

      Unfortunately I have switched to Windows due to my job. I haven’t played with mspdebug for around a year, but I know there have been issues with newer devices (i.e. ez-RF2500, TI Launchapd) and mspdebug… Check the forums out and ask around, lots of helpful people there.

      Sorry I can’t be of further help…
      Alvaro

      Reply
  7. Great tutorial. Should the last package on the list of the packages you should have installed (beginning) be “libreadline6-dev” instead of “ibreadline6-dev” ?

    Reply
  8. Can msp430gcc+IDE be used together with msp430 FET programmer/debugger?

    Reply
  9. I actually found that Eclipse is a bit cumbersome and dealing with all the settings for the toolchain is quite a pain in eclipse. Don’t get me wrong, Eclipse is a really good IDE, I am using it every day. But .. sincerely one day (and that relatively recent like few months ago) I got feed up with Eclipse because it was not doing code completion properly and I tested to Netbeans 7.0.1 for C/C++. Setting up the toolchain is a breeze, autocomplete actually works, you have the clean option of using your own Makefile (Eclipse allows that too but not as nice as Netbeans) etc. Small annoyances that made me look for something else. So all in all, Netebeans is not bad, I can even debug remotely much more easier, have a make target that burns the image directly on the board etc.

    I am an Linux user (ubuntu)1 and I write code for ARM, AVR and MSP430 … all toolchains are set up in the same netbeans install, everything is a breeze.

    Again, not bashing eclipse in any way. I used the eclipse so much that I have netbeans set to use all Eclipse keyboard shortcuts :) … Have a look @ netbeans 7 for C .. is not bad at all.

    Reply
    • Thanks for the feedback on Netbeans. Are you able to hook up gdb to Netbeans and debug? If you could send a few screenshots of the setup, we’ll be glad to put it in a blog post. Just used the “Contact Us” link on the top of the page.

      Reply
  10. Installing CDT fails:
    “Cannot complete the install because one or more required items could not be found.
    Software being installed: Target Communication Framework (Incubation) 0.4.0.201106081058 (org.eclipse.tm.tcf.feature.feature.group 0.4.0.201106081058)”

    Eclipse Platform
    Version: 3.7.0
    Build id: I20110613-1736

    No luck (skills) with bare mspgcc, now failing with eclipse too.

    I guess this is a sign… ;(

    Reply
  11. I’ve been trying to get eclipse working with msp430-gcc and mspdebug / msp430-gdb. It’s nearly there – I can build a project, and I can start and stop the code in the debugger, and set breakpoints.

    The only problems are:
    – some symbols get flagged as unrecognised by the IDE, even though the program seems to build, load and run OK. These are symbols like WDTCTL which are defined in the cpu specific header file.
    – the debugger isn’t reading variable values properly. The variables appear in the watch list, but don’t have the values you’d expect.

    Have you any thoughts on why this might be happening?

    Thanks,

    andy baxter

    Reply
    • Setting up Eclipse using the steps above led me to one of the problems reported by Andrew, where while debugging, the values of the stack variables were reported incorrectly.

      The issue appears to be with the optimization flag -O0. When I switch this flag to -Os, the stack variables are reported properly.

      To change the flag:
      - right-click on project
      - click “properties”
      - select “C/C++ Build” > “Settings” > “Tool Settings” > “GCC C Compiler” > “Optimization”
      - For “Optimization Level”, select “Optimize for Size (-Os)”

      Reply
      • Thanks Jean!

        Reply
      • this saved me many hours i’m sure! thanks!

        Reply
  12. Merci pour ces trucs très utiles je cherchais ca.

    Reply
  13. Hi all,
    I am trying to find a library for Bluetooth for Eclipse, can you please let me know if you know of any?

    Thanks,

    Wilmar

    Reply
  14. We’re a bunch of volunteers and opening a brand new scheme in our community.
    Your site provided us with useful information to work on.
    You’ve done a formidable task and our entire group can be grateful
    to you.

    Reply
  15. I am running ubuntu 13.04 64 bit with msp430-gcc

    For some reason the linking stage doesn’t work if the following is executed

    msp430-gcc –mmcu=msp430g2553 -Wl,-Map=led.map -L/usr/msp430/lib/ ./led.o -o led.elf

    I get an error

    /usr/lib/gcc/msp430/4.6.3/../../../../msp430/bin/ld: cannot open linker script file memory.x: No such file or directory

    As a work around I gave the exact location of the memory.x like this

    msp430-gcc –mmcu=msp430g2553 -Wl,-Map=led.map -L/usr/msp430/lib/ldscripts/msp430g2553/ ./led.o -o led.elf

    This works.

    This is not an eclipse specific issue, the linking stage fails even when I run it on command line using the first syntax and works only if the second syntax is used.

    Can any one throw some light on why the first syntax is not working.

    Reply
    • Hello Krishna, make sure you ask this question in the forum.

      Reply

Trackbacks/Pingbacks

  1. Một tutorial hay về mspgcc và Eclipse trên Linux « Embedded Networks - [...] Tình cờ tải được từ đây. [...]
  2. Một tutorial hay về mspgcc với Eclipse « Embedded Networks - [...] Tình cờ tải được từ đây. [...]
  3. Launchpad on Ubuntu – Setup « blahblahcoolstuffblah - [...] I think I’ll learn more as a result. If you feel like using eclipse then 43oh offers a step …
  4. Bits By The Pound » Setup development environment for EZ430-F2013 using Eclipse in Ubuntu - [...] A Step by Step Guide To MSP430 Programming under Linux [...]

Submit a Comment

Your email address will not be published. Required fields are marked *


two + = 7

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


Join the best MSP430 blog on the net and stay up-to-date with our latest news, projects and design resources. We will not share your info with anyone.