Skip to main content
fronders
Associate III
August 30, 2019
Question

[Bug report] CubeMX generated SAI Init code skips Syncro parameter

  • August 30, 2019
  • 5 replies
  • 1668 views

Hello, I am using CubeMX v5.3.0 with HAL F4 v1.24.1 on STM32F429ZI chip and Atollic TrueSTUDIO v9.3.0.

I am configuring SAI to be in full-duplex mode: SAI_A in Master with MCO mode (Master Transmit), SAI_B in Synchronous Slave mode (Slave Receive).

Here is the resulting code from MX_SAI_Init():

/* SAI1 init function */
void MX_SAI1_Init(void)
{
 
 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_RISINGEDGE;
 hsai_BlockA1.Init.OutputDrive = SAI_OUTPUTDRIVE_ENABLE;
 hsai_BlockA1.Init.NoDivider = SAI_MASTERDIVIDER_ENABLE;
 hsai_BlockA1.Init.FIFOThreshold = SAI_FIFOTHRESHOLD_1QF;
 hsai_BlockA1.Init.ClockSource = SAI_CLKSOURCE_PLLSAI;
 hsai_BlockA1.Init.AudioFrequency = SAI_AUDIO_FREQUENCY_44K;
 hsai_BlockA1.FrameInit.FrameLength = 64;
 hsai_BlockA1.FrameInit.ActiveFrameLength = 32;
 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_32B;
 hsai_BlockA1.SlotInit.SlotNumber = 2;
 hsai_BlockA1.SlotInit.SlotActive = 0x00000003;
 if (HAL_SAI_Init(&hsai_BlockA1) != HAL_OK)
 {
 Error_Handler();
 }
 
 hsai_BlockB1.Instance = SAI1_Block_B;
 hsai_BlockB1.Init.Protocol = SAI_FREE_PROTOCOL;
 hsai_BlockB1.Init.AudioMode = SAI_MODESLAVE_RX;
 hsai_BlockB1.Init.DataSize = SAI_DATASIZE_16;
 hsai_BlockB1.Init.FirstBit = SAI_FIRSTBIT_MSB;
 hsai_BlockB1.Init.ClockStrobing = SAI_CLOCKSTROBING_RISINGEDGE;
 hsai_BlockB1.Init.OutputDrive = SAI_OUTPUTDRIVE_ENABLE;
 hsai_BlockB1.Init.FIFOThreshold = SAI_FIFOTHRESHOLD_1QF;
 hsai_BlockB1.FrameInit.FrameLength = 64;
 hsai_BlockB1.FrameInit.ActiveFrameLength = 32;
 hsai_BlockB1.FrameInit.FSDefinition = SAI_FS_CHANNEL_IDENTIFICATION;
 hsai_BlockB1.FrameInit.FSPolarity = SAI_FS_ACTIVE_LOW;
 hsai_BlockB1.FrameInit.FSOffset = SAI_FS_BEFOREFIRSTBIT;
 hsai_BlockB1.SlotInit.FirstBitOffset = 0;
 hsai_BlockB1.SlotInit.SlotSize = SAI_SLOTSIZE_32B;
 hsai_BlockB1.SlotInit.SlotNumber = 2;
 hsai_BlockB1.SlotInit.SlotActive = 0x00000003;
 if (HAL_SAI_Init(&hsai_BlockB1) != HAL_OK)
 {
 Error_Handler();
 }
 
}

As you can see the above code lacks the hsai_BlockX1.Init.Syncro field setting.

This results in both master and slave be in Asynchronous mode (skipped Syncro field has value of 0 which is equal to SAI_ASYNCRONOUS)

The generated code should've had two more lines:

hsai_BlockA1.Init.Synchro = SAI_ASYNCHRONOUS;
 
....
 
hsai_BlockB1.Init.Synchro = SAI_SYNCHRONOUS;

Attaching the CubeMX project file and generated sai.c file

This topic has been closed for replies.

5 replies

fronders
frondersAuthor
Associate III
August 30, 2019

@Khouloud GARSI​  would you please take a look at this, thanks!

Mike_ST
Technical Moderator
September 2, 2019

Internal ticket entered.

Thank you for reporting.

Klang.Martin
Associate II
December 22, 2019

Any update on this? It's a pretty serious bug. Projects that used to work with previous STM32CubeMX versions now don't.

Piranha
Principal III
December 22, 2019

Serious are network bugs, but ST's code monkeys are to dumb to fix those! ;) Actually, exactly because this bug is trivial and easy to fix, they might fix it... someday, which could be years away. ;)

Klang.Martin
Associate II
December 23, 2019

Yes indeed, this actually seems to be fixed in v5.4.0 - thanks ST!

(wasn't working with v5.3.0)