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:

139 thoughts on “How-to: Launchpad Programming With Linux

  1. I ordered mine the day this article came out and just got the “On back order” message yesterday. My wife works for a stepping motor manufacturer here in Silicone Valley. Her company also use TI controllers in their applications. TI seems to be having a tough time with meeting their demands in their case as well. All I can say is hang in there and hope to see some posts in September when we all get ours. On a closing note …. Here’s what the total cost is for all interested ->MSP-EXP430 -$4.30, Shipping $7.92, TOTAL a rocking $12.22 No wonder it’s on back order!

  2. I ordered two from TI directly, when they were mentioned here, and had them in hand a couple of weeks ago, if not a month now.

    Handed one off to a friend, but like a couple of the others, just need to find the time to play with it.

  3. Just got my boars today so they are definitely moving, just taking a while. To all the ‘duino folks – how fast could you get your duinos the first day they were announced? Did you even try? TI can send you reels of 430s or most anything else they have if you want them faster; you’ll just have to source a box, a board, USB connector, cable, CD etc to build your own board :}

  4. Anyone else run into “undefined symbol” errors? I’m trying to compile some SD/mmc reading code and getting a whole list of errors like this: /opt/msp430-gcc-4.4.3/lib/gcc/msp430/4.4.3/msp1/libgcc.a(_mulsi3hw.o): In function `__umulsi3hw’: (.text.libgcc+0x2): undefined reference to `__MPY’

    It can’t find “multiply”? I am confused.

  5. I’m seeing the work/no work for the launchpad’s serial on Ubuntu Lucid, both in a VMware instance, and stand alone hardware.

    Stable for a few hours even, then the “T…ACM0” device is g-o-n-e. Even a hard reset does not restore???

    Great article, but I still have to run msdebug rf2500 as su…

  6. Just got mine today. Disappointed in the lack of cross platform tools. If they had released Windows, Mac and Linux development tools at the launch, I would be taking them more seriously.

  7. Thank you very much for the instructions.
    I installed suggested tools and tried my first compile and programming / debugging under Linux, running on a old Dell Dimension.
    Worked !!!

    For me also, I had to use ‘sudo mpcdebug rf2500’, but I am ok with that.

  8. greetings –

    i followed most of the direction provided here but i can not find the example code [http://blog.mahalo.com/hackaday/howto/Launchpad-blink.tar]. the link returns a mahalo.com page not found.

    i’ve been trying for several days to find an elusive make file example for a LaunchPad — mostly they the ones found do not work or are for other MSP430 boards.

    i was hoping your example code would provide the last bit of direction that would allow me to begin exploring the LaunchPad.

    any and all assistence is appreciated.

  9. Just got MSPGCC working on knoppix 6.2
    Only had to compile texinfo. But other than that, it was smooth sailing. Thanks for the great article.

    @ the above comments with the snotty, whiner attitude if you fail to adjust these very basic instructions to work for your distro/flavor. Then by all means ask for help if you have to, but do not talk trash about mac / linux / other os’s. It’s better you shut your mouth and stick to your precious, filth, virus and pr0n infested windows then.

  10. Didn’t work for you? Keep in mind, these directions have you getting the code through Subversion. That means you are getting the latest stuff that the MSPGCC programmers are working on. They might be in the middle of something and not have it in a working state.

    I haven’t tried it yet so I don’t know why the author chose to direct readers to grab it from Subversion. Maybe it is so new that the latest released version doesn’t work yet? Or maybe the author was just going for the latest and greatest.

    I would suggest that if you follow these directions and it doesn’t work then go to the MSPGCC SourceForge page and just download the latest release version instead of taking it from Subversion.

  11. Bump on linux launchpad serial port stability —

    Seems to be better on today’s release of Ubuntu 10.10. The temperature demo python logger has been stable for several hours…

    I’m really starting to enjoy this board! I wonder when 20 pin 8k-16k dip chip will be available?

  12. I Originally Posted at 9:49 pm on Aug 13th, 2010 that I ordered mine the day this article came out and just got the “On back order” message a that day.

    I also originally posted in that same post, that “On a closing note -It’s no wonder it’s on back order due to the low price” …. well, it’s October 13th now (2 Months later)… I missed out on all the funs stuff every else here is reporting on, and really feeling “RIPPED OFF” by Texas Instruments.

    I remember back when I was a kid, and I ordered this cool “Mystery Box” toy from the back page of my comic book. It too was on back order and I NEVER received that too. This is what I am feeling right now. I didn’t realize how PISSED OFF Texas Instruments actually made me, until now.

    It never matters how “Cheap” something is when you never receive the item in the first place.

    TI reference number: 105631

    -Joe

    Posted at 9:49 pm on Aug 13th, 2010 by Joegeek

  13. @joe:

    It took TI two months for me to get mine. Be patient. When they released these, I believe they received over 100000 orders, which was about 90000 more than they expected for the first run.

    And has anyone tried to get this running on Fedora 13, or am I just wasting my time and should switch to a diff. linux distro?

  14. I ordered mine in may and got it today.

    So far, I’ve got the crystal and headers soldered in. I played with the demo and mspdebug first. Then I compiled a gcc port of the demo from one of the links with gcc4 and flashed that. It ran, I looked at disassembly etc. So far, it’s looking good.

    (Laptop running Debian squeeze, 2.6.32)

  15. This didn’t work for me. Compiling the sample code gave me:
    main.c: In function ‘main’:
    main.c:64: error: ‘TASSEL__ACLK’ undeclared (first use in this function)
    main.c:64: error: (Each undeclared identifier is reported only once
    main.c:64: error: for each function it appears in.)
    main.c:64: error: ‘MC__UP’ undeclared (first use in this function)
    make: *** [main.o] Error 1

  16. Ahh found the problem.
    Dowloaded source contains line:
    TACTL = TASSEL__ACLK | MC__UP;
    Changing to:
    TACTL = TASSEL_1 | MC_1;
    Fixes it.
    Note also that the source code for mspgcc4 now uses a git repository:
    git clone git://mspgcc4.git.sourceforge.net/gitroot/mspgcc4/mspgcc4
    and now contains a msp430g2231.h header file eliminating the need for -mmcu=msp430x2012 in cflags

  17. @Rando: When Mike Szczys wrote the article, he forgot about the WordPress “feature”, that apparentyl sometimes converts quotes (“) into "

    When you create the udev rule, you cannot just copy&paste their text. You need to replace every " with the double quotation marks (“).

    The linked article about udev rules shows how.

  18. Excellent guide, thanks! For those of you with low-end machines, I got this working in Lubuntu 10.10 following the instructions as-is. I also got it working in bare bones Debian “lenny” after I added the “testing” repositories so that apt-get would install the correct versions (particularly gcc-4.4). buildgcc.sh stopped a few times complaining about missing commands but I just “apt-get install”-ed whatever was missing until it was satisfied.

  19. Great article, worked like a charm.

    My VLO is running almost dead on 13 kHz. I set the counter to count to 13000 and have less than half a second error over three minutes.

  20. Anybody out there using Gentoo? Apparently there is an overlay for the msp430. I tried following the directions from the overlay: https://github.com/radhermit/msp430-overlay/blob/master/README.asciidoc.

    The first thing I ran into was he’s using portage 2.2.something. I am still using the latest ‘stable’ release which is in the 2.1.9 series. His second step is “emerge crossdev::msp430” I’m not sure what the “::msp430” part does but my version of portage doesn’t like it. Does this direct portage to use the one in the overlay as opposed to the main crossdev? Or is it specifying a slot. Can slots contain letters? I tried just doing an “emerge crossdev”. It emerged crossdev and the msp430 target is available if I do a “crossdev -t help”.

    I tried “crossdev -t msp430”. It gets through binutils ok but then it tries to compile the linux headers. I’m not that experienced with cross compiling toolchains but I am guessing I would only need that if I was going to run the Linux kernel on the msp430? Intriguing as that sounds I don’t think it’s going to happen. I added the “–without-headers” option. I get farther now but it still fails when it tries to build msp43-gcc.

    One other thing… crossdev adds an /etc/portage/package.keywords/cross-msp430 file. One of the entries is “cross-msp430/[latest] * ~* -x86 -~x86”. I have never seen the “[latest]” form before. My portage doesn’t like it, I’m guessing it’s another 2.2 feature?

    Well, thanks in advance for any help/advice! I may just try installing per the directions here and forget the overlay. I hate to do that though, it’s so much nicer to let a distros package manager take control of things for ease of upgrading or uninstalling later.

  21. If the udev rules don’t work for you, make sure you didn’t copy them from the code box, which as morphed some double quotes into some HTML syntax.

    It should be (hoping this isn’t also transhtml’d):
    ATTRS{idVendor}==”0451″, ATTRS{idProduct}==”f432″, MODE=”0660″, GROUP=”plugdev”

  22. It doesn’t work since sourceforge got hacked. I hope they come back online soon.

    Stupid scripts that try to download “the latest from CVS” instead of something more stable, and more easy to find mirrored somewhere else.

  23. Ok, I got fed up with trying to make this work the ‘Gentoo way’ using Crossdev and just followed the directions here. It worked great! I don’t know what Roger Wolff was writing about but it seems to work fine now. I got the impression that support for this was pretty new under Linux. If so I would imagine that is why the latest from CVS is being used. The release version (is there one) is probably not functional enough yet. That was my guess anyway and I’d rather thank the author for making this possible and easy than complain about CVS. Thank you!

  24. Hy,
    I installed the gcc from here.
    When I try to compile it can’t find include librarys:

    main.c:31:16: error: io.h: Nincs ilyen fájl vagy könyvtár
    main.c:32:20: error: signal.h: Nincs ilyen fájl vagy könyvtár

    Could you help?
    Thank you!

Leave a Reply to KC8RWRCancel reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.