52. SPDIF receiver interface (SPDIFRX)

52.1 SPDIFRX interface introduction

The SPDIFRX interface handles S/PDIF audio protocol.

52.2 SPDIFRX main features

52.3 SPDIFRX functional description

The SPDIFRX peripheral, is designed to receive an S/PDIF flow compliant with IEC-60958 and IEC-61937. These standards support simple stereo streams up to high sample rate, and compressed multi-channel surround sound, such as those defined by Dolby or DTS.

The receiver provides all the necessary features to detect the symbol rate, and decode the incoming data. It is possible to use a dedicated path for the user and channel information in order to ease the interface handling. Figure 651 shows a simplified block diagram.

The SPDIFRX_DC block is responsible of the decoding of the S/PDIF stream received from SPDIFRX_IN[3:0] inputs. This block re-sample the incoming signal, decode the manchester stream, recognize frames, sub-frames and blocks elements. It delivers to the REG_IF part, decoded data, and associated status flags.

This peripheral can be fully controlled via the APB bus, and can handle two DMA channels:

Interrupt services are also available either as an alternative function to the DMA, or for signaling error or key status of the peripheral.

The SPDIFRX also offers a signal named spdifrx_frame_sync, which toggles every time that a sub-frame's preamble is detected. So the duty cycle is 50%, and the frequency equal to the frame rate.

This signal can be connected to timer events, in order to compute frequency drift.


a. Check the RCC capabilities in order to verify which sampling rates can be supported.

In addition the SPDIFRX also provides a signal named spdifrx_symb_ck toggling at the symbol rate.

Figure 651. SPDIFRX block diagram

Block diagram of the SPDIFRX interface. The diagram shows the internal structure of the SPDIFRX, divided into a Register interface and a SPDIFRX_DC (Data and Control) block. The Register interface includes registers: SPDIFRX_FMTx_DR, SPDIFRX_CR, SPDIFRX_IMR, SPDIFRX_CSR, SPDIFRX_SR, SPDIFRX_IFCR, and SPDIFRX_DIR. It is connected to a 32-bit APB bus and an IRQ interface. The SPDIFRX_DC block contains an RX_BUF (32 bits), a SYNC block, a SPDIFRX_SEQ (SPDIF data packing and sequencer), a SPDIFRX_DEC (Biphase and transition decoder), and a SPDIFRX_FE (Re-sync & Edge detection). The SPDIFRX_DC block is connected to external inputs SPDIFRX_IN[x], SPDIFRX_IN[x+1], and SPDIFRX_IN[x+n] (1). It also outputs spdifrx_symb_ck and spdifrx_frame_sync. The SPDIFRX_DC block is clocked by spdifrx_ker_ck, while the Register interface is clocked by spdifrx_pclk. A DMA interface is also present, connected to the Register interface and the SPDIFRX_DC block.
Block diagram of the SPDIFRX interface. The diagram shows the internal structure of the SPDIFRX, divided into a Register interface and a SPDIFRX_DC (Data and Control) block. The Register interface includes registers: SPDIFRX_FMTx_DR, SPDIFRX_CR, SPDIFRX_IMR, SPDIFRX_CSR, SPDIFRX_SR, SPDIFRX_IFCR, and SPDIFRX_DIR. It is connected to a 32-bit APB bus and an IRQ interface. The SPDIFRX_DC block contains an RX_BUF (32 bits), a SYNC block, a SPDIFRX_SEQ (SPDIF data packing and sequencer), a SPDIFRX_DEC (Biphase and transition decoder), and a SPDIFRX_FE (Re-sync & Edge detection). The SPDIFRX_DC block is connected to external inputs SPDIFRX_IN[x], SPDIFRX_IN[x+1], and SPDIFRX_IN[x+n] (1). It also outputs spdifrx_symb_ck and spdifrx_frame_sync. The SPDIFRX_DC block is clocked by spdifrx_ker_ck, while the Register interface is clocked by spdifrx_pclk. A DMA interface is also present, connected to the Register interface and the SPDIFRX_DC block.

1. 'n' is fixed to 3, and 'x' is set to 0.

52.3.1 SPDIFRX pins and internal signals

Table 474 lists the SPDIFRX internal input/output signals, Table 475 the SPDIFRX pins (alternate functions).

Table 474. SPDIFRX internal input/output signals

Signal nameSignal typeDescription
spdifrx_ker_ckDigital inputSPDIFRX kernel clock
spdifrx_pclkDigital inputSPDIFRX register interface clock
spdifrx_itDigital outputSPDIFRX global interrupt
spdifrx_dat_dmaDigital input/outputSPDIFRX DMA request (and acknowledge) for data transfer
spdifrx_ctrl_dmaDigital input/outputSPDIFRX DMA request (and acknowledge) for channel status and user information transfer
spdifrx_frame_syncDigital outputSPDIFRX frame rate synchronization signal
spdifrx_symb_ckDigital outputSPDIFRX channel symbol clock

Table 475. SPDIFRX pins

Pin namePin typeDescription
SPDIFRX_IN0Digital inputInput 0 for S/PDIF signal
SPDIFRX_IN1Digital inputInput 1 for S/PDIF signal

Table 475. SPDIFRX pins (continued)

Pin namePin typeDescription
SPDIFRX_IN2Digital inputInput 2 for S/PDIF signal
SPDIFRX_IN3Digital inputInput 3 for S/PDIF signal

52.3.2 S/PDIF protocol (IEC-60958)

S/PDIF block

A S/PDIF frame is composed of two sub-frames (see Figure 652). Each sub-frame contains 32 bits (or time slots):

Figure 652. S/PDIF sub-frame format

Diagram of S/PDIF sub-frame format showing 32 bits. Bits 0-3: Sync Preamble (Synchronization type B, M or W). Bits 4-27: Audio sample, up to 24 bits (LSb at bit 4, MSb at bit 27). Bits 28-31: Status bits (V, U, C, P). A bracket indicates 28 information bits from bit 4 to bit 31.

The diagram illustrates the 32-bit structure of an S/PDIF sub-frame. It is divided into four main sections: a 4-bit Sync Preamble (bits 0-3), a 24-bit Audio sample (bits 4-27), and a 4-bit Status section (bits 28-31). The Audio sample section is labeled with 'LSb' at bit 4 and 'MSb' at bit 27. The Status section contains bits V (Validity), U (User data), C (Channel status), and P (Parity). A bracket at the bottom indicates that bits 4 through 31 constitute the 28 information bits. The diagram is labeled MSv35981V1 in the bottom right corner.

Diagram of S/PDIF sub-frame format showing 32 bits. Bits 0-3: Sync Preamble (Synchronization type B, M or W). Bits 4-27: Audio sample, up to 24 bits (LSb at bit 4, MSb at bit 27). Bits 28-31: Status bits (V, U, C, P). A bracket indicates 28 information bits from bit 4 to bit 31.

For linear coded audio applications, the first sub-frame (left or “A” channel in stereophonic operation and primary channel in monophonic operation) normally starts with preamble “M”. However, the preamble changes to preamble “B” once every 192 frames to identify the start of the block structure used to organize the channel status and user information. The second sub-frame (right or “B” channel in stereophonic operation and secondary channel in monophonic operation) always starts with preamble “W”.

A S/PDIF block contains 192 pairs of sub-frames of 32 bits.

Figure 653. S/PDIF block format

Diagram of S/PDIF block format showing Frame 191, Frame 0, Frame 1, Frame 191, Frame 0. Each frame contains Sub-frame Ch A and Sub-frame Ch B, with preambles B, M, and W. Notes explain that for historical reasons preambles 'B', 'M', and 'W' are referred to as 'Z', 'X', and 'Y' respectively in professional applications.

NOTE
For historical reasons preambles "B", "M" and "W" are, for use in professional applications, referred to as "Z", "X" and "Y", respectively.

MSv35923V1

Diagram of S/PDIF block format showing Frame 191, Frame 0, Frame 1, Frame 191, Frame 0. Each frame contains Sub-frame Ch A and Sub-frame Ch B, with preambles B, M, and W. Notes explain that for historical reasons preambles 'B', 'M', and 'W' are referred to as 'Z', 'X', and 'Y' respectively in professional applications.

Synchronization preambles

The preambles patterns are inverted or not according to the previous half-bit value. This previous half-bit value is the level of the line before enabling a transfer for the first “B” preamble of the first frame. For the others preambles, this previous half-bit value is the second half-bit of the parity bit of the previous sub-frame. The preambles patterns B, M and W are described in the Figure 654.

Figure 654. S/PDIF preambles

Waveform diagram showing S/PDIF preambles for B, M, and W for previous half-bit = 0 and previous half-bit = 1 across UI 0 to UI 3 (1 UI to 8 UI intervals), indicating Lack of transitions! and Symbol boundary.

