MSP430 + Eclipse CDT on Fedora 19

Hello! This is a guide to install Eclipse and everything required to flash your project to a MSP430 board 🙂

First, you need to install Eclipse CDT (the Eclipse version using the C/C++ IDE) and there are three ways:

  1. Go the Eclipse’s website, download and install it yourself
  2. Use Fedora’s “Software” application (which is PackageKit, the GUI of yum) and search for “eclipse-cdt”
  3. Use your terminal, type su, press enter, give your root password and then type yum install eclipse-cdt. Type “y” to install all dependencies required for eclipse-cdt 🙂

After you have successfully installed Eclipse CDT you can continue to the main course. We need a plugin for MSP430 called msp430-eclipse by xPG. Don’t download anything yet. We’ll use Eclipse for that!

Now, open Eclipse go to Help->Install new software and add http://eclipse.xpg.dk as a software source. Use it to install the msp430 plugin.

Next, we need a tool-chain that includes all files to compile, debug etc our code specifically for our MSP430 platform! Visit xPG’s website as mentioned previously. Scroll down and choose the version of the tool-chain for your system.

We will need to install a few packages more though as xPG’s tool-chain is not sufficient (If you try to compile without those packages it will fail to find libmpc.so.2, or something like that). I fixed it by installing five msp430-related packages: msp430-binutils, msp430-gcc, msp430-libc, msp430mcu, mspdebug. Maybe some of them are not really needed but ok it’s only a few Kbytes and in the end everything works well. You can use step 2 or step 3 from above!

If you are confident for your tool-chain and skipped my previous steps, you don’t need to download any package (the next step), you just need to configure Eclipse later on.

Download and extract the package in an appropriate location (like your home folder, or any other folder inside it). Go to Eclipse (with the plugin already installed, like I showed you before) and from Eclipse’s menu click on MSP430 -> Tool Manager. Press  “Add…”, find the tool-package folder, select it and click OK. On the Tool Manager, select the tool-chain and press “Activate”.

If you want to use your own tool-chain, all MSP430 compilation and debug tools can be configured at Window->Preferences->MSP430.

As normal users we don’t have permission to use the USB bus. To fix that, go to Fedora’s “Users and Groups” or system-config-users (if you don’t have that install it like all other packages). Create a group named eg. “usb” and add your user into it (“Users” tab -> select your user-> Properties). Log out and log in again for changes to take effect.

Next, go to a terminal, type “su -” and create a file with the command: gedit /etc/udev/rules.d/71-persistent-msp430.rules . Then, copy, paste and save this:

SUBSYSTEM==”usb”, ATTRS{idVendor}==”0451″, ATTRS{idProduct}==”f432″, MODE=”0660″, GROUP=”usb”

The numbers “0451” and “f432” can be verified if you connect your board and use the command “lsusb”.  Now, go to a terminal for the last time and give these three commands:

systemctl restart systemd-udevd.service

systemctl restart systemd-udev-trigger.service

systemctl restart systemd-udev-settle.service

Now, let’s make a new project and test what we’ve done. This will require a MSP430 board, hopefully supported by the plugin (which is very probable as you will notice). Create a new C/C++ project and select the “Empty project” at the “MSP430 Cross Target Application” folder. Give it a name and then click Finish.

Right-click the project at the “Project Explorer” and choose Properties. Go to the “MSP430” section, select your MCU and debug settings. Next, go to the “C/C++ General” section -> Paths and Symbols, select GNU C at the “Includes” tab and include the path “/home/username/any_directory/msp430-toolchain-linux-amd64-3.0/msp430/include” (same for GNU C++)

Right-click the folder, create a src folder and place a source file into it preferably with a blink.c (a blinking LED example) file for your board such as this one in this blog. Don’t forget to include your board’s header file!

Build the project, then right-click the project and select MSP430->Upload to target (or use the icon for that job at the main bar).

The example should work and this brings us to the end of this tutorial 🙂

MSP430 (ez430) on Fedora

For learning purposes I currently have on my hands a EZ430-F2013 Development Kit (We all should also use Arduino 🙂 ). This kit comes with a CD containing proprietary software (an IDE) in order to program and debug the MSP430 microcontroller. So, I took the chance to run it on Fedora using Linux tools and a few resources on the internet. In this post I will write down how you can program and debug your ez430 using Fedora 13 and your terminal.

First, I plugged in the ez430 and opened a terminal (yes we will work only this way for now). Write down lsusb and hit enter. Then you should get some lines containing this one:

Bus 005 Device 003: ID 0451:f430 Texas Instruments, Inc. MSP-FET430UIF JTAG Tool

That means that by default your system recognises the device and you can actually communicate with it.

Next, we need our tools! Go to System ->Administration-> Add/Remove Software (or use yum install etc.). The software we need is (actually not sure if everything is needed):

  • latest version of gcc, texinfo, patch, ncurses5-dev, zlib, zlib-dev, libX11-dev, libusb-dev (not only libusb1-dev), libreadline6-dev, msp430-binutils, msp430-gcc, msp430-libc

and also : mspdebug (the program that actually does the work).To install it manually (in case there is an older version on the repository) download the .tar file create a  folder named “Programs” (in case you don’t have one) on your Home Folder.Then, extract the mspdebug folder there!

With your terminal (you can auto-complete the words in the directory using Tab on your keyboard) :

$ cd /home/(your user name on Fedora)/Programs/mspdebug-0.11

(now you are in the mspdebug folder with your terminal, the version 0.11 is the current one I use, yours can differ)

$ make (this will compile the program)

$ su -c “make install” (and give your root password to install it)

(the $ symbol is just to show that you are using different commands in the terminal, don’t copy it)

now you have installed mspdebug! Great!

If you are ready to use the MSP430 you should have a program already written. In case you don’t, get this example (modified by me to get it to compile) that flashes the internal LED of the device:

/* Blink LED example */
#include <msp430x20x3.h>

/** Delay function. **/
delay(unsigned int d) {
int i;
for (i = 0; i<d; i++) {
nop();
}
}

int main(void) {
WDTCTL = WDTPW | WDTHOLD;
P1DIR = 0xFF;
P1OUT = 0x01;   // THE x IS NOT Copy-Pasted CORRECTLY 🙂

for (;;) {
P1OUT = ~P1OUT;
delay(0x4fff);
}
}

Create a file named blink.c in a folder of your choice, copy this on the file and then cd on the folder. Now to compile it we need 3 lines (I also changed this to work):

$ msp430-gcc -Os -mmcu=msp430x2013 -o led.elf blink.c

$ msp430-objdump -DS led.elf > led.lst

$ msp430-objcopy -O ihex led.elf  led.hex

In order not to do this every single time, you need to run the program, you can create a Makefile based on the one in this site (it’s inside this zip file).

Next, to run mspdebug in order to flash the program into the MSP430, type :

$ mspdebug -d /dev/ttyUSB0 uif

(“/dev/ttyUSB0” is of course the ez430 if you don’t have any other device and “uif” the parameter to run it with mspdebug, check the manual for more)

To flash the program you need to type : prog led.hex . Notice that it is a command to control mspdebug and not the terminal). If you push Control+D mspdebug will close, the ez430 will reset, start the program and also blinking the LED! 🙂

My resources were 3 posts in this site : http://bit.ly/deonNa I should also mention that I have installed all the Fedora Electronic Lab packages with: $ su -c “yum groupinstall “electronic-lab”