Skip to content

Commit 49ff7e3

Browse files
Raymond0225mmahadevan108
authored andcommitted
drivers: sai: the 1st frame synchronization signal lost in slave side
According the RM document, RT1170 58.3.3 (should be same for other MCU which has a similiar SAI IP): "A valid frame sync is also ignored (slave mode) or not generated (master mode) for the first four bit clock cycles after enabling the transmitter or receiver." but in fact, we found master side send out a valid frame sync at the 3rd bit clock cycles which cause this frame sync is ignored by the slave side and frame data lost. To workaround this issue, bit clock is enabled before TE/RE. Signed-off-by: Raymond Lei <[email protected]>
1 parent 533f3cb commit 49ff7e3

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

mcux/mcux-sdk/drivers/sai/fsl_sai.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,8 +509,15 @@ void SAI_TxEnable(I2S_Type *base, bool enable)
509509
/* If clock is sync with Rx, should enable RE bit. */
510510
if (((base->TCR2 & I2S_TCR2_SYNC_MASK) >> I2S_TCR2_SYNC_SHIFT) == 0x1U)
511511
{
512+
base->RCSR = ((base->RCSR & 0xFFE3FFFFU) | I2S_RCSR_BCE_MASK);
512513
base->RCSR = ((base->RCSR & 0xFFE3FFFFU) | I2S_RCSR_RE_MASK);
513514
}
515+
/* Sometimes, bit clock starts just 3 clocks before frame synchronization
516+
* signal, which cause the 1st frame sync is ignored by the RX side as
517+
* described in RT1170 RM 58.3.3. To make bit clock at least 4 clocks earlier,
518+
* here, we enable bit clock firstly.
519+
*/
520+
base->TCSR = ((base->TCSR & 0xFFE3FFFFU) | I2S_TCSR_BCE_MASK);
514521
base->TCSR = ((base->TCSR & 0xFFE3FFFFU) | I2S_TCSR_TE_MASK);
515522
/* Also need to clear the FIFO error flag before start */
516523
SAI_TxClearStatusFlags(base, kSAI_FIFOErrorFlag);
@@ -539,8 +546,15 @@ void SAI_RxEnable(I2S_Type *base, bool enable)
539546
/* If clock is sync with Tx, should enable TE bit. */
540547
if (((base->RCR2 & I2S_RCR2_SYNC_MASK) >> I2S_RCR2_SYNC_SHIFT) == 0x1U)
541548
{
549+
base->TCSR = ((base->TCSR & 0xFFE3FFFFU) | I2S_TCSR_BCE_MASK);
542550
base->TCSR = ((base->TCSR & 0xFFE3FFFFU) | I2S_TCSR_TE_MASK);
543551
}
552+
/* Sometimes, bit clock starts just 3 clocks before frame synchronization
553+
* signal, which cause the 1st frame sync is ignored by the RX side as
554+
* described in RT1170 RM 58.3.3. To make bit clock at least 4 clocks earlier,
555+
* here, we enable bit clock firstly.
556+
*/
557+
base->RCSR = ((base->RCSR & 0xFFE3FFFFU) | I2S_RCSR_BCE_MASK);
544558
base->RCSR = ((base->RCSR & 0xFFE3FFFFU) | I2S_RCSR_RE_MASK);
545559
/* Also need to clear the FIFO error flag before start */
546560
SAI_RxClearStatusFlags(base, kSAI_FIFOErrorFlag);
@@ -851,7 +865,8 @@ void SAI_TxSetBitclockConfig(I2S_Type *base, sai_master_slave_t masterSlave, sai
851865
}
852866
else
853867
{
854-
tcr2 &= ~(I2S_TCR2_BCD_MASK);
868+
/* Clear BCP bit before set it. */
869+
tcr2 &= ~(I2S_TCR2_BCD_MASK | I2S_TCR2_BCP_MASK);
855870
tcr2 |= I2S_TCR2_BCP(config->bclkPolarity);
856871
}
857872

@@ -879,7 +894,8 @@ void SAI_RxSetBitclockConfig(I2S_Type *base, sai_master_slave_t masterSlave, sai
879894
}
880895
else
881896
{
882-
rcr2 &= ~(I2S_RCR2_BCD_MASK);
897+
/* Clear BCP bit before set it. */
898+
rcr2 &= ~(I2S_RCR2_BCD_MASK | I2S_RCR2_BCP_MASK);
883899
rcr2 |= I2S_RCR2_BCP(config->bclkPolarity);
884900
}
885901

0 commit comments

Comments
 (0)