Knowing the chef, a lib430 update.

If you have checked out the sourcecode for lib430 yet, you have probably already used the chef to build a library for your mcu of taste. However, if you use several different mcus, and would like to have it built for all of them we can use the buildall.sh script.

Also, you should not remember to call svn update frequently as there is a lot of work going on on the code all the time.

noccy@noccy-desktop:~/Development/mspdev/lib430$ ./buildall.sh
You must first create a file named MCUS and populate it with one microcontroller per line

So let’s create a MCUS file. Just use “cat > MCUS” if you are on *nix. Put in the mcus one per line and hit Ctrl-D when you are done.

noccy@noccy-desktop:~/Development/mspdev/lib430$ cat > MCUS
msp430g2553
msp430f2013
msp430g2452
^D

Calling on buildall will now call the chef to build for each of the controllers:

noccy@noccy-desktop:~/Development/mspdev/lib430$ ./buildall.sh
== Cooking for: msp430g2553 ==
      libair              : Failed          : See msp430g2553/libair.log
   ·· libarduino          : Successful      : (1 libraries, 1 headers)
   ·· libcomm             : Successful      : (1 libraries, 3 headers)
   ·· libcore             : Successful      : (0 libraries, 4 headers)
      libfat              : Failed          : See msp430g2553/libfat.log
      libhal              : Failed          : See msp430g2553/libhal.log
   ·· liblcd              : Successful      : (1 libraries, 1 headers)
      libmidi             : Failed          : See msp430g2553/libmidi.log
   ·· libsound            : Successful      : (0 libraries, 0 headers)
   :: 3 libraries and 9 headers have been installed.
== Cooking for: msp430f2013 ==
      libair              : Failed          : See msp430f2013/libair.log
      libarduino          : Failed          : See msp430f2013/libarduino.log
      libcomm             : Failed          : See msp430f2013/libcomm.log
   ·· libcore             : Successful      : (0 libraries, 4 headers)
      libfat              : Failed          : See msp430f2013/libfat.log
      libhal              : Failed          : See msp430f2013/libhal.log
   ·· liblcd              : Successful      : (1 libraries, 1 headers)
      libmidi             : Failed          : See msp430f2013/libmidi.log
   ·· libsound            : Successful      : (0 libraries, 0 headers)
   :: 1 libraries and 5 headers have been installed.
== Cooking for: msp430g2452 ==
      libair              : Failed          : See msp430g2452/libair.log
   ·· libarduino          : Successful      : (1 libraries, 1 headers)
      libcomm             : Failed          : See msp430g2452/libcomm.log
   ·· libcore             : Successful      : (0 libraries, 4 headers)
      libfat              : Failed          : See msp430g2452/libfat.log
      libhal              : Failed          : See msp430g2452/libhal.log
   ·· liblcd              : Successful      : (1 libraries, 1 headers)
      libmidi             : Failed          : See msp430g2452/libmidi.log
   ·· libsound            : Successful      : (0 libraries, 0 headers)
   :: 2 libraries and 6 headers have been installed.
noccy@noccy-desktop:~/Development/mspdev/lib430$

One thing you might notice is that some of the libraries doesn’t build for some of the microcontrollers. This can be sorted with custom #defines in the various libraries to adapt to the controller. This is where you come in. If you can get something working that wasn’t, your patches are more than welcome. I am a single developer, and this is a work in progress. So I hope you enjoy lib430!

lib430 updates

lib430 has been updated together with all the skeleton files. Actually, the skeleton files updated first, causing the chef to fail at building the libraries altogether. But everything has been sorted. If you have other projects that depend on the skeleton makefiles (primarily common.mk) you should use SOURCEC in your include file to define the source files to compile, rather than SOURCES. As an added bonus, you can now use SOURCECPP and SOURCEASM to point to C++ and assembly files to compile.

libArduino is in the process of being improved with basic “uptime” functionality. This makes the micros() and millis() usable in your code. They will however count with a reduced granularity, which means that subsequent calls to the functions are likely to return the same value. This is done to preserve memory and make sure that the counters can run long enough. The main file has also been updated to remove external dependencies on libCore for wdt_halt().

libAir is moving as well. It is however not working yet. The drivers for the RFM70 and CC1101 radios are still very much in the works.

libLcd should be working with HD44780 displays, but I have been unable to test this code fully as I suspect my 16×2 LCD is broken. However, the HD44780 is not the only display out there, so more drivers are needed. Have you got some code to contribute perhaps? :) Make sure to put yourself as @author in the header files.

