SliTaz GNU/Linux official and community documentation wiki.
.png
Translations of this page:

Slitaz_cooking et MSP430

Voici un récapitulatif des opérations nécessaires pour travailler avec les microcontrôlleurs MSP430 de Texas Instrument sous Slitaz.

Les outils issus du projet mspgcc http://sourceforge.net/projects/mspgcc/ permettent de compiler (gcc), assembler (as) et linker (ld) du code pour les MSP430:

  • binutils-msp430,
  • gcc-msp430,
  • msp430-libc,
  • msp430mcu.

Alors que mspdebug permet de flasher les MSP430. Il est développé par Daniel Beer (http://mspdebug.sourceforge.net/).

Comme je n'ai pas été capable de compiler depuis les sources :-(, je me suis restreint à utiliser les packets disponibles chez Debian. Il devient alors super facile de procéder à l'installation.;-)

Opérations préalables

Il faut télécharger les paquets suivants depuis le serveur debian:

  • binutils-msp430,
  • gcc-msp430,
  • msp430-libc,
  • msp430mcu.

Par exemple pour gcc-msp430 on ira sur la page suivante: http://packages.debian.org/en/sid/i386/gcc-msp430/download

Après téléchargement, on doit avoir:

tux@slitaz:~/Downloads$ ls
binutils-msp430_2.21~msp20110716-1_i386.deb
gcc-msp430_4.5.3~mspgcc-20110716-1_i386.deb
msp430-libc_20110612-2_i386.deb
msp430mcu_20110613-3_all.deb
tux@slitaz:~/Downloads$

Il y a également quelques paquets Slitaz à installer (en root):

tux@slitaz:~/Downloads$ su
password

root@slitaz:~# tazpkg get-install slitaz-toolchain
root@slitaz:~# tazpkg get-install usbutils
root@slitaz:~# tazpkg get-install libusb
root@slitaz:~# tazpkg get-install libusb-dev

binutils-msp430

On converti le paquet debian en tazpkg (en root):

root@slitaz:/home/tux/Downloads# tazpkg convert binutils-msp430_2.21~msp20110716-1_i386.deb

On l'installe:

root@slitaz:/home/tux/Downloads# tazpkg install binutils-msp430-2.21~msp20110716-1.tazpkg

gcc-msp430

On converti le paquet debian en tazpkg (en root):

root@slitaz:/home/tux/Downloads# tazpkg convert gcc-msp430_4.5.3~mspgcc-20110716-1_i386.deb

On l'installe:

root@slitaz:/home/tux/Downloads# tazpkg install gcc-msp430-4.5.3~mspgcc-20110716-1.tazpkg

msp430-libc

On converti le paquet debian en tazpkg (en root):

root@slitaz:/home/tux/Downloads# tazpkg convert msp430-libc_20110612-2_i386.deb

On l'installe:

root@slitaz:/home/tux/Downloads# tazpkg install msp430-libc-20110612-2.tazpkg

msp430mcu

On converti le packet debian en tazpkg (en root):

root@slitaz:/home/tux/Downloads# tazpkg convert msp430mcu_20110613-3_all.deb

On l'installe:

root@slitaz:/home/tux/Downloads# tazpkg install msp430mcu-20110613-3.tazpkg

mspdebug

On prépare la compilation (en utilisateur tux):

tux@slitaz:~/Downloads$ tar xvfz mspdebug-0.17.tar.gz
tux@slitaz:~/Downloads$ cd mspdebug-0.17/
tux@slitaz:~/Downloads/mspdebug-0.17$ make WITHOUT_READLINE=1

On installe en root:

tux@slitaz:~/Downloads/mspdebug-0.17$ su
Password: 
root@slitaz:~# cd /home/tux/Downloads/mspdebug-0.17/
root@slitaz:/home/tux/Downloads/mspdebug-0.17# make install
mkdir -p /usr/local/bin
mkdir -p /usr/local/share/man/man1
/usr/bin/install -m 0755 mspdebug /usr/local/bin/mspdebug
/usr/bin/install -m 0644 mspdebug.man \
        /usr/local/share/man/man1/mspdebug.1
root@slitaz:/home/tux/Downloads/mspdebug-0.17# exit

Un peu de ménage

Maintenant que tout est installé, on peut éventuellement se débarasser des fichiers suivants:

tux@slitaz:~/Downloads$ rm -f *deb
tux@slitaz:~/Downloads$ rm -f *tazpkg
tux@slitaz:~/Downloads$ rm -f mspdebug-0.17
tux@slitaz:~/Downloads$ rm -f mspdebug-0.17.tar.gz

Un petit test

