Friday 9 August 2013

Tutorial: Using the DSP on the BeagleBoard

Introduction


Hello! In this tutorial I'll be showing you how to utilise the BeagleBoard's TMS320C64x+ digital signal processor (DSP). I've recently started working on a project using the BeagleBoard and have been trying to use its DSP for a while now, but have found that most online resources are either hilariously outdated or contradict each other, making using the DSP rather arduous. Now that I've finally gotten it working, I've written this concise tutorial to help others that are struggling like I was.  

Requirements


+ An internet connection for downloading required files
+ A BeagleBoard; I used a BeagleBoard xM Rev. C
+ An x86/x86_64 host machine running GNU/Linux; I used Linux Mint 15 on my laptop
+ A micro-SD card reader compatible with your host machine
+ A micro-SD card, preferably with at least 4 GB capacity
~ (Optional) An ethernet connection to your BeagleBoard, allowing you to SSH into it over LAN

1 - Install Ubuntu 12.10 on the BeagleBoard


While you can probably get the DSP working with Angstrom, it's much much easier to use Ubuntu. Robert C Nelson maintains a number of Ubuntu images tailored to the BeagleBoard with a pre-configured DSP/Bridge-compatible kernel (this saves you building the kernel yourself and avoids a lot of the nitty-gritty). Download the latest version here, or to get the same version as me:

Host machine:
$ cd ~
$ mkdir dsp-stuff && cd dsp-stuff
$ wget http://rcn-ee.net/deb/rootfs/quantal/ubuntu-12.10-console-armhf-2013-07-22.tar.xz
$ tar xf ubuntu-12.10-console-armhf-2013-07-22.tar.xz
$ cd ubuntu-12.10-console-armhf-2013-07-22

Now you'll need to flash the Ubuntu image onto your micro-SD card. First, identify your card's device handle by inserting it into the card reader and running lsblk. USB card readers tend to show up as /dev/sdX whereas built-in card readers show up as /dev/mmcblkX. My card shows up as /dev/mmcblk0.

Once you've identified your card's device handle, run the setup_sdcard.sh script:

Host machine:
$ chmod +x ./setup_sdcard.sh
$ sudo ./setup_sdcard.sh --mmc /dev/mmcblk0 --uboot beagle_xm

There are two things to note here: first, you point the --mmc flag to the entire memory card, not just the first partition on the card (ie /dev/mmcblk0 as opposed to /dev/mmcblk0p1). Secondly, if you're using a normal BeagleBoard (not an xM) then change the --uboot flag to point to beagle instead of beagle_xm.

If everything went OK, the micro-SD card is now ready to be used in the BeagleBoard.

2 - Setup Ubuntu on the BeagleBoard


Login to the BeagleBoard (for example using serial communication) with username ubuntu and password temppwd.

First, update the system:

BeagleBoard:
$ sudo apt-get update
$ sudo apt-get upgrade

Change the root password:

BeagleBoard:
$ sudo -i
# passwd
# exit
# logout

Now log back into the BeagleBoard, directly into the root account using the password you just set. From here you can change the default username and password (replacing NEWNAME with your desired username):

BeagleBoard:
# passwd ubuntu
# usermod -l NEWNAME ubuntu

Now change the BeagleBoard's hostname (its name on your network). I chose to use 'bbxm':

BeagleBoard:
# echo bbxm > /etc/hostname

You'll also need to change your hosts file:

BeagleBoard:
# nano /etc/hosts

Change the 2nd line (127.0.1.1), replacing 'arm' with your chosen hostname. Since I chose to use 'bbxm', my /etc/hosts file looks like this:

127.0.0.1 localhost
127.0.1.1 bbxm

Now reboot the BeagleBoard:

BeagleBoard:
# reboot

While you can do everything over serial communication, or even plug a mouse/keyboard/monitor directly into the BeagleBoard, I find it's much cleaner and simpler to leave my board in a shoe box under the stairs with a wired ethernet connection to my router. This keeps my desk tidy and means I can SSH into it with my laptop from anywhere in the house.