MSv35982V1

Waveform diagram showing S/PDIF preambles for B, M, and W for previous half-bit = 0 and previous half-bit = 1 across UI 0 to UI 3 (1 UI to 8 UI intervals), indicating Lack of transitions! and Symbol boundary.

Coding of information bits

In order to minimize the DC component value on the transmission line, and to facilitate clock recovery from the data stream, bits 4 to 31 are encoded in biphase-mark.

Each bit to be transmitted is represented by a symbol comprising two consecutive binary states. The first state of a symbol is always different from the second state of the previous symbol. The second state of the symbol is identical to the first if the bit to be transmitted is

logical 0. However, it is different if the bit is logical 1. These states are named “UI” (unit interval) in the IEC-60958 specification.

The 24 data bits are transferred LSB first.

Figure 655. Channel coding example

Timing diagram showing Bit Clock, Source coding, Channel coding (Biphase-Mark), and BitStream Biphase-Mark Coded signals across 14 UI intervals.

The figure is a timing diagram illustrating channel coding. It consists of four horizontal signal lines and a top row of 14 shaded boxes representing Unit Intervals (UI), labeled from 1 UI to 14 UI. Vertical dashed lines separate these intervals.

The label 'MSv35921V1' is located in the bottom right corner of the diagram area.

Timing diagram showing Bit Clock, Source coding, Channel coding (Biphase-Mark), and BitStream Biphase-Mark Coded signals across 14 UI intervals.

52.3.3 SPDIFRX decoder (SPDIFRX_DC)

Main principle

The technique used by the SPDIFRX in order to decode the S/PDIF stream is based on the measurement of the time interval between two consecutive edges. Three kinds of time intervals may be found into an S/PDIF stream:

The SPDIFRX_DC block is responsible of the decoding of the received S/PDIF stream. It takes care of the following functions:

Figure 656 gives a detailed view of the SPDIFRX decoder.

Figure 656. SPDIFRX decoder

Block diagram of the SPDIFRX decoder architecture. The diagram shows the flow from multiple SPDIFRX_IN inputs through a noise filtering and edge detection block (SPDIFRX_FE) to a main decoder block (SPDIFRX_DC). Inside SPDIFRX_DC, the signal goes through a longest and shortest transition detector, a transition coder and preamble detector, and a biphasic decoder. It also includes a TRCNT counter, data packing, and a fine sync block. The final output goes through an RX_BUF and a SYNC block to produce data and ctrl_ch. Control signals like transition_pulse and transition_width_count are shown between blocks.
Block diagram of the SPDIFRX decoder architecture. The diagram shows the flow from multiple SPDIFRX_IN inputs through a noise filtering and edge detection block (SPDIFRX_FE) to a main decoder block (SPDIFRX_DC). Inside SPDIFRX_DC, the signal goes through a longest and shortest transition detector, a transition coder and preamble detector, and a biphasic decoder. It also includes a TRCNT counter, data packing, and a fine sync block. The final output goes through an RX_BUF and a SYNC block to produce data and ctrl_ch. Control signals like transition_pulse and transition_width_count are shown between blocks.

1. 'n' is fixed to 3, and 'x' is set to 0.

Noise filtering and rising/falling edge detection

The S/PDIF signal received on the selected SPDIFRX_IN is re-sampled using the spdifrx_ker_ck clock (acquisition clock). A simple filtering is applied in order cancel spurs. This is performed by the stage detecting the edge transitions. The edge transitions are detected as follow:

Figure 657. Noise filtering and edge detection

Timing diagram showing the relationship between SPDIFRX_IN[x], spdifrx_ker_ck, resampled input, filtered input, and transition_pulse. The diagram is divided into four states: S1, S2, S3, and S4. A 'Glitch !!' is indicated in state S2. The resampled input shows a sequence of bits (0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1) corresponding to the transitions in the input signal. The filtered input shows the resulting transitions, and the transition_pulse shows the detected edge pulses.
Timing diagram showing the relationship between SPDIFRX_IN[x], spdifrx_ker_ck, resampled input, filtered input, and transition_pulse. The diagram is divided into four states: S1, S2, S3, and S4. A 'Glitch !!' is indicated in state S2. The resampled input shows a sequence of bits (0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1) corresponding to the transitions in the input signal. The filtered input shows the resulting transitions, and the transition_pulse shows the detected edge pulses.

Longest and shortest transition detector

The longest and shortest transition detector block detects the maximum (MAX_CNT) and minimum (MIN_CNT) duration between two transitions. The TRCNT counter is used to measure the time interval duration. It is clocked by the spdifrx_ker_ck signal. On every transition pulse, the counter value is stored and the counter is reset to start counting again.

The maximum duration is normally found during the preamble period. This maximum duration is sent out as MAX_CNT. The minimum duration is sent out as MIN_CNT.

The search of the longest and shortest transition is stopped when the transition timer expires. The transition timer is like a watchdog timer that generates a trigger after 70 transitions of the incoming signal. Note that counting 70 transitions insures a delay a bit longer than a sub-frame.

Note that when the TRCNT overflows due to a too long time interval between two pulses, the SPDIFRX is stopped and the flag TERR of SPDIFRX_SR register is set to 1.

Transition coder and preamble detector

The transition coder and preamble detector block receives the MAX_CNT and MIN_CNT. It also receives the current transition width from the TRCNT counter (see Figure 656). This block encodes the current transition width by comparing the current transition width with two different thresholds, names THHI and THLO.

The thresholds THHI and THLO are elaborated using two different methods.

If the peripheral is doing its initial synchronization ('coarse synchronization'), then the thresholds are computed as follow:

Once the 'coarse synchronization' is completed, then the SPDIFRX uses a more accurate reference in order to elaborate the thresholds. The SPDIFRX measures the length of 24 symbols (WIDTH24) for defining THLO and the length of 40 symbols (WIDTH40) for THHI. THHI and THLO are computed as follow:

This second synchronization phase is called the 'fine synchronization'. Refer to Figure 660 for additional information.

As shown in the figure hereafter, \(TH_{LO}\) is ideally equal to 1.5 UI, and to \(TH_{HI}\) 2.5 UI.

Figure 658. Thresholds

Figure 658. Thresholds: A timing diagram showing the SPDIFRX Signal and its detection thresholds. The signal is a square wave. Above it, a bar is divided into three segments: 1 UI, 2 UI, and 3 UI. MIN_CNT spans the first two segments (1 UI + 2 UI). MAX_CNT spans all three segments (1 UI + 2 UI + 3 UI). Below the signal, three horizontal arrows indicate detection regions: 'Detection of Short Transition' (centered at 1.5 UI), 'Detection of Medium Transition' (centered at 2.5 UI), and 'Detection of Long Transition' (centered at 3.5 UI). Vertical lines mark the thresholds TH_LO at 1.5 UI and TH_HI at 2.5 UI. The diagram is labeled MSv35931V2.
Figure 658. Thresholds: A timing diagram showing the SPDIFRX Signal and its detection thresholds. The signal is a square wave. Above it, a bar is divided into three segments: 1 UI, 2 UI, and 3 UI. MIN_CNT spans the first two segments (1 UI + 2 UI). MAX_CNT spans all three segments (1 UI + 2 UI + 3 UI). Below the signal, three horizontal arrows indicate detection regions: 'Detection of Short Transition' (centered at 1.5 UI), 'Detection of Medium Transition' (centered at 2.5 UI), and 'Detection of Long Transition' (centered at 3.5 UI). Vertical lines mark the thresholds TH_LO at 1.5 UI and TH_HI at 2.5 UI. The diagram is labeled MSv35931V2.

The preamble detector checks four consecutive transitions of a specific sequence to determine if they form the part of preamble. Let us say TRANS0, TRANS1, TRANS2 and TRANS3 represent four consecutive transitions encoded as mentioned above. Table 476 shows the values of these four transitions to form a preamble. Absence of this pattern indicates that these transitions form part of the data in the sub frame and bi-phase decoder decode them.

Table 476. Transition sequence for preamble

Preamble typeBiphase data patternTRANS3TRANS2TRANS1TRANS0
Preamble B11101000TLTSTSTL
Preamble M11100010TLTLTSTS
Preamble W11100100TLTMTSTM

Bi-phase decoder

The Bi-phase decoder decodes the input bi-phase marked data stream using the transition information provided by the transition coder and preamble detector block. It first waits for the preamble detection information. After the preamble detection, it decodes the following transition information:

After decoding 28 data bits this way, this module looks for the following preamble data. If the new preamble is not what is expected, then this block generates an error signal (FERR set to 1). Refer to Section 52.3.9, for additional information on error flags.

Data packing

