Tuesday, November 2, 2010

mspgcc4-20101006 with gcc-4.4.3, gdb-7.0.1 and mspdebug-0.12

Hello!

I'm writing this blog hoping to provide a quick and painless procedure to get started with Texas Instrument's MSP430 LaunchPad board on Mac OS X. Their support for OSX is quite poor to say the least. I'm providing a self-contained package so that you don't have to waste your time like I did all day. Just download the following file, unzip and install:

Note that this is a set of command-line tools in the spirit of the equivalent CrossPack tools for AVR MCUs.
To test it:
  1. Download their temperature demo. Unzip.
  2. Open a Terminal, cd to the folder you just unzipped, then run
    make

    If you don't have 'make', just install Xcode (I know, it's overkill, but...).
  3. You should get a 'main.elf', now upload it to the LaunchPad with:
    sudo mspdebug rf2500 "prog main.elf"
  4. Done! You won't notice much of a change since you just uploaded the same blinking red/green demo that came pre-loaded, but you get the idea :)
Caveats:
  • You don't get a serial interface like Windows/Linux users do. The official wiki(yes, the official wiki) will tell you to install this driver, but you'll just waste your time yet again. This information is not only misleading, but absolutely wrong, that driver was written for the TUSB3410UARTPDK and will not work with the LaunchPad.
  • You can only program the board once, and then it won't get recognized again by mspdebug until you unplug it and plug it back in.Edit: fixed! download the lastest package.
What's under the hood?
The package will install a few things:
  • The mspgcc4 toolchain (current version: 20101006), which includes GCC/G++ 4.4.3, GDB 7.0.1 and related bintuils.
  • mspdebug (current version: 0.12). This is a programmer/debugger for the MSP430 devices. It's actually very neat, you can perform on-chip disassembly, debugging and step-by-step execution. I think you can piggyback gdb on it and debug from gdb or any of its front-ends, but I haven't actually tried it. Again, I included the binaries so that you don't have to deal with the homebrew/darwinports/libusb stuff yourself.
  • An especially crafted driver by Bill Westfield (westfw). This is sort of a "null" driver so that OSX doesn't take exclusive control over the LaunchPad when you plug it in.
I hope this helps. It goes without saying that this is a barely tested build of the toolchain and it might not even work for you. I just tested it on Snow Leopard (10.6.4), but it should work with Tiger and Leopard, too. Edit:. So far, the toolchain only works on Snow Leopard. Please drop your flames on the comment area below. If you get it to work, let me know as well.

