openchronos Hello World tutorial  This short tutorial is about getting started with the development of OpenChronos NG firmware for the eZ430Chronos watch under Ubuntu Linux LTS. This nice development tool in a watch was also described in my previous article:  https://www.itopen.it/2013/11/28/the-hackable-watch-a-wearable-msp430-mcu/.

Preparing the development environment

Starting the development with OpenCronos NG wasn’t the easiest thing I’ve done recently: most difficult step being to find a suitable code base, I ended up starting from a fork of  OpenCronos NG: https://sourceforge.net/u/joachimbreitner/openchronos-ng/ as explained in details at the end of the previous post: https://www.itopen.it/2013/11/28/the-hackable-watch-a-wearable-msp430-mcu/. The easy way to set up a working development environment in Linux Ubuntu 12.04 LTS is to use the pre-built Energia binaries, you can download the latest release from http://energia.nu/download/ , choose the version that matches  your Linux flavour and unzip the package somewhere in you home directory. For example, I did unzip the package directly in my home folder and I now have the compiler and other binaries available under: ~/energia-0101E0010/hardware/tools/msp430/bin/

Downloading openchronos-ng

As explained above, I chose to start from a fork:
$ # move to home folder (or choose another folder)
$ cd
$ # This step downloads the openchronos-ng branch
$ git clone git://git.code.sf.net/u/joachimbreitner/openchronos-ng u-joachimbreitner-openchronos-ng
$ cd u-joachimbreitner-openchronos-ng/
The makefile should be informed about the location of the compiler tools, just add the path to Common.mk:
COMPILER_PATH=~/energia-0101E0010/hardware/tools/msp430/bin/

CC		= $(COMPILER_PATH)msp430-gcc
LD		= $(COMPILER_PATH)msp430-ld
AS		= $(COMPILER_PATH)msp430-as
AR		= $(COMPILER_PATH)msp430-ar

Creating a new module

Now that your development environment is in place, we can start adding an Hello World! module that will print “Hello” and “World” on the watch display, alternating every second between the two strings. To add a new module in OpenCronos NG, you simply add two new file into the modules folder, let’s start:
$ pwd
/home/xxx/u-joachimbreitner-openchronos-ng
$ # Create the module files
$ touch modules/hello.cfg modules/hello.c
At the end we will have the following structure:
modules/
├── hello.c
└── hello.cfg
Now we will add some code into the hello module, this is the content of the files: The .cfg is just a configuration file for make config, that allows you to select if the module has to be built.
$ cat modules/hello.cfg 
[HELLO]
name = Hello
default = true
help = Displays Hello
The C code file hello.c:
/*
    hello.c: hello display module

    Copyright (C) 2013 Alessandro Pasotti <apasotti@gmail.com>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include 

/* drivers */
#include "drivers/display.h"

volatile uint8_t say_toggle = 0;

// The callback
static void say_hello(enum sys_message msg)
{
   if(say_toggle){
        display_chars(0, LCD_SEG_L2_5_0, " WORLD", SEG_SET);
    } else {
        display_chars(0, LCD_SEG_L2_5_0, " HELLO", SEG_SET);
    }
    say_toggle = ! say_toggle;    
}

/************************** menu callbacks ********************************/

// Called on module activation
static void hello_activate(void)
{
    display_chars(0, LCD_SEG_L1_3_0, "HELL", SEG_SET);
    // register messagebus callback every second
    sys_messagebus_register(&say_hello, SYS_MSG_RTC_SECOND);
}

// Called on module deactivation
static void hello_deactivate(void)
{
    sys_messagebus_unregister(&say_hello);	
}

// Module intialization
void mod_hello_init(void)
{
    menu_add_entry("HELLO", NULL, NULL,
        NULL, NULL, NULL, NULL,
        &hello_activate, &hello_deactivate);
}

Configuration and build

Now launch make config and choose to build Hello module (it should be selected by default), then save.
$ make config
$ make clean && make
The new firmware is named “openchronos.txt” and you can find it in the same folder, now you can upload it using the control center as explained in the user guide (see documentation in  http://www.ti.com/lit/zip/slac388).

Trackbacks/Pingbacks

  1.  ItOpen – Open Web Solutions, WebGis Development » Blog Archive » The hackable watch: a wearable MSP430 MCU