Skip to content

Commit cfb001b

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 40509f3 commit cfb001b

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,15 @@ void SAI_TxEnable(I2S_Type *base, bool enable)
500500
/* If clock is sync with Rx, should enable RE bit. */
501501
if (((base->TCR2 & I2S_TCR2_SYNC_MASK) >> I2S_TCR2_SYNC_SHIFT) == 0x1U)
502502
{
503+
base->RCSR = ((base->RCSR & 0xFFE3FFFFU) | I2S_RCSR_BCE_MASK);
503504
base->RCSR = ((base->RCSR & 0xFFE3FFFFU) | I2S_RCSR_RE_MASK);
504505
}
506+
/* Sometimes, bit clock starts just 3 clocks before frame synchronization
507+
* signal, which cause the 1st frame sync is ignored by the RX side as
508+
* described in RT1170 RM 58.3.3. To make bit clock at least 4 clocks earlier,
509+
* here, we enable bit clock firstly.
510+
*/
511+
base->TCSR = ((base->TCSR & 0xFFE3FFFFU) | I2S_TCSR_BCE_MASK);
505512
base->TCSR = ((base->TCSR & 0xFFE3FFFFU) | I2S_TCSR_TE_MASK);
506513
/* Also need to clear the FIFO error flag before start */
507514
SAI_TxClearStatusFlags(base, kSAI_FIFOErrorFlag);
@@ -530,8 +537,15 @@ void SAI_RxEnable(I2S_Type *base, bool enable)
530537
/* If clock is sync with Tx, should enable TE bit. */
531538
if (((base->RCR2 & I2S_RCR2_SYNC_MASK) >> I2S_RCR2_SYNC_SHIFT) == 0x1U)
532539
{
540+
base->TCSR = ((base->TCSR & 0xFFE3FFFFU) | I2S_TCSR_BCE_MASK);
533541
base->TCSR = ((base->TCSR & 0xFFE3FFFFU) | I2S_TCSR_TE_MASK);
534542
}
543+
/* Sometimes, bit clock starts just 3 clocks before frame synchronization
544+
* signal, which cause the 1st frame sync is ignored by the RX side as
545+
* described in RT1170 RM 58.3.3. To make bit clock at least 4 clocks earlier,
546+
* here, we enable bit clock firstly.
547+
*/
548+
base->RCSR = ((base->RCSR & 0xFFE3FFFFU) | I2S_RCSR_BCE_MASK);
535549
base->RCSR = ((base->RCSR & 0xFFE3FFFFU) | I2S_RCSR_RE_MASK);
536550
/* Also need to clear the FIFO error flag before start */
537551
SAI_RxClearStatusFlags(base, kSAI_FIFOErrorFlag);
@@ -842,7 +856,8 @@ void SAI_TxSetBitclockConfig(I2S_Type *base, sai_master_slave_t masterSlave, sai
842856
}
843857
else
844858
{
845-
tcr2 &= ~(I2S_TCR2_BCD_MASK);
859+
/* Clear BCP bit before set it. */
860+
tcr2 &= ~(I2S_TCR2_BCD_MASK | I2S_TCR2_BCP_MASK);
846861
tcr2 |= I2S_TCR2_BCP(config->bclkPolarity);
847862
}
848863

@@ -870,7 +885,8 @@ void SAI_RxSetBitclockConfig(I2S_Type *base, sai_master_slave_t masterSlave, sai
870885
}
871886
else
872887
{
873-
rcr2 &= ~(I2S_RCR2_BCD_MASK);
888+
/* Clear BCP bit before set it. */
889+
rcr2 &= ~(I2S_RCR2_BCD_MASK | I2S_RCR2_BCP_MASK);
874890
rcr2 |= I2S_RCR2_BCP(config->bclkPolarity);
875891
}
876892

0 commit comments

Comments
 (0)