cancel
Showing results for 
Search instead for 
Did you mean: 

[HAL] weird SAI configuration of clock strobing : is this a bug?

peterleif
Associate

Hello.

I am using SAI of STM32F4 & F7 MCUs as I2S input/output.

When configuring SAI as "master/slave receive" using HAL driver,

"Clock strobing" is set incorrectly.

Here is the corresponding code block of the STM32F4 HAL driver (stm32f4xx_hal_sai.c).

HAL_StatusTypeDef HAL_SAI_Init(SAI_HandleTypeDef *hsai)
{
=================================================================
=================================================================  
/* Compute CKSTR bits of SAI CR1 according ClockStrobing and AudioMode */
  if((hsai->Init.AudioMode == SAI_MODEMASTER_TX) || (hsai->Init.AudioMode == SAI_MODESLAVE_TX))
  { /* Transmit */
    ckstr_bits = (hsai->Init.ClockStrobing == SAI_CLOCKSTROBING_RISINGEDGE) ? 0 : SAI_xCR1_CKSTR;
  }
  else
  { /* Receive */
    ckstr_bits = (hsai->Init.ClockStrobing == SAI_CLOCKSTROBING_RISINGEDGE) ? SAI_xCR1_CKSTR : 0;
  }
=================================================================
=================================================================  
}

There is also a similar lines of code in stm32f7xx_hal_sai.c.

When the audio mode is set to receive mode, the value of ckstr_bits is inverted.

So, if Init.ClockStrobing is set to FALLINGEDGE, actual value that is set to the register is RISINGEDGE.

The I2S standard employs FALLINGEDGE, so you should set Init.ClockStrobing to FALLINGEDGE in Tx mode, and RISINGEDGE in Rx mode, which is weird (I confirmed this behavior).

Is this a bug in the HAL driver or somehow intended behavior?

0 REPLIES 0