This block is responsible of the decoding of the IEC-60958 frames and blocks. It also handles the writing into the RX_BUF or into SPDIFRX_CSR register.

52.3.4 SPDIFRX tolerance to clock deviation

The SPDIFRX tolerance to clock deviation depends on the number of sample clock cycles in one bit slot. The fastest spdifrx_ker_ck is, the more robust the reception is. The ratio between spdifrx_ker_ck frequency and the symbol rate must be at least 11.

Two kinds of phenomenon (at least) can degrade the reception quality:

52.3.5 SPDIFRX synchronization

The synchronization phase starts when setting SPDIFRXEN to 01 or 11. Figure 659 shows the synchronization process.

If the bit WFA of SPDIFRX_CR register is set to 1, then the peripheral must first detect activity on the selected SPDIFRX_IN line before starting the synchronization process. The activity detection is performed by detecting four transitions on the selected SPDIFRX_IN. The peripheral remains in this state until transitions are not detected. This function can be particularly helpful because the SPDIFRX switches in COARSE SYNC mode only if activity is present on the selected SPDIFRX_IN input, avoiding synchronization errors. See Section 52.4 for additional information.

The user can still set the SPDIFRX into STATE_IDLE by setting SPDIFRXEN to 0. If the WFA is set to 0, the peripheral starts the coarse synchronization without checking activity.

The next step consists on doing a first estimate of the thresholds (COARSE SYNC), in order to perform the fine synchronization (FINE SYNC). Due to disturbances of the SPDIFRX line, it can happen that the process is not executed first time right. For this purpose, the user can program the number of allowed re-tries (NBTR) before setting SERR error flag.

When the SPDIFRX is able to measure properly the duration of 24 and 40 consecutive symbols then the FINE SYNC is completed, the threshold values are updated, and the flag SYNCD is set to 1. Refer to Transition coder and preamble detector for additional information.

Two kinds of errors are detected:

When the first FINE SYNC is completed, the reception of channel status (C) and user data (U) starts when the next “B” preamble is detected (see Figure 663). Then the user can read IEC-60958 C and U bits through SPDIFRX_CSR register. According to this information the user can then select the proper settings for DRFMT and RXSTEO. For example if the user detects that the current audio stream transports encoded data, then he can put RXSTEO to 0, and DRFMT to 10 prior to start data reception. Note that DRFMT and RXSTEO cannot be modified when SPDIFRXEN = 11. Writes to these fields are ignored if SPDIFRXEN is already 11, though these field can be changed with the same write instruction that causes SPDIFRXEN to become 11. Then the SPDIFRX waits for SPDIFRXEN = 11 and the “B” preamble before starting saving audio samples.

Figure 659. Synchronization flowchart

Synchronization flowchart showing Initial Sync Process, Parallel flows, COARSE SYNC (Search for Longest/Shortest pulses, Compute COARSE thresholds), and FINE SYNC (Search for preamble, Decode symbols, Compute FINE thresholds).
graph TD
    Start([Initial Sync Process]) --> Wait[Wait for 4 transitions if WFA = 1, else skip this step]
    Wait --> Parallel[Parallel flows]
    
    subgraph LeftPath [ ]
        TRCNT{TRCNT overflows?}
        ErrorT[ERROR: Sync failure !
TERR = 1] end subgraph RightPath [ ] subgraph COARSE_SYNC [COARSE SYNC] SearchPulses[Search for Longest/Shortest pulses for 70 transitions] ComputeCoarse[Compute COARSE thresholds (THLO, THHI)] end subgraph FINE_SYNC [FINE SYNC] SearchPreamble[Search for preamble for 70 transitions] PreambleFound{preamble found within 70 trans. ?} Decode[Decode properly the next 40 symbols
Measurement of 24 and 40 symbols duration (WIDTH24, WIDTH40)] SymbDecoding{Symb. decoding (1) OK ?} ComputeFine[Compute FINE thresholds (THLO, THHI)] SetSyncD[Set SYNCND to 1] Done([Synchronization done]) end Attempt[ATTEMPT ++] AttemptEqNBTR{ATTEMPT == NBTR ?} ErrorS[ERROR: Sync failure !
SERR = 1] end Parallel --> TRCNT Parallel --> SearchPulses TRCNT -- N --> SearchPulses TRCNT -- Y --> ErrorT SearchPulses --> ComputeCoarse ComputeCoarse --> SearchPreamble SearchPreamble --> PreambleFound PreambleFound -- N --> Attempt PreambleFound -- Y --> Decode Decode --> SymbDecoding SymbDecoding -- N --> Attempt SymbDecoding -- Y --> ComputeFine Attempt --> AttemptEqNBTR AttemptEqNBTR -- N --> SearchPulses AttemptEqNBTR -- Y --> ErrorS ComputeFine --> SetSyncD SetSyncD --> Done ErrorT --> SyncStopped([Sync stopped]) ErrorS --> SyncStopped

(1) - The decoding is considered OK, when the symbols are properly decoded, and preamble occurs at the expected position

MSv35932V1

Synchronization flowchart showing Initial Sync Process, Parallel flows, COARSE SYNC (Search for Longest/Shortest pulses, Compute COARSE thresholds), and FINE SYNC (Search for preamble, Decode symbols, Compute FINE thresholds).

Refer to Frame structure and synchronization error for additional information concerning TRCNT overflow.

The FINE SYNC process is re-triggered every frame in order to update thresholds as shown in Figure 660 in order to continuously track S/PDIF synchronization.

Figure 660. Synchronization process scheduling

Timing diagram showing SPDIFRX_IN data stream, synchronization processes (COARSE, FINE), SPDIFRXEN control signal, and SYNCED status signal across STATE_SYNC and STATE_RCV phases.

The diagram illustrates the synchronization process scheduling for the SPDIFRX interface. It shows the following signals over time:

Legend:

Reference: MSv35984V2

Timing diagram showing SPDIFRX_IN data stream, synchronization processes (COARSE, FINE), SPDIFRXEN control signal, and SYNCED status signal across STATE_SYNC and STATE_RCV phases.

52.3.6 SPDIFRX handling

The software can control the state of the SPDIFRX through SPDIFRXEN field. The SPDIFRX can be into one of the following states:

Figure 661 shows the possible states of the SPDIFRX, and how to transition from one state to the other. The bits under software control are followed by the mention “(SW)”, the bits under SPDIFRX control are followed by the mention “(HW)”.

Figure 661. SPDIFRX states

State machine diagram for SPDIFRX showing transitions between STATE_IDLE, STATE_SYNC, STATE_STOP, and STATE_RCV.
stateDiagram-v2
    state STATE_IDLE
    state STATE_SYNC
    state STATE_STOP
    state STATE_RCV

    STATE_IDLE --> STATE_SYNC : SPDIFRXEN = 0b01 (SW) or SPDIFRXEN = 0b11 (SW)
    STATE_SYNC --> STATE_IDLE : SPDIFRXEN = 0b00 (SW)
    STATE_SYNC --> STATE_STOP : FERR = 1 (HW) or TERR = 1 (HW) or SERR = 1 (HW)
    STATE_SYNC --> STATE_RCV : SPDIFRXEN = 0b11 (SW) and SYNC = 1 (HW)
    STATE_RCV --> STATE_IDLE : SPDIFRXEN = 0b00 (SW)
    STATE_RCV --> STATE_STOP : FERR = 1 (HW) or TERR = 1 (HW)
    STATE_STOP --> STATE_IDLE : SPDIFRXEN = 0b00 (SW)
  

NOTE: SYNC is an internal event informing that the SPDIFRX is properly synchronized

MSv35985V3.

State machine diagram for SPDIFRX showing transitions between STATE_IDLE, STATE_SYNC, STATE_STOP, and STATE_RCV.

When SPDIFRX is in STATE_IDLE:

When SPDIFRX is in STATE_SYNC:

When SPDIFRX is in STATE_RCV:

When SPDIFRX is in STATE_STOP:

When SPDIFRXEN is set to 0, the SPDIFRX is disabled, meaning that all the state machines are reset, and RX_BUF is flushed. Note as well that flags FERR, SERR and TERR are reset.

52.3.7 Data reception management

The SPDIFRX offers a double buffer for the audio sample reception. A 32-bit buffer located into the spdifrx_ker_ck clock domain (RX_BUF), and the SPDIFRX_FMTx_DR register. The valid data contained into the RX_BUF are immediately transferred into SPDIFRX_FMTx_DR if SPDIFRX_FMTx_DR is empty.

The valid data contained into the RX_BUF are transferred into SPDIFRX_FMTx_DR when the two following conditions are reached:

Having a 2-word buffer gives more flexibility for the latency constraint.

The maximum latency allowed is \(T_{SAMPLE} - 2T_{PCLK} - 2T_{spdifrx\_ker\_ck}\)

