Skip to main content
caleb
Associate III
May 15, 2019
Solved

I2S full-duplex on STM32H7: STM32CubeMX doesn't produce working code

  • May 15, 2019
  • 2 replies
  • 3765 views

Hi again,

I'm attempting to use the I2S peripheral on the STM32H7, and the CubeMX produces half-duplex code.

Here you see that I'm using an STM32H743, selected I2S, full-duplex slave, but the only choices of mode I get are Mode Slave Transmit and Mode Slave Receive. There is no full duplex mode selectable.

0690X000008vwQPQAY.png

In addition, when I have mode slave transmit enabled, the data is spit out on the wrong pin (PA6 instead of PA7).

There is literally no code change between selecting 'Full-Duplex Slave' and 'Half-Duplex Slave', but there is a change in the .ioc file.

Any thoughts on how to make full duplex work? Any idea if this is a known problem in the CubeMX software?

In my case, I'm lucky, an only *require* the transmit, and not so much the receive.

Thanks so much!

-Caleb

This topic has been closed for replies.
Best answer by caleb

I'm just playing with that now. So far, I created my own MX_I2S1_Init that sets full duplex, and swaps TX and RX. I'm only doing polling IO for the moment, but it does work, with data going out on the correct pin (PA7).

void My_MX_I2S1_Init(void)
{
 
 hi2s1.Instance = SPI1;
 hi2s1.Init.Mode = I2S_MODE_SLAVE_FULLDUPLEX; // not supported by CubeMX 5.2, so we need to roll our own. 
 hi2s1.Init.Standard = I2S_STANDARD_PHILIPS;
 hi2s1.Init.DataFormat = I2S_DATAFORMAT_32B;
 hi2s1.Init.MCLKOutput = I2S_MCLKOUTPUT_DISABLE;
 hi2s1.Init.AudioFreq = I2S_AUDIOFREQ_48K;
 hi2s1.Init.CPOL = I2S_CPOL_LOW;
 hi2s1.Init.FirstBit = I2S_FIRSTBIT_MSB;
 hi2s1.Init.WSInversion = I2S_WS_INVERSION_DISABLE;
 hi2s1.Init.Data24BitAlignment = I2S_DATA_24BIT_ALIGNMENT_RIGHT;
 hi2s1.Init.MasterKeepIOState = I2S_MASTER_KEEP_IO_STATE_DISABLE;
 if (HAL_I2S_Init(&hi2s1) != HAL_OK)
 {
 Error_Handler();
 }
 
 // Swap TX and RX 
 MODIFY_REG(hi2s1.Instance->CFG2, SPI_CFG2_IOSWP, SPI_CFG2_IOSWP);
}

2 replies

waclawek.jan
Super User
May 15, 2019

And if you simply program the I2S registers for the full-duplex slave, without relying on Cube/CubeMX, it won't work either?

JW

caleb
calebAuthorBest answer
Associate III
May 15, 2019

I'm just playing with that now. So far, I created my own MX_I2S1_Init that sets full duplex, and swaps TX and RX. I'm only doing polling IO for the moment, but it does work, with data going out on the correct pin (PA7).

void My_MX_I2S1_Init(void)
{
 
 hi2s1.Instance = SPI1;
 hi2s1.Init.Mode = I2S_MODE_SLAVE_FULLDUPLEX; // not supported by CubeMX 5.2, so we need to roll our own. 
 hi2s1.Init.Standard = I2S_STANDARD_PHILIPS;
 hi2s1.Init.DataFormat = I2S_DATAFORMAT_32B;
 hi2s1.Init.MCLKOutput = I2S_MCLKOUTPUT_DISABLE;
 hi2s1.Init.AudioFreq = I2S_AUDIOFREQ_48K;
 hi2s1.Init.CPOL = I2S_CPOL_LOW;
 hi2s1.Init.FirstBit = I2S_FIRSTBIT_MSB;
 hi2s1.Init.WSInversion = I2S_WS_INVERSION_DISABLE;
 hi2s1.Init.Data24BitAlignment = I2S_DATA_24BIT_ALIGNMENT_RIGHT;
 hi2s1.Init.MasterKeepIOState = I2S_MASTER_KEEP_IO_STATE_DISABLE;
 if (HAL_I2S_Init(&hi2s1) != HAL_OK)
 {
 Error_Handler();
 }
 
 // Swap TX and RX 
 MODIFY_REG(hi2s1.Instance->CFG2, SPI_CFG2_IOSWP, SPI_CFG2_IOSWP);
}

Khouloud ZEMMELI
ST Employee
May 16, 2019

​Hello @caleb​ 

This is reported internally for further check.

Best Regards,

Khouloud.

Takemasa
Associate III
December 30, 2020

Hi @Khouloud ZEMMELI​ 

This problem still exists on CubeIDE v1.5.1. While the I2S is configured as a duplex by the CubeIDE configurator, the generated code initializes the I2S as a simplex mode.

Any update internally?

Regards

Takemasa