Skip to main content
Graduate II
March 25, 2025
Question

stm32h7b3i-dk SAI1 configuration

  • March 25, 2025
  • 2 replies
  • 861 views

Hi,

I am trying to use SAI instead of I2S6 since the BDMA seems to not trigger even after proper configuration.

I am using SAI for the first time so I am completely unsure about this config:

 
/**
 * @brief SAI1 Initialization Function
 * @PAram None
 * @retval None
 */
static void MX_SAI1_Init(void)
{

 /* USER CODE BEGIN SAI1_Init 0 */

 /* USER CODE END SAI1_Init 0 */

 /* USER CODE BEGIN SAI1_Init 1 */

 /* USER CODE END SAI1_Init 1 */
 hsai_BlockA1.Instance = SAI1_Block_A;
 hsai_BlockA1.Init.AudioMode = SAI_MODEMASTER_TX;
 hsai_BlockA1.Init.Synchro = SAI_ASYNCHRONOUS;
 hsai_BlockA1.Init.OutputDrive = SAI_OUTPUTDRIVE_DISABLE;
 hsai_BlockA1.Init.NoDivider = SAI_MASTERDIVIDER_ENABLE;
 hsai_BlockA1.Init.FIFOThreshold = SAI_FIFOTHRESHOLD_1QF;
 hsai_BlockA1.Init.AudioFrequency = SAI_AUDIO_FREQUENCY_22K;
 hsai_BlockA1.Init.SynchroExt = SAI_SYNCEXT_DISABLE;
 hsai_BlockA1.Init.MonoStereoMode = SAI_STEREOMODE;
 hsai_BlockA1.Init.CompandingMode = SAI_NOCOMPANDING;
 hsai_BlockA1.Init.TriState = SAI_OUTPUT_NOTRELEASED;
 if (HAL_SAI_InitProtocol(&hsai_BlockA1, SAI_I2S_STANDARD, SAI_PROTOCOL_DATASIZE_16BIT, 2) != HAL_OK)
 {
 Error_Handler();
 }
 hsai_BlockB1.Instance = SAI1_Block_B;
 hsai_BlockB1.Init.AudioMode = SAI_MODESLAVE_RX;
 hsai_BlockB1.Init.Synchro = SAI_SYNCHRONOUS;
 hsai_BlockB1.Init.OutputDrive = SAI_OUTPUTDRIVE_DISABLE;
 hsai_BlockB1.Init.FIFOThreshold = SAI_FIFOTHRESHOLD_1QF;
 hsai_BlockB1.Init.SynchroExt = SAI_SYNCEXT_DISABLE;
 hsai_BlockB1.Init.MonoStereoMode = SAI_STEREOMODE;
 hsai_BlockB1.Init.CompandingMode = SAI_NOCOMPANDING;
 hsai_BlockB1.Init.TriState = SAI_OUTPUT_NOTRELEASED;
 if (HAL_SAI_InitProtocol(&hsai_BlockB1, SAI_I2S_STANDARD, SAI_PROTOCOL_DATASIZE_16BIT, 2) != HAL_OK)
 {
 Error_Handler();
 }
 /* USER CODE BEGIN SAI1_Init 2 */

 /* USER CODE END SAI1_Init 2 */

}

DMA seems to be working and I am getting a values of around 65000 , so I suspect the audio driver or SAI configuration is wrong.

I have taken some portion of the audio driver from the stm32 repo . I was unsure how to use the driver also It gave me some errors when I included it in my build  (some functions had same name as the CubeMx generated ones).

I2C in the driver works and I confirmed this by reading the ID from the Codec. I can read and write registers . So I have created few functions to setup MIC and start it.

SAI configuration is shown above , and DMA was also configured using the GUI . which seems to work and read some values but these values are either close to zero or close to 65000 all the time.

 

 

    This topic has been closed for replies.

    2 replies

    ST Employee
    April 2, 2025

    Hello @AmrithHN ,

    Your issue could stem from several sources. Please check the following:

    1. GPIO Configuration for SAI:

      • Ensure that the GPIOs used for SAI are properly configured. Note that the GPIOs for SAI are different from those used for I2S.
      • If you are using CubeMX, verify that the configuration is correct.
    2. SAI1 Clock Source Configuration:

      • Confirm that the SAI1 clock source is correctly configured. In CubeMX, you need to set a clock source around 11.422 MHz to achieve an FS frequency of 22.050 KHz after SAI clock division. You can use one of the PLLs for this purpose.
    3. Driver Implementation:

      • It appears that you have developed a new driver similar to the CS42L51 driver component. If possible, I recommend using the existing CS42L51 driver in your software to avoid issues with function name conflicts.
      • You can find an example of the CS42L51 driver usage (without BSP) in the SAI_AudioPlay example for the STM32H7B3I-EVAL. You can use the same functions with the same parameters, except for codec_init.InputDevice, which should be set to CS42L51_IN_MIC1 before calling AudioDrv->Init(AudioCompObj, &codec_init).

    BR

    AmrithHNAuthor
    Graduate II
    April 4, 2025

    Thank You so much for checking this out.

    I am really new to SAI or I2S in general , I think the clock configuration is the issue.

    I will try using the existing drivers, problem was its having too much abstractions and uses multiple files to configure so it wasnt easy to understand .

     

    Thank you so much !

     

    Regards

    Amrith

    AmrithHNAuthor
    Graduate II
    April 12, 2025

    I tried using the BSP , just adding them to cubeMX generated project gave me many errors

    1. It has i2s , sai and dfdsm all mixed up

    2. I just need the audio init and sai and maybe some call backs

    3. The BSP is so poorly written (why do I need to have i2s SAI and dfdsm all at the same time makes no sense)