Desenvolvimento embarcado no Debian Linux com LaunchPad Tiva C Series e MSP430 | Embedded development on Debian Linux with LaunchPad Tiva C Series and MSP430

English bellow.

Aproveitando a oportunidade com o início das aulas do curso Embedded Systems – Shape the World na plataforma edX.org, ministrado pelos professores Jonathan Valvano e Ramesh Yerraballi da University of Texas at Austin, publiquei no embarcados.com.br um tutorial que tem por objetivo oferecer aos interessados alternativas para configuração de um ambiente desenvolvimento para as plataformas LaunchPad Tiva C TM4C123G e MSP430, ambas da Texas Instruments.


Hitching a ride at the start of classes of Embedded Systems – Shape the World course at edX.org, taught by professors Jonathan Valvano and Ramesh Yerraballi of University of Texas at Austin, the main objective of this tutorial is to offer an alternative setup for a development environment for LaunchPad Tiva C TM4C123G e MSP430, both from Texas Instruments.

These kits are a great low coast alternative for study and project development, the TM4C123G is based on ARM Cortex M4F microcontroller and MSP-EXP430G2, on the low power comsumption microcontroller MSP430.

At the course, Embedded Systems – Shape the World, users can use both the TM4C123G as the LM4F120 kit and the initial goal of this tutorial was to allow the students to uses the Linux along the classes, however, for that the students receive their grades, it’s necessary to integrate the development tool Keil uVision, with a DLL developed by professor Valvano, called TExaS. This library integrates the lab exercises with the edX platform. More informations here.

Despite that, as some users have as development platform the Linux system, the search for alternative tools as hardware compatibility is constant. Some manufactures offers partial support to your platforms and few of then offers full support, at Texas website is possible to see that the MSP430 for example, doesn’t have full Linux support through the Code Composer Studio IDE.

So, basically the Linux users have two choices: become sad for not use your preferred operating system or come out and fight. Happily the community of users and developers is here to help us, and sometimes is really surprising all the support that already exists developed by the open source community.

We need basically of a text editor, compiler, debugger and a tool to send the code to the board, this set of tools is also called toolchain.

The text editor is definitively the easier part, can be simpler as Vi or a integrated development environment (IDE) that, as the name, integrates many other tools and even simmulation tools. Keil uVision and Code Composer Studio are two examples of these tools.

Using Debian Linux 8 (codename Jessie), and most likely any other Debian based distributions as Ubuntu and Linux Mint, we can configure a basic development environment for the platforms LaunchPad Tiva C TM4C123G and MSP430. All the installation is based on softwares available on Debian Linux repository and is needed root or sudo permissions.

For the LaunchPad TM4C123G, we’ll install the following packages (and its respective dependencies):

$ sudo apt-get install gcc-arm-none-eabi gdb-arm-none-eabi lm4flash lmicdiusb unzip make

We need to adjust some permissions for the current user and after this, login the system again:

$ sudo adduser $USER dialout

After the packages install it’s possible to plug the TM4C123G on the USB and see the system recognition:

$ sudo dmesg

The output will be something like this:

[ 5104.297091] usb 2-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3          
[ 5104.297094] usb 2-2: Product: In-Circuit Debug Interface                     
[ 5104.297096] usb 2-2: Manufacturer: Texas Instruments                         
[ 5104.297098] usb 2-2: SerialNumber: 0E2195C8                                  
[ 5104.297789] cdc_acm 2-2:1.0: This device cannot do calls on its own. It is not a modem.
[ 5104.297817] cdc_acm 2-2:1.0: ttyACM0: USB ACM device

It’s possible to see that the system recognizes the LaunchPad board, and that is available at /dev/ttyACM0. Otherwise, we can also check:

$ lsusb | grep -i luminary
Bus 002 Device 012: ID 1cbe:00fd Luminary Micro Inc. In-Circuit Debug Interface
      
$ ls -l /dev/ttyACM0
crw-rw---- 1 root dialout 166, 0 Jan 31 19:03 /dev/ttyACM0

We can notice that access permission to the device /dev/ttyACM0 is for user root and group dialout, thats the reason for we included the current user on this group.

However, it’s not possible to directly access the device as normal users before write a specific rule to the udev system, or libusb will return us a error:

$ echo 'ATTRS{idVendor}=="1cbe", ATTRS{idProduct}=="00fd", GROUP="dialout", MODE="0660"' | sudo tee /etc/udev/rules.d/99-stellaris-launchpad.rules

$ sudo chmod 0644 /etc/udev/rules.d/99-stellaris-launchpad.rules

