AnsweredAssumed Answered

[STM32F4Discovery]Unable to do basic audio

Question asked by michele.fratello on Jun 1, 2013
Latest reply on Jun 2, 2013 by michele.fratello
Hi all.
I got my first f4-discovery some day ago from my robotics and embedded systems professor.
I wanted to try some basic audio manipulation, but it turned out i can even output some synthetic wave from the codec.

I based my code on the stm32f4_discovery_audio_codec.[ch] library, but maybe i fail in configure correctly the whole.
Here is the code i wrote.
#include <stm32f4_discovery.h>
#include <stm32f4xx_conf.h>
#include <stm32f4_discovery_audio_codec.h>
void initWave(void);
uint16_t buffer[256];
uint16_t index;
int main (void)
    int volume = 100;
    int AudioFreq = 256*440;
    /* Initialize I2S interface */ 
    /* Initialize the Audio codec and all related peripherals (I2S, I2C, IOExpander, IOs...) */ 
    index = 0;
    EVAL_AUDIO_Play((uint16_t*)buffer, 256);
    return 0;
void initWave(void)
    uint16_t i;
    for(i = 0; i <= 0xFF; i++)
        buffer[i] = ((i & 0x80) >> 7) * 0xFF;
void EVAL_AUDIO_TransferComplete_CallBack(uint32_t pBuffer, uint32_t Size)
    index = 0;
    EVAL_AUDIO_Play((uint16_t*)buffer, 256);
uint16_t EVAL_AUDIO_GetSampleCallBack(void)
    return buffer[index++];
And this is the head of stm32f4_discovery_audio_codec.h where i set the defines:
             CONFIGURATION: Audio Codec Driver Configuration parameters
/* Audio Transfer mode (I2S Interrupt) */
#define I2S_INTERRUPT                 /* Uncomment this line to enable audio transfert with I2S interrupt*/
/* Audio Transfer mode (DMA, Interrupt or Polling) */
#define AUDIO_MAL_MODE_NORMAL           // Uncomment this line to enable the audio
                                        //Transfer using DMA
//#define AUDIO_MAL_MODE_CIRCULAR       // Uncomment this line to enable the audio
                                        //Transfer using DMA
/* For the DMA modes select the interrupt that will be used */
#define AUDIO_MAL_DMA_IT_TC_EN  //Uncomment this line to enable DMA Transfer Complete interrupt
//#define AUDIO_MAL_DMA_IT_HT_EN    //Uncomment this line to enable DMA Half Transfer Complete interrupt
//#define AUDIO_MAL_DMA_IT_TE_EN    //Uncomment this line to enable DMA Transfer Error interrupt
/* Select the interrupt preemption priority and subpriority for the DMA interrupt */
#define EVAL_AUDIO_IRQ_PREPRIO           0   /* Select the preemption priority level(0 is the highest) */
#define EVAL_AUDIO_IRQ_SUBRIO            0   /* Select the sub-priority level (0 is the highest) */
/* Uncomment the following line to use the default Codec_TIMEOUT_UserCallback()
   function implemented in stm32f4_discovery_audio_codec.c file.
   Codec_TIMEOUT_UserCallback() function is called whenever a timeout condition
   occurs during communication (waiting on an event that doesn't occur, bus
   errors, busy devices ...). */  
/* Enable this define to use the I2S DMA for writing into DAC register */
//#define DAC_USE_I2S_DMA

Basically i have 256 samples from a square wave and i want the codec to generate a signal with 440Hz, so i want the codec to output the 256 samples 440 times per second, is it right?
Have you some advice for me? It is becoming really frustrating.
Thank you for your help