Le test que je propose est le suivant: Faire clignoter la led disponible sur le kit “ez430-2013” disponible pour 20$ chez Texas.

Pour cela, il faut:

  • avoir installé tous les outils (binutils-msp430, gcc-msp430, msp430-libc, msp430mcu et mspdebug),
  • être en possession du kit “ez430-2013”. C'est une petite clef USB bien sympa.
  • être en possession d'une prise USB de libre sur le pc.

Les étapes à suivre sont:

  • faire un petit répertoire pour mettre tous les fichiers,
  • rédiger le programme main.c,
  • rédiger le Makefile,
  • compiler le programme,
  • flasher le programme du kit “ez430-2013”.

Création du répertoire de travail

tux@slitaz4:~$ mkdir -p ./Documents/test_msp430/ez430_201x/blink_led
tux@slitaz4:~$ cd Documents/test_msp430/ez430_201x/blink_led

Rédaction du main.c

Avec l'éditeur de son choix, créer le fichier suivant et le sauver en <main.c>.

#include <msp430.h>
#include <legacymsp430.h>

void main(void)
{
  volatile unsigned int i = 0;
  
  /*on utiliser pas le watchdog*/
  WDTCTL = WDTPW + WDTHOLD;
  
  /*on configure la pin P1.0 en output.
  C'est ici que la led est connectée.*/
  P1DIR |= 0x01;

  while(1)
  {
    /*on attend un peu pour voir le clignotement, sinon trop rapide.*/
    for(i = 65500; i > 0; i--) nop();
    
    /*on inverse l'état de la sortie.*/
    P1OUT ^= 0x01;
  }
}

Rédaction du Makefile

Avec l'éditeur de son choix, créer le fichier suivant et le sauver en <Makefile>. Il faut gaffe à bien mettre des tabulations (et non pas des espaces).

C=msp430-gcc
CFLAGS=-Os -Wall -g -mmcu=msp430f2012

OBJS=main.o


all: $(OBJS)
	$(CC) $(CFLAGS) -o main.elf $(OBJS)

%.o: %.c
	$(CC) $(CFLAGS) -c $<

clean:
	rm -fr main.elf $(OBJS)

Compilation du programme

Il suffit de lancer la commande “make” pour créer le fichier <main.elf>.

tux@slitaz4:~/Documents/test_msp430/ez430_201x/blink_led$ make
msp430-gcc -Os -Wall -g -mmcu=msp430f2012 -o main.elf main.o

Voici les fichiers qui devraient être dans notre répertoire de travail:

tux@slitaz4:~/Documents/test_msp430/ez430_201x/blink_led$ ls
main.c    main.elf  main.o    Makefile

Flasher le programme dans le chip

Pour flasher le programme dans le chip, on utilise l'outils “mspdebug”. Pour faire simple, il faut:

  • se logguer en root,
  • insérer le kit “ez430-2013” dans un port usb du pc,
  • lancer “mspdebug”,
  • flasher le chip,
  • quitter et apprécier. :-)

Voici le récapitulatif:

root@slitaz4:/home/tux/Documents/test_msp430/ez430_201x/blink_led# mspdebug uif
MSPDebug version 0.21 - debugging tool for MSP430 MCUs
Copyright (C) 2009-2012 Daniel Beer <dlbeer@gmail.com>
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

ti3410: warning: can't detach kernel driver: No such file or directory
TI3410 device is in boot config, setting active
Initializing FET...

FET protocol version is 10002000
Set Vcc: 3000 mV
Configured for Spy-Bi-Wire
Device: MSP430F20x2
Number of breakpoints: 2
fet: FET returned NAK
warning: device does not support power profiling
Chip ID data: f2 01 02

Available commands:
    =           erase       isearch     opt         run         setwatch_w  
    alias       exit        load        power       save_raw    simio       
    break       fill        load_raw    prog        set         step        
    cgraph      gdb         locka       read        setbreak    sym         
    delbreak    help        md          regs        setwatch    verify      
    dis         hexout      mw          reset       setwatch_r  verify_raw  

Available options:
    color           gdb_loop        iradix          
    fet_block_size  gdbc_xfer_size  quiet           

Type "help <topic>" for more information.
Press Ctrl+D to quit.

(mspdebug) prog main.elf
Erasing...
Programming...
Writing  116 bytes at f800 [section: .text]...
Writing   32 bytes at ffe0 [section: .vectors]...
Done, 148 bytes total
(mspdebug) exit
root@slitaz4:/home/tux/Documents/test_msp430/ez430_201x/blink_led# 

ENJOY

Et maintenant, la led devrait clignoter. :-)

 
fr/guides/msp430.txt · Last modified: 2013/02/01 19:43 by totoetsasoeur