It’s interesting to reboot the system after these changes to reload the udev rules.

Now we can test the device. The test consists in download the Texas Instruments library here, the download is free but you need to register before.

We can now extract the downloaded exe file (it’s a zip file indeed), access the created directory and simply run:

$ make

After this we’ll access the path examples/boards/ek-tm4c123gxl/blinky/sourcerygxx, where the file blinky.bin is, a already compiled program (we can also explore the source code on the same folder). So we can now send the program to the board using:

$ lm4flash blinky.bin

That returns something like:

Found ICDI device with serial: 0E2195C8
ICDI version: 9270

After this, the board will restart and execute the program that will blink the LED. If you got the following error:

Unable to open USB device: LIBUSB_ERROR_ACCESS
Unable to find any ICDI devices

It’s the udev problem mentioned above and you can confirm running as root:

$ sudo lm4flash blinky.bin

If works as root, please check the 99-stellaris-launchpad.rules content and restart the system. Now we have the TM4C123G working, let’s configure the support for the MSP430, starting again for the packages installation:

$ sudo apt-get install gcc-msp430 gdb-msp430 mspdebug

Again we need to add the current user to the groups, loging again on the system:

$ sudo adduser $USER plugdev

Now it’s possible to plug the board on the USB and check the system:

$ sudo dmesg

We must see something like:

[ 4789.736733] usb 2-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 4789.736736] usb 2-2: Product: Texas Instruments MSP-FET430UIF                
[ 4789.736737] usb 2-2: Manufacturer: Texas Instruments                         
[ 4789.736739] usb 2-2: SerialNumber: B2FF467AF9CB5035                          
[ 4789.736890] usb 2-2: ep 0x82 - rounding interval to 1024 microframes, ep desc says 2040 microframes
[ 4789.742783] cdc_acm 2-2:1.0: This device cannot do calls on its own. It is not a modem.
[ 4789.742789] cdc_acm 2-2:1.0: No union descriptor, testing for castrated device
[ 4789.742807] cdc_acm 2-2:1.0: ttyACM0: USB ACM device

Again the system recognizes the LaunchPad, making him available at /dev/ttyACM0. We can also check:

$ lsusb | grep -i z430
Bus 002 Device 010: ID 0451:f432 Texas Instruments, Inc. eZ430 Development Tool
                                                                                     
$ ls -l /dev/ttyACM0
crw-rw---- 1 root plugdev 166, 0 Jan 31 18:58 /dev/ttyACM0

At this time the access permissions on /dev/ttyACM0 are to the user root and group plugdev. We’ll not have problems if our user are already at this group.

Let’s test the board using the mspdebug tool, if everything is alright must work as normal user:

$ mspdebug --usb-list

Returning something like:

Devices on bus 002:
    002:008 0451:f432 eZ430-RF2500

Now that we have all the environment ok, let’s test compiling a simple code and running at MSP430 board. So we can type at our favorite text editor:

/* MSP430 blink example */
#include

/** 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;

  for (;;) {
    P1OUT = ~P1OUT;
    //delay(0x4fff); /* We can try to change this delay value */
    delay(0x1fff);
  }
}

We will same the source and compile with:

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

And now upload to the board with the mspdebug, using prog blink.elf and run:

$ msgdebug rf2500

Type "help" for more information.
Use the "opt" command ("help opt") to set options.                              
Press Ctrl+D to quit.

(mspdebug)

prog blink.elf
run

And now we have our program running at MSP430.

The main goal of this tutorial was to provide a minimal development environment to the LaunchPad Tiva C TM4C123G and MSP430 platforms, at Debian Linux operating system.

There are other tools available, but not even with full support and it’s interesting to count with this support via the system software repository.

Starting with this minimal setup, it’s possible to use an IDE like Eclipse, mapping the compiler, linker and debugger into this IDE.

A partir de uma configuração mínima como a apresentada, é possível utilizar por exemplo um ambiente de desenvolvimento integrado (IDE) como o Eclipse, mapeando o compilador, linker, depurador e ferramenta de gravação dentro do IDE, centralizando seu ambiente de desenvolvimento.

All trademarks and products mentioned are the property of their respective owners.

References:

http://www.ti.com/tool/ek-tm4c123gxl
http://www.ti.com/tool/ccstudio-tm4x
http://www.ti.com/tool/msp-exp430g2
http://www.ti.com/tool/ccstudio-msp
http://www.ti.com/tool/msp430-gcc-opensource
http://energia.nu/guide/guide_linux/
http://energia.nu/pin-maps/guide_tm4c123launchpad/
http://energia.nu/pin-maps/guide_msp430g2launchpad/