MSP430 Launchpad on Linux

I got an MSP430 Launchpad in the mail a couple of days ago. So I’ve been playing with that the last couple of days. The first day I went through the tools on the wiki and grabbed both IDE’s and all the downloadable links I could. This had to be done on Windows since it’s the only platform they support. Being a Linux user 99% of the time, I wasn’t too pleased with this situation, so I investigated the tools available for Linux, and that’s what I did all of yesterday.

First, I searched the Arch Linux repos (including AUR) for MSP430 related tools. I used yaourt and searched for both msp & msp430. I compiled and installed the compiler, the C library, and two debuggers (more on this later.) After these were installed I grabbed the source to the temperature demo that comes preloaded on the chip. First thing I had to do was change the source in order for it to build with msp430-gcc. The changes were trivial and it didn’t take too long to get it compiled. What took me the longest time was trying to figure out if I needed to define what mcu I’m using. After a bit of research I fired up the debugger, erased the flash, reflashed, and did some light debugging.

Now, for how it’s done. The packages you’ll need are as follows: Updated 2012-06-13binutils-msp430 2.21.1-2
gcc-msp430 4.6.3-1
msp430-gdb 7.2-3
msp430-libc 20120224-2
msp430mcu 20120406-2
mspdebug 0.8-1
If you’re using a distro other than Arch, it’s up to you to figure out how to get and/or build the programs from the source. If you’re using Arch, you can obviously use the AUR packages with ABS. If you’re an i686 user you can grab my prebuild binaries if you’d like from here. Now that you have a toolchain, I’m sure you’ll want to test it out. Grab my “ported” temperature demo.UPDATE The here’s the fully working temperature demo. You’ll need to extract it, fire up a terminal, go to that directory, and you should be able to just type: make. If all goes as planned, you’ll have main.elf in that directory. So now it’s time to try it out, fire up mspdebug. The actual command is probably going to be something like: sudo mspdebug -R. Permissions on the USB device might be able to be changed so it doesn’t have to be run as root, but for me and for now, it’s not too big of a deal. You should get something like this: sudo mspdebug -R
MSPDebug version 0.8 - debugging tool for MSP430 MCUs
Copyright (C) 2009, 2010 Daniel Beer daniel@tortek.co.nz
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 interface 1 on 027
FET protocol version is 30066536
Configured for Spy-Bi-Wire
Set Vcc: 3000 mV
Device ID: 0xf201
Device: MSP430F2013
Code memory starts at 0xf800

Available commands:
= erase hexout mw read run sym
cgraph gdb isearch opt regs set
dis help md prog reset step

Available options:
color

Type "help topic" for more information.
Press Ctrl+D to quit.

(mspdebug) You’re now ready to do some damage!. First, let’s just erase the flash. Just type: erase. (mspdebug) erase
Erasing...
(mspdebug)
If you’d like to check that the flash is indeed erased, try this:(mspdebug) dis 0xf800 2048
f800: ff ff ff ff AND.B @R15+, 0xffff(R15)
f804: ff ff ff ff AND.B @R15+, 0xffff(R15)
f808: ff ff ff ff AND.B @R15+, 0xffff(R15)
...........
fff4: ff ff ff ff AND.B @R15+, 0xffff(R15)
fff8: ff ff ff ff AND.B @R15+, 0xffff(R15)
fffc: ff ff ff ff AND.B @R15+, 0xffff(R15)
(mspdebug)
As you can see, the entire 2kb of flash is erased. So, now that it’s all gone, and the original demo lights turned off (because the program that was running was toasted) we’ll want to load our built program into flash: (mspdebug) prog main.elf
Erasing...
Writing 128 bytes to fc00...
Writing 128 bytes to fc80...
Writing 128 bytes to fd00...
Writing 128 bytes to fd80...
Writing 128 bytes to fe00...
Writing 8 bytes to fe80...
Writing 32 bytes to ffe0...
(mspdebug)
As you can see, erasing the first time was most likely not needed. Now we’re ready to fire up GDB:(mspdebug) gdb
Bound to port 2000. Now waiting for connection...
At this point you’ll want to fire up another terminal, browse back to the source directory, and do: msp430-gdb main.elf
GNU gdb (GDB) 7.0.1
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=i686-pc-linux-gnu --target=msp430".
For bug reporting instructions, please see:
http://www.gnu.org/software/gdb/bugs/
Reading symbols from /home/harley/Source/msp430/MSP-EXP430G2-Launchpad/main.elf...done.
(gdb) target remote localhost:2000
Remote debugging using localhost:2000
0x0000fc00 in _reset_vector__ ()
(gdb)
Basically, start up msp430-gdb with main.elf, set the target to a remote machine (in this case localhost at port 2000), and msp430-gdb and mspdebug do some magic, and you’re ready to start debugging. Since you’re debugging a remote target, remember you “continue” instead of “run.”

There you have it, you should be in pretty good shape to start experimenting with the MSP430 Launchpad on Linux.

Addendum:
Big thanks to Henry von Tresckow (hvontres) who fixed the temperature demo to fully work with mspgcc. I’m yet to test it, but his changes look convincing enough. I’ve tested the changes and they seem to work fine. Here’s the updated temperature demo (updated 2012-06-13.)

Update:
Added msp430mcu as a required package. Thanks Frankie Robertson for pointing that out in the comments. 🙂


