1. Project Objective
The core objective of this task was to successfully enable and debug multiple I2S interfaces (I2S1, I2S2, I2S3) on the RK3568 platform to establish digital audio communication with external devices, such as an FPGA. This specifically included:
- Configuring I2S1 and I2S3 as audio output (Playback).
- Configuring I2S2 as audio input (Capture).
2. Debugging Workflow and Process
The entire debugging process followed a clear workflow: Hardware Analysis -> DTS Configuration -> Command-line Testing -> Problem Isolation and Resolution.
Preparation - Hardware Resource Analysis:
- First, the I2S hardware resources of the RK3568 SoC were analyzed to clarify the basic functions and use cases of the I2S0/1/2/3 controllers (e.g., I2S0 for HDMI, I2S1/2/3 for general purpose).
- The I2S controller nodes (
i2s@fe4...) in the DTS were mapped to the corresponding GPIO pins on the product schematic, laying a solid foundation for the subsequentpinctrlconfiguration.
Implementation - DTS Configuration and Sound Card Registration:
- Utilized the
simple-audio-carddriver model to “link” the SoC’s I2S controller (CPU DAI) with a virtualdummy-codec(Codec DAI), thereby registering three separate sound cards within the ALSA framework. - DTS nodes were written for
card 1(I2S1, output),card 2(I2S2, input), andcard 3(I2S3, output) respectively.
- Utilized the
Verification - Systematic Testing and Issue Detection:
- Using the
aplay -landarecord -lcommands, it was successfully verified that all three sound cards were registered in the system. - I2S1 (Output): Tested with
speaker-test -D hw:1,0 ...; the device functioned normally with no errors. - I2S2 (Input): Tested with
arecord -D hw:2,0 ...; the command hung as expected while waiting for an external clock, which is consistent with the correct behavior of I2S Slave mode. - I2S3 (Output): Tested with
speaker-test -D hw:3,0 ...; a critical issue was discovered: although the device could be opened, it continuously reported aWrite error: -32, Broken pipeerror.
- Using the
3. Core Knowledge Acquisition and Consolidation
During the debugging process, a systematic understanding of the Linux audio subsystem and DTS was developed.
I2S Protocol Fundamentals:
- Pin Functions: Clarified the core roles of SCLK (Bit Clock), WS/LRCLK (Frame Sync/Left-Right Select), SD/D0 (Serial Data), and MCLK (Master Clock).
- Master/Slave Mode: Gained an in-depth understanding of the differences between Master (clock provider) and Slave (clock consumer) modes, and mastered the “data source as the clock source” best practice principle (SoC as Master for output, SoC as Slave for input).
Linux Audio Subsystem (ASoC & ALSA):
- ASoC Architecture: Mastered the core “Platform-Codec-Machine” three-component decoupled architecture. Clearly mapped the
rockchip-i2s-tdmdriver to Platform,dummy-codecto Codec, andsimple-audio-cardto Machine. - DAI Concept: Understood that CPU DAI and Codec DAI are the two software endpoints used by the Machine driver for “linking”.
- ASoC Architecture: Mastered the core “Platform-Codec-Machine” three-component decoupled architecture. Clearly mapped the
In-depth Device Tree (DTS) Application:
- Master/Slave Configuration: Confirmed that I2S Master/Slave mode is configured within the
simple-audio-cardnode via properties likesimple-audio-card,bitclock-masterandsimple-audio-card,frame-master, not in the I2S hardware node itself. - Debugging Tools: Mastered the core debugging technique of using the
dtcutility for reverse engineering. The ability to decompile a.dtbback to a.dtson the development host to inspect the final effective device tree became the key to solving critical issues.
- Master/Slave Configuration: Confirmed that I2S Master/Slave mode is configured within the
4. Key Issues and Solutions
Two typical issues were encountered and successfully resolved through analysis.
Issue 1: DTS Compilation Failure:
Unable to parse input tree- Symptom: Adding a standalone
dummycodecnode in a.dtsifile caused a syntax error during compilation. - Analysis: DTS syntax requires that all custom top-level nodes must be contained within the scope of the root node
/ { ... };. - Solution: The
dummycodecnode definition was moved inside the/ { ... };structure, resolving the issue and deepening the understanding of DTS file structure.
- Symptom: Adding a standalone
Issue 2: Continuous
Broken pipeErrors During I2S3 Testing- Symptom:
speaker-testconstantly encountered data underrun errors when writing data to I2S3. - Analysis Process:
- Initial Check: Tried simplifying the
pinctrlconfiguration for I2S3, but the issue persisted. - Core Method - Comparative Analysis: Since I2S1 was working correctly, its final configuration served as the “golden reference.”
- Key Tool -
dtc: Used thedtcutility to decompile the final.dtbfile and extract the effective node definitions for I2S1 and I2S3 for a line-by-line comparison. - Difference Found: Discovered that the problematic I2S3 node contained an extra proprietary property,
rockchip,bclk-fs = <32>;, which was absent in the working I2S1 node.
- Initial Check: Tried simplifying the
- Root Cause: This proprietary property forced the I2S hardware to use a fixed clock ratio, which conflicted with the dynamic ratio being set by the
simple-audio-carddriver, leading to hardware malfunction. - Solution: In the board-level DTS file, the conflicting property inherited from the upstream
.dtsiwas explicitly removed using the/delete-property/ rockchip,bclk-fs;directive for the&i2s3_2chnode, completely resolving the problem.
- Symptom:
5. Testing Methods and Tools
This debugging effort led to the establishment of a standard, reproducible command-line testing (and debugging) workflow:
- Device Enumeration:
aplay -l/arecord -l(To check if sound cards are registered) - Output Testing:
speaker-test -D hw:X,Y -c 2 -r 48000 -f S16_LE(To verify the output path without needing an audio file) - Input Testing:
arecord -D hw:X,Y -c 2 -r 48000 -f S16_LE -d 5 test.wav(To verify the input path configuration) - DTS Verification:
dtc -I dtb -O dts -o final.dts <path_to_dtb>(To decompile and inspect the final device tree)
6. Tech Stack and Tools
- Hardware Platform: Rockchip RK3568 SoC
- Software Environment: Linux Kernel 5.10, Buildroot
- Core Technologies: Device Tree (DTS), I2S ASoC Subsystem
- Debugging Tools:
dtc,speaker-test,aplay,arecord, dmesg, serial console