2009
10.23

Welcome

Welcome to Bits By The Pound! You have reached a page where technology enthusiasts can talk about their passion.

2015
12.15

Open

So, the other day, I received the latest issue of Make magazine. Overall, fun and quick to read, but really targeted towards the beginning maker. On the last page was an infortisement about the Nvidia Jetson TK1 development board, on sale for $99USD. Whats this, I say, so I consult the Book of Knowledge. The Nvidia site says the Jetson TK1 has a quad core A15 (nice) and 192 CUDA cores (???). I am not a GPU guy, but I assume the CUDA cores have something to do with an Nvidia GPU, probably the shader cores (otherwise, having a large focus on the GPU business, why would they mention it). Time for more knowledge. Wikipedia has all the knowledge you would ever want, so lets look there. I will paraphrase a bit, but GPU this, parallel programming that, then “supports programming frameworks such as OpenACC and OpenCL”. More Yak shaving. In the OpenAAC article, they talk about Open64, OpenUH, OpenARC, OpenMP and OpenHMPP.

At this point, I was not willing to dive deeper, because, well, you know, I was just looking at the basics of what this board can do. Now my brain is full of OpenX monikers. At this rate, the OpenX crowd are going to reserve or use up all of the good names, just like all the valuable TLDs were snapped up, leaving crap names for great products like toggl.

So this is my official announcement, that I would like to reserve OpenIAN before it gets squandered on some stupid Internet Application Networking, or some other equally atrocious backronym.

OpenTalk to you OpenLater,
– OpenIAN

2015
12.10

Running rsync as a daemon

Adapted from http://www.jveweb.net/en/archives/2011/01/running-rsync-as-a-daemon.html

Environment: Lubuntu 14.04, QNAP TS-431

The first step in order to create a powerful backup facility with Time Machine like functionality requires that you run an rsync daemon on the machine to be backed up.

Create /etc/rsyncd.conf

lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid

[foobarHome]
    path = /home/foobar
    comment = The home directory for foobar
    uid = foobar
    gid = foobar
    read only = yes
    list = yes
    auth users = rsyncClient
    secrets file = /etc/rsyncd.secrets
    hosts allow = 192.168.1.0/255.255.255.0

[foobarMusic]
    path = /home/foobar/Music
    comment = The music directory for foobar
    uid = foobar
    gid = foobar
    read only = yes
    list = yes
    auth users = rsyncClient
    secrets file = /etc/rsyncd.secrets
    hosts allow = 192.168.1.0/255.255.255.0

In this case the foobarHome and foobarMusic sections are known as modules and foobarHome and foobarMusic are the module names. The module names are important and used when remotely connecting to the rsync daemon.

Create /etc/rsyncd.secrets

rsyncClient:<password for rsyncClient>

Secure /etc/rsyncd.secrets

> sudo chmod 600 /etc/rsyncd.secrets

Enable the rsync daemon

Edit

/etc/default/rsync

and enable by changing RSYNC_ENABLE to true. Optionally change the NICE values

RSYNC_ENABLE=true
RSYNC_NICE='10'
RSYNC_IONICE='-c3'

Start the rsync daemon

> sudo service rsync start

Connect to the rsync daemon

To connect to the rsync daemon, specify a module name as set up in the rsyncd.conf file. You may append file paths to the module name

> rsync -rtv rsync://user@host/module/source/ destination/
2015
12.03

Samba, linux and QNAP

OS: Lubuntu 14.04
NAS: QNAP TS-431

Here is the procedure that worked for me to access Samba shares published from your QNAP NAS.

Enable SAMBA on the NAS

From the web UI to the NAS, go to

Control Panel -> Network Services -> Win/Mac/NFS

and select the Microsoft Networking tab. Make sure that the “Enable file service for Microsoft networking” is checked. Set the workgroup to match the workgroup setting on all of your Windows boxes. For me, that is WORKGROUP. Click the Advanced Options button and set the “Highest SMB version” to the highest value, which for me was SMB 3.0. Note that this may not be necessary, as the default is SMB 2.1, which may work fine. I have not tested with that. Click Apply

Install cifs-utils on your Linux box

> sudo apt-get install cifs-utils

Create an SMB credentials file on your Linux box

In your home directory create and edit .smbcredentials and add the following

username=<some NAS user>
password=<the matching password>

you can use the NAS default admin user account as the user

