Programming and Debugging with the TI Launchpad on Mac OS X
Total Page:16
File Type:pdf, Size:1020Kb
Programming and Debugging with the TI Launchpad on Mac OS X Scope: These instructions are a summary of the steps I followed to start using the TI Launchpad under Mac OS X. This isnʼt as straightforward as it sounds, but it is possible develop code, debug and program from within Mac OS X without having to boot into a copy of Windows (these instructions can also be extended to most variants of Linux). Introduction: The TI Launchpad is Texas Instruments low cost microcontroller development board for the MSP430 microcontroller line. These microcontrollers are very low power, very low cost and reasonably fast. There are many variants in each class, each with different peripherals and features. <rant>Unfortunately, TI doesnʼt officially support anything except Windows, and the limited support for Mac they do offer extends to a broken driver for communicating through USB. Furthermore, TIʼs closed source policy hampers clever people trying to write open source compilers, debuggers and programmers. I canʼt speak to the true reasons for this, but my cynical side would say that they do this to force people to use their size limited free version of IAR or Code Composer (~$500 for a single seat license with the unrestricted version). Contrast this policy with the free development tools for Windows by ATMEL for its AVR line, and the well developed, open source AVR GCC toolchain that forms the basis of the Wiring environment used by the Arduino. </rant> Arguments about operating systems and open versus closed source software aside, the MSP430 line of microcontrollers are actually quite attractive (for more on the open versus closed source debate or what the best operating system is, please refer to any public forum on the internet)(Be aware that Godwinʼs law is accelerated in these sorts of discussions.). In comparison to the AVR line of microcontrollers, the MSP430 line has the following advantages: a smaller instruction set, 16 versus 8 bits, easier flash access, lower power consumption and lower cost. Its (relative) simplicity and low cost were the main reasons behind using it for this course. Getting under the hood of your Mac: Mac OS X is a great operating system for surfing the web, editing pictures, listening music, and all the other stuff that people actually use their computers for these days. At its core, however, it is really just a variant of Unix (BSD, actually), and all that power user functionality you associate with Unix/ Linux is still there. If youʼve never opened up Terminal, head to /Applications/Utilities/ and run Terminal.app. You should have a window like this open up: A Terminal Window If youʼve never used the command line before, then youʼve got some learning to do. Start here: http://www.doc.ic.ac.uk/~wjk/Unixintro/ or http://laplace.physics.ubc.ca/210/ Notes_unix.html . You need to be comfortable working at the command line to get the MSP430 development tools installed. If this is a real problem, then you may want to reconsider microcontroller software development as a vocation. Once youʼve got a handle on the terminal, you need to set up your Mac to develop software. To do any development on a Mac, you need to install the XCode developer tools. These arenʼt installed be default, but they are included with every Mac on the install disk, or you can register as a developer with Apple and download the latest version (itʼs free to register). This should be a straightforward install, since itʼs been nicely packaged by Apple, so I wonʼt go into details. The next piece of software you need to install is fink. Fink is a package manager for Mac that allows you to easily install open source programs on your computer without having to download, compile and install all of the libraries and software by hand. It is possible to install software from source by hand in the same way it is possible to build your own car from scratch. Weʼll let fink do the heavy lifting. The fink website has a very good set of directions for installing fink from source (you just installed the Xcode developer tools, you may as well use them): http://www.finkproject.org/download/srcdist.php Some notes: "-The ./bootstrap call will ask you a lot of questions. The default answers should be fine for most people. "-There will be a lot of text streaming across the screen as the software compiles. This is good, but it does take a while. When the process is finished, be sure to read the last few lines to be sure there were no errors. If there are, you!ll have to sort them out before you continue. "-Be sure to close the terminal window and re-open it after the /sw/bin/ pathsetup.sh command, or the next commands won!t work. "-fink selfupdate-rsync takes awhile to run, be patient. "-When you run fink, it may ask you for your user password. This is expected, since it is writing to system files that are normally protected from the user. Now that you have fink installed, we are almost ready to install the MSP430 development tools. However, these tools are still a little buggy, so in the fink database, they!ve been labeled as unstable. This doesn!t mean they don!t work, it just means that they haven!t been around long enough to be thoroughly tested. However, it does require a little more work on our part to get them working. We need to tell fink that we want to work with the unstable packages. To do this, we type the following: fink configure This will run you through a series of questions. You can choose the defaults for most of them, except one that asks if you want to use unstable packages. For this, choose y (yes). After you!ve configured fink to use unstable packages, update the package list: fink selfupdate Now, we are ready to install the msp430 development tools (the “toolchain”). Run the following fink command to get the packages: fink install msp430-libc msp430-gdb mspdebug You are almost ready to plug in the device and connect. The only thing that is missing is the USB driver to communicate with the Launchpad. This is the only bit of software that TI provides (unsupported) for the Mac, and it doesn!t work. We need to rely on reverse engineered tools from clever people. Download and install the MSP430LPCDC 1.0.3b.zip driver from http://www.mediafire.com/?7zurj5ncg5794 . This has been nicely packaged with a Mac installer, allows you to communicate the the USB as if it were a serial port to the chip and also allows you to program and debug the chip. At this point, if you plug in the the launchpad, you should be able to communicate with it. With the board plugged in, type the following: mspdebug rf2500 This should bring cause a lot of text to flow by, and leave you at a command that looks like: (mspdebug) Type exit to leave the program. To check if we have the compilers and debuggers, type the following on separate lines: msp430-gcc --version msp430-as --version msp430-gdb --version If any of these commands gives an error, there was a problem somewhere along the line that needs to be fixed, and you won!t be able to compile code for the microcontroller until you do. At this point, you could open up your favorite text editor, paste in some code, compile and link at the command line, and finally upload it to the microcontroller. Be aware that the gcc compilers have a slightly different syntax than the IAR or code composer compilers, especially for interrupt routines. There are notes at the bottom of this document on how to switch between the different compilers. However, the C language is standardized, so using code examples from other compilers very instructive. It is also possible to compile assembly in gcc, but the Code Composer or IAR examples will be difficult to use because the directives of the various assemblers are very different (the assembly language is the same in each case, but the book keeping conventions are different). A trick to get the gcc directives is to write an empty C program and then look at the intermediate assembly that the compiler produces. Use this as a template for your assembly program, and start adding your own code. Synopsis: Step 1: Install Xcode developer Tools. Step 2: Install fink from source. Step 3: Set up fink to use unstable packages. Step 4: Install the msp430 development toolchain. Step 5: Install the USB driver. Step 6: Check the driver and toolchain work. Links: Unix Intro: http://www.doc.ic.ac.uk/~wjk/Unixintro/ Matt Choptuik!s Unix Intro: http://laplace.physics.ubc.ca/210/Notes_unix.html Wikipedia Page on the MSP430 microcontroller: Tons of good information and history of the MSP430 16 bit microcontroller. http://en.wikipedia.org/wiki/TI_MSP430 Launchpad Wiki: A good place to start getting information on the TI Launchpad and the MSP430 microcontroller line. http://processors.wiki.ti.com/index.php/MSP430_LaunchPad_(MSP-EXP430G2) Getting Started with the MSP430 Launchpad: A video tutorial and workbook to get started using the MSP430 launchpad. Based around windows and their Code Composer software, but it gives you a really solid foundation and worked examples. http://processors.wiki.ti.com/index.php/ Getting_Started_with_the_MSP430_LaunchPad_Workshop mspdebug: Open source version of msp430-gdbproxy; a tool that allows you to talk to the microcontroller using the Launchpad board through spy by wire (it!s actually more than that, but that!s what we use it for.