34 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. I don't have make installed, so I'm downloading XCode now.

    However, mspdebug should work at this point, but:

    dyld: Library not loaded: /usr/local/Cellar/libusb-compat/0.1.3/lib/libusb-0.1.4.dylib

    I'm presuming therefore I need to find libusb-compat from somewhere.

    I now find libusb-compat needs sudo port - which requires XCode - so I'm stuck waiting. :)

    Might it be an idea to point out the install order a little more clearly to "virgin developers" like myself :)

    ReplyDelete
  3. Welp, got everything installed but I'm stuck on "make" now.

    I downloaded the project you indicated, but now this:


    MSP-EXP430G2-Launchpad $ ls
    Debug lnk_msp430f2012.cmd test_RX.c.old
    MSP430F2012.ccxml main.c
    MSP-EXP430G2-Launchpad $ make
    make: *** No targets specified and no makefile found. Stop.

    Sad times :(

    ReplyDelete
  4. Ah. I think you meant the temperature demo here:

    http://losinggeneration.homelinux.org/2010/07/02/msp430-launchpad-on-linux/

    Which has a makefile ;)

    We're getting there! Together! I love you!

    ReplyDelete
  5. cr3: you don't need to install the three components manually. Just download the package I mentioned in the beginning of the article and off you go.

    Anyway, you seem to be almost there... Let me know if it works!

    ReplyDelete
  6. I am trying to call __delay_cycles but at compile time I get undefined reference to `__delay_cycles' at link time. Does this mean it didn't find the correct headers? I'm trying to compile for the MSP430G2231 on the launchpad. I tried changing -mmcu to different names to no avail. Any ideas?

    ReplyDelete
  7. Matt -- I think __delay_cycles is IAR-specific and has not been ported to mspgcc4. Check out TI's temperature demo (link on the post). They use something like this:

    static void __inline__ delay(register unsigned int n)
    {
    __asm__ __volatile__ (
    "1: \n"
    " dec %[n] \n"
    " jne 1b \n"
    : [n] "+r"(n));
    }

    Since it's an inline function and each dec+jne loop takes 3 cycles, that should pause your program for exactly 3*n cycles (assuming no interruptions).

    ReplyDelete
  8. This seem to ONLY work on Snow Leopard, will fail with "dyld: unknown required load command 0x80000022" on anything below this.

    ReplyDelete
  9. Thank-you! So much for the nice easy to use package. I was able to program my MSP430 with your breathing light demo using the included makefile. However I can't find any information about how I could put my own C or Assembly program on the thing? Any push in the right direction would be greatly appreciated. I mostly want to use this to learn Assembly. So instructions on how to load Assembly programs would be nice.

    p.s. Is it just me or is most of your website in English but some of the buttons are in spanish?

    ReplyDelete
  10. Tanner: everything should be in english now :)

    I haven't programmed the MSP430 in assembler myself, but you can use msp430-gcc to assemble code and generate the .elf:

    msp430-gcc -Os -Wall -g -mmcu=msp430x2012 -c main.s
    msp430-gcc -Os -Wall -g -mmcu=msp430x2012 -o main.elf main.o

    If you need an idea of how a ".s" looks like, its syntax, etc, you can also have gcc generate one for you from a .c source code with:

    msp430-gcc -Os -Wall -mmcu=msp430x2012 -S -c main.c

    I theory, compiling a .c into .s, then assembling into an .o should produce the same result as compiling directly a .c into an .o.

    That way, at least you can write some code in C and look how it looks like in assembler.

    Good luck!

    ReplyDelete
  11. Hi, first thank you for setting this up, its very welcome. Hope to see a lot of postings. Good luck.

    I tried to avoid usb drivers except the main. Had bad experiense that other driver took away usb connections from some of mine projects ( pic with out of the box working usb ).

    So my question, is libusb working well, no influence on the standard drivers?
    Is it possable to connect more then one launch-pad at the same time?

    ReplyDelete
  12. rva, thanks for the kind words. The driver checks for the VendorID and ProductID, so in theory (I haven't written it myself), no other device should be "masked out" by this driver.

    You shouldn't find any conflict with libusb either, unless another application decides to install a different/incompatible version of libusb... Which you have to check by hand (CMD-I) from the installer, since OSX packages don't usually check dependencies at all.

    ReplyDelete
  13. life is easier now,
    thanks dude!

    ReplyDelete
  14. Does this toolkit run on a 32-bit system? I get the following when attempting to execute any of the binaries:

    Bad CPU type in executable

    I am attempting to run on a Mac Mini with an Intel Core Duo processor.

    ReplyDelete
  15. @Richard: apparently not, sorry :( I have no way to test this other than on my own computer. I'm thinking of posting the pkg project and a brief shell script, so anyone can build the package on their architecture.

    ReplyDelete
  16. Woo hoo! It works! You sir are a genius.
    I had to remove the TIVCP extension first to get it to work.
    I don't see how TI thinks they're going to break into the hobbyist market with this complicated mess of drivers etc...
    Anyway, thanks again.

    ReplyDelete
  17. well, firstly thanks for all. but __delay_cycles() does not work. do u have any solution

    ReplyDelete
  18. @altu: read 12 comments above for a function that does cycle-precision delays. Or, take a look at TI's temperature demo (link on the post).

    ReplyDelete
  19. So - I've been trying to get the VCP driver working on my macbook (core duo / 32bit/ 10.6.7) with the launchpad.
    I built the driver supplied by TI (v1.2.1), modified the VID/PID to match my device, and the device is recognised. The kext loads and runs, but it fails to upload the firmware to the device. The driver complains that FindNextInterface is returning NULL.
    Anyone else hit this? Any ideas?
    On one of the many other disperate forums, someone alluded to a v1.2.2 of the driver - does this exist?

    Thanks,
    reg

    ReplyDelete
  20. Thank you! I got the Breathing Demo to work on my MBP. I had to run sudo make install to get it to compile

    ReplyDelete
  21. what about the host software for a mac? any tutorials?

    ReplyDelete
  22. Big Guy: What do you mean by host software?

    ReplyDelete
  23. Got this working first time, thanks Javi!

    ReplyDelete
  24. clean and easy install
    then added the build parameters to NetBeans

    Now I'd say its almost better than TIs IDE ^_^

    ReplyDelete
  25. http://mspdebug.sourceforge.net/faq.html#rf2500_osx worked for me after getting a "Permission denied" message while trying to push the .elf file on the msp.
    (Intel i7 / Snow Leopard)

    ReplyDelete
  26. This is very useful!!
    easy to install.
    (Macbook air w/ snow leopard)

    ReplyDelete
  27. Javier, It worked!!
    I am really happy to confirm that the osx-lauchpad package works on a MBP Snow Leopard 10.6.8
    I downloaded the Breathing LED program -> unzipped -> from terminal, typed: sudo make install (from the unzipped directory)
    thats it. Thanks...

    ReplyDelete
  28. Now there's a beta serial driver for the launchpad.
    http://www.43oh.com/forum/viewtopic.php?f=7&t=1591&start=10#p10955
    Are you planning to upgrade the packages at some point?
    Thanks!

    ReplyDelete
  29. sanpedro: that's interesting news... I'll see if I can get some spare time and build a new package with this driver in.

    ReplyDelete
  30. That would be great! Javi, we will be very happy if you'll include that stuff in a new post. Thank you for your work so far! Greetings from Hungary, EU

    ReplyDelete
  31. When I try to make, I get this error:
    make: *** No rule to make target `install'. Stop.

    I'm in the folder you linked to, when I try to do it. Any help?

    ReplyDelete
  32. hi...Im student from Informatics engineering nice article,
    thanks for sharing :)

    ReplyDelete
  33. Thanks for review, it was excellent and very informative.
    thank you :)

    ReplyDelete