> chmod 600 .smbcredentials

Add mounts to /etc/fstab on your Linux box

Edit /etc/fstab as sudo and add the following lines to the bottom

# mount the NAS
///Multimedia /mnt/multimedia cifs credentials=/home//.smbcredentials,rw,user 0 0

You can create as many mounts as you want. For example, I created a directory under /homes on the NAS and then mount that as /mnt/backup and backup my laptop to that share.

Mount the new mounts

> sudo mount -a

2014
12.29

Creating a time-lapse movie using avconv

This note explains how to take a number of still images and combine them into a movie using “avconv”.

This note applies to:

  • Ubuntu 14.04
  • avconv 9.16

Planning

Before starting a time-lapse project, one should consider some constraints. The number of pictures that can be taken by the camera is constrained by the size of the memory card where the camera saves its information. On the other hand, the largest possible number of pictures should be taken, since it provides for a smoother end video.

Therefore, an approximate length of the event to be recorded must be used, in conjunction with the total number of pictures that can be saved to memory, to compute the interval between each picture taken.

Also, one should consider the power needs for the extended duration that the camera is used.

Finally, the memory card used by the camera should be fast enough to record the images at the rate that they will be produced.

Image collection

After all pictures have been taken, one ends up with a large collection of images, generally numbered sequentially by the camera using a special naming convention. For this note, an example is used to demonstrate the process. In this example, about 2300 pictures were taken every two seconds, over a period of 1 hour and 20 minutes. The resulting collection was picture named as follows:

IMG_6796.JPG
IMG_6797.JPG
IMG_6798.JPG
IMG_6799.JPG
IMG_6800.JPG
IMG_6801.JPG
IMG_6802.JPG
IMG_6803.JPG
IMG_6804.JPG
...
IMG_9170.JPG
IMG_9171.JPG
IMG_9172.JPG
IMG_9173.JPG

Creating Movie

On Ubuntu, the command-line tool “avconv” can be used to combines still images into a movie. The command required to combine the images from the previous example is:

avconv -r 10 -start_number 6796 -i IMG_%d.JPG -q:v 0 -s hd1080 -vcodec libx264 -crf 25 movie.mp4

The parameter “-r 10” sets the number of frames per second on the input stream. This is an important parameter since it influences both the smoothness of the video and its length. The higher the number, the smoother the resulting video. Ideally, the input frame rate should be 25 to 30 frames per seconds for the best smoothness.

However, following our example, at 25 frames per second, the resulting video would be 1.5 minutes long. In our example, we wish to have the resulting movie showing the original event over 4 minutes. Therefore, the input rate is set to 10.

The parameter “-start_number 6796” specifies the number at which the file name sequence starts at. This parameter is used with the input file format parameter “-i IMG_%d.JPG”, where the portion of the name with %d is replaced by a number, to find each image file.

The parameter “-q:v 0” sets the highest output video quality.

The parameter “-s hd1080” is used to sets the output dimensions of the video to high definition.

The parameters “-vcodec libx264” and “-crf 25” are used to set the output CODEC to H.264 and output frame rate. The output frame rate does not affect the length of the movie.

Conclusion

Although there are many factors to consider when making a time-lapse movie, the command-line tool “avconv” is really useful stitch together the video portion of the project. “avconv” is the successor to “ffmpeg”. Both tools are mature and contain a large number of options.

Therefore, use the options above as a starting point and experiment until you reach the desired effect.

2014
12.02

Graphical notification from scripts

Environment: Linux

My laptop is getting long in the tooth and some programs load very slowly. Since some of these programs are exposed on the desktop as shortcuts to scripts, you need to double click on them to launch them. Unfortunatly, because they load slow and there is no feedback, I can never tell if my double click was recognized. After looking around a bit, I found a tool, notify-send, that allows you to inject messages into the desktop’s notification system.

First, install the package

sudo apt-get install libnotify-bin

I wanted to modify the launch script for Android Studio, which is the studio.sh file in Android Studio’s bin directory. I added the following at the top of the script:

notify-send -t 6000 -i ~/installs/android-studio/bin/idea.png "Starting" "<b>Android Studio</b>"

notification

This puts up a notification message for 6000ms with the idea.png icon with a summary of Starting and the body of Android Studio in bold below it. The notification pops up immediately, giving sufficient feedback so that I don’t keep mashing the mouse button to launch it.

