PhidgetSBC2 and D-Link DWA-160

So I've had a little project going on with the foosball table at work: a system to detect when someone scores a goal. I've built a prototype photogate that goes inside of the goal. My design is to have 2 photogates hooked up to my PhidgetSBC2 and write some ruby code to detect a goal and send a message to a connected iPad app to indicate who scored. Everything was going fine until I took the PhidgetSBC2 to our foosball table and discovered our 2.4GHz network had no coverage there. Which means the wifi usb adapter I had for the PhidgetSBC2 was useless. Undeterred I started on 2 different solutions.

D-Link DWA-160

The first solution I thought of was to find a 5.0GHz wifi adapter that is compatible with debian. I quickly found that the D-Link DWA-160 has support in debian via the ar9170usb module & firmware.

Ad-Hoc network

The second solution I thought of was to create an ad-hoc network with the 2.4GHz wifi adapter and connect to that via the iPad (or my macbook pro for working on the code). This is fairly easy to achieve but I felt it was the worst solution because it meant less CPU and RAM for my ruby code and wasn't very solid (felt very hacky with the PhdigetSBC2 config). To create an ad-hoc network you nee to use wpa_cli to add a new network in mode 1. Then add an /etc/init.d script to bring the wireless interface up on each boot. Throw in a DHCP server and you've got a wireless network to connect to.

External router

The third solution was to get a wireless router and just plug the PhidgetSBC2 into it. This didn't connect to our network at work so we couldn't connect to the server from anywhere in our office (kills the ability to write an application that shows the score on our projector).

Using a D-Link DWA-160

Going with my first solution I ran out and bought a D-Link DWA-160 and plugged it into the PhidgetSBC2 and quickly discovered that it did not work. I also tried carl9170 because while the PhidgetSBC2 uses debian squeeze it is running linux 3.1.6. After struggling for a few hours trying to get it to work with the firmware-atheros package I gave up and decided to try to compile carl9170 myself. After spending a few days trying to compile it in the PhidgetSBC2 I gave up and tried to get some help in IRC. Thanks to some help from pkgadd of #linux-wireless on irc.freenode.net I finally realized that the firmware wasn't the problem. The problem was that the kernel that comes with the PhidgetSBC2 doesn't have carl9170 support.

If you are interested in using a DWA-160 with your own PhidgetSBC, you can skip down and download the kernel I made and install it yourself.

Building a kernel

So I fired up a nice Extra Large EC2 instance with Ubuntu 12.04 and went about building my own kernel following the instructions from the Phidgets Kernel Dev Package for the PhidgetSBC2. After sshing into the server I started by installing the packages I would need.

sudo apt-get install build-essential gcc-arm-linux-gnueabi ncurses-dev u-boot-tools -y

And then I downloaded the patch from Phidgets and the 3.1.6 kernel source itself.

curl -O http://www.phidgets.com/downloads/libraries/phidgetsbc2-kerneldev_1.0.1.20120327.tar.gz
tar -zxvf phidgetsbc2-kerneldev_1.0.1.20120327.tar.gz
curl -O http://www.kernel.org/pub/linux/kernel/v3.x/linux-3.1.6.tar.gz
tar -zxvf linux-3.1.6.tar.gz

Then I moved into the linux source and applied the patch and ran the make task that Phidgets created:

cd linux-3.1.6
patch -p1 < ../phidgetsbc2_kerneldev_1.0.1.20120327/linux-3.1.6-phidget_sbc2.patch
make phidget_sbc2_defconfig

Next I had to use the menu config to enable carl9170 support.

make menuconfig

These images show the menu selections that enable carl9170 support.

Select Device Drivers

Select Network Device Support

Select Wireless LAN

Modularize Atheros Wireless Cards and then Select Atheros Wireless Cards

Modularize Atheros 802.11n wireless cards support and Linux Community AR9170 802.11n USB support and Inlude Atheros ath9k AHB bus support

Yes to save changes

And now I built the kernel image (I used -j8 to use all 8 ECUs of the Extra Large instance):

make -j8 uImage

After that is done I needed to compile the modules and install them into a directory so I could copy them to the PhidgetSBC2.

make -j8 modules
mkdir ../modules
INSTALL_MOD_PATH=../modules make modules_install

After that was done I gzipped up arch/arm/boot/uImage and ../modules/lib and copied them to my PhidgetSBC2 and extracted them.

If you want to use a DWA-160 with your own PhidgetSBC2 you can download the gzipped file (phidgetsbc2-carl9170.tar) and extract it onto your PhidgetSBC2 and follow along. You will need to enable the ssh server and to add the debian repositories (see the manual).

Installing the kernel

Installing the modules and the kernel to the PhidgetSBC2 is super easy:

apt-get install wget
rm -rf /lib/{modules,firmware}
cp -r lib/{modules,firmware} /lib
wget "http://linuxwireless.org/en/users/Drivers/carl9170/fw1.9.5?action=AttachFile&do=get&target=carl9170-1.fw" -O /lib/firmware/carl9170-1.fw
depmod

flash_eraseall /dev/mtd3
nandwrite -p /dev/mtd3 uImage
reboot

After rebooting I now get this from dmesg when I plug in the DWA-160:

