Tuesday, September 18, 2012

How to strip file extension in a bash shell script function

FILENAME=`echo $1 | sed -e 's/\..*//g'`
From a BASH function take the first command line argument and strip off the extension and then assign it to the variable FILENAME.

It's probably not the best way of doing it, but it's how it happened.  I couldn't find any one liners from the googles :'(

Post your better solution in the comments below!11111!!!!

This is the total function (in my bash.bashrc):

mk430 () {
  FILENAME=`echo $1 | sed -e 's/\..*//g'`
  msp430-gcc -mmcu=msp430f2274 -o $FILENAME.elf $1
}
for compiling MSP430 C files to elfs, there's probably a better alias too!

Sunday, September 9, 2012

MSP430 eZ430-RF2500 on Arch Linux

Hi, I didn't see much info on this particular model and Arch. So I'll log what I do here:

I plugged in the USB dongle with the breakout board attached, ran lsusb which showed this entry:

Bus 008 Device 004: ID 0451:f432 Texas Instruments, Inc. eZ430 Development Tool
So far so good. Now I need to install some stuff:
$ yaourt mspdebug-git
yaourt is a AUR package manager, you can do this manually by searching aur.archlinux.com and then installing the package with makepkg.

The build fails: make: /bin/install: Command not found
I run these commands to make a soft-link to `which install`:
$ cd /bin
$ sudo ln -s /usr/bin/install install

then select Restart building mspdebug-git? [y/N] y

The build succeeds and the package installs.
I type...
$ sudo mspdebug rf2500
because shamwowzow, I'm a frolicking alien and it connects to the device and gives me a prompt, I see the availiable commands and enter:
(mspdebug) run
The light on the breakout board begins flashing, I plugin the other board and the green light turns on... signalling a wireless connection I suppose.
I used sudo because I guess my normal user doesn't have permission to do this kind of magic yet, probably have to add it to some group.
[EDIT]: $ sudo gpasswd -a uucp

NOW TO TRY AND WRITE SOME CODE FOR THIS JOLLY WAG.

I search AUR for mspgcc for a gcc toolchain or whatever, and it shows me a lot of stuff. I dunno what to do so I read this ubuntu guide for some ideas. Then I read this arch linux guide for another MSP430.  Seems promising. I search AUR for MSP430, seems like there's a package called `gcc-msp430`  I'll try that...
$ yaourt gcc-msp430
 I type `1-3` to install the 3 packages... I lazily don't edit the PKGBUILDs like a lazy arch user that's prone to blowing off his feet because of silly mistakes. Things compile, things install, things download and repeat, I type `y` and `n` seemingly arbitrarily to get through this maze of discrete choice towards getting code into some carefully crafted silicon hanging in it's bare PCB off the dongle at the front of my PC....

Wow. This takes a long time, I was running BOINC (like SETI for AIDS and malaria and protein folding) and turned it off so my CPU could focus on compiling all this MSP430 junk...

The next patch would create the file ld/emulparams/msp430uni.sh,
which already exists!  Assume -R? [n]
Uh oh, I'm just going to press enter and hope the god of good defaults saves me.

Apply anyway? [n]
Skipping patch.
1 out of 1 hunk ignored
Uh oh, now its doing the same thing with `msp430.em`... I'm going to ctrl-c and try putting `y` instead...
I just ran `yaourt gcc-msp430` again, it's retrieving sources.... I dont think yaourt has a cache >.>

Ugh. That was a mistake.
Ok so I pressed `y` to make it assume -R (which means reversed or something, idk) and now it finally came back with:

make[4]: *** No rule to make target `emulparams/msp430uni.sh', needed by `emsp430.c'.  Stop.
make[4]: Leaving directory `/tmp/yaourt-tmp-nak/aur-mspgcc-binutils/src/binutils-2.21.1/ld'
make[3]: *** [all-recursive] Error 1
going to "restart building" again and try just pressing enter like I did the first time... I really don't know what I'm doing at this point, as if I ever did... wow didn't even come to that point.

Targets (1): mspgcc-binutils-20120406-1
Total Installed Size:   9.95 MiB
Proceed with installation? [Y/n]
(1/1) checking package integrity                                       [#######################################] 100%
(1/1) loading package files                                            [#######################################] 100%
(1/1) checking for file conflicts                                      [#######################################] 100%
error: failed to commit transaction (conflicting files)
mspgcc-binutils: /usr/bin/msp430-addr2line exists in filesystem
mspgcc-binutils: /usr/bin/msp430-ar exists in filesystem
...
with a ton more "exists in filesystem" messages, then quits saying no packages were upgraded. I don't know what's happening, I don't think it does either.
Well I guess I'll try and compile some LED blinking code from here and put it on there.

$ msp430-gcc -g -o led.elf led.c
led.c:1:26: fatal error: msp430x20x3.h: No such file or directory
compilation terminated.
Guess I need some headers... or something...
$ yaourt msp430-libc
Uhh ok its doing mspgcc-binutils again... pray for it.
Wow... I'm just not very good at yaourt, I've been installing crap I don't need by doing stuff like 1-3 ... I need to do a little cleaning after I'm done I think.
$yaourt msp430mcu
this says it installs the headers... getting closer

[nak@arch msp430]$ msp430-gcc -g -o led.elf led.c
/usr/bin/msp430-ld: cannot open linker script file memory.x: No such file or directory
collect2: ld returned 1 exit status
OKAY THIS IS THE -mmcu FOR THE eZ430-RF2500:
msp430-gcc -mmcu=msp430f2274 -o led.elf led.c
it output an elf without any errors, now to put it on the board...

WOOO ROCKSTAR FROM MARS
$ sudo mspdebug rf2500
(mspdebug) erase
Erasing...
(mspdebug) prog led.elf
Erasing...
Programming...
Writing  154 bytes at 8000 [section: .text]...
Writing   32 bytes at ffe0 [section: .vectors]...
Done, 186 bytes total
(mspdebug) run
Running. Press Ctrl+C to interrupt...

And the LED is blinking~
I'll created a compressed version of this sometime.