Note that the body allows some simple HTML to be used and the icon argument can either contain the location of an image file or the name of a system standard icon such as these listed here http://askubuntu.com/questions/189231/where-are-the-stock-icon-names-defined-for-the-unity-panel-service-indicators-an

2014
11.13

Oracle Java and update-alternatives

Environment: Ubuntu 14.04

The Linux alternatives system is an excellent way to install and use different program equivalents. If you update Oracle Java quite often (or even once), it can be a tedious task installing new links and removing any old ones.

Since I always install the JDKs in the /usr/lib/jvm directory with the pattern jdk* (eg /usr/lib/jvm/jdk1.8.0_20), this can make it easy for a script to find all of the JDKs. The script shown below will search for all of the JDKs in /usr/lib/jvm and allow you to install or remove all of the programs in the JDK’s bin directory into the alternatives system.

The syntax is:

./updatejava.sh -i

to install a JDK and

./updatejava.sh -r

to remove a JDK.

The script will show the list of JDKs and prompt as to which JDK it should perform the install or delete. Selecting the number corresponding to the JDK and hitting Enter will start the operation.

#!/bin/bash

# ---===( Config constants )===---
PRIORITY=2000
BASEDIR=/usr/lib/jvm

# ---===( usage )===---
usage(){
  echo "Make changes to the alternatives system wrt Java JDKs"
  echo " -i to INSTALL a JDK"
  echo " -r to REMOVE a JDK"
}

# ---===( )===---
if [ $# == 0 ]
then
  usage
  exit
fi

DO_REMOVE=0
DO_INSTALL=0

while getopts hir option
do
  case "$option" in
    r)
      DO_REMOVE=1
      OPERATION="REMOVE"
      ;;
    i)
      DO_INSTALL=1
      OPERATION="INSTALL"
      ;;
    *)
      usage
      exit
      ;;
  esac
done

JDKS=`find $BASEDIR -maxdepth 1 -type d -iname 'jdk*' 2&gt; /dev/null`
echo "Which JDK do you want to $OPERATION? "

# List the JDKs
echo "$JDKS" | awk '{printf("%2d : %s\n", NR,$0)}'

read CHOICE

DIR=`echo $JDKS | cut -d' ' -f $CHOICE`/bin

(
# Get the basename for all of the files that do not have a . in them from the bin dir
cd $DIR
FILES=`find . -maxdepth 1 -executable -type f ! -iname "*.*" -exec basename {} \;`

if [[ "$DO_REMOVE" == 1 ]]
then
  echo "Removing JDK"
  for f in $FILES; do sudo update-alternatives --remove $f $(readlink -f ./$f) ; done
elif [[ "$DO_INSTALL" == 1 ]]
then
  echo "Installing JDK"
  for f in $FILES; do sudo update-alternatives --install /usr/bin/$f $f $(readlink -f ./$f) $PRIORITY ; done
fi
)
2014
09.12

This note explains how to use a WebDAV drive using Windows 7. In particular, this note addresses issues that arise when the WebDAV drive enforces SSL, using a self-signed certificate, and basic authentication. All the steps detailed below are performed on a Windows 7 computer where the Web drive is intended to be used.

This note relates to:

  • Windows 7 client
  • WebDAV drive served by Apache 2.2

References:

Adjust Registry

This step is required if the WebDAV drive enforces user authentication using HTTP “Basic Auth”.

Start the program “regedit.exe” using the following steps:

  • Press “Start” button
  • Choose “Run”
  • Enter “regedit.exe” and press enter

In the regedit program, navigate down the tree using the following path: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WebClient\Parameters

Within the “Parameters” section, set the value of setting “BasicAuthLevel” to 2. The meaning of the values are:

  • 0 – Basic authentication disabled
  • 1 – Basic authentication enabled for SSL shares only
  • 2 or greater – Basic authentication enabled for SSL shares and for non-SSL shares

Close the regedit program.

Reboot Windows.

Import Self-Signed Certificate

This steps imports the WebDAV certificate to the store of trusted certificate. This step is necessary only if the certificate
is self-signed.

