cancel
Showing results for 
Search instead for 
Did you mean: 

SAI IO on pins from SAI example

benyBoy
Associate II
Posted on June 16, 2018 at 05:58

Hi,

I am trying to change the SAI IO pins on the STM32F769_Discovery board using the SAI example.

I would like to point the defined SAI block to arduino pins on the Discovery board so I can view them on the scope.

I get nothing on the scope with changes in code below.

Before the changes I am getting audio playback from the .bin file.

There is no error thrown from setup of the SAI.

Can someone help me understand why the SAI example doesn't change 'UpdatePointer' in the callbacks HAL_SAI_TxCpltCallback or HAL_SAI_TxHalfCpltCallback when I change the SAI pins from the codec to external pins?

or in other words the code waits here and never gets a callback.

/* Wait a callback event */

while(UpdatePointer==-1);

Is the code expecting an interrupt from wm8994 or something that i'm missing ?

  

/* SAI peripheral configuration defines */

#define AUDIO_SAIx SAI1_Block_A

#define AUDIO_SAIx_CLK_ENABLE() __HAL_RCC_SAI1_CLK_ENABLE()

#define AUDIO_SAIx_FS_GPIO_PORT GPIOF           // GPIOE

#define AUDIO_SAIx_FS_AF GPIO_AF6_SAI1

#define AUDIO_SAIx_FS_PIN GPIO_PIN_6               // GPIO_PIN_4 //

#define AUDIO_SAIx_SCK_GPIO_PORT GPIOF         // GPIOE //

#define AUDIO_SAIx_SCK_AF GPIO_AF6_SAI1

#define AUDIO_SAIx_SCK_PIN GPIO_PIN_7              // GPIO_PIN_5 //

#define AUDIO_SAIx_SD_GPIO_PORT GPIOF                 // GPIOE //

#define AUDIO_SAIx_SD_AF GPIO_AF6_SAI1

#define AUDIO_SAIx_SD_PIN GPIO_PIN_10                 // GPIO_PIN_6 //

#define AUDIO_SAIx_MCLK_GPIO_PORT GPIOA               // GPIOG //

#define AUDIO_SAIx_MCLK_AF GPIO_AF6_SAI1

#define AUDIO_SAIx_MCLK_PIN GPIO_PIN_6                  // GPIO_PIN_7 //

#define AUDIO_SAIx_MCLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE() // __HAL_RCC_GPIOG_CLK_ENABLE() //

#define AUDIO_SAIx_SCK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE() // __HAL_RCC_GPIOE_CLK_ENABLE() //

#define AUDIO_SAIx_FS_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE() // __HAL_RCC_GPIOE_CLK_ENABLE() //

#define AUDIO_SAIx_SD_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE() // __HAL_RCC_GPIOE_CLK_ENABLE() //
5 REPLIES 5
benyBoy
Associate II
Posted on June 16, 2018 at 16:59

Now i'm trying to use external mclk from dsp for SAI1 in the SAI example

static void Playback_Init(void)

{

RCC_PeriphCLKInitTypeDef RCC_PeriphCLKInitStruct;

RCC_PeriphCLKInitStruct.PeriphClockSelection = RCC_PERIPHCLK_SAI2; // why SAI2 and not SAI1 in SAI example code?

RCC_PeriphCLKInitStruct.Sai2ClockSelection = RCC_SAI2CLKSOURCE_PIN;

if(HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphCLKInitStruct) != HAL_OK){ Error_Handler(); }

/* Initialize SAI */

I have my external clock defined in stm32f7xx_hal_conf.h  but this is for HAL_I2S? 

External clock source for I2S peripheral

* This value is used by the I2S HAL module to compute the I2S clock source

* frequency, this source is inserted directly through I2S_CKIN pad.

#if !defined (EXTERNAL_CLOCK_VALUE)

#define EXTERNAL_CLOCK_VALUE ((uint32_t)24576000U) /*!< Value of the Internal oscillator in Hz*/

#endif /* EXTERNAL_CLOCK_VALUE */

is the MCLK not needed in slave mode ? its made from multiplying SCK & LRCLK? 

