Channels ▼

Al Williams

Dr. Dobb's Bloggers

Cross Product of Pi

August 19, 2013

I've been on a Raspberry Pi kick the last few weeks. Of course, there's nothing you do on a Pi that you can't do on any Linux system. Part of its power is that it is just a cheap Linux box. That means all the Portaudio DTMF code I've been working on would work just as well on a desktop box or a Beagle Board or any of a dozen other Linux-based computers.

I've made the point before that you can often use the Linux tools to do things without so much coding, and the tone decoding is a good case in point. I can use two pieces of software right out of the Raspberry Pi repositories to get the same function. The trick is using multimon, a piece of software aimed at ham radio operators. It can do many things, including decode DTMF tones. You can install it with apt-get right on the Pi.

There are probably a dozen ways to make multimon work with the Pi, but here's what I did:

mkfifo fifo.wav   # create a named pipe to hold audio data
arecord –r 22050 –D hw:AK5370 –f S16_LE –t wav >fifo.wav &
multimon –a DTMF –t wav fifo.wav

The arecord options, of course, depend on the hardware you have plugged into your Pi. You can use arecord –L to find out what devices are connected.

Turns out multimon sometimes gives you multiple outputs from a single tone, so it isn't quite as robust as my code. However, you could probably work around it and since you have the source, you could fix it and contribute the fix back to the open source community.

Which leads to my real topic this week: How to build software for the Pi. There is something attractive about being able to log into the Pi and just build software on the box. This isn't bad at all for me because I'm decidedly low tech with my tools — just emacs and the compiler. You can use the –X option for ssh to let windows show up on your X desktop. I often use sshfs to mount the Pi's filesystem too so I can use desktop tools to edit files.

However, the novelty of this wears off pretty quickly. The Pi is a lot slower than my desktop. If you like to use a big IDE, it probably is even worse. Of course, you can use the sshfs trick to do your editing, but you still have to compile on the little board. That is, unless you build a toolchain on your desktop that can cross compile for the Pi.

I've built a lot of cross compile chains and it is always a headache. I decided this time to try Crosstool-ng. It purports to be a tool for building toolchains with an interface reminiscent of configuring the Linux kernel.

You can follow the instructions for building crosstool on their web site. To build a Raspberry Pi chain, you want to select the ARM platform (32-bit and little endian) when you run ct-ng menuconfig from a working directory. You also want to select a Linux OS. My Pi uses the 3.2.27 kernel, which wasn't a choice, so I just selected the closest 3.2 kernel — it shouldn't make much difference. You might also want to change the compiler (I used the experimental Linaro compiler) and move the install location (but note that you need write permission for that directory; ct-ng won't prompt you for your root password).

Once you have your configuration saved, you can run ct-ng build and the tool will download all the files necessary and build everything. I have a pretty fast connection and it took about 10 minutes to download everything, so this is a good thing to do right before lunch. The total build on my machine took about a half hour.

I wound up with a directory called /opt/crosstools/x-tools/arm-unknown-linux-gnueabi that had all the compiler and binary tools required to build a program (because I had set the prefix to /opt/crosstools/x-tools). It was easy to add that directory to my path and compile a Raspberry Pi program:

PATH="/opt/crosstool/x-tools/arm-unknown-gnueabi/bin:$PATH"

Don't forget the tools get named with the cross target. If you run gcc you will still get your native system gcc. You want to use arm-unknown-linux-gnueabi-gcc (or whatever tool you are trying to run). A typical session might look like this:

arm-unknown-linux-gnueabi-gcc –g –o hellopi hellopi.c
scp hellopi pi@rasppi:    # copy to remote target
ssh pi@rasppi ./hellopi

The crosstool-ng really works and not just for the Raspberry Pi. It does take a few minutes to run, but it saves a lot of time and annoyance compared to trying to build everything and configure it yourself.

Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 


Video