Let’s explore how to port the ReSpeaker 2-Mics Pi HAT v2 to BeagleY-AI single-board computer. The BeagleY-AI’s McASP interface enables high-fidelity I2S communication, while its C7x DSP offloads real-time audio preprocessing tasks like noise reduction.
What is ReSpeaker 2-Mics Pi HAT v2?
ReSpeaker 2-Mics Pi HAT is a dual-microphone expansion board for Raspberry Pi designed for AI and voice applications. This means that you can build a more powerful and flexible voice product that integrates Amazon Alexa Voice Service, Google Assistant, and so on.
Porting Process1. Create a bootable microSD card
For this tutorial I am using BeagleY-AI Debian 12.9 2025-03-05 XFCE (v6.6.x-ti). To download the image file, go to beagleboard website link.
To flash the image to microSD card, follow the tutorial in getting start page.
2. Driver configuration and installation
Check do your current Linux kernel loaded TLV320AIC31xx driver module
$ls /lib/modules/$(uname -r)/kernel/sound/soc/codecs/snd-soc-tlv320aic31xx.ko.xz
If snd-soc-tlv320aic31xx.ko.xz file not exists, follow the below step to build form the source code. If the file exists skip step 3 direct navigate “Load device tree”.
3.Build drivers from source code (cross-compiling)
For this tutorial I’m using Kernel: 6.6.58-ti-arm64-r23
Get the kernel sources
# beagleboard linux kernel
$ git clone --depth=1 -b v6.6.58-ti-arm64-r23 https://github.com/beagleboard/linux.git
Cross-compile Linux kernel
$ cd linux
# default configuration
$ make distclean
$ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- bb.org_defconfig
# config camera
$ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- menuconfig
# -> Device Drivers
# -> Sound card support
# -> Advance Linux Sound Architecture
# -> ALSA for SoC audio support
# -> CODEC drivers
# -> Texas Instruments TLV320AIC31xx CODECs
# Set "TLV320AIC31xx" to module,
# Press "m", save to original name (.config) and exit
$ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- Image dtbs modules LOCALVERSION="-ti-arm64-r23" -j$(nproc)
Plug in the SD card which burned in” Create a bootable microSD card” to PC.
Install onto the SD card
$ sudo cp arch/arm64/boot/Image /media/$(users)/BOOT/
$ sudo cp arch/arm64/boot/dts/ti/*.dtbo /media/$(users)/BOOT/overlays/
# you can use "make kernelversion" to check kernel version
$ sudo cp -ra modules/lib/modules/$(make kernelversion)-ti-arm64-r23/ /media/$(users)/rootfs/lib/modules/
$ sync
Boot BeagleY-AI with SD card.
4. Load device tree overlay
Step 1: Get compiled Device Tree Source (DTS) for the ReSpeaker 2-Mics Pi HAT (modified for BeagleY-AI)
# Download the compiled Device Tree Source (DTS)
$ curl https://raw.githubusercontent.com/jaydon2020/ReSpeaker-2-Mics-Pi-HAT-v2-BeagleY-AI/refs/heads/main/overlays/k3-am67a-beagley-ai-respeaker.dtbo -o k3-am67a-beagley-ai-respeaker.dtbo
# Move the .dtbo file to /boot/firmware/overlays/
$ mv k3-am67a-beagley-ai-respeaker.dtbo /boot/firmware/overlays/
Step 2: Modify the extlinux.conf
file to add device tree configuration.
Add the overlay to label microSD (default)
and append fdtoverlays /overlays/k3-am67a-beagley-ai-respeaker.dtbo
after the fdt
line.
Step 3: Restart system.
$ sudo reboot -f
4) Testing Audio Pipeline
alsamixer is a terminal user interface mixer program for the Advanced Linux Sound Architecture (ALSA) that is used to configure sound settings and adjust the volume.
$ alsamixer
Record sound with aplay system utility
You will see the device ID as below.
$ arecord -l
**** List of CAPTURE Hardware Devices ****
card 0: seeed2micvoicec [seeed2micvoicec], device 0: 2b00000.audio-controller-tlv320aic3x-hifi tlv320aic3x-hifi-0 [2b00000.audio-controller-tlv320aic3x-hifi tlv320aic3x-hifi-0]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: HDMI [it66122 HDMI], device 0: 2b10000.audio-controller-i2s-hifi i2s-hifi-0 [2b10000.audio-controller-i2s-hifi i2s-hifi-0]
Subdevices: 1/1
Subdevice #0: subdevice #0
$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: seeed2micvoicec [seeed2micvoicec], device 0: 2b00000.audio-controller-tlv320aic3x-hifi tlv320aic3x-hifi-0 [2b00000.audio-controller-tlv320aic3x-hifi tlv320aic3x-hifi-0]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: HDMI [it66122 HDMI], device 0: 2b10000.audio-controller-i2s-hifi i2s-hifi-0 [2b10000.audio-controller-i2s-hifi i2s-hifi-0]
Subdevices: 1/1
Subdevice #0: subdevice #0
Basic Recording & Playback
1. Record mono audio (16-bit, 16kHz)
arecord -D plughw:0,0 --format S16_LE --rate 16000 --channels 1 --duration 5 test_mono.wav
- Why plughw?The ReSpeaker HAT's hardware (
hw:0,0
) natively supports stereo input only.plughw
automatically converts the stereo stream to mono by averaging channels. --channels 1
: Single-channel (microphone array mixes inputs by default)
2. Playback recorded audio
aplay -D hw:0,0 test_mono.wav
Verify Stereo Channels
ReSpeaker's dual mics map to left/right channels in stereo mode:
# Record stereo audio (48kHz)
arecord -D hw:0,0 --format S16_LE --rate 48000 --channels 2 --duration 5 test_stereo.wav
# Playback recorded audio (48kHz)
aplay -D hw:0,0 test_stereo.wav
5) On-board User LEDs and Button
To get started, clone https://github.com/jaydon2020/ReSpeaker-2-Mics-Pi-HAT-v2-BeagleY-AI.git repository to your BeagleY-AI.
git clone https://github.com/jaydon2020/ReSpeaker-2-Mics-Pi-HAT-v2-BeagleY-AI.git
cd mic_hat
sudo apt update
sudo apt install python3-libgpiod
sudo apt install python3-spidev
APA102 LEDs
To use the LEDs, you need enable SPI interface first. To enable SPI interface, open the BeagleY-AI /boot/firmware/extlinux/extlinux.conf
$ sudo nano /boot/firmware/extlinux/extlinux.conf
> label microSD (default)
> kernel /Image
> append console=ttyS2,115200n8 root=/dev/mmcblk1p3 ro rootfstype=ext4 resume=/dev/mmcblk1p2 rootwait net.ifnames=0 quiet
> fdtdir /
> fdt /ti/k3-am67a-beagley-ai.dtb
> fdtoverlays /overlays/k3-am67a-beagley-ai-respeaker.dtbo /overlays/k3-am67a-beagley-ai-spidev0.dtbo
> initrd /initrd.img
Add the overlay to label microSD (default)
and append /overlays/k3-am67a-beagley-ai-spidev0.dtbo
after the fdt
line.
Each on-board APA102 LED has an additional driver chip. The driver chip takes care of receiving the desired color via its input lines, and then holding this color until a new command is received.
sudo python3 interfaces/pixels.py
User Button
There is an on-board User Button, which is connected to GPIO_17.
Execute the example script from the repository which you cloned at Step 4, and it should display "on" when you press the button:
$ python3 button.py
off
off
on
on
off
6) Record Sound with Python
To get started, clone https://github.com/jaydon2020/ReSpeaker-2-Mics-Pi-HAT-v2-BeagleY-AI.git repository to your BeagleY-AI.
git clone https://github.com/jaydon2020/ReSpeaker-2-Mics-Pi-HAT-v2-BeagleY-AI.git
cd mic_hat
sudo apt-get install portaudio19-dev libatlas-base-dev
We use PyAudio python library to record sound with Python.First, run the following script to get the device index number of ReSpeaker:
python3 recordings/detect_microphone.py
You will see the device ID as below:
Audio Input ID and name: 1 - seeed2micvoicec: 2b00000.audio-controller-tlv320aic3x-hifi tlv320aic3x-hifi-0 (hw:1,0)
To record the sound, open recording_examples/record.py
file with nano
, vim
or other text editor and change RESPEAKER_INDEX =
1 to index number of ReSpeaker on your system. Then run python script record_mono.py
to make a recording:
python3 recordings/record_mono.py
If you want to extract channel 0 data from 2 channels, have a look at the content of record_one_channel.py
. For other channel X, please change [0::2] to [X::2].
python3 recording_examples/record_one_channel.py
To play the recorded samples you can either use aplay system utility, for example
aplay -f cd -D hw:2,0 output.wav # for Stereo sound
aplay -D plughw:2,0 output_one_channel.wav #for Mono sound from one channel
Demo Application: Keyword Spotting Using AIgit clone https://github.com/TexasInstruments/edgeai-keyword-spotting
cd edgeai-keyword-spotting
sudo apt-get install portaudio19-dev libatlas-base-dev
# Create a venv
uv venv --seed
source .venv/bin/activate
uv pip install pyaudio
uv pip install "numpy<2"
uv pip install librosa
uv pip install tflite_runtime
Modified the code mlcommons-tiny-kws/audio-inference-tinykws.py
. Under main function change to device_index
to the selected device. To identify the microphone id run python detect_microphone.py
def main(modeldir, modelname):
print('main in audio-inference-tinykws')
audio = AudioInference(modeldir=modeldir, modelname=modelname, device_index=1, )
audio.setup()
while (audio.input_stream.is_active()): time.sleep(2)
audio.stop()
Example
Preprocess Time is 17.470 ms
run inference next..
Inference Time is 2.3411 ms
******
detected class: Unknown
******
finished with inference
Preprocess Time is 17.268 ms
run inference next..
Inference Time is 2.2400 ms
******
detected class: Up
******
finished with inference
Preprocess Time is 16.938 ms
run inference next..
Inference Time is 2.3250 ms
******
detected class: Unknown
******
finished with inference
Device Tree Configuration Guide
1. Device Tree Overlay Fundamentals
- Enable hardware-specific configurations without modifying the base DTS
- Map ReSpeaker HAT to BeagleY-AI's McASP/I2C interfaces
# (Declares overlay activation timestamp in kernel)
&{/chosen} {
overlays {
k3-am67a-beagley-ai-respeaker.kernel = __TIMESTAMP__;
};
};
$ ls /proc/device-tree/chosen/overlays/
# Shows loaded overlays (e.g., k3-am67a-beagley-ai-respeaker.kernel)
2. Master Clock (MCLK) Configuration
Critical for I2S Timing:
tlv320aic3104_mclk: tlv320aic3104_mclk {
#clock-cells = <0>;
compatible = "fixed-clock";
clock-frequency = <12288000>; // 12.288 MHz (supports 48kHz family rates)
};
3. Sound Card Definition
Links McASP ↔ Codec ↔ Physical Jacks:
sound1 {
compatible = "simple-audio-card";
simple-audio-card,format = "i2s";
simple-audio-card,name = "seeed2micvoicec";
status = "okay";
/* Audio Routing */
simple-audio-card,widgets = "Headphone", "Headphone Jack", "Line", "Line In";
simple-audio-card,routing =
"Headphone Jack", "HPLOUT",
"Headphone Jack", "HPROUT",
"LINE1L", "Line In",
"LINE1R", "Line In";
/* CPU (McASP) Interface */
dailink0_master: simple-audio-card,cpu {
sound-dai = <&mcasp0>; // McASP controller
system-clock-direction-out; // McASP provides clock
};
/* Codec (TLV320AIC3104) Interface */
simple-audio-card,codec {
sound-dai = <&tlv320aic3104>; // I2C codec
clocks = <&tlv320aic3104_mclk>; // Attach MCLK
clock-names = "mclk";
};
};
4. I2C Configuration for Audio Codec
TLV320AIC3104 Setup:
&mcu_i2c0 {
status = "okay";
tlv320aic3104: tlv320aic3104@18 {
compatible = "ti,tlv320aic3104";
reg = <0x18>; // I2C address 0x18
clocks = <&tlv320aic3104_mclk>;
clock-names = "mclk";
ai3x-micbias-vg = <2>; // MICBIAS = 2.5V (supports electret mics)
};
};
5. Pin Multiplexing (I2S Pins)
McASP0 Pin Assignment:
&main_pmx0 {
main_mcasp0_pins_default: main-mcasp0-codec-default-pins {
pinctrl-single,pins = <
// BCLK (Bit Clock)
J722S_IOPAD(0x01a4, PIN_INPUT, 0) // BCLK → HAT Pin 12 (D25)
// WCLK (Word Clock)
J722S_IOPAD(0x01a8, PIN_INPUT, 0) // WCLK → HAT Pin 35 (C26)
// DIN (Data In from Microphones)
J722S_IOPAD(0x01a0, PIN_INPUT, 0) // DIN → HAT Pin 38 (F24)
// DOUT (Data Out to Speaker)
J722S_IOPAD(0x019c, PIN_OUTPUT, 0) // DOUT → HAT Pin 40 (B25)
>;
};
};
Verify pin numbers against BeagleY-AI Pinout
6. McASP Platform Driver Configuration
I2S Master Mode Setup:
&mcasp0 {
status = "okay";
#sound-dai-cells = <0>;
pinctrl-names = "default";
pinctrl-0 = <&main_mcasp0_pins_default>;
/* Timing Configuration */
auxclk-fs-ratio = <256>; // MCLK = 256 * fs (e.g., 48kHz → 12.288MHz)
op-mode = <0>; // I2S Mode (vs TDM/AC97)
tdm-slots = <2>; // Stereo (2 channels)
/* Serial Direction Matrix */
serial-dir = <
2 1 0 0 // AXR0: RX (mic in), AXR1: TX (speaker out)
0 0 0 0
0 0 0 0
0 0 0 0
>;
/* FIFO Configuration */
tx-num-evt = <0>; // TX FIFO depth (prevents I/O errors)
rx-num-evt = <0>; // RX FIFO depth
};
Troubleshooting & Workarounds1. Device Tree Overlay Not Applied
Symptom
k3-am67a-beagley-ai-respeaker.dtbo
missing in /proc/device-tree/chosen/overlays/- Audio hardware not detected by
arecord -l
Diagnosis:
$ ls /proc/device-tree/chosen/overlays/
# If missing: k3-am67a-beagley-ai-respeaker.kernel
Solutions:
Verify extlinux.conf
Syntax:
$ sudo nano /boot/firmware/extlinux/extlinux.conf
Ensure proper formatting:
label microSD (default)
kernel /Image
append ...
fdtdir /
fdt /ti/k3-am67a-beagley-ai.dtb
fdtoverlays /overlays/k3-am67a-beagley-ai-respeaker.dtbo
2. Audio Driver Not Loade
Symptom
snd_soc_tlv320aic3x
missing in lsmod- dmesg shows
"supply DVDD/AVDD not found"
Diagnosis:
$ lsmod | grep -i tlv320 # Should show snd_soc_tlv320aic3x
$ dmesg | grep -i tlv320 # Check regulator errors
Solutions:
Reinstall Kernel Modules:
# On host PC after cross-compiling:
$ sudo cp -r modules/lib/modules/$(make kernelversion)-ti-arm64-r23/ /media/user/rootfs/lib/modules/
$ sudo depmod -a # Rebuild module dependencies
Bypass Regulator Warnings:Add dummy regulators to device tree overlay:
/ {
vdd_audio_1v8: regulator-audio {
compatible = "regulator-fixed";
regulator-name = "vdd-audio-1v8";
regulator-min-microvolt = <1800000>;
regulator-max-microvolt = <1800000>;
};
};
3. "Input/Output Error" During Recording
Symptoms:
$ arecord -D hw:0,0 -f S32_LE test.wav
arecord: pcm_read:2221: read error: Input/output error
Root Cause:TI SDK ≥9.2 disables McASP FIFO buffers by default (tx-num-evt = <0>; rx-num-evt = <0>
). References
Solution:Modify the McASP node in your device tree overlay:
&mcasp0 {
status = "okay";
#sound-dai-cells = <0>;
pinctrl-names = "default";
pinctrl-0 = <&main_mcasp0_pins_default>;
op-mode = <0>; /* IIS Mode */
tdm-slots = <2>;
/* Enable FIFO buffers */
tx-num-evt = <0>; /* FIFO depth for transmit */
rx-num-evt = <0>; /* FIFO depth for receive */
};
References- BeagleBoard.org, “BeagleY-AI Debian 12.9 (v6.6.x-ti), ” Mar. 2025. [Online]. Available: https://www.beagleboard.org/distros/beagley-ai-debian-12-9-2025-03-05-xfce-v6-6-x-ti
- BeagleBoard.org, “BeagleY-AI Quick Start Guide.” [Online]. Available: https://docs.beagleboard.org/boards/beagley/ai/02-quick-start.html
- Seeed Studio, “ReSpeaker 2-Mics Pi HAT v2 Wiki.” [Online]. Available: https://wiki.seeedstudio.com/respeaker_2_mics_pi_hat_raspberry_v2/
- B. Fraser, “BeagleBone Driver Creation Guide, ” Simon Fraser University, 2023. [Online]. Available: https://opencoursehub.cs.sfu.ca/bfraser/grav-cms/cmpt433/guides/files_bbg/DriverCreationGuide-FullKernelDownload.pdf
- Texas Instruments, “TLV320AIC31xx Audio Codec Configuration Guide, ” Application Report SLAA403, 2021. [Online]. Available: https://www.tij.co.jp/jp/lit/an/slaa403/slaa403.pdf
- Texas Instruments, “Keyword Spotting Using AI at the Edge with Sitara Processors” SPRADE0, 2023. [Online]. Available: https://www.ti.com/lit/ab/sprade0/sprade0.pdf
- Texas Instruments, “AM623: arecord PCM_READ Error Discussion, ” E2E Forum, 2023. [Online]. Available: https://e2e.ti.com/support/processors-group/processors/f/processors-forum/1470003/am623-arecord-pcm_read-2221-read-error-input-output-error
- MLSysBook, “Keyword Spotting Lab Guide, ” 2023. [Online]. Available: https://mlsysbook.ai/contents/labs/arduino/nicla_vision/kws/kws.html
- BeagleBoard Community, “BeagleY-AI Pinout Diagram.” [Online]. Available: https://pinout.beagley.ai/
- BelaPlatform, “Seeed 4-Mic Voicecard Device Tree Source, ” GitHub Repository, 2022. [Online]. Available: https://github.com/BelaPlatform/bb.org-overlays/blob/bela-bbb-cape-universal/src/arm/seeed-4mic-voicecard-00A0.dts
- St, “Soundcard configuration - stm32mpu, ” St.com, 2024. [Online]. Available: https://wiki.st.com/stm32mpu/wiki/Soundcard_configuration (accessed Apr. 20, 2025).
Comments
Please log in or sign up to comment.