2019-08-30 02:38 AM
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
2019-08-30 02:41 AM
@Khouloud GARSI would you please take a look at this, thanks!
2019-09-02 01:19 AM
Internal ticket entered.
Thank you for reporting.
2019-12-21 07:15 PM
Any update on this? It's a pretty serious bug. Projects that used to work with previous STM32CubeMX versions now don't.
2019-12-21 11:42 PM
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. ;)
2019-12-22 05:26 PM
Yes indeed, this actually seems to be fixed in v5.4.0 - thanks ST!
(wasn't working with v5.3.0)