Where \(T_{SAMPLE}\) is the audio sampling rate of the received stereo audio samples, \(T_{PCLK}\) is the period of spdifrx_pclk clock, and \(T_{spdifrx\_ker\_ck}\) is the period of spdifrx_ker_ck clock.

The SPDIFRX offers the possibility to use either DMA (spdifrx_dat_dma and spdifrx_ctrl_dma) or interrupts for transferring the audio samples into the memory. The recommended option is DMA, refer to Section 52.3.12: DMA interface for additional information.

The SPDIFRX offers several way on handling the received data. The user can either have a separate flow for control information and audio samples, or get them all together.

For each sub-frame, the data reception register SPDIFRX_FMTx_DR contains the 24 data bits, and optionally the V, U, C, PE status bits, and the PT (see Mixing data and control flow).

Note that PE bit stands for parity rror bit, and is set to 1 when a parity error is detected in the decoded sub-frame.

The PT field carries the preamble type (B, M or W).

V, U and C are a direct copy of the value received from the S/PDIF interface.

The bit DRFMT allows the selection between 3 audio formats as shown in Figure 662.

This document describes 3 data registers: SPDIFRX_FMTx[2:0] (x = 2 to 0), but in reality there is only one physical data register, having 3 possible formats:

Figure 662. SPDIFRX_FMTx_DR register format

Diagram showing the SPDIFRX_FMTx_DR register format for three different DRFMT settings: 0b00, 0b01, and 0b10. It includes the IEC60958 block format and sub-frame structure, and maps specific bits from the sub-frame into the register fields.

The diagram illustrates the mapping of IEC60958 sub-frame data into the SPDIFRX_FMTx_DR register based on the DRFMT setting.

IEC60958 block format: Shows three frames (Frame 191, Frame 0, Frame 1). Each frame contains a Sync Preamble (M), Channel A (Ch A), and Channel B (Ch B). Frame 0 also contains a Block (B) and a Word (W).

IEC60958 sub-frame: A 32-bit sub-frame structure: Sync Preamble (bits 0-3), S0 (bit 4), S1 (bit 5), S2 (bit 6), S3 (bit 7), S8 (bit 12), S21 (bit 25), S22 (bit 26), S23 (bit 27), V (bit 28), U (bit 29), C (bit 30), P (bit 31).

SPDIFRX_FMT0_DR (i.e. DRFMT = 0b00): A 32-bit register. Bits 31-24 are status fields: 0, 0, PT[1:0] or 0, C or 0, U or 0, V or 0, PE or 0. Bit 23 is S23. Bits 22-1 are DR[23:0]. Bit 0 is S0.

SPDIFRX_FMT1_DR (i.e. DRFMT = 0b01): A 32-bit register. Bit 31 is S23. Bits 30-8 are DR[23:0]. Bits 7-0 are status fields: S0, 0, 0, PT[1:0] or 0, C or 0, U or 0, V or 0, PE or 0.

SPDIFRX_FMT2_DR (i.e. DRFMT = 0b10): A 32-bit register. Bit 31 is S23. Bits 30-16 are DRNL2[15:0]. Bits 15-16 are S8 and S23. Bits 14-0 are DRNL1[15:0]. Bit 0 is S8.

Diagram showing the SPDIFRX_FMTx_DR register format for three different DRFMT settings: 0b00, 0b01, and 0b10. It includes the IEC60958 block format and sub-frame structure, and maps specific bits from the sub-frame into the register fields.

MSv35925V4

Setting DRFMT to 00 or 01, offers the possibility to have the data either right or left aligned into the SPDIFRX_FMTx_DR register. The status information can be enabled or forced to zero according to the way the software wants to handle them.

The format given by DRFMT= 10 is interesting in non-linear mode, as only 16 bits per sub-frame are used. By using this format, the data of two consecutive sub-frames are stored into SPDIFRX_FMTx_DR, dividing by two the amount of memory footprint. Note that when RXSTEO = 1, there is no misalignment risks (i.e. data from ChA are always stored into SPDIFRX_FMTx_DR[31:16]). If RXSTEO = 0, then there is a misalignment risk in case of overrun situation. In that case SPDIFRX_FMTx_DR[31:16] always contain the oldest value and SPDIFRX_FMTx_DR[15:0] the more recent value (see Figure 664).

In this format the status information cannot be mixed with data, but the user can still get them through SPDIFRX_CSR register, and use a dedicated DMA channel or interrupt to transfer them to memory (see Section 52.3.8)

Mixing data and control flow

The user can choose to use this mode in order to get the full flexibility of the handling of the control flow. The user can select which field must be kept into the data register (SPDIFRX_FMTx_DR).

52.3.8 Dedicated control flow

The SPDIFRX offers the possibility to catch both user data and channel status information via a dedicated DMA channel. This feature allows the SPDIFRX to acquire continuously the channel status and user information. The acquisition starts at the beginning of a IEC 60958 block. Two fields are available to control this path: CBDMAEN and SPDIFRXEN. When SPDIFRXEN is set to 01 or 0x11, the acquisition is started, after completion of the synchronization phase. When 8 channel status and 16 user data bits are received, they are packed and stored into SPDIFRX_CSR register. A DMA request is triggered if the bit CBDMAEN is set to 1 (see Figure 663).

If CS[0] corresponds to the first bit of a new block, the bit SOB is set to 1. Refer to Section 52.5.8. A bit is available (CHSEL) in order to select if the user wants to select channel status information (C) from the channel A or B.

Figure 663. Channel/user data format

Timing diagram and register format for Channel/user data format. Signals include SPDIFRX_IN, SPDIFRXEN (0b01 or 0b11), SYNCD, spdifrx_dat_dma, spdifrx_ctrl_dma. Frames depicted: Frame 191, Frame 0, Frame 7, Frame 8, Frame 15, Frame 16. Events marked: Synchronization done, Acquisition of C and U bits started !!!, Start of a new block, Transfer of first SPDIFRX_CB word with SOB = 1, Transfer of second SPDIFRX_CB word with SOB = 0. Below is the bit map of SPDIFRX_CSR format with bits 31-25 reserved, 24 SOB, 23-16 CS[7:0], 15-0 USR[15:0].

SPDIFRX_CSR format

3125242316150
reservedSOBCS[7:0]USR[15:0]

MSv35924V3

Timing diagram and register format for Channel/user data format. Signals include SPDIFRX_IN, SPDIFRXEN (0b01 or 0b11), SYNCD, spdifrx_dat_dma, spdifrx_ctrl_dma. Frames depicted: Frame 191, Frame 0, Frame 7, Frame 8, Frame 15, Frame 16. Events marked: Synchronization done, Acquisition of C and U bits started !!!, Start of a new block, Transfer of first SPDIFRX_CB word with SOB = 1, Transfer of second SPDIFRX_CB word with SOB = 0. Below is the bit map of SPDIFRX_CSR format with bits 31-25 reserved, 24 SOB, 23-16 CS[7:0], 15-0 USR[15:0].

Note: Once the first start of block is detected (B preamble), the SPDIFRX is checking the preamble type every 8 frames.

Note: Overrun error on SPDIFRX_FMTx_DR register does not affect this path.

52.3.9 Reception errors

Frame structure and synchronization error

The SPDIFRX, detects errors, when one of the following condition occurs:

When one of those flags goes to 1, the traffic on selected SPDIFRX_IN is then ignored, an interrupt is generated if the IFEIE bit of the SPDIFRX_CR register is set.

The normal procedure when one of those errors occur is:

Refer to Figure 661 for additional information.

Parity error

For each sub-frame, an even number of zeros and ones is expected inside the 28 information bits. If not, the parity error bit PERR is set in the SPDIFRX_SR register and an interrupt is generated if the parity interrupt enable PERRIE bit is set in the SPDIFRX_CR register. The reception of the incoming data is not paused, and the SPDIFRX continue to deliver data to SPDIFRX_FMTx_DR even if the interrupt is still pending.

The interrupt is acknowledged by clearing the PERR flag through PERRCF bit.

If the software wants to guarantee the coherency between the data read in the SPDIFRX_FMTx_DR register and the value of the bit PERR, the bit PMSK must be set to 0.

Overrun error

If both SPDIFRX_FMTx_DR and RX_BUF are full, while the SPDIFRX_DC needs to write a new sample in RX_BUF, this new sample is dropped, and an overrun condition is triggered. The overrun error flag OVR is set in the SPDIFRX_SR register and an interrupt is generated if the OVRIE bit of the SPDIFRX_CR register is set.

If the RXSTEO bit is set to 0, then as soon as the RX_BUF is empty, the SPDIFRX stores the next incoming data, even if the OVR flag is still pending. The main purpose is to reduce as much as possible the amount of lost samples. Note that the behavior is similar independently of DRFMT value. See Figure 664.

