Reference BSP for Petalinux 2017.3 referenced in this write-up is located here:
http://zedboard.org/support/design/1521/11
Introduction
The Murata 1DX Pmod can be used to add Wi-Fi and Bluetooth connectivity to your ZYNQ design. This write-up covers the steps necessary to enable connectivity, providing an example based on the ZedBoard Development Kit (XC7Z020). The Murata 1DX module is also used on Avnet’s MiniZedevaluation platform.
Hardware Description:
Starting with the Vivado hardware project included inside the official Petalinux 2017.3 BSP release for the Avnet ZedBoard, the following hardware modifications are performed:
Step 1: Enable the secondary SD interface (SD1) on the ZYNQ-7000. This is used by the Wi-Fi radio. Select MIO pins 10..15 as these correspond to Pmod connector JEx on the ZedBoard. JEx is the only Pmod connector on the ZedBoard that interfaces directly to MIO pins. The pinout of the 1DX Pmod was designed to match up to this connector. You do not need to enable the CD, WP or Power pins.
Step 2: Enable EMIO GPIO with a width of “3”. These are used for reset and control signals on the 1DX Pmod (BT_REG_ON, BT_DEV_WAKE, WL_DEV_WAKE). They’re routed to the secondary Pmod interface (JDx on the ZedBoard). These signals will be routed through ZYNQ PL.
Step 3: Add an AXI 16550 UART to the ZYNQ’s block diagram (PL). This will be used by the 1DX’s Bluetooth radio. Although the ZYNQ’s PS includes a secondary UART, its maximum baud rate is datasheet limited to 1 Mbps. The AXI 16550 UART allows us to achieve a speed of 3 Mbps, which is necessary to support Bluetooth’s higher throughput use cases such as streaming audio. The AXI 16550 UART is further customized to use an external baud rate clock (48 MHz), required to generate 3 Mbps. This clock is supplied by one of the ZYNQ PS block’s four PL clock outputs.
Step 4: Route UART and GPIO control signals up to the top level of the design and add location constraints (.xdc constraint and top level files are provided in the project).
Software Description:
Software setup for Petalinux requires four major “ingredients”:
- Kernel drivers for Wi-Fi and Bluetooth.
- Device Tree Modifications
- Wi-Fi and Bluetooth firmware binaries required by the 1DX
- Upper level software utilities needed to establish connectivity to user application space
Kernel Drivers (petalinux-config -c kernel):
Step 1: Enable generic Bluetooth functionality in the Linux kernel (Networking Support -> Bluetooth subsystem support). Enable both Bluetooth High Speed and Bluetooth Low Energy options. Next, select “Bluetooth device drivers” and enable the following: HCI UART Driver, H4 protocol support, and Broadcom protocol support.
Step 2: Enable generic Wireless LAN support (Networking support -> Wireless). Enable “cfg80211” wireless configuration API.
Step 3: Enable Broadcom Full MAC driver (Device Drivers -> Network device support -> Wireless LAN (enable). Next, select “Broadcom devices” and then enable SDIO bus support for FullMAC driver. This is the “brcmfmac” open source driver included in the main line kernel source tree. All other options may be de-selected.
Step 4: Save settings and exit kernel configuration.
Device Tree modifications:
Step 1: In your Petalinux project, edit project-spec/meta-user/recipes-bsp/device-tree/files/system-user.dtsi.
Note: The 1DX’s “WL_REG_ON” input is a reset input, but it’s treated as a virtual voltage regulator from the perspective of the Linux kernel. This is tied to MIO[9] on the ZYNQ device. The devicetree entry below will automatically toggle this pin when the kernel boots, bringing the 1DX out of reset.
/include/ "system-conf.dtsi"
/ {
aliases {
serial0 = &uart1;
serial1 = &uart0;
};
/* WiFi Module: WL_REG_ON is tied to MIO[9] */
wlreg_on: wlreg-on {
compatible = "regulator-fixed";
regulator-name = "wlreg_on";
enable-active-high;
gpio = <&gpio0 9 0>;
regulator-min-microvolt = <3300000>;
regulator-max-microvolt = <3300000>;
startup-delay-us = <100>;
};
};
/* SD Interface for Wi-Fi Module */
&sdhci1 {
status = "okay";
bus-width= <4>;
xlnx,has-cd = <0x0>;
xlnx,has-power = <0x0>;
xlnx,has-wp = <0x0>;
non-removeable;
broken-cd;
vmmc-supply = <&wlreg_on>;
brcmf: brcmf@1 {
status = "okay";
reg = <1>;
compatible = "brcm,bcm43430-fmac";
};
};
Wi-Fi and Bluetooth Firmware Binaries:
A custom recipe (minized-firmware) is placed in the meta-user/recipes-bsp directory of the Petalinux project. This recipe includes firmware binaries for the Wi-Fi and Bluetooth radios. The main Wi-Fi firmware binary, “brcmfmac43430-sdio.bin”, was sourced from the “linux-firmware” Yocto recipe and is compatible with this release of the Linux kernel. The other files were sourced directly from Murata and are specific to the 1DX module. The recipe copies these files to the target root filesystem.
Patches:
BlueZ, the open source Bluetooth stack used by Linux, requires a patch to be applied. This is included under meta-user/recipes-connectivity/bluez5.
Run-Time Packages and Utilities
There are several software packages installed to the target root filesystem by Petalinux necessary to use Wi-Fi and Bluetooth. Most of these are specified in the file meta-user/recipes-core/images/petalinux-user-image.bbappend. Please refer to this file in the included BSP.
In addition to the software packages above, the entire Yocto build must have several features enabled. These are specified in the file meta-user/conf/layer.conf.
Pulseaudio: This is an audio server used to create audio sources and sinks for Linux user-space applications. We’ll use this to create a bridge to the Bluetooth stack (BlueZ). Look under meta-user/recipes-multimedia.
Miscellaneous Files: A few small modifications to the target root filesystem are applied in the recipes “minized-misc” and “custom”, both found under “recipes-bsp”.
Run-Time for Wi-Fi:
When the ZedBoard boots, you should see the orange Wi-Fi LED turn on the Pmod and evidence of the Wi-Fi driver loading:
brcmfmac: brcmf_c_preinit_dcmds: Firmware version = wl0: May 27 2016 00:13:38 version 7.45.41.26 (r640327) FWID 01-df77e4a7
brcmfmac: brcmf_cfg80211_reg_notifier: not a ISO3166 code (0x30 0x30)
Edit /etc/wpa_supplicant.conf to match that of your local Wi-Fi AP:
ctrl_interface=/var/run/wpa_supplicant
ctrl_interface_group=0
update_config=1
network={
key_mgmt=WPA-PSK
ssid="MySsidName"
psk="MyPassword"
}
Launch wpa_supplicant with the following command:
wpa_supplicant -Dnl80211 -iwlan0 -c/etc/wpa_supplicant.conf -B
Use DHCP to get an IP address :
udhcpc -i wlan0
You should now be on the network. Note: a script is included (/usr/local/bin/wifi.sh) that can be run from the command prompt. It will automatically copy wpa_supplicant.conf from the SD card.
Run-Time for Bluetooth:
Three scripts (ble.sh, bt.sh and speaker.sh) are included in /usr/local/bin. To stream audio to a Bluetooth speaker, run the “speaker.sh” script. You should see the following output:
root@avnet-digilent-zedboard-2017_3:~# speaker.sh
# To turn on BT_REG_ON, which is on EMIO GPIO #0
echo 939 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio939/direction
echo 1 > /sys/class/gpio/gpio939/value
# Set uart0 = 16550 UART in PL = ttyS2 baudrate:
stty -F /dev/ttyS0 115200
stty -F /dev/ttyS0 crtscts
# Initialize the device (you should really pick an unique MAC):
hciattach /dev/ttyS0 -t 10 bcm43xx 3000000 flow nosleep $BD_ADDR
bcm43xx_init
Set Controller UART speed to 3000000 bit/s
Flash firmware /etc/firmware/BCM43430A1.1DX.hcd
Set BDADDR UART: a4:08:ea:e1:c9:6f
Set Controller UART speed to 3000000 bit/s
Device setup complete
#Configure the right BT device:
hciconfig hci0 up
pulseaudio --system -D
W: [pulseaudio] main.c: Running in system mode, but --disallow-exit not set.
W: [pulseaudio] main.c: Running in system mode, but --disallow-module-loading not set.
N: [pulseaudio] main.c: Running in system mode, forcibly disabling SHM mode.
N: [pulseaudio] main.c: Running in system mode, forcibly disabling exit idle time.
bluetoothctl
[NEW] Controller A4:08:EA:E1:C9:6F BlueZ 5.41 [default]
[bluetooth]#
Place your Bluetooth speaker into pairing/discovery mode. Then, type “scan on”:
[bluetooth]# scan on
Discovery started
[CHG] Controller A4:08:EA:E1:C9:6F Discovering: yes
[NEW] Device 00:1D:DF:C7:63:BA JBL Flip
[bluetooth]#
Note the Bluetooth address of the “JBL Flip” speaker seen above. Type “scan off”, then “pair XX:XX:XX:XX:XX:XX” to match that of your speaker.
[bluetooth]# pair 00:1D:DF:C7:63:BA
Attempting to pair with 00:1D:DF:C7:63:BA
[CHG] Device 00:1D:DF:C7:63:BA Connected: yes
[CHG] Device 00:1D:DF:C7:63:BA UUIDs: 00001108-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1D:DF:C7:63:BA UUIDs: 0000110b-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1D:DF:C7:63:BA UUIDs: 0000111e-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1D:DF:C7:63:BA Paired: yes
Pairing successful
Now, type “connect xx:xx:xx:xx:xx:xx”:
[bluetooth]# connect 00:1D:DF:C7:63:BA
Attempting to connect to 00:1D:DF:C7:63:BA
[CHG] Device 00:1D:DF:C7:63:BA Connected: yes
Connection successful
You may now type “quit” to exit bluetoothctl.
Finally, to play an .MP3 file on your SD card, type “mpg123 /mnt/filename.mp3”. You should hear music play from the speaker.
Important Note regarding Software Licensing
This BSP includes OpenEmbedded recipes that aren't covered by standard GPL software licenses. For example, MPEG Audio libraries are covered by a proprietary/commercial license. These recipes are specified in the file meta-user/recipes-core/images/petalinux-user-image.bbappend:
gstreamer1.0-plugins-ugly
mpg123
In order to use these licenses in the, the following line was added to the file meta-user/conf/layer.conf:
LICENSE_FLAGS_WHITELIST_append = " commercial"