If you want to be able to SSH into the BeagleBoard, log in (as your username or root, it doesn't matter) and find the board's local IP address:

BeagleBoard:
# ip addr

You're looking for the inet address of eth0. My BeagleBoard's local IP address is 192.168.0.18, as shown below:


To SSH into the BeagleBoard:

Host machine:
$ ssh 192.168.0.18

You may receive a warning about the server's key/certificate, just click Yes.

3 - Install DSP/Bridge drivers on the BeagleBoard


If your host Linux machine is 64-bit, you'll need to ensure you have a multiarch system. To check whether your machine is 32-bit or 64-bit, do the following:

Host machine:
$ dpkg --print-architecture

If the output is amd64 then you'll need the 32-bit libraries. You can check if you already have them by entering:

Host machine:
$ dpkg --print-foreign-architectures

If you see an i386 then you're already multiarch. If not, install the 32-bit libraries:

Host machine:
$ sudo apt-get install ia32-libs

You can now download and run the create_dsp_package.sh script from Robert C Nelson's github repository:

Host machine:
$ cd ~/dsp-stuff
$ wget https://raw.github.com/RobertCNelson/tools/master/x86/ti_omap/create_dsp_package.sh
$ chmod +x ./create_dsp_package.sh
$ sudo ./create_dsp_package.sh

If the script encounters a connection timeout when attempting to download a file from gforge.ti.com, you can download the required file from here instead. Place the file in your ~/dsp-stuff/dl folder and run the script again; it should work now.

The script will have created a DSP_Install_libs.tar.gz archive, which you should move over to the BeagleBoard:

Host machine:
$ scp ./DSP_Install_libs.tar.gz ash@192.168.0.18:~/DSP_Install_libs.tar.gz

Now SSH into the BeagleBoard and install DSP/Bridge:

BeagleBoard:
$ tar xf DSP_Install_libs.tar.gz
$ chmod +x ./install-DSP.sh
$ sudo ./install-DSP.sh

Next build the DSP-side drivers:

BeagleBoard:
$ sudo /boot/uboot/tools/update.sh
$ sudo /boot/uboot/tools/pkgs/ti-tidspbridge.sh

Start DSP/Bridge:

BeagleBoard:
$ sudo /etc/init.d/dsp_init start

And finally, check that DSP/Bridge is working:

BeagleBoard:
$ sudo dsp-test

If everything went OK, you should see the following:



4 - Install DSP for Dummies


DSP for Dummies (DFD) is a "framework designed to allow programmers to easily interface their programs to the DSP". It really does make using the DSP rather simple!

Before you can install DFD, you'll need some pre-requisite tools. First, install the ARM Linux cross compiler on your host machine:

Host machine:
$ sudo apt-get install gcc-arm-linux-gnueabi

Next, download the Texas Instruments C6000 Code Generation tools. You'll need to register for a free Texas Instruments account, and if you're outside of the US you'll need to fill out a short export form too. You can get the latest Linux version here.

I ran into issues with the installer crashing Cinnamon over and over again (I use Linux Mint 15). I found that by dropping into a TTY (Ctrl-Alt-F3 for example) and running the .bin directly from there instead worked just fine.

When asked for an installation directory, I chose /opt/dsp-tools, but you can install it wherever you want.

Next, you'll need the DLLcreate tool (copy the whole wget command in one go, it will work!):

Host machine:
$ sudo -i
# cd /opt
# wget -q "http://dev.omapzoom.org/?p=tidspbridge/userspace-dspbridge.git;a=blob_plain;f=source/dsp/bdsptools/bridge-tools.tar;hb=HEAD" -O - \
    | tar xf - --strip-components 3 --wildcards ti/dspbridge/dsp/doffbuild/bin/*
# exit

Now you're ready to install DFD. First, grab the source code:

Host machine:
$ cd ~/dsp-stuff
$ wget http://processors.wiki.ti.com/images/c/c3/Dsp-for-dummies.tar.gz
$ tar xf Dsp-for-dummies.tar.gz
$ cd dsp-for-dummies

Before you can compile the matrix multiplication example, you'll need to make a slight alteration to the Makefile:

Host machine:
$ nano Makefile

Ensure that Line 2 reads:

CROSS_COMPILE ?= arm-linux-gnueabi-

Also, if you installed the Texas Instruments C6000 Code Generation tools to a directory other than /opt/dsp-tools, you'll need to change Line 21 accordingly. For example, if you installed the tools to /home/ash/c6000, Line 21 should read:

DSP_TOOLS := /home/ash/c6000

You're now ready to compile!

5 - Test DFD


Compile the matrix multiplication example:

Host machine:
$ make clean
$ make

This will generate two files in the dsp-for-dummies directory, dummy and dummy.dll64P. The first of these is the GPP-side binary executable and can be placed anywhere on the BeagleBoard. The second file is the DSP-side binary which needs to be placed in the BeagleBoard's /lib/dsp directory.

SSH into the BeagleBoard and navigate to where you copied the dummy file:

BeagleBoard:
$ ./dummy 128 0 3



You should see lots of numbers be printed to the screen. If so, everything is working! :)
If not, see below.

6 - Troubleshooting


When you try to run the dummy example, you may see something like this:

-bash: ./dummy: No such file or directory

This is most likely due to a hardware/software-float ABI mismatch with the particular ARM Linux cross compiler you're using on your host machine. There are two solutions to this. The first is a bit hackish, and is to simply install the ARMEL libraries on the BeagleBoard:

BeagleBoard:
$ sudo apt-get install libc6-armel

The "better" solution is to explicitly use a hardware-float ARM Linux cross compiler on your host machine:

Host machine:
$ sudo apt-get gcc-arm-linux-gnueabihf

Note the hf at the end of gnueabi. You'll also have to modify ~/dsp-stuff/dsp-for-dummies/Makefile again so that Line 2 now reads:

CROSS_COMPILE ?= arm-linux-gnueabihf-

Again noting the hf at the end of gnueabi. Remake the example and copy it over to the BeagleBoard again; it should work now.

Closing Words


Hopefully after following this tutorial you have a working DSP/Bridge and DSP for Dummies installation on your BeagleBoard and can now successfully communicate between the GPP and DSP!

Feel free to leave comments, especially if you spot any errors :)

12 comments:

  1. Hi, thanks a lot for the tutorial, it helped me a lot, bat can u tell me how do you configure the wired connection to the beagle board?

    ReplyDelete
    Replies
    1. I mean It's not automatically activated. I try with $ dhclient eth0 but it doesn't connect to the network i got an error: Cannot find device "eth0"

      Delete
    2. Hello! Strange that the ethernet is not working straight away for you.

      I suggest following the instructions here in order to identify your ethernet device name: https://wiki.archlinux.org/index.php/Network_Configuration#Get_current_device_names

      Once you have the correct device name, you can then try to initialise DHC again.

      By the way, I'm assuming you've already tried to do a ping test to Google? So for example:

      ping -c 3 8.8.8.8

      If you get any responses then the BeagleBoard's ethernet is already working :-)

      Delete
    3. Hi, I think the problem is that I'm working with Gumstix Overo Fire (OMAP 3530 - C64x+ DSP TI), I install other image and Ethernet works perfectly, but I have to build this kernel by myself like you mention in order to get the DSP working.

      The problem that I have right now is with DFD (Dummy example). For application running on DSP side, I got no answer after the message "Processing on DSP":

      root@overo:~/dspbridge# ./dummy 4 0 3
      WRAPPER v4
      Matrix dimension = 4
      Setting up dsp
      info: create_node: dsp node created
      Calling dsp_node_run
      Calling dmm_buffer_new
      info: setup_dmm_buffers: dsp node running
      Calling dmm_buffer_allocate
      Input buffer:
      Matrix A:
      0 1 2 3
      4 5 6 7
      8 9 10 11
      12 13 14 15

      Matrix B:
      16 17 18 19
      20 21 22 23
      24 25 26 27
      28 29 30 31
      Processing on DSP

      But for the ARM side it works fine:

      ~/dspbridge# ./dummy 4 1 3
      WRAPPER v4
      Matrix dimension = 4
      Mode == CPU
      Setting up dsp
      info: create_node: dsp node created
      Calling dsp_node_run
      Calling dmm_buffer_new
      info: setup_dmm_buffers: dsp node running
      Calling dmm_buffer_allocate
      Input buffer:
      Matrix A:
      0 1 2 3
      4 5 6 7
      8 9 10 11
      12 13 14 15

      Matrix B:
      16 17 18 19
      20 21 22 23
      24 25 26 27
      28 29 30 31
      Processing on CPU



      Output buffer:

      Matrix C:
      152 158 164 170
      504 526 548 570
      856 894 932 970
      1208 1262 1316 1370
      info: destroy_node: dsp node deleted
      info: dsp_finish: dsp node terminated

      I didn't change any part of the program, just compile it directly from the dsp-for-dummies. It seems that you didn't got this problem on the DSP side, but I have no idea what's happening.

      Delete
    4. Hmm .. Under Part 3 of the tutorial where you install the DSP/Bridge drivers, the very last step is to check that everything has been installed correctly by doing:

      sudo dsp-test

      On the BeagleBoard (in your case, the Overo). What message do you see when you run this? It should say 'copied 1000 times successfully'; if it doesn't then it would appear the DSP/Bridge drivers haven't been properly installed on your board which is why DFD doesn't get a response.

      Can you check to ensure you've properly installed the DSP/Bridge drivers :-)?

      Delete
  2. Hi,

    I got stuck on the part where I have to build the DSP-side drivers on the Beagle Board:

    $ sudo /boot/uboot/tools/update.sh
    $ sudo /boot/uboot/tools/pkgs/ti-tidspbridge.sh

    (this is towards the end of 3 - Install DSP/Bridge drivers on the BeagleBoard)

    It appears that my uboot directory is empty... No tools directory, no update.sh file, no pkgs directory, and no ti-tidspbridge.sh file.
    What did I do wrong?

    ReplyDelete
    Replies
    1. Hi,

      Did you properly configure your root filesystem using one of Robert C Nelson's pre-built Ubuntu images?

      If not, be sure to follow the instructions in Section 1 of this tutorial. The SD card setup script takes the "--uboot beagle_xm" argument, so presumably the files you are missing are copied over at that point.

      You might want a more recent version of Ubuntu, you can find the 14.04 images here: http://rcn-ee.net/deb/rootfs/trusty/

      Hope this helps!

      Delete
    2. Greetings Ash,

      Thank you for the reply.

      I did use 14.04 and happy to hear that you feel it was the right thing to do.

      Unfortunately, even after several tries I do not get update.sh, ti-tidspbridge.sh, or pkgs anywhere.

      I tried the following line to setup the SD card:

      sudo ./setup_sdcard.sh --mmc /dev/sdc --dtb omap3-beagle-xm

      I used --dtb instead of --uboot as my version of setup_sdcard.sh does not seem to support --uboot. I did not see --uboot in the command line parser case statement of setup_sdcard.sh. --dtb is also recommended by http://elinux.org/BeagleBoardUbuntu#BeagleBoard_xM when they talk about setup_sdcard.sh usage.

      Delete
    3. Hi,

      I have got same problem as I am also using version 14.04 and I stuck on the third part. There is not update.sh or ti_tidspbridge.sh. I cannot find tools directory in the uboot or anywhere else.

      has anyone find any solution for this part?

      Id appreciate for your help.

      Mehrab

      Delete
  3. Amazing article, tagged it as favourite!!

    Just one thing. As this is a fairly old article, I had problems on the DFD package. TI has released DSP Tools 8.x which does not use COFF ABI, so it won't compile, unless you use DSP Tools version 7.4.x or older. The error you'll see (with 8.x) when running
    $ make V=1

    is:

    arm-linux-gnueabihf-gcc -O3 -Wall -Wextra -Wno-unused-parameter -std=c99 -D_GNU_SOURCE -DDSP_API=1 -DDEBUG -MMD -o dummy_arm.o -c dummy_arm.c
    arm-linux-gnueabihf-gcc -O3 -Wall -Wextra -Wno-unused-parameter -std=c99 -D_GNU_SOURCE -DDSP_API=1 -DDEBUG -MMD -o dsp_bridge.o -c dsp_bridge.c
    arm-linux-gnueabihf-gcc -O3 -Wall -Wextra -Wno-unused-parameter -std=c99 -D_GNU_SOURCE -DDSP_API=1 -DDEBUG -MMD -o log.o -c log.c
    arm-linux-gnueabihf-gcc -Wl,--as-needed -o dummy dummy_arm.o dsp_bridge.o log.o
    /opt/dsptools/bin/cl6x -I/opt/dsptools/include -mv=64p -eo.o64P -c dummy_dsp.c
    "dummy_dsp.c", line 103: warning: function "BCACHE_wb" declared implicitly
    /opt/dsptools/bin/cl6x -I/opt/dsptools/include -mv=64p -eo.o64P -c dummy_bridge.s
    /opt/dsptools/bin/lnk6x -r -cr --localize='$bss' -o dummy.x64P dummy_dsp.o64P dummy_bridge.o64P
    /opt/doffbuild/bin/DLLcreate dummy.x64P -o=dummy.dll64P
    DLLcreate Utility v1.5.1
    Copyright (c) 2002-2006 Texas Instruments Incorporated

    >> fatal error: this application only supports COFF version 2
    make: *** [dummy.dll64P] Error 1


    After using DSP Tools version 7.4.x (specifically 7.4.14) it worked.

    ReplyDelete
  4. Thank you for the amazing tutorial Ash Wilding.
    I am working with OpenCV on beagleboard to optimize image processing algorithms. I want to speed up the execution time of my programs using DSP on the board. How can i do it?
    Thanks!

    ReplyDelete
  5. Hi there,

    Is it possible to use this library with an audio cape?

    Regards,
    c

    ReplyDelete