How-to: Launchpad programming with Linux

When TI released their Launchpad development board at the end of June it generated a lot of Buzz. Here’s a package that delivered a programmer, debugger, two microcontrollers, and some accessories for less than five bucks (including shipping). They even provided a choice of two software suites but only for users running Windows who don’t mind proprietary software. If you’re looking to go another way you should consider trying out the open source alternative MSPGCC. After the break we’ll take a look at getting the tool-chain up and running in a Linux environment.

We’ll be working with Ubuntu 10.04 Lucid Lynx. When the Launchpad is connected to USB it is identified and mounted to /dev/ttyACM0. It’s not immediately apparent how to use the device but fortunately it can be done. To talk to the hardware for programming and debugging we’ll need to use MSPDebugger. For compiling our code we’ll be using the MSPGCC open source compiler package.

Compiling and Installing MSPGCC

The first thing we’ll need to do is satisfy our build dependencies.

sudo apt-get install subversion gcc-4.4 texinfo patch \
libncurses5-dev zlibc zlib1g-dev libx11-dev libusb-dev \
libreadline6-dev

Now we’ll checkout the source code from the subversion repository:

svn checkout https://mspgcc4.svn.sourceforge.net/svnroot/mspgcc4

Next we enter the directory and start compiling:

cd mspgcc4
sudo sh buildgcc.sh

This will take some time so go read some posts and come back in 20-45 minutes.

To add the tools we just installed to the path, we need to edit the /etc/profile file:

sudo nano /etc/profile

Add this line to the end of the file (CTRL-X to exit once you’re done):

export PATH=${PATH}:/opt/msp430-gcc-4.4.3/bin

Now reload the profile you just edited for this to take effect:

source /etc/profile

Great, now you have the tools necessary to compile your C code into an .elf file that the microprocessor will understand. Next we’ll need a way to get that file onto the chip.

Compiling MSPDebug

We’ll use the MSPDebug instructions for downloading and compiling. First you need to go to the download page and get the latest version. We downloaded version 0.9 and will use that in the filename for the following commands. Now go to the directory where you saved that download and unpack the archive, compile, and install the package using the following set of commands:

tar xvfz mspdebug-0.9.tar.gz
cd mspdebug-0.9
make
sudo make install

That should take just a few seconds and it’s the last of the tools that we need. Next we can use our new software to connect with the device.

The code

It’s best to try out some proven code the first time around. Download our simple code package to test out the compiler and use the debugger for programming. This is much simpler than the temperature demo found on Ramblings and Broken Code be we are using their Makefile and once you’re comfortable with the process there’s a lot of great code examples in that package.

Unpack the code, open a terminal window, and navigate to the directory where the files are located. Compile the file by typing:

make

If that went well, great. If you get an error like “msp430-gcc: command not found” there’s something wrong with your path to the MSPGCC tools.

Connecting to the chip

MSPDebug is what we use to connect to the chip. The following command will most likely NOT work for you:

mspdebug rf2500

Spitting out the error message:

Trying to open interface 1 on 033
rf2500: warning: can't detach kernel driver: Operation not permitted
rf2500: can't claim interface: Operation not permitted
rf2500: failed to open RF2500 device

This is most likely caused by a permission problem. This will work if you add ‘sudo’ to the beginning but that’s not ideal. Let’s add a UDEV rule to take care of the Launchpad every time we plug it in. We need to create a rule file that has this line of code in it:

ATTRS{idVendor}=="0451", ATTRS{idProduct}=="f432", MODE="0660", GROUP="plugdev"

Use nano to open and edit this file. Press CTRL-X to exit when you’re finished, then reload UDEV:

sudo nano /etc/udev/rules.d/46-TI_launchpad.rules

sudo restart udev

*** If you need more help with this, take a look at our guide to writing udev rules ***