can anyone point me in the right direction to make SAI in MODESLAVE_TX work with the SAI example code?

Posted on June 16, 2018 at 23:58

I am trying to change the SAI IO pins on the STM32F769_Discovery board using the SAI example.

You cannot assign function block signals to arbitrary pins of the mcu, see the Alternate function mapping table in datasheet, for example:

0690X0000060LIXQA2.png

is the MCLK not needed in slave mode ? its made from multiplying SCK & LRCLK? 

MCLK is a signal needed by the internal circuits of the codec (ADC, DAC). It is not needed to transfer data. Thus, the mcu as slave does not need it at all, and as master provides it as a convenience for those codecs which can't generate it themselves.

JW

Posted on June 17, 2018 at 02:24

 ,

 ,

0690X0000060LIcQAM.png

Thanks JW!

I tried these pins , I have

5.6mhz mclk

705khz sclk

but the SAI example code is stuck here without any callbacks being triggered

/* Wait a callback event */

 ,

while(UpdatePointer==-1),

does the SAI example need to be hooked to anything in order for ,HAL_SAI_TxHalfCpltCallback to trigger ?

I just have the SAI1_B pins hooked up to a scope?

my pin SAI_B pin assignment is like this..

 ,

/* SAI peripheral configuration defines */

 ,

♯ define AUDIO_SAIx SAI1_Block_B // CHANGED TO Block_B from A !

♯ define AUDIO_SAIx_CLK_ENABLE() __HAL_RCC_SAI1_CLK_ENABLE()

♯ define AUDIO_SAIx_FS_GPIO_PORT GPIOF

 ,

♯ define AUDIO_SAIx_FS_AF GPIO_AF6_SAI1

 ,

♯ define AUDIO_SAIx_FS_PIN GPIO_PIN_9 // PF9

♯ define AUDIO_SAIx_SCK_GPIO_PORT GPIOF

 ,

♯ define AUDIO_SAIx_SCK_AF GPIO_AF6_SAI1

 ,

♯ define AUDIO_SAIx_SCK_PIN GPIO_PIN_8 // PF8

♯ define AUDIO_SAIx_SD_GPIO_PORT GPIOF

 ,

♯ define AUDIO_SAIx_SD_AF GPIO_AF6_SAI1

 ,

♯ define AUDIO_SAIx_SD_PIN GPIO_PIN_6 // PF6

♯ define AUDIO_SAIx_MCLK_GPIO_PORT GPIOF

 ,

♯ define AUDIO_SAIx_MCLK_AF GPIO_AF6_SAI1

 ,

♯ define AUDIO_SAIx_MCLK_PIN GPIO_PIN_7 // PF7

 ,

 ,

♯ define AUDIO_SAIx_MCLK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()

 ,

♯ define AUDIO_SAIx_SCK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()

 ,

♯ define AUDIO_SAIx_FS_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()

 ,

♯ define AUDIO_SAIx_SD_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()
Posted on June 17, 2018 at 12:29

I am not going to debug Cube-based examples, sorry.

Go through the example and try to spot inconsistencies/places with fixed relationship to SAI1A. I took a glance into what may be a similar example for 'L4 and immediately spotted a fixed DMA channel assignment, for example.

JW

Posted on June 17, 2018 at 15:40

Hi JW, no worries , you helped a lot already!

for anyone else trying the same thing , I changed DMA to stream5 after seeing this DMA map

I'm using SAI1_B 

0690X00000604fDQAQ.jpg

 hSaiDma.Init.Channel   = DMA_CHANNEL_0;

add to stm32f7xx_it.c

void DMA2_Stream5_IRQHandler(void)

{

HAL_DMA_IRQHandler(SaiHandle.hdmatx);

}

SAI WORKING in SAI example on external pins.

I don't think there is a pin available for stm32f769i_discovery on SAI1_blockA for SD input.

I might have to solder a bodge wire onto a Test Point for SAI SD input or maybe I find a way on SAI2.

Anyway , I understand now you need to use / assign pins mapped to SAI ports and use the correct DMA stream and Channel for SAIx.

 Thanks JW.