usb 1-1.3: new full speed USB device number 4 using s3c2410-ohci
usb 1-1.3: New USB device found, idVendor=07d1, idProduct=3a09
usb 1-1.3: New USB device strings: Mfr=16, Product=32, SerialNumber=48
usb 1-1.3: Product: 11n adapter
usb 1-1.3: Manufacturer: ATHER
usb 1-1.3: SerialNumber: 12345
usb 1-1.3: reset full speed USB device number 4 using s3c2410-ohci
usbcore: registered new interface driver carl9170
usb 1-1.3: driver   API: 1.9.4 2011-06-30 [1-1]
usb 1-1.3: firmware API: 1.9.5 2012-03-14
ath: EEPROM regdomain: 0x807c
ath: EEPROM indicates we should expect a country code
ath: doing EEPROM country->regdmn map search
ath: country maps to regdmn code: 0x3a
ath: Country alpha2 being used: CA
ath: Regpair used: 0x3a
ieee80211 phy0: Selected rate control algorithm 'minstrel_ht'
Registered led device: carl9170-phy0::tx
Registered led device: carl9170-phy0::assoc
usb 1-1.3: Atheros AR9170 is registered as 'phy0'

And bam! The DWA-160 showed up in the PhidgetSBC2 web admin and I could see our 5.0GHz network and connect to it.

Join the conversation

2 Comments

  1. FWIW – you might want to try using the phidgets_native gem instead. There’s no ffi requirement and it’s faster and much more stable. (Plus it supports arm)

  2. Hi 🙂
    I try to build the kernel, I given :
    make -j8 uImage
    and this is the ouput:
    CHK include/linux/version.h
    CHK include/generated/utsrelease.h
    make[1]:
    include/generated/mach-types.h' is up to date.
    CALL scripts/checksyscalls.sh
    CHK include/generated/compile.h
    AS arch/arm/kernel/entry-armv.o
    AS arch/arm/kernel/entry-common.o
    CC arch/arm/kernel/irq.o
    CC arch/arm/kernel/ptrace.o
    CC arch/arm/kernel/process.o
    AS arch/arm/mach-s3c2410/sleep.o
    arch/arm/kernel/entry-armv.S: Assembler messages:
    arch/arm/kernel/entry-armv.S:42: Error: ARM register expected --
    ldr r2,[ r6,#(0x10)]'
    arch/arm/kernel/entry-armv.S:42: Error: ARM register expected -- ldr r0,[ r6,#(0x14)]'
    arch/arm/kernel/entry-armv.S:42: Error: ARM register expected --
    ldr r2,[ r6,#(0x10)]'
    arch/arm/kernel/entry-armv.S:42: Error: ARM register expected -- ldr r0,[ r6,#(0x14)]'
    make[1]: *** [arch/arm/kernel/entry-armv.o] Error 1
    make[1]: *** Waiting for unfinished jobs....
    CC arch/arm/mach-s3c2410/gpio.o
    LD arch/arm/mach-s3c2412/built-in.o
    LD arch/arm/mach-s3c2416/built-in.o
    CC arch/arm/mach-s3c2440/s3c2440.o
    CC arch/arm/mach-s3c2440/dsc.o
    LD arch/arm/mach-s3c2443/built-in.o
    arch/arm/mach-s3c2410/sleep.S: Assembler messages:
    arch/arm/mach-s3c2410/sleep.S:48: Error: ARM register expected --
    ldr r7,[ r4 ]'
    arch/arm/mach-s3c2410/sleep.S:49: Error: ARM register expected -- ldr r8,[ r5 ]'
    arch/arm/mach-s3c2410/sleep.S:50: Error: ARM register expected --
    ldr r9,[ r6 ]'
    arch/arm/mach-s3c2410/sleep.S:64: Error: ARM register expected -- streq r7,[ r4 ]'
    arch/arm/mach-s3c2410/sleep.S:65: Error: ARM register expected --
    streq r8,[ r5 ]'
    arch/arm/mach-s3c2410/sleep.S:66: Error: ARM register expected -- `streq r9,[ r6 ]'
    make[1]: *** [arch/arm/mach-s3c2410/sleep.o] Error 1
    make[1]: *** Waiting for unfinished jobs....
    CC arch/arm/mach-s3c2440/irq.o
    CC arch/arm/plat-s3c24xx/cpu.o
    make: *** [arch/arm/mach-s3c2410] Error 2
    make: *** Waiting for unfinished jobs....
    CC arch/arm/plat-s3c24xx/irq.o
    CC arch/arm/plat-s3c24xx/devs.o
    CC arch/arm/mach-s3c2440/clock.o
    CC arch/arm/mach-s3c2440/dma.o
    CC arch/arm/mach-s3c2440/s3c244x.o
    CC arch/arm/mach-s3c2440/s3c244x-irq.o
    CC arch/arm/plat-s3c24xx/gpio.o
    make: *** [arch/arm/kernel] Error 2
    CC arch/arm/plat-s3c24xx/gpiolib.o
    CC arch/arm/mach-s3c2440/s3c244x-clock.o
    CC arch/arm/mach-s3c2440/mach-phidget_sbc2.o
    CC arch/arm/plat-s3c24xx/clock.o
    CC arch/arm/plat-s3c24xx/pm.o
    CC arch/arm/plat-s3c24xx/irq-pm.o
    AS arch/arm/plat-s3c24xx/sleep.o
    CC arch/arm/plat-s3c24xx/s3c2410-clock.o
    CC arch/arm/plat-s3c24xx/dma.o
    CC arch/arm/plat-s3c24xx/setup-i2c.o
    LD arch/arm/mach-s3c2440/built-in.o
    LD arch/arm/plat-s3c24xx/built-in.o
    I don’t find the file uImage, I think that something goes wrong…

Leave a comment

Your email address will not be published. Required fields are marked *