Figure 664. S/PDIF overrun error when RXSTEO = 0

Timing diagram for SPDIF overrun error when RXSTEO = 0. It shows two scenarios: DRFMT = 0b0x and DRFMT = 0b10. The top scenario (DRFMT = 0b0x) shows an overrun when Ch B2 cannot be written to the RX_BUF because it is full. The bottom scenario (DRFMT = 0b10) shows an overrun when D6 is available and the RX_BUF is full. Both scenarios include signals for SPDIFRX_IN, RX_BUF FULL, RX_BUF and SPDIFRX_FMTx_DR content, SPDIFRX_DMA_REQ, Samples stored into memory, and SPDIFRX_IRQ (OVR).

DRFMT = 0b0x

Ch B2 cannot be written into the RX_BUF because it is FULL → Overrun !

Ch A3 can be written into the RX_BUF

SPDIFRX_IN: M Ch A1 W Ch B1 B Ch A2 W Ch B2 M Ch A3 W Ch B3 M Ch A4 W Ch B4 B Ch A5 W Ch B5

RX_BUF FULL: High during Ch B2, Ch A3, Ch B3, Ch A4, Ch B4, Ch A5

RX_BUF and SPDIFRX_FMTx_DR content: Ch B0, Ch A1, Ch B1, Ch A2, Ch B1, Ch A3, Ch B3, Ch A4, Ch B4, Ch A5

SPDIFRX_DMA_REQ: Pulses for each channel

Samples stored into memory: Ch B0, Ch A1, Ch B1, Ch A2, Ch B1, Ch A3, Ch B3, Ch A4, Ch B4, Ch A5

SPDIFRX_IRQ (OVR): High during overrun, acknowledged by SW

DRFMT = 0b10

RX_BUF cannot be emptied because SPDIF_RX is FULL

D6 is available and RX_BUF is FULL → Overrun !

IEC60958 block format: Frame 191, Frame 0, Frame 1, Frame 2, Frame 3, Frame 4

RX_BUF FULL: High during Frame 2, Frame 3, Frame 4

RXNE: Pulses at frame boundaries

spdifrx_dat_dma: Pulses at frame boundaries

spdifrx_it: High during overrun, acknowledged by SW

Data read from SPDIFRX_FMTx_DR: D0, D1, D2, D3, D4, D5, D7, D8, D9, D10

SPDIFRX_FMTx_DR: 31 16-15 0, D0 D1, D2 D3, D4 D5, D7 D8, D9 D10

D6 is lost, SPDIFRX[31:16] contains the oldest data

MSv35929V4

Timing diagram for SPDIF overrun error when RXSTEO = 0. It shows two scenarios: DRFMT = 0b0x and DRFMT = 0b10. The top scenario (DRFMT = 0b0x) shows an overrun when Ch B2 cannot be written to the RX_BUF because it is full. The bottom scenario (DRFMT = 0b10) shows an overrun when D6 is available and the RX_BUF is full. Both scenarios include signals for SPDIFRX_IN, RX_BUF FULL, RX_BUF and SPDIFRX_FMTx_DR content, SPDIFRX_DMA_REQ, Samples stored into memory, and SPDIFRX_IRQ (OVR).

If the RXSTEO bit is set to 1, it means that stereo data are transported, then the SPDIFRX has to avoid misalignment between left and right channels. So the peripheral has to drop a second sample even if there is room inside the RX_BUF in order to avoid misalignment. Then the incoming samples can be written normally into the RX_BUF even if the OVR flag is still pending. Refer to Figure 665.

The OVR flag is cleared by software, by setting the OVRCF bit to 1.

Figure 665. S/PDIF overrun error when RXSTEO = 1 Timing diagram for SPDIFRX overrun error when RXSTEO = 1. The diagram shows the sequence of symbols (M, W, B) and channels (Ch A1 to Ch B5) on the SPDIFRX_IN line. It tracks the RX_BUF FULL status, the data written to the RX_BUF and SPDIFRX_FMTx_DR, the dma transfer, and the samples stored into memory. An overrun occurs when Ch B2 cannot be written because the buffer is full. Another note indicates Ch A3 cannot be written even if the buffer is not full to avoid misalignments. The spdifrx_it interrupt is shown, and a box indicates it is 'Acknowledged by SW'. The diagram is labeled MSv47488V1.
Timing diagram for SPDIFRX overrun error when RXSTEO = 1. The diagram shows the sequence of symbols (M, W, B) and channels (Ch A1 to Ch B5) on the SPDIFRX_IN line. It tracks the RX_BUF FULL status, the data written to the RX_BUF and SPDIFRX_FMTx_DR, the dma transfer, and the samples stored into memory. An overrun occurs when Ch B2 cannot be written because the buffer is full. Another note indicates Ch A3 cannot be written even if the buffer is not full to avoid misalignments. The spdifrx_it interrupt is shown, and a box indicates it is 'Acknowledged by SW'. The diagram is labeled MSv47488V1.

52.3.10 Clocking strategy

The SPDIFRX block needs two different clocks:

In order to decode properly the incoming S/PDIF stream the SPDIFRX_DC must re-sample the received data with a clock at least 11 times higher than the maximum symbol rate, or 704 times higher than the audio sample rate. For example if the user expects to receive a symbol rate to up to 12.288 MHz, the sample rate must be at least 135.2 MHz. The clock used by the SPDIFRX_DC is the spdifrx_ker_ck.

The frequency of the spdifrx_pclk must be at least equal to the symbol rate.

Table 477. Minimum spdifrx_ker_ck frequency versus audio sampling rate(1)

Symbol rateMinimum spdifrx_ker_ck frequencyComments
3.072 MHz33.8 MHzFor 48 kHz stream
6.144 MHz67.6 MHzFor 96 kHz stream
12.288 MHz135.2 MHzFor 192 kHz stream

1. Check the RCC capabilities in order to verify which sampling rates can be supported.

52.3.11 Symbol clock generation

The SPDIFRX block provides a symbol clock on signal named spdifrx_symb_ck, which can be used as the reference kernel clock for another audio device such as SAI or SPI/I2S. It can be used for SPDIFRX to I2S bridge function.

The symbol clock is built using the values of WIDTH24, WIDTH40 and the symbol boundaries.

The duty cycle of the symbol clock is close to 50% during the reception of the sub-frame payload. However, the duty cycle can be altered when the SPDIFRX transitions from a symbol clock generated with WIDTH24 and WIDTH40 to a clock generated by the symbol clock boundaries or vice-versa.

The symbol clock has an important jitter mainly due to:

For that reason the application must consider the quality degradation if the symbol clock is used as the reference clock for A/D or D/A converters.

The generation of this symbol clock is controlled by the CKSEN bit. When CKSEN = '1', the clock symbol is generated when the SPDIFRX completes successfully the first fine synchronization (SYNCD = 1), and when it receives correct data from the selected SPDIFRX input.

When the SPDIFRX goes to STATE_STOP, or STATE_IDLE, the symbol clock is gated if the bit CKSBKPEN = '0'. If the CKSBKPEN = '1', then a backup symbol clock is still generated if the SPDIFRX is properly synchronized (i.e. valid values available for WIDTH24 and WIDTH40). Table 478 gives more details on the conditions controlling the generation of the symbol clock.

Table 478. Conditions of spdifrx_symb_ck generation

SPDIFRX states and conditionsCKSENCKSBKPENspdifrx_symb_ck state
Any state0XDisabled
– SPDIFRX in STATE_SYNC and completing successfully the fine synchronization (SYNCD = '1') or,
– SPDIFRX in STATE_RCV, and valid data are received via the selected SPDIFRX input.
10Enabled
– SPDIFRX in STATE_IDLE or,
– SPDIFRX in STATE_STOP or,
– SPDIFRX did not complete the fine synchronization (on-going)
– SPDIFRX is in STATE_RCV, but no data (transitions) detected on the selected SPDIFRX input.
0Disabled

Table 478. Conditions of spdifrx_symb_ck generation (continued)

SPDIFRX states and conditionsCKSENCKSBKPENspdifrx_symb_ck state
  • – SPDIFRX in STATE_IDLE, but with valid values for WIDTH40 and WIDTH24 or
  • – SPDIFRX in STATE_SYNC and completing successfully the fine synchronization (SYNCD = '1') or,
  • – SPDIFRX in STATE_SYNC the on-going fine synchronization is not completed, but WIDTH40 and WIDTH24 contain the valid values from the previous synchronization or,
  • – SPDIFRX in STATE_RCV, and valid data are received via the selected SPDIFRX input or,
  • – SPDIFRX in STATE_STOP, but with valid values for WIDTH40 and WIDTH24.
