cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeMX generated code STM32N657X0 initialization missing for IC7

Tuomas95
Associate

When generating code with CubeMX (Version 6.14.1) for the STM32N657X0 with the following clock configuration for SAI1:

image.png

image.png

image.png

 

With the above MX configuration and below code, the SAI1 FS is around 2 KHz:

Tuomas95_0-1749197472317.png

After adding the lines:

PeriphClkInitStruct.ICSelection[RCC_IC7].ClockSelection = RCC_ICCLKSOURCE_PLL3;
PeriphClkInitStruct.ICSelection[RCC_IC7].ClockDivider = 1;

to HAL_SAI_MspInit() in stm32n6xx_hal_msp.c the signals are correctly generated:

Tuomas95_1-1749197704410.png

/* FILE: stm32n6xx_hal_msp.c */
void HAL_SAI_MspInit(SAI_HandleTypeDef* hsai)
{

  GPIO_InitTypeDef GPIO_InitStruct;
  DMA_NodeConfTypeDef NodeConfig;
  RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
/* SAI1 */
    if(hsai->Instance==SAI1_Block_A)
    {
    /* Peripheral clock enable */

  /** Initializes the peripherals clock
  */
    PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_SAI1;
    PeriphClkInitStruct.Sai1ClockSelection = RCC_SAI1CLKSOURCE_IC7;
    /* BELOW MISSING FROM GENERATED CODE */
    PeriphClkInitStruct.ICSelection[RCC_IC7].ClockSelection = RCC_ICCLKSOURCE_PLL3; // MANUALLY ADDED
    PeriphClkInitStruct.ICSelection[RCC_IC7].ClockDivider = 1; // MANUALLY ADDED
    /* ABOVE MISSING FROM GENERATED CODE */
    if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
    {
      Error_Handler();
    }

    if (SAI1_client == 0)
    {
       __HAL_RCC_SAI1_CLK_ENABLE();

    /* Peripheral interrupt init*/
    HAL_NVIC_SetPriority(SAI1_A_IRQn, 0, 0);
    HAL_NVIC_EnableIRQ(SAI1_A_IRQn);
    }
    SAI1_client ++;
    /*...*/
}
/* FILE: main.c */

/**
  * @brief SAI1 Initialization Function
  * @PAram None
  * @retval None
  */
static void SAI1_Init_TDM(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.Protocol = SAI_FREE_PROTOCOL;
  hsai_BlockA1.Init.AudioMode = SAI_MODEMASTER_TX;
  hsai_BlockA1.Init.DataSize = SAI_DATASIZE_16;
  hsai_BlockA1.Init.FirstBit = SAI_FIRSTBIT_MSB;
  hsai_BlockA1.Init.ClockStrobing = SAI_CLOCKSTROBING_FALLINGEDGE;
  hsai_BlockA1.Init.Synchro = SAI_ASYNCHRONOUS;
  hsai_BlockA1.Init.OutputDrive = SAI_OUTPUTDRIVE_ENABLE;
  hsai_BlockA1.Init.NoDivider = SAI_MASTERDIVIDER_ENABLE;
  hsai_BlockA1.Init.FIFOThreshold = SAI_FIFOTHRESHOLD_1QF;
  hsai_BlockA1.Init.AudioFrequency = SAI_AUDIO_FREQUENCY_16K;
  hsai_BlockA1.Init.SynchroExt = SAI_SYNCEXT_DISABLE;
  hsai_BlockA1.Init.MckOutput = SAI_MCK_OUTPUT_ENABLE;
  hsai_BlockA1.Init.MonoStereoMode = SAI_MONOMODE;
  hsai_BlockA1.Init.CompandingMode = SAI_NOCOMPANDING;
  hsai_BlockA1.Init.TriState = SAI_OUTPUT_NOTRELEASED;
  hsai_BlockA1.Init.PdmInit.Activation = DISABLE;
  hsai_BlockA1.FrameInit.FrameLength = 128;
  hsai_BlockA1.FrameInit.ActiveFrameLength = 16;
  hsai_BlockA1.FrameInit.FSDefinition = SAI_FS_CHANNEL_IDENTIFICATION;
  hsai_BlockA1.FrameInit.FSPolarity = SAI_FS_ACTIVE_LOW;
  hsai_BlockA1.FrameInit.FSOffset = SAI_FS_BEFOREFIRSTBIT;
  hsai_BlockA1.SlotInit.FirstBitOffset = 0;
  hsai_BlockA1.SlotInit.SlotSize = SAI_SLOTSIZE_16B;
  hsai_BlockA1.SlotInit.SlotNumber = 8;
  hsai_BlockA1.SlotInit.SlotActive = SAI_SLOTACTIVE_0 | SAI_SLOTACTIVE_1 | SAI_SLOTACTIVE_2 | SAI_SLOTACTIVE_3 | SAI_SLOTACTIVE_4 | SAI_SLOTACTIVE_5 | SAI_SLOTACTIVE_6 | SAI_SLOTACTIVE_7;
  if (HAL_SAI_Init(&hsai_BlockA1) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN SAI1_Init 2 */

  /* USER CODE END SAI1_Init 2 */

}
1 ACCEPTED SOLUTION

Accepted Solutions
Mahmoud Ben Romdhane
ST Employee

Hello @Tuomas95 ,

 

Thank you for your contribution and bringing this issue to our attention.

This issue is reported and raised to the Development Team under an internal ticket number: 211832.

 

Thanks.

Mahmoud

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

2 REPLIES 2
Mahmoud Ben Romdhane
ST Employee

Hello @Tuomas95 ,

First let me thank you for posting and welcome to the ST Community.

Your request is under investigation, and I will get back to you ASAP.

Thanks.

Mahmoud

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Mahmoud Ben Romdhane
ST Employee

Hello @Tuomas95 ,

 

Thank you for your contribution and bringing this issue to our attention.

This issue is reported and raised to the Development Team under an internal ticket number: 211832.

 

Thanks.

Mahmoud

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.