Unplug the Launchpad and plug it back in. Make sure you’re in the same directory as the ‘main.elf’ file created by the compiler earlier. Now give MSPDebug another try:

mspdebug rf2500

Now you will be greeted with the (mspdebug) prompt. It’s just a matter of programming the chip and running that program:

prog main.elf
run

Both LEDs will start blinking at about 1 Hz. Congratulations, you’ve compiled and loaded a program using open source tools.

A look into how the code works:

Let’s take a quick look into how this simple program works in an effort to get you comfortable with learning to code with MSPGCC. The keywords used in the code are defined in the include files from MSPGCC. You need to spend some time in the /opt/msp430-gcc-4.4.3/msp430/include/msp430 directory until you get used to the keywords. Once you get the hang of it you can probably guess new keywords based on what you read in the datasheets for the microprocessors.

Our code blinks two LEDs. Blinking means we need to use some method of tracking time. First let’s investigate the system clock:

Download a copy of the MSP430x2xx family datasheet (we’re using Rev. E) and follow along. This is a more useful document than the chip-specific datasheet as it lists the operating information for all of the peripherals.

Review the various system clock features in Section 5.1 paying attention to LFXT1CLK, VLOCLK, and ACLK. Next read Section 5.2 on page 289 which tells us that after power-up the system clock will be running at 1.1 MHz. If we used the system clock for timing we’re going to have trouble counting high enough with a 16-bit timer for a meaningful delay. Be we can use the auxiliary clock instead. The same page of the datasheet tells us that the ACLK is sourced from LFXT1CLK (an external crystal or clock source) but let’s change that. The VLOCLK can be used as a source for the auxiliary clock and it runs at 12 kHz, so 1-second timing is well within the range of a 16-bit counter. Let’s set up the clock source. Section 5.2.2 clearly tells us “VLOCLK source is selected by setting LFXT1Sx = 10 when XTS = 0.”. Now we just check the register description until we find that LFXT1S is set on register BCSCTL3 and then write code to implement this setting:

BCSCTL3 |= LFXT1S_2;

Next we want to set up an interrupt based on the auxiliary clock. In Section 12 you can read about TimerA. We’ll configure it to run in UP mode. On page 410 the configuration of the timer control register TACTL is covered. We need TASSELx to be set to use ACLK and MCx configured for UP mode. Notice that the settings for each portion of the register are listed in binary next to the description. We can use these to select the proper bits. Setting the MC bits to 1 (binary 01) and TASSEL bits to 1 (binary 01) with the following code:

TACTL |= TASSEL_1 | MC_1;

Now we must enable the capture/compare interrupt for TimerA compare/capture register 0:

TACCTL0 = CCIE;

Now we can start the timer by writing a value to it. Because we are using the internal very low oscillator at 12 kHz, we can count up to 11999 to keep track of about 1 second passing (0 is counted and that’s why we set the compare match for one cycle less than the clock speed):

TACCR0 = 12000;

And finally we enable global interrupts:

eint();

Now we just need some code in an Interrupt Service Routine that will toggle the LEDs:

interrupt(TIMERA0_VECTOR) TIMERA0_ISR(void) {
  LED_OUT ^= (LED0 + LED1);	//Toggle both LEDs
}

We pulled all of this together to make the example file. Take some to trying to understand what the datasheet is telling you. Although they can be confusing, everything you need to know is there.

Resources:

Comments

  1. Alan says:

    @augre

    I’m assuming from the compiler output that you’re compiling the example when you get those messages.

    It looks like you’ve got the /etc/profile file wrong, or you typed in a differrent install directory when compiling mspgcc, but then I can’t see how make managed to invoke the conpiler.

    You are typing `make` and not `gcc main.c` right?

    Can we see what you typed and the English output please?

  2. augre says:

    Thank you for you response.
    I did the all steps of the howto:
    sudo apt-get install subversion gcc-4.4 texinfo patch \
    libncurses5-dev zlibc zlib1g-dev libx11-dev libusb-dev \
    libreadline6-dev
    svn checkout https://mspgcc4.svn.sourceforge.net/svnroot/mspgcccd mspgcc4
    sudo sh buildgcc.sh
    sudo nano /etc/profile
    Added this line to end:
    export PATH=${PATH}:/opt/msp430-gcc-4.4.3/bin
    and then:
    source /etc/profile

    than:
    augre@lilian:~/Letöltések/Hack-a-Day-had_launchpad-blink-30c9b4c$ make
    msp430-gcc -Os -Wall -g -mmcu=msp430x2012 -c main.c
    main.c:31:16: error: io.h: Nincs ilyen fájl vagy könyvtár means: There is no file or directory
    main.c:32:20: error: signal.h: Nincs ilyen fájl vagy könyvtár means: There is no file or directory
    main.c: In function ‘initLEDs’:
    main.c:42: error: ‘P1DIR’ undeclared (first use in this function)
    main.c:42: error: (Each undeclared identifier is reported only once
    main.c:42: error: for each function it appears in.)
    main.c:42: error: ‘BIT0’ undeclared (first use in this function)
    main.c:42: error: ‘BIT6’ undeclared (first use in this function)
    .
    .

    Thank you!

  3. augre says:

    My /etc/profile looks like:
    # /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
    # and Bourne compatible shells (bash(1), ksh(1), ash(1), …).

    if [ -d /etc/profile.d ]; then
    for i in /etc/profile.d/*.sh; do
    if [ -r $i ]; then
    . $i
    fi
    done
    unset i
    fi

    if [ "$PS1" ]; then
    if [ "$BASH" ]; then
    PS1=’\u@\h:\w\$ ‘
    if [ -f /etc/bash.bashrc ]; then
    . /etc/bash.bashrc
    fi
    else
    if [ "`id -u`" -eq 0 ]; then
    PS1=’# ‘
    else
    PS1=’$ ‘
    fi
    fi
    fi

    umask 022
    export PATH=${PATH}:/opt/msp430-gcc-4.4.3/bin

    In Ubuntu 10.10

  4. Alan says:

    The compiler is found and excecuted, so the path is probably ok, can you do `echo $PATH` ?

    Also, what’s in /opt/msp430-gcc-4.4.3/msp430/include ?

  5. augre says:

    augre@lilian:~$ echo $PATH
    /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/opt/msp430-gcc-4.4.3/bin:/opt/msp430-gcc-4.4.3/bin

    in my /opt/msp430-gcc-4.4.3/msp430/ there isn’t include:
    augre@lilian:/opt/msp430-gcc-4.4.3/msp430$ ls
    bin lib
    this is empty:
    augre@lilian:/opt/msp430-gcc-4.4.3/include$

    I don’t know why are these empty.
    do you have idea?

  6. Alan says:

    That would be why it’s not working, try downloading (check out), building and installing mspgcc again.

  7. augre says:

    I installed msp430-gcc-4.4.5 and it works fine!
    Thank you!

  8. Anonymous says:

    >>Drone – 10:05 pm on Aug 11th, 2010 by Drone

    Troll! “Until I turn on Linux and shit gold nuggets I’ll never use it I’ll have to use winblows” … back to your cave.

  9. Smiffy says:

    Thanks guys, followed your guide, It Just Worked. Not having to run IAR or CCS in a Windows VM makes me a happy bunny. Especially since I don’t like IDEs anyway. gcc FTW.

  10. Smiffy says:

    Re above – that was on Debian Lenny, BTW.

  11. suddenly feels like a noob says:

    I was able to compile source once. now when i type in ‘make’ all i get is this

    joey@pillaged-computer:~/launchpad stuff/demo program$ make
    msp430-gcc -Os -Wall -g -mmcu=msp430x2012 -c main.c
    make: msp430-gcc: Command not found
    make: *** [main.o] Error 127

    Any help?

  12. Smiffy says:

    Assuming you haven’t removed msp430-gcc by mistake, I would say that the problem is that it simply isn’t in your PATH.

    What you need to do is find where msp430-gcc is, then either add it to your PATH in .bashrc (or .profile depending on what shell you are using) or just change your makefile so that:

    CC=/full/path/to/msp430-gcc

    In my case, it’s here:

    /opt/msp430-gcc-4.4.3/bin/msp430-gcc

    Hope this helps.

  13. suddenly feels like a noob says:

    worked like a charm. thanks

  14. Takide says:

    @Smiffy I’m having the same problem as “suddenly feels like a noob” but I don’t understand what I’m supposed to do. Any help?
    reply soon!
    -Takide

  15. Alan says:

    @Takide

    Run these commands and post the output:
    which msp430-gcc
    find /opt -name “msp430-gcc”
    echo $PATH

  16. Takide says:

    nm I fixed it. but i made a program with the __delay_cycles() function in it and when i compiled it I got this error: undefined reference to `__delay_cycles’

  17. Randy Young says:

    Don’t give up on the serial port emulation of LP on linux until you try and connect through an external hub. Would not work on USB connect on mother board!

    I’m using the Python temperature recording app mentioned in the excellent article…

  18. tekstop says:

    Great tutorial! I got it working in Ubuntu 11. Thanks!

  19. dboy_mi says:

    Hi. I used your tutorial to get my launchpad up and running. All’s well while using the terminal but while trying to hook it up with eclipse [following this tutorial http://www.43oh.com/wp-content/uploads/2010/11/MSP430_MSPGCC_Eclipse_gdb.pdf ] I get an “error: MCU msp430x2231 not supported
    Known MCU names:”
    Is there anything I can modify in order for it to work? Consider me as an almost absolute beginner in Linux[ubuntu,puppylinux].

    Great work on the whole site.

  20. Victor says:

    Great! I got it working in Linux mint 10, no need to change udev rules.

  21. Paolinz says:

    Hi guys,
    I have a question: I programmed my msp430G2231 with the code posted. Then I try to program it with another code written by me but it didn’t work. So I try to reprogram with the code posted. But now both LED don’t blink and stay on all the time.
    What can be my problem?
    Have i burned my msp430?

  22. Cyberman says:

    The WASP script no longer works for mspgcc building it breaks in a number of points, it is also no longer maintained.

    The first point is versions have changed (insight 6.8-1 no longer exists for example and is now insight 6.8-1a but extracts to insight_6.8-1). Small things like this break the script and there are QUITE a few.

    There are more than just a handful of patches since the July version also (looks to be about 17). They are small etc. however they add up. Doing this manually is quite laborious I’ve found (lOL) I use to do linux kernel patching, but THAT was easier since I didn’t have 8 different source trees to patch (bintools insight etc etc).

    So what is recommended these days to build the launchpad chain under linux?

  23. Andy Piper says:

    This is currently being pointed to as a good source of how to get running with Launchpad on Linux from the TI wiki.

    I can’t get this to work on Ubuntu 11.04 – binutils availble version has changed, I edited make scripts to get a “good” one, patching then failed… gave up and grabbed a binary msp430 gcc from another link on the Contiki site. I can now compile some basic code but nothing which sources msp430* header files. Bit of a mess. I’m afraid Arduino is a far nicer initial experience on Linux.

  24. jg says:

    Fails when looking for insight-6.8-1 and gdb-7.0.1
    The ftp sites only have “a” versions of those bz2’s.
    Solution is to do the following before running the “sudo sh buildgcc.sh” command:

    First comment out 3 lines in mspgcc4/do-gdb.sh
    # wget -c “$PKG_SRC_URL” -O “$PKG_NAME-$PKG_V …
    # echo “Unpacking $PKG_NAME…”
    # tar xjf “$PKG_NAME-$PKG_VERSION.tar.bz2″

    Then download these files by hand and “tar xjf” them in the mspgcc4/build directory before running the “sudo sh buildgcc.sh” command:

    http://gd.tuwien.ac.at/gnu/sourceware/insight/releases//insight-6.8-1a.tar.bz2

    http://ftp.uni-kl.de/pub/gnu/gdb/gdb-7.0.1a.tar.bz2

    Worked for me on Ubuntu 10.10

  25. Drew says:

    I know this post has been dead for a while, but I have a question.

    After trying to make the test code, I hit the issue mentioned in the text:
    ” If you get an error like “msp430-gcc: command not found” there’s something wrong with your path to the MSPGCC tools.”

    I’m stumped on how to fix this. Any insight?

  26. Fritzchen Paulchen says:

    OS: openSUSE 11.3
    Kernel: 2.6.34.10-0.4-desktop

    Hi there, I have some problems with the installation of mspdebug-0.18. When I have unpacked the archive and want to compile with make, it prints me the following error.

    cc -DUSE_READLINE -O1 -Wall -Wno-char-subscripts -ggdb -I. -Isimio -Iformats -Idrivers -Iutil -Iui -DLIB_DIR=\"/usr/local/lib/\" -o util/usbutil.o -c util/usbutil.c
    In file included from util/usbutil.c:22:0:
    util/usbutil.h:22:17: fatal error: usb.h: Datei oder Verzeichnis nicht gefunden
    compilation terminated.
    make: *** [util/usbutil.o] Fehler 1

    So I have tried to install libusb-dev but there is no package under openSuse called this way. There was just libusb-1_0-devel which I have installed when the error occured.

    So please could someone help me out with that openSuse beside some comments like “Go and get some real distribution” ;)

  27. yamaplos says:

    Kenneth, sorry, rt*m is not working for me :-(

    I have spent the last hour trying to overcome
    main.c:17:16: error: io.h: No such file or directory
    main.c:18:20: error: signal.h: No such file or directory
    I did find the avr/include directory, even copied those files to the blink directory…

    with no success. Surprisingly, despite a bout of “msp430-gcc: command not found” which I solved by setting a path, everything else in these directions seems OK – mspdebug rf2500 is responding, run, reset, dis… all OK

    thanks!

  28. Alex says:

    Thanks Thanks Thanks !!!

  29. I think there’s a mistake in the way the udev rule is displayed, on my browser at least (Chrome 16.0)

    It is showing the double quote characters as ‘"’ instead of the actual character.

  30. Jim Kemp says:

    These instructions still work like a charm. So much easier than the super complex CCS toolchain – their latest version is a 1.2GB download. Plus, MSPGCC has no code size limits, I love that.

    Thanks again.

  31. dibin says:

    when u build the script it asks for enter choices can you specify what option should i enter

  32. gabe says:

    NOTE: this project is dead.

    the readme file for this project points to the GIT repo on source force which is also dead and points on every page to:

    http://sourceforge.net/projects/mspgcc/

  33. gabe says:

    also, your distro probably have packages for it already. debian has plenty, just open aptitude and search for msp430. you will find binutils-msp430, gcc-msp430, gdb-msp430…

    just note that the actual binaries are named oposite from the packages. e.g. `msp430-gcc`

  34. I had to do the io.h to msp430.h and signal.h to legacymsp430.h substitution above,

    plus in main.c replace
    TACTL = TASSEL__ACLK | MC__UP; //Set TimerA to use auxiliary clock in UP mode

    with

    TACTL = TASSEL_1 | MC_1; //Set TimerA to use auxiliary clock in UP mode

    –Mark

  35. Patrick says:

    Meanwhile, there are repository packages for some distributions available. Makes installation more comfortable.

    http://sourceforge.net/apps/mediawiki/mspgcc/index.php?title=MSPGCC_Wiki

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 96,513 other followers