2023-05-05 04:17 AM
Hi,
Having STM32F723 DISCO with simple play/record example. Need to process sound by 20ms periods, so I've calculated PCM buffer size as :
```
#define AUDIO_CHANNELS 2
#define AUDIO_PCM_BIT_RESOLUTION 16
#define AUDIO_SAMPLE_LENGTH_MS 20
#define AUDIO_SAMPLE_SIZE (AUDIO_CHANNELS * (SAMPLE_RATE/1000) * AUDIO_SAMPLE_LENGTH_MS)
#define AUDIO_PERIODS 2
#define AUDIO_BUFFER_SIZE (AUDIO_SAMPLE_SIZE * AUDIO_PERIODS)
```
So I'm expect the HAL_SAI_TxHalfCpltCallback & HAL_SAI_TxCpltCallback to trigger each 20ms, but it triggers each 10ms:
```
[0000:00:00:00.000] Firmware v1.0 started, h/w rev: 0x1000
[0000:00:00:00.000] System clock: 216 MHz, HCLK/AHB clock: 216 MHz, PCLK1/APB1 clock: 54 MHz, PCLK2/APB2 clock: 108 MHz
[0000:00:00:00.655] SAI clock: 49.142856 MHz
[0000:00:00:00.655] Audio inited: Sample rate: 16000, channels: 2, period length: 20 ms, AUDIO_PCM16BIT_SAMPLE_SIZE: 640, doubled AUDIO_PCM16BIT_BUFFER_SIZE: 1280
[0000:00:00:00.655] Board inited
[0000:00:00:00.655] App started
[0000:00:00:00.655] Generating sine table for 200Hz
[0000:00:00:00.832] Sine table gen completed
[0000:00:00:00.833] Audio started
[0000:00:00:00.843] BSP_AUDIO_OUT_HalfTransfer_CallBack
[0000:00:00:00.853] BSP_AUDIO_OUT_TransferComplete_CallBack
[0000:00:00:00.863] BSP_AUDIO_OUT_HalfTransfer_CallBack
[0000:00:00:00.873] BSP_AUDIO_OUT_TransferComplete_CallBack
```
What can be the problem ?
2023-05-05 08:11 AM
If I change SlotInit.SlotNumber to 2 then I'm having correct 20 ms interrupts :
```
[0000:00:00:00.552] BSP_AUDIO_OUT_HalfTransfer_CallBack
[0000:00:00:00.572] BSP_AUDIO_OUT_TransferComplete_CallBack
```
But TP7 (SAI2_SCK_A) is still shows 1.025Mhz and now no sound at all. The SAI_I2S_STANDARD do not change anything here.
2023-05-05 08:12 AM
I do not touch WM8994 modes - all left as is from stm32f723e_discovery_audio.c
2023-05-05 08:37 AM
Found the issue, I've called the :
```
if (BSP_AUDIO_OUT_Init((spk ? OUTPUT_DEVICE_SPEAKER : OUTPUT_DEVICE_HEADPHONE), AUDIO_DEFAULT_VOLUME, SAMPLE_RATE))
return AUDIO_ERROR_IO;
if (BSP_AUDIO_IN_Init(SAMPLE_RATE, AUDIO_PCM_BIT_RESOLUTION, AUDIO_CHANNELS))
return AUDIO_ERROR_IO;
```
But looks like BSP_AUDIO_IN_Init mangles the SAI settings, if I comment out the BSP_AUDIO_IN_Init() then playback work as expected !
Seems like full duplex was never tested or intented in stock BSP code ;(
Thanks AScha for pointing out to the problem, though I still do not understand how it is working with SAI2_SCK_A 1.025Mhz
2023-05-05 08:54 AM
1M because 4 slot (= channels) are sent, but only 2 filled with data, 2 slots as dummy (null filled);
so 64 b in a frame, but 32 b (2 x 16 b ) is the real data.
2023-05-05 09:00 AM
BTW: with SAI_SLOT_NUMBER set to 2 speaker output no longer works (silence) but headphone is ok.
2023-05-05 09:03 AM
I've hoped that stock example is something that should work and tested at factory with all outputs, sample rates, etc. but seems this is just buggy skeleton code
2023-05-05 09:08 AM
oh, its STM standard.... :)
2023-05-05 10:07 PM
They are always using 4 slots - 2 for speaker, 2 for headphone, I think this is for having the same SAI config for OUTPUT_DEVICE_BOTH mode. Next I've found the BSP_AUDIO_IN_OUT_Init() which works at least for 4 slots. Thanks AScha for your help again !