cancel
Showing results for 
Search instead for 
Did you mean: 

I2S code generated by STM32CubeMX for STM32F746 - no MCKO

fmcarp
Associate
Posted on December 12, 2015 at 19:37

Hello,

I'm using STM32CubeMX to generate a project for STM32F746VGT6.

Everything works fine except I2S3, there is no clock output on MCKO pin (PC7) and the call of HAL_I2S_Transmit(...) generates a timeout error.

The I2S3-related code generated by

STM32CubeMX 

is:

void HAL_I2S_MspInit(I2S_HandleTypeDef* hi2s)

{

  GPIO_InitTypeDef GPIO_InitStruct;

  if(hi2s->Instance==SPI3)

  {

  /* USER CODE BEGIN SPI3_MspInit 0 */

  /* USER CODE END SPI3_MspInit 0 */

    /* Peripheral clock enable */

    __SPI3_CLK_ENABLE();

  

    /**I2S3 GPIO Configuration    

    PC7     ------> I2S3_MCK

    PA15     ------> I2S3_WS

    PC10     ------> I2S3_CK

    PC12     ------> I2S3_SD 

    */

    GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_10|GPIO_PIN_12;

    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

    GPIO_InitStruct.Pull = GPIO_NOPULL;

    GPIO_InitStruct.Speed = GPIO_SPEED_LOW;

    GPIO_InitStruct.Alternate = GPIO_AF6_SPI3;

    HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

    GPIO_InitStruct.Pin = GPIO_PIN_15;

    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

    GPIO_InitStruct.Pull = GPIO_NOPULL;

    GPIO_InitStruct.Speed = GPIO_SPEED_LOW;

    GPIO_InitStruct.Alternate = GPIO_AF6_SPI3;

    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  /* USER CODE BEGIN SPI3_MspInit 1 */

  /* USER CODE END SPI3_MspInit 1 */

  }

void MX_I2S3_Init(void)

{

  hi2s3.Instance = SPI3;

  hi2s3.Init.Mode = I2S_MODE_MASTER_TX;

  hi2s3.Init.Standard = I2S_STANDARD_PHILIPS;

  hi2s3.Init.DataFormat = I2S_DATAFORMAT_16B;

  hi2s3.Init.MCLKOutput = I2S_MCLKOUTPUT_ENABLE;

  hi2s3.Init.AudioFreq = I2S_AUDIOFREQ_8K;

  hi2s3.Init.CPOL = I2S_CPOL_LOW;

  HAL_I2S_Init(&hi2s3);

}

After calling these initialization routines in the main function, the MCKO on PC7 pin is not present (checked with an oscilloscope).In the main loop I call HAL_I2S_Transmit(&hi2s3, DummySamples, 5, 250) - this is generating a timeout error.

Any clues ?

Thank you.

#i2s #stm32cubemx #mcko
3 REPLIES 3
islero
Associate
Posted on December 14, 2015 at 07:28

Hi Florin

I'm working on a similar issue myself, except it's a F4 platform. The clock architectures are the same from what I gather. Have you tried other sampling rates? What is the input frequency into the I2S clock generator? 

Do you have access to a debugger? It's worth traversing HAL_I2S_Init routine to figure out what values are being programmed into the I2SCFGR (configure) and I2SPR (prescaler) registers. Check that the MCO bit is set also. I'd be interested to know the division factor of your prescaler as it's limited to 8 bits, perhaps it can't create an acceptable clock rate based on your input clock. 

STM32Cube should alert you to any issues but this isn't always the case. My I2S issue was caused by the code generation tool setting my GPIO output speed to ''GPIO_SPEED_LOW'' when it should be at least medium, but this is in regard to a 192KHz sample rate. Let us know how you go.  

fmcarp
Associate
Posted on December 14, 2015 at 11:26

Hi Junkers,

The STM32F7 that I'm using also has a separate SAI (serial audio interface) block that can be configured to work as I2S (among many other protocols). I activated it using SMT32CubeMX (as I did with the simple I2S block) and it works perfect, all signals are visible on the O'scope.

I'm considering to move my application to this SAI block because I also need bidirectional communication with a codec IC and the simple I2S block on STM32F746 is only half-duplex (can be only receiver or transmitter).

Regarding the clock tree, if the prescaler can't set your desired sample rate, you can see the actual rate on STM32CubeMX (and error value), but it will activate it, the same thing happens with the SAI.

I also informed the ST tech support about this issue, maybe they will answer.

I have a STLink v2 debugger, I will check the bit to see if it's really activated by HAL code. 

I am aware that those free HAL libraries are not perfect, in the past I found some small mistakes (inverted bits etc.), so they should be labelled as ''use with your own risk'' 🙂

Regards

son1
Associate II
Posted on December 30, 2015 at 12:40

Did you set clock for Port A and Port C?

__GPIOA_CLK_ENABLE();

__GPIOC_CLK_ENABLE();