Open Internet Explorer as an administrator. Only IE will work for this step (Firefox and Chrome are not helping for this situation).
To open IE as an administrator, press on the “Start” button and find the Internet Explorer entry. Right click on the Internet Explorer entry in the start menu and choose “Run as administrator”.

  • In IE, browse to the site where the WebDAV is stored. It should be a URL that looks like “https://www.mycompany.com/dav/”. If the certificate has not been previously accepted, a dialogue box opens warning the user that the certificate is not trusted. Choose to “Continue to this website (not recommended)”.
  • Once the page of the WebDAV is displayed, the address bar will contain a tab titled “Certificate Error”. Click on this tab and choose “View Certificates”.
  • Click on the “Install Certificate…” button.
  • Choose the option “Place all certificates in the following store” and click on the “Browse…” button
  • Select “Trusted Root Certification Authorities” folder and press “OK” button
  • Click on “Next” and then “Finish”
  • Accept warnings

Once the certificate is installed, IE can be dismissed since it is no longer used.

Mount WedDAV drive

Mount the WebDAV drive using the following steps:

  • Start Windows Explorer (Start > All Programs > Accessories > Windows Explorer)
  • Right-click on “Computer” icon and select “Map Network Drive”
  • Select a letter for your drive
  • Enter the URL for the WebDAV drive (https://www.mycompany.com/dav/) in the field titled “Folder”
  • Select “Connect using different credentials”
  • Press “Finish” button
  • Enter user name and password

At this point, the WebDAV drive should be accessible like any other drive.

2014
01.28

Send message with SSL or STARTTLS using Java Mail

This note explains how to send an e-mail message using JavaMail, including using an SSL connection or the STARTTLS built-in security.

This note applies to:

  • Java version 1.7
  • JavaMail version 1.4.1

If using Maven, the JavaMail artifact can be obtained using the following dependency:

<dependency>
    <groupId>com.sun.mail</groupId>
    <artifactId>javax.mail</artifactId>
    <version>${mail.version}</version>
</dependency>

Often, a properties file is loaded to configure the SMTP transport layer. This allows a user to configure outgoing mail server without having to change the code. Here is a code excerpt to obtain a session and

    import javax.mail.Authenticator;
    import javax.mail.Message;
    import javax.mail.Multipart;
    import javax.mail.PasswordAuthentication;
    import javax.mail.Session;
    import javax.mail.Transport;

    public void send(String to, String from, Properties mailProperties) throws Exception {

        // Check for user name and password
        String userName = null;
        String userPassword = null;
        String prot = mailProperties.getProperty("mail.transport.protocol",null);
        if( null != prot ){
            userName = mailProperties.getProperty("mail."+prot+".user",null);
            userPassword = mailProperties.getProperty("mail."+prot+".password",null);
        }
       
        // Create session
        Session mailSession = null;
        if( null != userName && null != userPassword ) {
            final String name = userName;
            final String pw = userPassword;
           
            Authenticator auth = new Authenticator(){
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(name,pw);
                }
            };
            mailSession = Session.getInstance(mailProperties, auth);
        } else {
            mailSession = Session.getInstance(mailProperties);
        }
       
        // Create a default MimeMessage object.
        MimeMessage message = new MimeMessage(mailSession);
       
        // Set "from" address
        message.setFrom(new InternetAddress(from));
       
        // Set "to" address
        message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
       
        // Subject
        message.setSubject("Hello");
       
        // Body
        message.setText("Hello World");
       
        // Send message
        Transport.send(message);   
    }

Plain Text

For plain text access to the SMTP service, the following properties can be used:

mail.transport.protocol=smtp
mail.smtp.host=<host>
mail.smtp.port=25
mail.smtp.auth=true
mail.smtp.user=<username>
mail.smtp.password=<password>

STARTTLS

For sending a message using the STARTTLS built-in security, the following properties should be used:

mail.transport.protocol=smtp
mail.smtp.host=<host>
mail.smtp.port=587
mail.smtp.auth=true
mail.smtp.user=<username>
mail.smtp.password=<password>
mail.smtp.starttls.enable=true

SSL

For sending a message using SMTP over SSL, the following properties should be used:

mail.transport.protocol=smtp
mail.smtp.host=<host>
mail.smtp.port=465
mail.smtp.auth=true
mail.smtp.user=<username>
mail.smtp.password=<password>
mail.smtp.socketFactory.port=465
mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory

Debugging

There is a property which sets the “debug” mode for JavaMail. It can be set with the following properties:

mail.debug=true
2013
02.10

This note explains how to set up Eclipse for developing images for the EZ430-F2013. This note assumes that the development environment is set up in Ubuntu 12.10.

