1. Project Background and Requirement Breakdown
1.1 Application Scenario
In professional audio equipment, conference systems, multichannel capture devices, and USB audio interfaces, there is a frequent need to bridge data between USB and an external audio codec: the PC sends and receives audio streams over the standard USB Audio protocol, while the MCU converts USB packets into the TDM timing a codec understands — and vice versa. The difficulty of such a bridge lies not in any single interface, but in the interconnection of two real-time domains.
A customer set out to develop a UAC2.0-based multichannel audio bridge. Their requirements can be broken down into four hard constraints.
1.2 Original Customer Requirements
The customer's requirements fall into four areas — the USB side, the audio format, the codec interface, and the channel configuration — detailed one by one below.
(1) USB-side requirements
USB Audio Class 2.0 Device
Full-duplex audio
Windows native driver support
No custom driver installation required
Put another way: the MCU acts as the USB Device, the Windows PC as the USB Host, the Windows built-in UAC2.0 driver is used, and playback and recording are supported simultaneously.
(2) Audio format requirements
48 kHz sampling rate
PCM format
24-bit valid audio data
32-bit slot alignment
(3) Codec interface requirements
The MCU and codec communicate over an SAI TDM interface: TDM mode, 32-bit slot width, 24-bit valid audio data, and a 48 kHz sampling rate.
(4) Channel configuration — asymmetric transmit and receive
This is the point that sets the project apart from a common stereo demo:
Audio direction
Channel count
Data flow
Playback
2 channels
PC → USB OUT → MCU → TDM TX → codec DAC → speaker
Recording
6 channels
MIC → codec ADC → TDM RX → MCU → USB IN → PC
1.3 Four Core Challenges Introduced by Asymmetric Channels
Compared with a typical 2-in/2-out stereo USB Audio demo, this project has to solve four problems at once:
UAC2 multichannel descriptor configuration: describe asymmetric IN/OUT endpoints in the UAC2 descriptor topology and have Windows correctly enumerate them as two logical devices — a "2ch speaker + 6ch mic".
Asymmetric channel design: because playback and recording have different channel counts, the USB-side buffer layout and the TDM-side slot layout cannot map one-to-one; independent mapping logic is required.
Multichannel TDM transport: within an 8-slot TDM frame, the two playback channels must be padded/aligned, while the six recording channels must be extracted/reassembled.
Real-time USB–SAI bridging: USB is packet-driven and paced by microframes; SAI is a continuous bit stream paced by the sample clock. The two must be decoupled with DMA and buffering.
1.4 Scope of This Article
This article goes beyond a simple "it works" conclusion. Following the engineering thread of requirements → hardware → selection → architecture → data format → descriptors → TDM → DMA → verification, it explains the key decisions, register/field-level details, and calculation methods at every layer, offering a reusable reference design for similar multichannel USB audio bridges.
2. Hardware Platform and Key Hardware Modifications
2.1 Hardware Inventory
The hardware and software versions used in this project are listed below (version details sourced from the project README):
Category
Model / Version
Notes
MCU board
FRDM-MCXN236
Main controller, Cortex-M33
Audio codec board
AUD-EXP-42448 Rev B
Multichannel audio codec card (CS42448)
Adapter board
MCXN FRDM Adapter Board Rev A1
Signal routing and breakout
Cable
USB Type-C cable
Connects to the J11 Type-C port
Peripherals
3.5 mm headphone / speaker
Playback verification
IDE
MCUXpresso IDE 25.06.0
Development and debugging
SDK
FRDM-MCXN236 SDK 26.06
Drivers and USB Audio framework
The MCXN236 integrates a USB Device controller, Flexcomm SAI interface, eDMA controller, and Cortex-M33 core — a single chip that satisfies the project's real-time audio transport needs. The CS42448 provides multichannel ADC/DAC and a TDM interface, making it well suited to multichannel capture and playback.
2.2 Hardware Stack and Connections
Because the FRDM-MCXN236 cannot connect directly to the AUD-EXP-42448, the MCXN FRDM Adapter Board is used to break out and route the audio signals (MCLK, BCLK, FSYNC, TXD, RXD, and others).
Figure 1. Hardware stack: AUD-EXP-42448 + MCXN FRDM Adapter Board + FRDM-MCXN236
From top to bottom, the hardware stack is:
AUD-EXP-42448 (CS42448 codec / MIC input / Line Out output) | MCXN FRDM Adapter Board (audio signal routing) | FRDM-MCXN236 (USB Device + SAI + eDMA) | +--- J11 Type-C → Windows PC
The hardware signal connection schematic is shown below:
Figure 2. Hardware connection schematic
2.3 Key Hardware Modification: The SJ3 Jumper
This is a hardware detail that is easy to trip over. According to the README, the default J1-3 configuration of the FRDM-MCXN236 targets motor-control applications. To enable the SAI interface, the SJ3 solder-bridge connections must first be changed:
Open SJ3 pads 1–2, and short SJ3 pads 2–3.
Figure 3. SJ3 jumper modification
If this step is missed, the SAI signals are not routed out correctly and no amount of software configuration will produce a TDM waveform. It is a hardware-first prerequisite.
2.4 J31 Signal Mapping
The adapter board connects to the MCU board through J31 (HDR 2×12). The key SAI/I2C signal definitions are:
J31 pin
Signal
Notes
3
P3_6 / SAI0_MCLK
Master clock
5
P4_3 / I2C0_INT
Codec interrupt
7
P3_18 / SAI0_RX_BCLK
Receive bit clock
9
P2_7 / SAI0_RX_FS
Receive frame sync
11
P1_2 / SAI0_TXD0
Transmit data
13
P1_17 / I2C2_SCL
Codec control bus
15
P1_16 / I2C2_SDA
Codec control bus
17
P2_18 / RESET
Reset
19
P2_1 / SAI0_RXD0
Receive data
21
P0_0 / GPIO
General purpose
23
P3_16 / SAI0_TX_BCLK
Transmit bit clock
Additional signals such as P3_17 / SAI1_TX_FS and P2_5 / SAI0_TXD1 are used for specific TDM timing scenarios.
Figure 4. J31 pin definition
3. Solution Selection: Dual-SDK Fusion
The final design is based on two SDK examples, each contributing its strengths.
3.1 USB: dev_composite_hid_audio_unified_bm
From the FRDM-MCXN236 SDK, this example provides:
A complete USB Device stack (bare-metal, no RTOS)
UAC2 framework
Audio endpoints and isochronous transport pipes
Windows-compatible descriptors (enumerated as "USB AUDIO + HID DEMO")
It was chosen because it is natively matched to the hardware platform (MCXN236): the USB protocol stack is tightly coupled to the on-chip USB controller, so reusing it directly avoids low-level porting risk.
3.2 TDM: sai_edma_tdm_record_playback
From the RT1170 SDK, this example provides:
SAI TDM configuration reference (8 slots / 32-bit)
eDMA transfer framework
Codec initialization reference
Multichannel slot management
It was chosen because the MCXN236 SDK lacks a ready-made 8-slot TDM transmit/receive example, while the RT1170's SAI peripheral and eDMA usage closely resemble the MCXN family, making its TDM multichannel management logic directly reusable.
3.3 Why This Mix
Each SDK contributes a different, complementary piece of the solution:
Area
From MCXN236 SDK
From RT1170 SDK
USB Device stack
✅ Natively matched
—
UAC2 descriptors
✅ Already Windows-validated
—
SAI TDM multichannel
—
✅ 8-slot example
eDMA double buffering
—
✅ Reference framework
The risk is that the two codebases differ in naming style, peripheral handles, and interrupt structure, so they must be unified during integration. The project uses frdmmcxn236_dev_composite_hid_audio_unified_bm as the baseline template for naming and comments, keeping newly added audio functions stylistically consistent.
3.4 Porting Breakdown
The work concentrates in three areas:
Modify the USB Audio descriptors: playback 2ch / recording 6ch / 24-bit.
Port the TDM implementation: migrate the SAI, eDMA, and TDM logic from the RT1170 example to the MCXN236.
Adjust channel mapping: change the reference project's symmetric 8-channel structure to an asymmetric one — playback 2ch + recording 6ch.
4. System Architecture
4.1 Overall Architecture
The overall software and data path architecture is shown below:
Figure 5. UAC2.0 full-duplex audio system block diagram
The diagram shows two independent data paths:
Playback (speaker path): PC (native UAC2 driver) → USB OUT endpoint → MCU (2ch PCM packed into 8-slot TDM) → SAI TX TDM → codec DAC slots 0/1 → 2ch speaker.
Recording (mic path): 6ch MIC → codec ADC → 8-slot TDM (slots 0–5 = MIC1–6) → SAI RX TDM → MCU (extract 6ch) → USB IN endpoint → PC.
4.2 Symmetry and Asymmetry of the Bidirectional Paths
One design insight worth emphasizing: the physical TDM layer is symmetric (both directions use 8 slots / 32-bit), while the logical channel layer is asymmetric (2ch vs 6ch). The essence of the bridge happens in the two conversions between "logical channels ↔ physical slots":
The playback direction performs a 2ch → 8-slot padding: only slot 0 (L) and slot 1 (R) are valid; slots 2–7 are filled with zeros.
The recording direction performs an 8-slot → 6ch extraction: slots 0–5 are taken; slots 6–7 are ignored.
4.3 Bandwidth Budget Analysis
From an engineering standpoint, working out the bandwidth before writing code avoids pitfalls in USB endpoint configuration.
TDM-side bit clock:
Sample rate fs = 48 kHz Slots per frame = 8 Bits per slot = 32 Frame length = 8 x 32 = 256 bits BCLK (bit clock) = fs x 256 = 48000 x 256 = 12.288 MHz FSYNC (frame sync) = fs = 48 kHz
USB-side data rate (24-bit audio carried in 4-byte containers over USB):
Playback : 2ch x 4 B x 48000 = 384,000 B/s ~ 3.07 Mbps Recording: 6ch x 4 B x 48000 = 1,152,000 B/s ~ 9.22 Mbps Full-duplex total ~ 12.29 Mbps
This magnitude dictates that the USB endpoints must use isochronous transfer, with wMaxPacketSize correctly budgeted per microframe (see Section 6.4). The 12.288 MHz BCLK also directly constrains the SAI clock dividers and MCLK selection (see Section 7.2).
5. Audio Data Format Design
5.1 Unified Format Parameters
The entire system uses a single, unified audio format to avoid any resampling or bit-width conversion:
Parameter
Configuration
Sampling rate
48 kHz
Format
PCM
Valid bits
24
Slot width
32
TDM slots
8
5.2 Alignment of 24-bit Valid Data in 32-bit Slots
Although the actual audio data is only 24 bits, it occupies a 32-bit slot in the TDM frame:
+------------------------+---------+ | 24-bit Audio (MSB) | Padding | +------------------------+---------+ <-------- 24 bits ------><- 8 b - > 32-bit Slot
The key point is the alignment. In 32-bit-slot TDM mode, the CS42448 aligns 24-bit valid data to the MSB (left-aligned), with the lower 8 bits as padding. The USB-side 24-bit audio is likewise MSB-aligned within its 32-bit container. Because both sides use the same alignment, DMA can move 32-bit words as a "transparent pipe" without per-sample bit shifting or assembly — an important prerequisite for real-time performance.
If the alignment does not match (for example, MSB on one side and LSB on the other), the audible symptom is abnormal volume or noise rather than complete silence — a condition that is easily misdiagnosed as an analog-circuit problem.
5.3 Three Benefits of 32-bit Slots
Clean TDM alignment: 8 slots × 32 bits = 256 bits per frame; frame boundaries land on whole bytes, making the FSYNC-to-BCLK relationship clear.
DMA efficiency: each transfer is in 32-bit words — exactly one word per slot — so burst lengths are regular.
Simple USB data organization: with 24-bit samples held in 32-bit containers, the USB endpoint buffer and the TDM slot buffer can share the same data structure.
6. UAC2 Descriptor Deep Dive
6.1 SDK Default vs. Customer Requirement
The SDK's default audio demo is playback 2ch / recording 2ch / 16-bit, while the customer requires playback 2ch / recording 6ch / 24-bit. The differences are confined to the recording channel count and the bit resolution on both sides.
Item
SDK default
Customer requirement
Change
Playback channels
2
2
Keep
Recording channels
2
6
Modify
Bit resolution
16
24
Modify
Sample rate
48 kHz
48 kHz
Keep
Format
PCM
PCM
Keep
6.2 Audio Control Interface Topology
UAC2 descriptors are not a bag of isolated fields — they form a topology. Before changing channel counts or bit widths, it is essential to understand the key entities in the Audio Control interface:
USB OUT --> [Input Terminal: USB] --> [Feature Unit] --> [Output Terminal: Speaker] | USB IN <-- [Output Terminal: USB] <-- [Feature Unit] <-- [Input Terminal: Mic]
Input Terminal (IT): the data source. On the playback path the IT points to USB OUT; on the recording path it points to the microphone.
Output Terminal (OT): the data destination, pointing to the speaker and USB IN respectively.
Feature Unit (FU): volume/mute control; its bMute/bVolume channel count must match upstream and downstream.
Clock Source / Clock Selector: entities new in UAC2 relative to UAC1, describing the sampling clock.
The key to the asymmetric design: playback and recording are two independent Audio Streaming interfaces, each with its own Input/Output Terminals, Feature Unit, and isochronous endpoint. Channel count and bit resolution can therefore be configured independently without interfering with each other.
6.3 Key Field Modifications
The descriptor fields that need changing are:
Descriptor
Field
Playback
Recording
Meaning
Input/Output Terminal
bNrChannels
2
6
Number of channels
Audio Streaming Format
bNumChannels
2
6
Streaming interface channel count
Audio Streaming Format
bBitResolution
24
24
Valid bit resolution
Audio Streaming Format
bSubSlotSize
4
4
Bytes per subslot (4-byte container for 24-bit)
Feature Unit
bmaControl channel mask
2ch
6ch
Channel coverage of volume/mute control
Format Descriptor
bmChannelConfig
stereo mask
6ch mask
Spatial location of channels
Isochronous Endpoint
wMaxPacketSize
sized for 2ch
sized for 6ch
Maximum packet length per microframe
Two of these fields are the most error-prone:
bSubSlotSize = 4: 24-bit valid data must be placed in a 4-byte (32-bit) container. If set incorrectly to 3, Windows will parse a packed 24-bit stream that is misaligned with the TDM 32-bit slot layout.
bmChannelConfig: six channels require the correct channel mask (Front Left/Right, Front Center, LFE, Surround Left/Right, and so on); otherwise Windows may enable only part of the channels or report the format as unsupported.
6.4 Bandwidth Budget for Asymmetric Endpoints
The wMaxPacketSize of an isochronous endpoint must cover the data volume within one microframe. Taking High-Speed (125 µs microframes) as an example:
Samples per microframe = 48000 / 8000 = 6 samples Playback : 2ch x 4 B x 6 = 48 B + UAC2 header Recording: 6ch x 4 B x 6 = 144 B + UAC2 header
From this, the wMaxPacketSize of each endpoint is determined, with headroom reserved for the UAC2 packet header. Isochronous transfer has no retransmission and no handshake — insufficient bandwidth budgeting shows up directly as pops, clicks, or dropped samples, so this step must be calculated precisely rather than guessed.
6.5 Verifying the Windows Native Driver
The ultimate criterion for correct descriptors is that Windows automatically loads the UAC2.0 driver and enumerates the device in Device Manager and Sound Settings with the expected format — with no INF file or custom driver. Measured results are presented in Section 10.
7. SAI TDM Implementation and Clock Tree
7.1 TDM Frame Structure
The project uses 8 slots per frame / 32-bit slot width:
Frame (256 bits) +-- Slot0 --+-- Slot1 --+-- Slot2 --+-- Slot3 --+-- Slot4 --+-- Slot5 --+-- Slot6 --+-- Slot7 L/R(ch0/1) reserved reserved reserved reserved reserved reserved reserved
Playback mapping: slot 0 → Left (CH0), slot 1 → Right (CH1), slots 2–7 reserved and written as zeros.
Recording mapping: slot 0 → MIC1, slot 1 → MIC2, slot 2 → MIC3, slot 3 → MIC4, slot 4 → MIC5, slot 5 → MIC6, slots 6–7 reserved.
7.2 Clock Tree Derivation
SAI clock configuration is central to whether TDM works at all. Working backward from the target format gives each clock stage:
Clock
Formula
Result
Sample rate fs
Given by requirement
48 kHz
Frame sync FSYNC
= fs
48 kHz
Bit clock BCLK
fs × slots × slot width = 48000 × 8 × 32
12.288 MHz
Master clock MCLK
Typically 256 × fs or 512 × fs
12.288 / 24.576 MHz
As the codec, the CS42448's MCLK/BCLK/FSYNC must be configured consistently with the SAI master/slave mode. Two common engineering approaches exist:
MCU as master: the SAI outputs MCLK/BCLK/FSYNC and the codec is configured as slave. The advantage is a single clock source and deterministic timing — this is the approach used in this project.
Codec as master: the codec outputs the clocks and the SAI is configured as slave. This suits cases where the codec's internal PLL provides a low-jitter clock.
Either way, the hard constraint BCLK = 12.288 MHz and FSYNC = 48 kHz must be met; otherwise slot boundaries drift, causing channel misalignment or noise.
7.3 Slot–Channel Mapping Implementation
The mapping logic sits between the USB buffer and the SAI buffer:
Figure 6. Playback/Recording data paths and slot mapping
Playback direction (2ch → 8 slots): take two 32-bit samples from the USB OUT buffer, write them into slots 0 and 1 of the TDM TX buffer, and write zeros to the other six slots.
Recording direction (8 slots → 6ch): extract the six samples from slots 0–5 of the TDM RX buffer, write them in order into the six channel positions of the USB IN buffer, and discard slots 6–7.
This is where "asymmetric" is truly implemented, and it is also where most of the changes after porting the reference project are concentrated.
7.4 CS42448 Interface Timing Considerations
The codec's TDM format must be configured with the same slot count (8) and slot width (32-bit) as the SAI.
Only two outputs are used on the DAC side (slots 0/1); six inputs are used on the ADC side (slots 0–5).
Codec register initialization — TDM mode, data format, channel enables, and so on — is completed over I2C (SCL/SDA on J31).
8. Bidirectional eDMA Transfer and Ping-Pong Buffering
8.1 Why DMA Is Mandatory
A continuous 48 kHz / 24-bit / 6ch audio stream, if moved sample by sample by the CPU, would create a very high interrupt load and excessive jitter. eDMA handles all data movement, and the CPU is notified only at half-buffer/full-buffer boundaries, handing real-time performance over to hardware.
8.2 Ping-Pong Double Buffering
Both the playback and recording paths use double buffering:
Playback: USB OUT → Ping-Pong Buffer → eDMA → SAI TX → codec DAC Recording: codec ADC → SAI RX → eDMA → Ping-Pong Buffer → USB IN
Double buffering works like this: while the eDMA is moving one buffer (say, Ping), the CPU/USB side prepares the other (Pong); when the eDMA completion interrupt arrives, the roles swap. This guarantees that at any instant there is one buffer "being transferred" and one "being prepared", producing a continuous stream and avoiding:
Underflow (playback buffer read empty → audio break/click)
Overflow (recording buffer written full → dropped samples)
Audio drop (lost frames from USB-packet/SAI-timing mismatch)
8.3 Latency Analysis
End-to-end latency is mainly the sum of three parts:
Total latency ~ USB buffer depth + DMA buffer depth + codec/FIFO latency
With N samples per buffer at 48 kHz, a single buffer stage contributes N / 48000 seconds of latency. Ping-pong double buffering doubles the effective buffer depth in exchange for jitter resilience. The engineering trade-off is:
Buffers too small → sensitive to USB scheduling jitter, prone to underflow/overflow;
Buffers too large → increased latency, degrading call/monitoring experience.
For a USB audio interface, total latency is usually kept in the range of a few milliseconds. This project prioritizes stability — first ensuring glitch-free full-duplex operation, then fine-tuning buffer depth for the target application.
8.4 Engineering Measures Against Underflow/Overflow
Use independent buffers and DMA channels for USB and SAI so they never block each other.
Use frame sync (FSYNC) as the pace for checking buffer pointers; realign to a frame boundary immediately if an overrun is detected.
Prime before start on power-up / plug-in: prepare the first data block on the playback path before enabling SAI TX, avoiding an empty read at startup.
Leave margin in buffer sizing for the worst case, covering Windows scheduling jitter.
9. Development Flow and Staged Verification
The project progressed in three stages, each with a clear verification point (from the project development flow):
9.1 Stage 1: USB Descriptor Configuration (Complete)
Playback device: 2 channels, 48 kHz, 24-bit
Recording device: 6 channels, 48 kHz, 24-bit
Verification point: the USB UAC2.0 device enumerates on Windows as a 2-channel speaker and a 6-channel microphone.
9.2 Stage 2: SAI/TDM Interface Development (Complete)
Sampling rate: 48 kHz
Slot width: 32-bit
TDM slots: 8 slots per frame
Valid audio data: 24-bit
Verification point: SAI TX/RX operates with 8-slot TDM, 48 kHz, 32-bit slots (verify the waveform with a logic analyzer or codec loopback).
9.3 Stage 3: USB–SAI Buffer Integration (Complete)
Playback path: USB OUT 2ch → SAI TX 8-slot TDM
Recording path: SAI RX 8-slot TDM → USB IN 6ch
Verification point: channel-to-slot and slot-to-channel mapping is correct, with no drops over long full-duplex runs.
9.4 Debugging Takeaways
Hardware first, software second: an unmodified SJ3 jumper leaves SAI with no signal — the first prerequisite to rule out.
Verify each domain separately, then integrate: validating USB enumeration and SAI waveforms independently before bridging greatly narrows the problem space.
Alignment is a hidden trap: mismatched MSB/LSB alignment produces "sound, but wrong" — use a test signal of known amplitude to locate it.
Unify naming style: using the MCXN236 SDK example as a template reduces the cognitive cost of fusing two SDKs.
10. Test Results and Evidence
10.1 Test Setup
PC: Windows, using the native UAC2.0 driver
Connection: the FRDM-MCXN236's J11 Type-C port connected to the PC via a USB Type-C cable
Firmware: compiled image programmed to the target board
Audio peripherals: AUD-EXP-42448 Line Out 1/2 connected to a headphone/speaker; the on-board MIC2 used as the recording input
10.2 Windows Device Enumeration
Once plugged in, the device is correctly enumerated in the Windows Sound control panel:
Speakers Properties → Default Format: 24 bit, 48000 Hz (Studio Quality)
Figure 7. Windows speaker enumeration: 24 bit, 48000 Hz
Microphone Properties → Default Format: 6 channel, 24 bit, 48000 Hz
Figure 8. Windows microphone enumeration: 6 channel, 24 bit, 48000 Hz
The enumeration results match the project targets exactly, with no custom driver installed.
10.3 Playback Test
A 3.5 mm headphone/speaker is connected to AUD-EXP-42448 Line Out 1/2. Selecting "USB AUDIO + HID DEMO" as the playback device in Windows and playing music produces normal audio in the headphone.
Figure 9. Windows output device selection: Speakers (2- USB AUDIO+HID DEMO)
10.4 Recording Test
Open the Windows Sound Recorder, select "USB AUDIO + HID DEMO" as the input device, click Record, and capture audio through the AUD-EXP-42448 on-board MIC2. After recording, play it back and the captured content can be heard in the headphone. The recording waveform is shown below:
Figure 10. Sound Recorder waveform and input device selection
11. Conclusion and Engineering Value
11.1 Recap
This article has presented the implementation of a UAC2.0 multichannel audio bridge on the MCXN236. By combining the USB Audio framework from the MCXN236 SDK with the SAI TDM reference design from the RT1170 SDK, we built a full-duplex audio bridge that works with the Windows native driver.
11.2 Solution Features
USB Audio Class 2.0 Device
Windows native driver (no custom driver)
Full-duplex audio
Asymmetric design: playback 2 channels / recording 6 channels
24-bit PCM / 48 kHz sampling rate
SAI TDM interface (8 slots / 32-bit slot)
eDMA streaming + ping-pong double buffering
11.3 Typical Applications
USB audio interfaces
Multichannel recording devices
Conference audio systems
Industrial audio acquisition equipment
Audio gateway products
11.4 Future Extensions
This architecture can be extended to support:
More TDM channels (reusing the unused slots)
Higher sampling rates (96/192 kHz, requiring clock and bandwidth recalculation)
Audio DSP processing (EQ, noise reduction, mixing, AEC)
Multichannel microphone-array beamforming
This project provides a complete reference design for multichannel USB audio bridging — from hardware to software, from descriptors to timing.
記事全体を表示