11Enabled
  • – SPDIFRX in IDLE, with invalid values for WIDTH40 and WIDTH24 or,
  • – SPDIFRX in STOP with invalid values for WIDTH40 and WIDTH24 (SERR = '1') or,
  • – SPDIFRX in STATE_SYNC with invalid values for WIDTH40 and WIDTH24, and did not completed the on-going fine synchronization or,
  • – SPDIFRX in STATE_RCV and no transitions detected on the selected SPDIFRX input
Disabled

Note that when the flag SERR is set to '1', neither the symbol clock nor the backup clock can be generated, since there is no synchronization.

Note that when both CKSEN and CKSBKPEN are set to '1', the symbol clock looses some transitions when the SPDIFRX switches from STATE_SYNC or STATE_RCV to STATE_STOP, or STATE_IDLE.

The bits CKSEN and CKSBKPEN are located into SPDIFRX control register (SPDIFRX_CR).

52.3.12 DMA interface

The SPDIFRX interface is able to perform communication using the DMA.

Note: The user must refer to product specifications for availability of the DMA controller.

The SPDIFRX offers two independent DMA channels:

The DMA mode for the data can be enabled for reception by setting the RXDMAEN bit in the SPDIFRX_CR register. In this case, as soon as the SPDIFRX_FMTx_DR is not empty, the SPDIFRX interface sends a transfer request to the DMA. The DMA reads the data received through the SPDIFRX_FMTx_DR register without CPU intervention.

For the use of DMA for the control data refer to Section 52.3.8.

52.3.13 Interrupt generation

An interrupt line is shared between:

Figure 666. SPDIFRX interface interrupt mapping diagram

Figure 666: SPDIFRX interface interrupt mapping diagram. The diagram shows the logic for generating the spdifrx_it interrupt. Inputs include SYNCD, SYNCDIE, RXNE, RXNEIE, PERR, PERRIE, OVR, OVRIE, CSRNE, CSRNEIE, SBD, SBDIE, SERR, FERR, TERR, and IFEIE. SYNCD and SYNCDIE are inputs to an AND gate. RXNE and RXNEIE are inputs to an AND gate. PERR and PERRIE are inputs to an AND gate. OVR and OVRIE are inputs to an AND gate. CSRNE and CSRNEIE are inputs to an AND gate. SBD and SBDIE are inputs to an AND gate. SERR, FERR, and TERR are inputs to an OR gate, whose output is then fed into an AND gate along with IFEIE. The outputs of all six AND gates are then fed into a large OR gate, which produces the final spdifrx_it interrupt signal.

MSv35928V3

Figure 666: SPDIFRX interface interrupt mapping diagram. The diagram shows the logic for generating the spdifrx_it interrupt. Inputs include SYNCD, SYNCDIE, RXNE, RXNEIE, PERR, PERRIE, OVR, OVRIE, CSRNE, CSRNEIE, SBD, SBDIE, SERR, FERR, TERR, and IFEIE. SYNCD and SYNCDIE are inputs to an AND gate. RXNE and RXNEIE are inputs to an AND gate. PERR and PERRIE are inputs to an AND gate. OVR and OVRIE are inputs to an AND gate. CSRNE and CSRNEIE are inputs to an AND gate. SBD and SBDIE are inputs to an AND gate. SERR, FERR, and TERR are inputs to an OR gate, whose output is then fed into an AND gate along with IFEIE. The outputs of all six AND gates are then fed into a large OR gate, which produces the final spdifrx_it interrupt signal.

Clearing interrupt source

Note: The SBD event can only occur when the SPDIFRX is synchronized to the input stream (SYNCD = 1).
The SBD flag behavior is not guaranteed when the sub-frame which contains the B preamble is lost due to an overrun.

52.3.14 Register protection

The SPDIFRX block embeds some hardware protection avoid erroneous use of control registers. The table hereafter shows the bit field properties according to the SPDIFRX state.

Table 479. Bit field property versus SPDIFRX state

RegistersFieldSPDIFRXEN
00
(STATE_IDLE)
01
(STATE_SYNC)
11
(STATE_RCV)
SPDIFRX_CRINSELrwrr
WFArwrr
NBTRrwrr
CHSELrwrr
CBDMAENrwrwrw
PTMSKrwrwrw
CUMSKrwrwrw
VMSKrwrwrw
PMSKrwrwrw
DRFMTrwrwr
RXSTEOrwrwr
RXDMAENrwrwrw
SPDIFRX_IMRAll fieldsrwrwrw

The table clearly shows that fields such as INSEL must be programmed when the SPDIFRX is in STATE_IDLE. In the others SPDIFRX states, the hardware prevents writing to this field.

Note: Even if the hardware allows the writing of CBDMAEN and RXDMAEN “on-the-fly”, it is not recommended to enable the DMA when the SPDIFRX already receives data.

Each of the mask bits (such as PMSK, VMSK) can be changed “on-the-fly” at any SPDIFRX state, but any change does not affect data which are already hold in SPDIFRX_FMTx_DR.

52.4 Programming procedures

The following example illustrates a complete activation sequence of the SPDIFRX block. The data path and channel status and user information both use a dedicated DMA channel. The activation sequence is then split into the following steps:

A simple way to check if valid data are available into the SPDIFRX_IN line is to switch the SPDIFRX into the STATE_SYNC, with bit WFA set to 1. The description hereafter focuses on detection. It is also possible to implement this function as follows:

For those two implementations, the bit WFA is set to 0.

52.4.1 Initialization phase

Then the CPU receives interrupts coming either from DMA or SPDIFRX.

52.4.2 Handling of interrupts coming from SPDIFRX

When an interrupt from the SPDIFRX is received, then the software has to check what is the source of the interrupt by reading the SPDIFRX_SR register.

52.4.3 Handling of interrupts coming from DMA

If an interrupt comes from the DMA channel used of the channel status (SPDIFRX_CSR):

If no error occurred (that is PERR), the CPU can start the decoding of channel information. For example bit 1 of the channel status informs the user if the current stream is linear or not. This information is very important in order to set-up the proper processing chain. In the same way, bits 24 to 27 of the channel status give the sampling frequency of the stream incoming stream.

Thanks to that information, the user can then configure the RXSTEO bit and DRFMT field prior to start the data reception. For example if the current stream is non linear PCM then RXSTEO is set to 0, and DRFMT is set to 10. Then the user can enable the data reception by setting SPDIFRXEN to 11.

The SOB bit, when set to 1 indicates the start of a new block. This information helps the software to identify the bit 0 of the channel status. Note that if the DMA generates an interrupt every time 24 values are transferred into the memory, then the first word always corresponds to the start of a new block.

If an interrupt comes from the DMA channel used of the audio samples (SPDIFRX_FMTx_DR):

The process performed here depends of the data type (linear or non-linear), and on the data format selected.

For example in linear mode, if PE or V bit is set a special processing can be performed locally in order to avoid spurs on output. In non-linear mode those bits are not important as data frame have their own checksum.

52.5 SPDIFRX interface registers

52.5.1 SPDIFRX control register (SPDIFRX_CR)

Only 32-bit accesses are allowed in this register.