This note relates to:

  • Ubuntu 12.10
  • EZ430-F2013
  • msp430-gcc version 4.6.3
  • Eclipse Classic version 4.2.1

References:

Install Command-Line Tools

The installation of command-line tools to support the EZ430-F2013 development kit is covered in a different note. Please refer to the note Use EZ430-F2013 in Ubuntu to complete this step.

Install CDT

In Eclipse, the packages that support C/C++ development are named the C Development Toolkit, or CDT. Portions of the CDT are required to enabled a development environment for the EZ430-F2013:

  • C/C++ Development Tools
  • C/C++ Development Tools SDK
  • C/C++ Debugger Services Framework (DSF) Examples
  • C/C++ GDB Hardware Debugging

To install the CDT, in Eclipse:

Create a C project to use MSP-GCC

Create a C project:

  • “File” > “New” > “Project…” > “C/C++ / C Project”
  • Enter a project name
  • Use default location
  • Project Type: Executable > Empty Project > Linux GCC
  • Press Finish

Set up new project to use MSP-GCC:

  • Right-click on project, select “Properties”
  • Select page “C/C++ Build” > “Settings”
  • Select configuration “[ All configurations ]”
  • Select settings “Tool Settings” > “GCC C Compiler”
    • Command: msp430-gcc -mmcu=msp430f2013
  • Select settings “Tool Settings” > “GCC C Compiler” > “Includes”
    • Add include path: /usr/msp430/include
  • Select settings “Tool Settings” > “GCC C Compiler” > “Optimization”
    • Optimization Level: “Optimize for size (-Os)”
  • Select settings “Tool Settings” > “GCC C Linker”
    • Command: msp430-gcc -mmcu=msp430f2013 -Wl,-Map=${BuildArtifactFileBaseName}.map
  • Select settings “Tool Settings” > “GCC C Linker” > “Libraries”
    • Add library search path: /usr/msp430/lib
  • Select settings “Tool Settings” > “GCC Assembler”
    • Command: msp430-as
  • Select settings “Tool Settings” > “GCC Assembler” > “General”
    • Add include path: /usr/msp430/include
  • Select settings “Build Artifact”
    • Artifact type: “Executable”
    • Artifact extension: “elf”
  • Select settings “Binary Parsers”
    • select “Elf Parser”
  • Press “Apply” and “OK”

Once the project is set up correctly, it should be possible to build an image from source by right-clicking on the project and selecting “Build Project”. In the console, the output of the build should look something like the following:

00:00:00 **** Build of configuration Debug for project XXX ****
make all
Building file: ../main.c
Invoking: GCC C Compiler
msp430-gcc -mmcu=msp430f2013 -I/usr/msp430/include -Os -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.c"
Finished building: ../main.c
 
Building target: xxx.elf
Invoking: GCC C Linker
msp430-gcc -mmcu=msp430f2013 -Wl,-Map=xxx.map -L/usr/msp430/lib -o "xxx.elf"  ./main.o  
Finished building target: xxx.elf

00:00:00 Build Finished (took 166ms)

Set Up Debugger Configuration

To debug the project directly from the IDE, a debugger must be configured. The following steps are used to configure a debugger to use the command-line tool “msp430-gdb”:

  • Select “Run” > “Debug Configuration…”
  • Select “GDB Hardware Debugging”
  • Press the “New” icon
  • Set name
  • Tab “Main”:
    • Project: select project
  • Tab “Debugger”:
    • GDB Command: msp430-gdb
    • Set “Use remote target”
    • JTAG Device: Generic TCP/IP
    • Host name or IP address: localhost
    • Port number: 2000
  • Tab “Startup”:
    • Reset and Delay: 3
    • Set: “Halt”
    • Initialization Commands: “monitor erase”
    • Set: “Load image”
    • Set: “Use project binary”
    • Set: “Load symbols”
    • Set: “Use project binary”
  • Tab “Common”:
    • Save as: “Shared file” (select project)
    • Display in favorite menu: “Debug”
  • Press “Apply”

Running the debugger from the IDE is the equivalent to running “msp430-gdb” at the command-line. It first requires that “mspdebug” runs to bridge to the EZ430-F2013 development kit. This can be perform from a terminal or from an Eclipse run configuration (next section).

To run the debugger, select from the menu “Run” > “Debug Configurations…”, choose the debugger create and press the button “Debug”.

