Bluetooth audio on embedded hardware

I would really like the bluetooth-alsa project to get far enough along to really shine on embedded platforms. gumstix is the perfect little device for working this out. This device currently ships with an Infineon Singlestone PBA31307.




Bluegiga Class 1 bluecore4 module

Adding your own bluetooth module will allow things like full 921k data connection, SCO over HCI(*), and class 1 ranges. This adapter can do EDR, but the pxa255 UART cannot go beyond 921k unfortunately.

* To do SCO over HCI, you will need a kernel patch to avoid crashes and to maintain more consistent audio quality. I am talking with Marcel Holtmann about merging this patch upstream.

The model for this adapter is wt11-a-hci from Note that the data sheet referenced from semiconductorstore is old. Go directly to bluegiga for updated docs.

Wiring it up

Using GPIO48-51 as I'm suggesting here conflicts with the pcmcia pins, so plan to leave the GPIO settings alone and use HWUART through GPIO42-45 if you need pcmcia. You do this either on a module without bluetooth or by clearing GPIO7 and hoping the pins can all be used while the built-in module is held in reset.

The first thing to do after getting this module is to wire it up and try to reconfigure it from a PC so the module will use the uart/h4 interface.

23.3v regulated typical 200mA max 220mA
213.3v to disable spi? (I left this unconnected)
8usb d+ for programming
9usb d- for programming
5 rtsgpio50 hwctsmodule uart rts->hwcts (asserted by module)
10 ctsgpio51 hwrtsmodule uart cts<-hwrts (asserted by gumstix)
26 txgpio49 hwrxdmodule uart tx->hwrxd (asserted by module)
6 rxgpio48 hwtxdmodule uart rx<-hwtxd (asserted by gumstix)
17 resetgpio16 "PW[M]0"reset (active high)

Firmware settings

Making the adapter use its uart connection is done using the bccmd app from bluez utils cvs (configure with --enable-bccmd to get bccmd)

bccmd can "brick" your adapter if you make a mistake! To test things without risking this, connect both usb to a pc and the uart connected to the gumstix. (I power the gumstix from usb when doing this.) Then run

 bccmd psset -r 0x3cd 4
To set the adapter to use the uart and do a soft reset. I had to do this twice before it would actually disconnect from usb and reconnect on the uart.

Then attach to the adapter on the gumstix:

# shut down internal bluetooth
/etc/init.d/S30bluetooth stop

# switch the built-in bluetooth to BTUART for now
echo "AF1 in" >/proc/gpio/GPIO42
echo "AF2 out" >/proc/gpio/GPIO43
echo "AF1 in" >/proc/gpio/GPIO44
echo "AF2 out" >/proc/gpio/GPIO45
# make the "HWUART" labeled pads on the audiostix actually carry HWUART
echo "AF1 out" >/proc/gpio/GPIO48
echo "AF1 in" >/proc/gpio/GPIO49
echo "AF1 in" >/proc/gpio/GPIO50
echo "AF1 out" >/proc/gpio/GPIO51

# bring it up
echo "GPIO out set" >/proc/gpio/GPIO16
sleep 1
echo clear >/proc/gpio/GPIO16
sleep 1

# attach the adapter
/usr/sbin/hciattach -s 115200 ttyS3 csr 921600

# check for the adapter
hciconfig -a
hcitool scan
Once you are satisfied that works, cold boot everything and this time make it permanent from the pc:
 bccmd psset -s default 0x3cd 4

Bringing up CSR automatically

It's working (woohoo)

# hciconfig hci0 revision
hci0:   Type: UART
        BD Address: 00:07:80:81:BC:3E ACL MTU: 384:8 SCO MTU: 64:8
        Build 2810
        Chip version: BlueCore4-External
        Max key size: 56 bit
        SCO mapping:  HCI
# hciconfig -a hci0
hci0:   Type: UART
        BD Address: 00:07:80:81:BC:3E ACL MTU: 384:8 SCO MTU: 64:8
        RX bytes:4577 acl:95 sco:0 events:289 errors:0
        TX bytes:2735 acl:95 sco:0 commands:80 errors:0
        Features: 0xff 0xff 0x8f 0xfe 0x9b 0xf9 0x00 0x80
        Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 
        Link policy: RSWITCH HOLD SNIFF PARK 
        Link mode: SLAVE ACCEPT 
        Name: 'Gumstix (0)'
        Class: 0x820116
        Service Classes: Networking
        Device Class: Computer, Palm
        HCI Ver: 2.0 (0x3) HCI Rev: 0xafa LMP Ver: 2.0 (0x3) LMP Subver: 0xafa
        Manufacturer: Cambridge Silicon Radio (10)

fwiw... S30bluetooth runs echo AF1 out > /proc/gpio/GPIO12 on start but has no corresponding action in stop. This sends out a clock signal that the infineon needs apparently.