Address offset: 0x00

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.CKS
BKP
EN
CKSENRes.INSEL[2:0]
rwrwrwrwrw
1514131211109876543210
Res.WFANBTR[1:0]CHSELCBDMAENPTMSKCUMSKVMSKPMSKDRFMT[1:0]RXSTEORXDMAENSPDIFRXEN[1:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:22 Reserved, must be kept at reset value.

Bit 21 CKSBKPEN: Backup symbol clock enable

This bit is set/reset by software.

1: The SPDIFRX generates a backup symbol clock if CKSEN = 1.

0: The SPDIFRX does not generate a backup symbol clock.

Bit 20 CKSEN: Symbol clock enable

This bit is set/reset by software.

1: The SPDIFRX generates a symbol clock.

0: The SPDIFRX does not generate a symbol clock.

Bit 19 Reserved, must be kept at reset value.

Bits 18:16 INSEL[2:0]: SPDIFRX input selection(1)

000: SPDIFRX_IN0 selected

001: SPDIFRX_IN1 selected

010: SPDIFRX_IN2 selected

011: SPDIFRX_IN3 selected

other: reserved

Bit 15 Reserved, must be kept at reset value.

Bit 14 WFA: Wait for activity(1)

This bit is set/reset by software.

1: The SPDIFRX waits for activity on SPDIFRX_IN line (4 transitions) before performing the synchronization.

0: The SPDIFRX does not wait for activity on SPDIFRX_IN line before performing the synchronization.

Bits 13:12 NBTR[1:0]: Maximum allowed re-tries during synchronization phase(1)

Bit 11 CHSEL: Channel selection(1)

Bit 10 CBDMAEN: Control buffer DMA enable for control flow(1)

Note: When this bit is set, the DMA request is made whenever the CSRNE flag is set.

Bit 9 PTMSK: Mask of preamble type bits(1)

Bit 8 CUMSK: Mask of channel status and user bits(1)

Bit 7 VMSK: Mask of validity bit(1)

Bit 6 PMSK: Mask parity error bit(1)

Bits 5:4 DRFMT[1:0]: RX data format(1)

Bit 3 RXSTEO: Stereo mode(1)

This bit is set/reset by software.

1: The peripheral is in stereo mode.

0: The peripheral is in mono mode.

Note: This bit is used in case of overrun situation in order to handle misalignment.

Bit 2 RXDMAEN: Receiver DMA enable for data flow(1)

This bit is set/reset by software.

1: DMA mode is enabled for reception.

0: DMA mode is disabled for reception.

Note: When this bit is set, the DMA request is made whenever the RXNE flag is set.

Bits 1:0 SPDIFRXEN[1:0]: Peripheral block enable(1)

This field is modified by software.

It must be used to change the peripheral phase among the three possible states: STATE_IDLE, STATE_SYNC and STATE_RCV.

00: Disable SPDIFRX (STATE_IDLE).

01: Enable SPDIFRX synchronization only.

10: Reserved

11: Enable SPDIF receiver.

Note: It is not possible to transition from STATE_RCV to STATE_SYNC, the user must first go the STATE_IDLE. it is possible to transition from STATE_IDLE to STATE_RCV: in that case the peripheral transitions from STATE_IDLE to STATE_SYNC and as soon as the synchronization is performed goes to STATE_RCV. 1. Refer to Section 52.3.14: Register protection for additional information on fields properties.

52.5.2 SPDIFRX interrupt mask register (SPDIFRX_IMR)

Address offset: 0x04

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.IFE
IE
SYNCD
IE
SBLK
IE
OVR
IE
PERR
IE
CSRNE
IE
RXNE
IE
rwrwrwrwrwrwrw

Bits 31:7 Reserved, must be kept at reset value.

Bit 6 IFEIE: Serial interface error interrupt enable

This bit is set and cleared by software.

0: Interrupt is inhibited.

1: A SPDIFRX interface interrupt is generated whenever SERR = 1, TERR = 1, or FERR = 1 in the SPDIFRX_SR register.

Bit 5 SYNCDIE: Synchronization done

This bit is set and cleared by software.

0: Interrupt is inhibited.

1: A SPDIFRX interface interrupt is generated whenever SYNCD = 1 in the SPDIFRX_SR register.

52.5.3 SPDIFRX status register (SPDIFRX_SR)

Address offset: 0x08

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.WIDTH5[14:0]
rrrrrrrrrrrrrrr
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.TERRSERRFERRSYNCDSBDOVRPERRCSRNERXNE
rrrrrrrrr

Bit 31 Reserved, must be kept at reset value.

Bits 30:16 WIDTH5[14:0]: duration of 5 symbols counted with spdifrx_ker_ck

This value represents the amount of spdifrx_ker_ck clock periods contained on a length of 5 consecutive symbols. This value can be used to estimate the S/PDIF symbol rate. Its accuracy is limited by the frequency of spdifrx_ker_ck.

For example if the spdifrx_ker_ck is fixed to 84 MHz, and WIDTH5 = 147d. The estimated sampling rate of the S/PDIF stream is:

\(F_s = 5 \times F_{\text{spdifrx\_ker\_ck}} / (\text{WIDTH5} \times 64) \sim 44.6 \text{ kHz}\), so the closest standard sampling rate is 44.1 kHz.

Note that WIDTH5 is updated by the hardware when SYNCD goes high, and then every frame.

Bits 15:9 Reserved, must be kept at reset value.

Bit 8 TERR: Time-out error

This bit is set by hardware when the counter TRCNT reaches its max value. It indicates that the time interval between two transitions is too long. It generally indicates that there is no valid signal on SPDIFRX_IN input.

This flag is cleared by writing SPDIFRXEN to 0.

An interrupt is generated if IFEIE=1 in the SPDIFRX_IMR register.

0: No sequence error is detected.

1: Sequence error is detected.

Bit 7 SERR: Synchronization error

This bit is set by hardware when the synchronization fails due to amount of re-tries for NBTR.

This flag is cleared by writing SPDIFRXEN to 0.

An interrupt is generated if IFEIE = 1 in the SPDIFRX_IMR register.

0: No synchronization error is detected.

1: Synchronization error is detected.

Bit 6 FERR: Framing error

This bit is set by hardware when an error occurs during data reception: such as preamble not at the expected place, short transition not grouped by pairs.

This is set by the hardware only if the synchronization is completed (SYNCD = 1).

This flag is cleared by writing SPDIFRXEN to 0.

An interrupt is generated if IFEIE=1 in the SPDIFRX_IMR register.

0: No Manchester violation detected

1: Manchester violation detected

Bit 5 SYNCD: Synchronization done

This bit is set by hardware when the initial synchronization phase is properly completed.

This flag is cleared by writing a 1 to its corresponding bit on SPDIFRX_IFCR register.

An interrupt is generated if SYNCDIE = 1 in the SPDIFRX_IMR register.

0: Synchronization is pending.

1: Synchronization is completed.

Bit 4 SBD: Synchronization block detected

This bit is set by hardware when a “B” preamble is detected.

This flag is cleared by writing a 1 to its corresponding bit on SPDIFRX_IFCR register.

An interrupt is generated if SBLKIE = 1 in the SPDIFRX_IMR register.

0: No “B” preamble is detected.

1: “B” preamble is detected.

Bit 3 OVR: Overrun error

This bit is set by hardware when a received data is ready to be transferred in the SPDIFRX_FMTx_DR register while RXNE = 1 and both SPDIFRX_FMTx_DR and RX_BUF are full.

This flag is cleared by writing a 1 to its corresponding bit on SPDIFRX_IFCR register.

An interrupt is generated if OVRIE=1 in the SPDIFRX_IMR register.

0: No overrun error

1: Overrun error is detected.

Note: When this bit is set, the SPDIFRX_FMTx_DR register content is not lost but the last data received are.

Bit 2 PERR: Parity error

This bit is set by hardware when the data and status bits of the sub-frame received contain an odd number of 0 and 1.

This flag is cleared by writing a 1 to its corresponding bit on SPDIFRX_IFCR register.

An interrupt is generated if PIE = 1 in the SPDIFRX_IMR register.

0: No parity error

1: Parity error

Bit 1 CSRNE: Control buffer register not empty

This bit is set by hardware when a valid control information is ready.

This flag is cleared when reading SPDIFRX_CSR register.

An interrupt is generated if CBRDYIE = 1 in the SPDIFRX_IMR register.

0: No control word available on SPDIFRX_CSR register

1: A control word is available on SPDIFRX_CSR register.

Bit 0 RXNE: Read data register not empty

This bit is set by hardware when a valid data is available into SPDIFRX_FMTx_DR register.

This flag is cleared by reading the SPDIFRX_FMTx_DR register.

An interrupt is generated if RXNEIE=1 in the SPDIFRX_IMR register.

0: Data is not received.

1: Received data is ready to be read.

52.5.4 SPDIFRX interrupt flag clear register (SPDIFRX_IFCR)

Address offset: 0x0C

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.SYNCD
CF
SBD
CF
OVR
CF
PERR
CF
Res.Res.
wwww

Bits 31:6 Reserved, must be kept at reset value.

Bit 5 SYNDCDF: clears the synchronization done flag

Writing 1 in this bit clears the flag SYNCD in the SPDIFRX_SR register.

Reading this bit always returns the value 0.

Bit 4 SBDCF: clears the synchronization block detected flag

Writing 1 in this bit clears the flag SBD in the SPDIFRX_SR register.

Reading this bit always returns the value 0.

Bit 3 OVRCF: clears the overrun error flag

Writing 1 in this bit clears the flag OVR in the SPDIFRX_SR register.

Reading this bit always returns the value 0.

Bit 2 PERRCF: clears the parity error flag

Writing 1 in this bit clears the flag PERR in the SPDIFRX_SR register.

Reading this bit always returns the value 0.

Bits 1:0 Reserved, must be kept at reset value.

52.5.5 SPDIFRX data input register (SPDIFRX_FMT0_DR)

Address offset: 0x10

Reset value: 0x0000 0000

This register can take three different formats according to DRFMT. Here is the format when DRFMT = 00:

31302928272625242322212019181716
Res.Res.PT[1:0]CUVPEDR[23:16]
rrrrrrrrrrrrrr
1514131211109876543210
DR[15:0]
rrrrrrrrrrrrrrrr

Bits 31:30 Reserved, must be kept at reset value.

Bits 29:28 PT[1:0]: preamble type

These bits indicate the preamble received.

00: not used

01: Preamble B received

10: Preamble M received

11: Preamble W received

Note that if PTMSK = 1, this field is forced to zero

Bit 27 C: channel status bit

Contains the received channel status bit, if CUMSK = 0, otherwise it is forced to 0

Bit 26 U: user bit

Contains the received user bit, if CUMSK = 0, otherwise it is forced to 0

Bit 25 V: validity bit

Contains the received validity bit if VMSK = 0, otherwise it is forced to 0

Bit 24 PE: parity error bit

Contains a copy of PERR bit if PMSK = 0, otherwise it is forced to 0

Bits 23:0 DR[23:0]: data value

Contains the 24 received data bits, aligned on D[23]

52.5.6 SPDIFRX data input register (SPDIFRX_FMT1_DR)

Address offset: 0x10

Reset value: 0x0000 0000

This register can take three different formats according to DRFMT. Here is the format when DRFMT = 01:

31302928272625242322212019181716
DR[23:8]
rrrrrrrrrrrrrrrr
1514131211109876543210
DR[7:0]Res.Res.PT[1:0]CUVPE
rrrrrrrrrrrrrr

Bits 31:8 DR[23:0]: data value

Contains the 24 received data bits, aligned on D[23]

Bits 7:6 Reserved, must be kept at reset value.

Bits 5:4 PT[1:0]: preamble type

These bits indicate the preamble received.

00: not used

01: preamble B received

10: preamble M received

11: preamble W received

Note that if PTMSK = 1, this field is forced to zero

Bit 3 C: channel Status bit

Contains the received channel status bit, if CUMSK = 0, otherwise it is forced to 0

Bit 2 U: user bit

Contains the received user bit, if CUMSK = 0, otherwise it is forced to 0

Bit 1 V: validity bit

Contains the received validity bit if VMSK = 0, otherwise it is forced to 0

Bit 0 PE: parity error bit

Contains a copy of PERR bit if PMSK = 0, otherwise it is forced to 0

52.5.7 SPDIFRX data input register (SPDIFRX_FMT2_DR)

Address offset: 0x10

Reset value: 0x0000 0000

This register can take 3 different formats according to DRFMT.

The data format proposed when DRFMT = 10, is dedicated to non-linear mode, as only 16 bits are used (bits 23 to 8 from S/PDIF sub-frame).

31302928272625242322212019181716
DRNL2[15:0]
rrrrrrrrrrrrrrrr
1514131211109876543210
DRNL1[15:0]
rrrrrrrrrrrrrrrr

Bits 31:16 DRNL2[15:0]: data value

This field contains the channel A

Bits 15:0 DRNL1[15:0]: data value

This field contains the channel B

52.5.8 SPDIFRX channel status register (SPDIFRX_CSR)

Address offset: 0x14

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.SOBCS[7:0]
rrrrrrrrr
1514131211109876543210
USR[15:0]
rrrrrrrrrrrrrrrr

Bits 31:25 Reserved, must be kept at reset value.

Bit 24 SOB: start of block

This bit indicates if the bit CS[0] corresponds to the first bit of a new block

0: CS[0] is not the first bit of a new block

1: CS[0] is the first bit of a new block

Bits 23:16 CS[7:0]: channel A status information

Bit CS[0] is the oldest value

Bits 15:0 USR[15:0]: user data information

Bit USR[0] is the oldest value, and comes from channel A, USR[1] comes channel B.

So USR[n] bits come from channel A if n is even, otherwise they come from channel B.

52.5.9 SPDIFRX debug information register (SPDIFRX_DIR)

Address offset: 0x18

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.TLO[12:0]
rrrrrrrrrrrrr
1514131211109876543210
Res.Res.Res.THI[12:0]
rrrrrrrrrrrrr

Bits 31:29 Reserved, must be kept at reset value.

Bits 28:16 TLO[12:0]: threshold LOW (\(TLO = 1.5 \times UI / T_{\text{spdifrx\_ker\_ck}}\))

This field contains the current threshold LOW estimation. This value can be used to estimate the sampling rate of the received stream. The accuracy of TLO is limited to a period of the spdifrx_ker_ck. The sampling rate can be estimated as follow:

Sampling Rate = \([2 \times TLO \times T_{\text{spdifrx\_ker\_ck}} \pm T_{\text{spdifrx\_ker\_ck}}] \times 2/3\)

Note that TLO is updated by the hardware when SYNCD goes high, and then every frame.

Bits 15:13 Reserved, must be kept at reset value.

Bits 12:0 THI[12:0]: threshold HIGH (\(\text{THI} = 2.5 \times \text{UI} / T_{\text{spdifrx\_ker\_ck}}\))

This field contains the current threshold HIGH estimation. This value can be used to estimate the sampling rate of the received stream. The accuracy of THI is limited to a period of the spdifrx_ker_ck. The sampling rate can be estimated as follow:

Sampling Rate = \([2 \times \text{THI} \times T_{\text{spdifrx\_ker\_ck}} \pm T_{\text{spdifrx\_ker\_ck}}] \times 2/5\)

Note that THI is updated by the hardware when SYNCD goes high, and then every frame.

52.5.10 SPDIFRX version register (SPDIFRX_VERR)

Address offset: 0x3F4

Reset value: 0x0000 0012

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.MAJREV[3:0]MINREV[3:0]
rrrrrrrr

Bits 31:8 Reserved, must be kept at reset value.

Bits 7:4 MAJREV[3:0]: SPDIFRX major revision

Major revision is 1.

Bits 3:0 MINREV[3:0]: SPDIFRX minor revision

Minor revision is 2.

52.5.11 SPDIFRX identification register (SPDIFRX_IPIDR)

Address offset: 0x3F8

Reset value: 0x0013 0041

31302928272625242322212019181716
ID[31:16]
rrrrrrrrrrrrrrrr
1514131211109876543210
ID[15:0]
rrrrrrrrrrrrrrrr

Bits 31:0 ID[31:0]: SPDIFRX identifier

52.5.12 SPDIFRX size identification register (SPDIFRX_SIDR)

Address offset: 0x3FC

Reset value: 0xA3C5 DD01

31302928272625242322212019181716
SID[31:16]
rrrrrrrrrrrrrrrr
1514131211109876543210
SID[15:0]
rrrrrrrrrrrrrrrr

Bits 31:0 SID[31:0]: Size identification

These bits return the size of the memory region allocated to SPDIFRX registers.
The size of this memory region is of 1 Kbyte.

52.5.13 SPDIFRX interface register map

Table 480. SPDIFRX interface register map and reset values

OffsetRegister name313029282726252423222120191817161514131211109876543210
0x00SPDIFRX_CRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.CKSBKPENCKSENRes.INSEL[2:0]Res.WFANBTR[1:0]CHSELCBDMAENPTMSKCUMSKVMSKPMSKDRFMT[1:0]RXSTEORXDMAENSPDIFRXEN[1:0]
Reset value00000000000000000000
0x04SPDIFRX_IMRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.IFEIESYNCDIESBLKIEOVRIEPERRIECSRNEIERXNEIE
Reset value0000000
0x08SPDIFRX_SRRes.WIDTH5[14:0]Res.Res.Res.Res.Res.Res.Res.Res.TERRSERRFERRSYNCDSBDOVRPERRCSRNERXNE
Reset value00000000000000000000000
0x0CSPDIFRX_IFCRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.SYNCDCFSBD CFOVR CFPERR CFRes.Res.
Reset value0000
0x10SPDIFRX_FMT0_DRRes.Res.PT[1:0]CUVP
E
DR[23:0]
Reset value00000000000000000000000000000000
0x10SPDIFRX_FMT1_DRDR[23:0]Res.PT[1:0]CUVP
E
Reset value00000000000000000000000000000000
0x10SPDIFRX_FMT2_DRDRNL2[15:0]DRNL1[15:0]
Reset value00000000000000000000000000000000
ST logo
ST logo

Table 480. SPDIFRX interface register map and reset values (continued)

OffsetRegister name313029282726252423222120191817161514131211109876543210
0x14SPDIFRX_CSRResResResResResResResSOBCS[7:0]USR[15:0]
Reset value000000000000000000000000
0x18SPDIFRX_DIRResResResTLO[12:0]ResResResTHI[12:0]
Reset value0000000000000000000000000
0x3F4SPDIFRX_VERRResResResResResResResResResResResResResResResResResResResResResResResMAJREV [3:0]MINREV [3:0]
Reset value00010010
0x3F8SPDIFRX_IPI DRID[31:0]
Reset value0000000000010011000000000100001
0x3FCSPDIFRX_SID RSID[31:0]
Reset value1010001111000101110111010000001
Refer to Section 2.5: Memory organization for the register boundary addresses.