Run MSPDEBUG from Eclipse

It is possible to run “mspdebug” from Eclipse using a run configuration. Here are the steps to set it up:

  • Select “Run” > “External Tools” > “External Tools Configurations…”
  • Right-click on “Program” and select “New”
  • Enter name: MSPDebug
  • Select “Main” tab:
    • Location: /usr/bin/mspdebug
    • Arguments: uif -d /dev/ttyUSB0 gdb

Once set up as an external tool, to run “mspdebug”, select “Run” > “External Tools” > “External Tools Configurations…”, click on the program called “MSPDebug” and press the “Run” button.

Conclusion

There are many short-cuts in Eclipse to run external tools and debug configurations without using the tedious menus. One of these short-cuts are located on the main tool bar. These short-cuts makes it very convenient to start “mspdebug” and “msp430-gdb”. The ability of developing and debugging using the EZ430-F2013 directly from Eclipse greatly reduces the development cycle of an image targeted for the MSP430.

2013
02.09

Use EZ430-F2013 in Ubuntu

This note explains how to install the command-line tools in Ubuntu to compile, load and run images destined for the Texas Instrument EZ430-F2013.

The TI EZ430-F2013 is a USB development environment for small dongles that host a TI MSP430 micro-controller (MSP430-F2012 and MSP430-F2013).

This note relates to:

Install Packages

The packages required to work with the MSP430 are available from the main repositories.

sudo apt-get install binutils-msp430 gcc-msp430 gdb-msp430 msp430-libc msp430mcu mspdebug

Verify Drivers for EZ430-F2013

Insert the EZ430-F2013 in a USB port. Then, run “dmesg” to verify that it was detected correctly:

dmesg

The output should end with a set of lines that looks as follows:

[47661.708176] usb 5-1: new full-speed USB device number 8 using uhci_hcd
[47661.905243] usb 5-1: New USB device found, idVendor=0451, idProduct=f430
[47661.905253] usb 5-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[47661.905260] usb 5-1: Product: MSP-FET430UIF JTAG Tool
[47661.905266] usb 5-1: Manufacturer: Texas Instruments
[47661.905272] usb 5-1: SerialNumber: TUSB3410572A43E3DB45FFB1
[47661.909238] ti_usb_3410_5052 5-1:1.0: TI USB 3410 1 port adapter converter detected
[47662.492172] usb 5-1: reset full-speed USB device number 8 using uhci_hcd
[47662.636193] usb 5-1: device firmware changed
[47662.636240] ti_usb_3410_5052: probe of 5-1:1.0 failed with error -5
[47662.636365] usb 5-1: USB disconnect, device number 8
[47662.804100] usb 5-1: new full-speed USB device number 9 using uhci_hcd
[47663.029224] usb 5-1: New USB device found, idVendor=0451, idProduct=f430
[47663.029233] usb 5-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[47663.029240] usb 5-1: Product: MSP-FET430UIF JTAG Tool
[47663.029246] usb 5-1: Manufacturer: Texas Instruments
[47663.029252] usb 5-1: SerialNumber: TUSB3410572A43E3DB45FFB1
[47663.032921] ti_usb_3410_5052 5-1:1.0: TI USB 3410 1 port adapter converter detected
[47663.032950] ti_usb_3410_5052: probe of 5-1:1.0 failed with error -5
[47663.037227] ti_usb_3410_5052 5-1:2.0: TI USB 3410 1 port adapter converter detected
[47663.037509] usb 5-1: TI USB 3410 1 port adapter converter now attached to ttyUSB0

The report from “dmesg” shows that the development kit was mounted to /dev/ttyUSB0. For the remainder of the note, this value is assumed. However, you might need to adjust this value to fit your particular installation.

ls /dev/ttyUSB*

Writing a program for MSP430-F2013

Create a new source file.

gedit sos.c

Paste the following code:

#include <msp430f2013.h>

#define DIM(x) (sizeof(x)/sizeof(x[0]))
#define DOT  {10000, 1}
#define DASH {30000, 1}
#define SP   { 8000, 0}
#define LTR  {16000, 0}
#define WRD  {80000, 0}

#define MORSE_S DOT,SP,DOT,SP,DOT,LTR
#define MORSE_O DASH,SP,DASH,SP,DASH,LTR

typedef struct _Segment {
    unsigned long delay;
    unsigned char state;
} Segment;