libComm currently implements a mostly working FIFO buffer, while the Software UART (suart) support is still untested. The Hardware UART (huart) implementation is not yet complete, and the same goes for SPI and I²C.

Please download it and have a go at it, and if possible feel free to pitch in. If you have code to contribute for any of the libraries, or would like to propose a new library for the collection just let me know.

lib430

I have posted an update on G+ about libArduino on Google+ but I have not mentioned lib430 yet. If you were observant, the clues were to be found in the SVN repository and the build instructions. Either way it’s about time to officially tell you about lib430 and what it is. So here goes.

lib430 is not a library per se. It is a collection of libraries to cover all the most common areas. The one that is probably most interesting to anybody who is new to lib430 is libcomm which implements communication routines, both via hardware and software uart including SPI and I²C. The reason I am building it is because I would rather create proper building blocks before I start building stuff.

lib430 is licensed under a GNU GPL license, and is thus an open source project. What is important is that it remains a collection of modular and useful libraries, and as such it will hopefully grow to provide a reliable and efficient foundation for future MSP developers to build on.

How to get it.

Check it out from the Subversion repository:

$ svn checkout http://svn.noccy.com/mspdev mspdev

That part is simple enough. Once the checkout is done you can use the “svn update” command to keep it fresh.

How to build it.

The chef is ready to serve you a freshly compiled library to use. You need, however, first either…

  • Attach your Launchpad to the computer via USB and wait for the device to be ready. This is so that our magical voodoo-induced Makefiles will be able to detect your microcontroller.
  • Define the “MCU” environment variable. In bash you do that by either putting the variable before the command (f.ex. “MCU=msp430g2553 ./chef -b”) or exporting it (f.ex. “export MCU=msp430g2553 && ./chef -m msp430g2553 -b”.)
Once we know what we want, and the chef will serve it up:
$ ./chef -m msp430g2553 -b
== Cooking for: msp430g2553 ==
 :: libair: Installing
 :: libarduino: Installing
...

The -b switch will tell the script to build the library for the specified mcu (-m mcu). You can also delete old libraries with the -d switch. -p to package it into a tar.gz file or -a descriptive-name to create a patch file that you can contribute to the project if you don’t have write access to the Subversion repository.

How to use it.

If you have played with libraries in C earlier, you probably know this already. If not, I will introduce you gently into the beautiful world of libraries. First of all, libraries are nothing but archives (or compressed folders if you prefer) containing object files (.o). So, when you link with a library, you link with the object files in there.

As such, you can provide the library as an input file to the linker, or you can keep the files in a known location and use the -llib (lowercase “L”)switch to link to the library. Both of these alternatives do require you to use the -Ipath (capital “i”) option to specify the path where the include files can be found. If you have copied the include files and the library files (extension “.a”) into your project, a simple -I. will suffice. Otherwise you need to provide the path to where they are located on your filesystem.

The -l (lowercase”L”) alternative however requires you to provide yet another path, the location to where the library files can be found using the -Lpath argument. Without this the compiler won’t be able to find the libraries much less link them. Also, you strip the “lib” part of the files when specified with -l, so as such “libfoo.a” becomes “-lfoo”.

Making things easier for us are the makefiles that you can find in the skeleton folder. Copy the Makefile to your project folder, and modify the definitions appropriately:

# Source files and target binary, define your source files here to have them
# compiled, and define the target basename. An .elf binary will be created as
# well as a .hex file:
SOURCES = main.c database.c config.c
SOURCESA =
TARGET = mspov

include ../../skeleton/common.mk

LIBS = -L../../lib430/$(MCU)/lib
INCLUDES = -I../../lib430/$(MCU)/include
LIBS += -lair

Take notice to the fact that the include statement is defined before the library definitions. This is because the MCU variable will be in the include, and it is needed to find the appropriate paths for the LIBS and INCLUDES variables.

Now you know how to set up the building. Now how to actually use it. The best way to figure that part out for now is by looking at the include files. Doxygen will eventually be used to automate documentation building. Either way, once the code is in place,  just type “make” to build your project.

Contributing.

You can contribute by providing patches. These patches should be sent to the lib430 list at https://groups.google.com/group/lib430. SVN write access can be arranged for contributors.

More Information.

  • Hyperlinked Markdown: lib430 README
  • Supported Compilers: GCC
  • Supported Microcontrollers: TI msp430 series
  • Language: C (GNU)