Skip to main content
Visitor II
February 28, 2024
Solved

How to sound the audio lineout with STM32H735G-DK

  • February 28, 2024
  • 1 reply
  • 1719 views

I'm very beginner of programing and STM.

I'd like to make it sound the audio line out with sine wave from STM32H735G-DK.

I read the document(UM2679) and understood that SAI and I2C4 are connected to the audio.

But I don't know how to use these.

Especially, I couldn't understand how to set volume and start to play.

Attached files are the one I tried and it doesn't work.

I put a button on the screen and set the interaction with function name "startAudio" as it sounds when I push the button.

Please tell me your advice.

I couldn't attach the file Screen1View.cpp.

So I put it down in text below.

 

#include <gui/screen1_screen/Screen1View.hpp>
#include "main.h"
#include <stdio.h>
#include <math.h>

#define SAMPLE_RATE 48000
#define BUFFER_SIZE 1024
#define PI 3.141592

uint8_t audioBuffer[BUFFER_SIZE];

void generateAudioData();


Screen1View::Screen1View()
{

}

void Screen1View::setupScreen()
{
    Screen1ViewBase::setupScreen();
}

void Screen1View::tearDownScreen()
{
    Screen1ViewBase::tearDownScreen();
}

void Screen1View::startAudio()
{
    generateAudioData();
    HAL_SAI_Transmit_DMA(&hsai_BlockA1,(uint8_t*)audioBuffer,BUFFER_SIZE);
}

void generateAudioData(){
    float frequency = 440.0;
    float amplitude = 0.5;
    for(int i = 0; i < BUFFER_SIZE; i++)
    {
        float t = (float)i / SAMPLE_RATE;
        float sine_wave = sin(2 * PI * frequency * t);
        audioBuffer[i] = (uint8_t)((sine_wave * amplitude + 0.5) * 255);
    }
}
    This topic has been closed for replies.
    Best answer by Dor_RH

    Hello @f-fujii,

    For the STM32H735-DK, the BSP example offers several functionalities:

    • Subdemo 7 and Subdemo 8: These subdemos include a recording feature. The application is designed to use the MB1299 MEMS microphones daughterboard connected to CN20.
    • Subdemo 6: This subdemo includes an AudioPlay feature.

    The complete project is available on the STM32CubeH7 page. By following this example, you can successfully output sound through the audio lineout.

    I hope my answer has helped you. When your question is answered, please select this topic as solution that answered you, it will help others find that answer faster.

    Thanks for your contribution.

    Dor_RH

    1 reply

    Dor_RHAnswer
    ST Employee
    October 14, 2024

    Hello @f-fujii,

    For the STM32H735-DK, the BSP example offers several functionalities:

    • Subdemo 7 and Subdemo 8: These subdemos include a recording feature. The application is designed to use the MB1299 MEMS microphones daughterboard connected to CN20.
    • Subdemo 6: This subdemo includes an AudioPlay feature.

    The complete project is available on the STM32CubeH7 page. By following this example, you can successfully output sound through the audio lineout.

    I hope my answer has helped you. When your question is answered, please select this topic as solution that answered you, it will help others find that answer faster.

    Thanks for your contribution.

    Dor_RH