Segment segments[] = {
        MORSE_S
        ,MORSE_O
        ,MORSE_S
        ,WRD
};

int main(void)
{
    WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer
    P1DIR |= 0x01;                            // Set P1.0 to output direction

    int sequence = 0;

    for (;;)
    {
        volatile unsigned long i;

        Segment segment = segments[sequence];

        if( segment.state ) {
            P1OUT |= 0x01; // Turn on LED
        } else {
            P1OUT &= 0xfe; // Turn off LED
        }

        i = segment.delay; // Delay
        do (i--);
        while (i != 0);

        // Go to next segment
        ++sequence;
        if( sequence >= DIM(segments) ){
            sequence = 0;
        }
    }

    return 0;
}

The code above drives the LED found on the MSP430-F2013 to emit “SOS” in Morse code. A number of definitions are already declared in the file “msp430f2013.h”. Many header files relating to the MSP430 can be found in the directory /usr/msp430/include.

Compiling and Linking Program

Compiling and linking programs/images for the MSP430 is done by using “msp430-gcc”, which is a version of “gcc” that targets the MSP430 micro-controller. Most options available for “gcc” are also available for “msp430-gcc”.

Compiling using “msp430-gcc” yields object files, as with “gcc”. However, invoking the linker produces *.elf files, which can be loaded on the MSP430-F2013 via the development kit (EZ430-F2013).

Following the example started above, the two lines required to produce an object file from the source code, and then link into an image:

msp430-gcc -c -mmcu=msp430f2013 -g -Os -Wall -Wunused -IInclude -o sos.o sos.c
msp430-gcc sos.o -mmcu=msp430f2013 -Wl,-Map=sos.map  -o sos.elf

mspdebug

A command line utility called “mspdebug” is used to perform most operations that involves the EZ430-F2013 development kit.

First, insert the EZ430-F2013 in a USB port and verify that it is mounted to /dev/ttyUSB0 (see steps above).

When invoking “mspdebug”, one must specify the device that the EZ430-F2013 is mounted as.

mspdebug uif -d /dev/ttyUSB0

This command opens a shell where a number of commands can be sent to the development kit. To leave the shell, press CTRL-D.

Loading Image on MSP430-F2013

Loading an image on an instance of MSP430-F2013 via the development kit is accomplished by using “mspdebug”:

mspdebug uif -d <device> "prog <elf-file>"

where:

  • <device> refers to the device file name where the USB development kit is mounted
  • <elf-file> refers to the ELF file produce by the msp430-gcc linker

Following the example above:

mspdebug uif -d /dev/ttyUSB0 "prog sos.elf"

Debugging MSP430

Via the EZ430-F2013, one can debug the program loaded in the MSP430, including single-step execution, via the “gdb” debugger provided by the MSP430 packages. The command-line utility “msp430-gdb” is similar to “gdb” but designed for the MSP430 micro-controller. However, “mspdebug” is needed to bridge “msp430-gdb” to the MSP430 via the EZ430-F2013 development kit.

The command “gdb” within the shell provided by “mspdebug” start a server that listens to commands from “msp430-gdb” and forwards them to the EZ430-F2013 development kit. When “msp430-gdb” connects to “mspdebug”, it provides a shell similar to the one provided by “gdb”.

The command required to start the server is:

mspdebug uif -d <device> gdb

In a different terminal, attach the debugger with the following command:

msp430-gdb <elf-file>

The commands available in “gdb” are also available in “msp430-gdb”:

  • To execute program: continue
  • To stop program: CTRL-C
  • To list stack variables: info locals
  • To list global variables: info variables

To continue the example started above:

mspdebug uif -d /dev/ttyUSB0 gdb &
msp430-gdb sos.elf

Debug using X Debugger: ddd

If X is available, one can use “ddd”, which is a GUI application to simplify the use of gdb.

sudo apt-get install ddd

To use “msp430-gdb” via “ddd”, one must first start “mspdebug” and then invoke “ddd” by specifying “msp430-gdb”. To continue the example in this note:

mspdebug uif -d /dev/ttyUSB0 gdb &
ddd --debugger msp430-gdb sos.elf

Conclusion

Using the TI EZ430-F2013 development kit with an Ubuntu platform is a snap since all the tools required are readily available in the main repositories. Furthermore, anyone familiar with gcc and gdb can easily transition to the line of tools designed for the MSP430 since the commands and options are almost the same.