26 thoughts on “MSP430 Launchpad on Linux

  • nrp

    How did you manage to get ti_usb_3410_5052 to work with the LaunchPad?

    My 3 LaunchPads all have USB IDs of 0451:f432, which is not covered by that driver (at least in the stock kernel). I edited the ti_usb_3410_5052 module to add the device, but then it just fails to load the firmware:

    [ 706.522314] usb 5-1: firmware: requesting ti_usb-v0451-pf432.fw
    [ 706.526361] usb 5-1: firmware: requesting ti_3410.fw
    [ 706.533390] usb 5-1: ti_download_firmware – error downloading firmware, -8

    My eZ430U with an ID of 0451:f430 works with the same driver.

    Reply
  • WestfW

    Essentially the same procedure should work for MacOS (i have it working on an ez430-f2013) In addition to mspgcc and mspdebug (which will require libusb and libelf, available via fink), you will also need the “Beta TUSB3410 Drivers for MacOS.” These can be requested from “usb@ti.com” (email your “legal company name, contact info, and intended application.” Tell them you want to use LaunchPad on Mac.) They sent source code that needed recompiled (using XCode) with the USB device and product IDs “fixed” to match the launchpad or ez430 (bcdDevice=257, idProduct=62512 (as displayed by the plist editor that you should use to edit them.)) It went pretty smoothly (aside from learning how to compile cross-compilers), and I’m … pleased.

    Reply
  • Pingback: Using the TI MSP430 LaunchPad with Ubuntu 10.04 | eclecticc

  • Terry

    Just what I was looking for, thank you! I just received my MSP430 Launchpad and as I “99%” Linux user, native tools are always what I look for first!
    I am so impressed with the generous nature of the GNU/Linux/OpenSource community! You have done an excellent service for the community as well as myself. Thanks again.
    Terry

    Reply
  • Beretta

    Glad to see this is working– I tried this setup in x64 Arch a while ago with the FET430UIF, and wasn’t able to get it to work right. I’ll have my launchpad soon, and will give it another go to see if I can get it working in the 64 bit environment as well.

    Reply
  • hvontres

    Hello,
    I was wondering if anyone here has managed to get the serial port to work under linux.I tried to get the Temperature demo to print to a terminal window but so far I have had no luck talking to /dev/ttyACM0. The board works under Windows, so I know it’s not a hardware failure.

    TIA,
    Henry

    Reply
  • Terry

    you can use MINICOM as a serial terminal program under Linux
    alternatively you can just cat out the /dev/ttyACM0 port:

    stty 2400 < /dev/ttyACM0 # Temp demo is at 2400
    cat /dev/ttyACM0 # reads whatever the port spews out

    Reply
  • Pingback: MSP430 launchpad dev kit how too — Justin's Tech

  • Pingback: TI MSP430 LaunchPad - Stew’s Spot

  • Pingback: ScannerPrincess » Blog Archive » Setting up an MSP-EXP430G2 LaunchPad

  • Pingback: MSP430 tools for linux — Justin's Tech

  • Pingback: How-to: Launchpad programming with Linux - Hack a Day

  • Andrew

    I love this post, but for some reason, when I compile the code, it’s too chunky. The only modification I have made is to use the TI msp430g2231.h header, and when I compile, region .text overflows by 236 bytes. Anyone else have this problem?

    Reply
  • Unai Uribarri

    The link to the source files is broken. This is the correct link

    Also, gcc 4.4.5 doesn’t generate a working program; the Transmit routine includes the following synchronization loop:

    while (CCR0 != TAR) // Prevent async capture
    CCM0 = TAR; // Current state of TA counter

    TAR autoincrements every 8 cycles but the code generated by gcc for the loop needs 11 cycles to execute. Therefore, this loop never exits.

    I have replaced that code by:

    for (;;)
    {
    unsigned int tar = TAR;
    CCR0 = tar;
    if (TAR == tar)
    break;
    }

    This code only need 6 cycles to execute and therefore can finish.

    Reply
    • losinggeneration Post author

      Thanks the link was indeed broken. It’s fixed now. The link you provided was my first go at it which was slightly broken in some areas. The updated (fixed) link has different code for the Trasmit function: while ( CCTL0 & CCIE )delay(5); And static void __inline__ delay(register unsigned int n)
      {
      __asm__ __volatile__ (
      "1: \n"
      " dec %[n] \n"
      " jne 1b \n"
      : [n] "+r"(n));
      }
      This too should end up being roughly 6 cycles (I don’t have time right now to verify for sure though.)

      Reply
      • Niall Parker

        I’ve got the demo code running OK but the serial transmit seems to be broken most of the time, I get error on the python code timing out on port open (or an io error when just using stty, cat). Once in all my tests it worked, haven’t repeated it though.
        I have updated the firmware in the emulator with the latest from TI, could the timings have changed ?

        Reply
  • Michael

    I know this is sort of old but I’m trying to follow this.
    I have installed all the dependent packages (albeit slightly newer versions) but when I go to the temp program and try to compile it, every definition (of the msp430) can’t be found. Like ‘CPUOFF’ undeclared. Seems it doesn’t know where io.h or signal.h are. I am using Archlinux also.

    Reply
    • losinggeneration Post author

      I’ve updated the package versions to reflect the current Arch Linux MSP430 packages as of today. I’ve also updated main.c and the Makefile to build again. I don’t have a Launchpad in front of me so I can’t actually test it.

      Reply
  • Pingback: MSP-GCC 编译器安装与使用小记 « andy的linux小屋

  • Ty

    I followed your guide about a month ago and got everything working, but now when I tried it out again the plot never appears. The python program hangs at “Setting up port” and never goes further. If I unplug the board it detects that though.

    Not really sure what’s up with it. It worked randomly earlier but just kept making a window for each point it plotted.

    Thoughts? Thanks!

    Reply

Speak Your Mind

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

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>