Forum: Mikrocontroller und Digitale Elektronik STM32F7-Discovery hal-lib


von Thomas K. (thomas_k502)


Lesenswert?

Hallo,

eine kurze Frage. Beschäftige mich seit kurzem zum ersten mal mit den 
hal-libs für das stm32f7-Board.
Ich möchte gerne einfach mal den Audiocodec zum laufen bekommen. Das 
Modul stm32746g_discovery_audio.c bietet dafür ja ausreichend Code. 
Unter anderem die Funktion
uint8_t BSP_AUDIO_IN_OUT_Init(uint16_t InputDevice, uint16_t 
OutputDevice, uint8_t Volume, uint32_t AudioFreq)

Nun meine Frage, hat jemand schonmal diese Funktion verwendet? So wie es 
aussieht brauch ich diese ja nur aufzurufen und schon sollte aus dem 
Klinke etwas herausbekommen. Ich höre allerdings nur Rauschen, 
proportional zu der Volume-Einstellung... allerdings kein Ton. Habe ich 
einen Denkfehler?

Zu dem einfachen Code:
1
#include "stm32f7xx_hal.h"
2
#include "stm32746g_discovery.h"
3
#include "stm32746g_discovery_audio.h"
4
5
uint16_t buttonState = 0;
6
void buttonLED_Init();
7
void audioTest();
8
int main(void)
9
{
10
11
  HAL_Init();
12
13
  BSP_LED_Init(LED_GREEN);
14
  uint8_t process;
15
  process = BSP_AUDIO_IN_OUT_Init(INPUT_DEVICE_DIGITAL_MICROPHONE_2, OUTPUT_DEVICE_HEADPHONE, 80, 48000);
16
  if(process == AUDIO_OK)
17
  {
18
    BSP_LED_On(LED_GREEN);
19
  }
20
}

von Thomas K. (thomas_k502)


Lesenswert?

natürlich ist in der main noch ne while-Schleife, vergessen zu kopieren

von Please fill in this field (Gast)


Lesenswert?

Thomas K. schrieb:
> Hallo,
>
> So wie es
> aussieht brauch ich diese ja nur aufzurufen und schon sollte aus dem
> Klinke etwas herausbekommen. Ich höre allerdings nur Rauschen,
> proportional zu der Volume-Einstellung... allerdings kein Ton. Habe ich
> einen Denkfehler?

So wie es aussieht, bist Du mit dieser Auffassung auf dem Holzweg.

Hättest Du recherchiert, wüsstest Du:


41      1. How To use this driver:
42  --------------------------
43     - This driver supports STM32F4xx devices on STM32F4-Discovery 
Kit:
44          a) to play an audio file (all functions names start by 
BSP_AUDIO_OUT_xxx)
45          b) to record an audio file through MP45DT02, ST MEMS (all 
functions names start by AUDIO_IN_xxx)
46
47  a) PLAY A FILE:
48  ==============
49     + Call the function BSP_AUDIO_OUT_Init(
50                                      OutputDevice: physical output 
mode (OUTPUT_DEVICE_SPEAKER,
51 
OUTPUT_DEVICE_HEADPHONE, OUTPUT_DEVICE_AUTO or
52                                                   OUTPUT_DEVICE_BOTH)
53                                      Volume: initial volume to be set 
(0 is min (mute), 100 is max (100%)
54                                      AudioFreq: Audio frequency in Hz 
(8000, 16000, 22500, 32000 ...)
55                                      this parameter is relative to 
the audio file/stream type.
56                                     )
57        This function configures all the hardware required for the 
audio application (codec, I2C, I2S,
58        GPIOs, DMA and interrupt if needed). This function returns 0 
if configuration is OK.
59        If the returned value is different from 0 or the function is 
stuck then the communication with
60        the codec (try to un-plug the power or reset device in this 
case).
61        - OUTPUT_DEVICE_SPEAKER: only speaker will be set as output 
for the audio stream.
62        - OUTPUT_DEVICE_HEADPHONE: only headphones will be set as 
output for the audio stream.
63        - OUTPUT_DEVICE_AUTO: Selection of output device is made 
through external switch (implemented
64           into the audio jack on the discovery board). When the 
Headphone is connected it is used
65           as output. When the headphone is disconnected from the 
audio jack, the output is
66           automatically switched to Speaker.
67        - OUTPUT_DEVICE_BOTH: both Speaker and Headphone are used as 
outputs for the audio stream
68           at the same time.
69     + Call the function BSP_AUDIO_OUT_Play(
70                                    pBuffer: pointer to the audio data 
file address
71                                    Size: size of the buffer to be 
sent in Bytes
72                                   )
73        to start playing (for the first time) from the audio 
file/stream.
74     + Call the function BSP_AUDIO_OUT_Pause() to pause playing
75     + Call the function BSP_AUDIO_OUT_Resume() to resume playing.
76         Note. After calling BSP_AUDIO_OUT_Pause() function for pause, 
only BSP_AUDIO_OUT_Resume() should be called
77            for resume (it is not allowed to call BSP_AUDIO_OUT_Play() 
in this case).
78         Note. This function should be called only when the audio file 
is played or paused (not stopped).
79     + For each mode, you may need to implement the relative callback 
functions into your code.
80        The Callback functions are named BSP_AUDIO_OUT_XXXCallBack() 
and only their prototypes are declared in
81        the stm32f4_discovery_audio.h file. (refer to the example for 
more details on the callbacks implementations)
82     + To Stop playing, to modify the volume level, the frequency or 
to mute, use the functions
83         BSP_AUDIO_OUT_Stop(), BSP_AUDIO_OUT_SetVolume(), 
AUDIO_OUT_SetFrequency() BSP_AUDIO_OUT_SetOutputMode and 
BSP_AUDIO_OUT_SetMute().
84     + The driver API and the callback functions are at the end of the 
stm32f4_discovery_audio.h file.

von Axel R. (Gast)


Lesenswert?

1
41      1. How To use this driver:
2
42  --------------------------
3
43     - This driver supports STM32F4xx devices on STM32F4-Discovery Kit:
4
44  a) to play an audio file (all functions names start by SP_AUDIO_OUT_xxx)
5
45  b) to record an audio file through MP45DT02, ST MEMS (all functions names start by AUDIO_IN_xxx)
6
46
7
47  a) PLAY A FILE:
8
48  ==============
9
49     + Call the function BSP_AUDIO_OUT_Init(
10
50                                      OutputDevice: physical output mode (OUTPUT_DEVICE_SPEAKER,
11
51                                   OUTPUT_DEVICE_HEADPHONE, OUTPUT_DEVICE_AUTO or
12
52                                      OUTPUT_DEVICE_BOTH)
13
53      Volume: initial volume to be set(0 is min (mute), 100 is max (100%)
14
54                                      AudioFreq: Audio frequency in Hz(8000, 16000, 22500, 32000 ...)
15
55                                      his parameter is relative to the audio file/stream type.
16
56                                     )
17
57        This function configures all the hardware required for the audio application (codec, I2C, I2S,
18
58        GPIOs, DMA and interrupt if needed). This function returns 0 if configuration is OK.
19
59        If the returned value is different from 0 or the function is stuck then the communication with
20
60        the codec (try to un-plug the power or reset device in this case).
21
61        - OUTPUT_DEVICE_SPEAKER: only speaker will be set as output for the audio stream.
22
62        - OUTPUT_DEVICE_HEADPHONE: only headphones will be set as output for the audio stream.
23
63        - OUTPUT_DEVICE_AUTO: Selection of output device is made through external switch (implemented
24
64           into the audio jack on the discovery board). When the Headphone is connected it is used
25
65           as output. When the headphone is disconnected from the audio jack, the output is
26
66           automatically switched to Speaker.
27
67        - OUTPUT_DEVICE_BOTH: both Speaker and Headphone are used as outputs for the audio stream
28
68           at the same time.
29
69     + Call the function BSP_AUDIO_OUT_Play(
30
70                                    pBuffer: pointer to the audio data file address
31
71                                    Size: size of the buffer to be sent in Bytes
32
72                                   )
33
73        to start playing (for the first time) from the audio file/stream.
34
74     + Call the function BSP_AUDIO_OUT_Pause() to pause playing
35
75     + Call the function BSP_AUDIO_OUT_Resume() to resume playing.
36
76         Note. After calling BSP_AUDIO_OUT_Pause() function for pause, only BSP_AUDIO_OUT_Resume() should be called
37
77            for resume (it is not allowed to call BSP_AUDIO_OUT_Play() in this case).
38
78         Note. This function should be called only when the audio file is played or paused (not stopped).
39
79     + For each mode, you may need to implement the relative callback functions into your code.
40
80        The Callback functions are named BSP_AUDIO_OUT_XXXCallBack() and only their prototypes are declared in
41
81        the stm32f4_discovery_audio.h file. (refer to the example for more details on the callbacks implementations)
42
82     + To Stop playing, to modify the volume level, the frequency or to mute, use the functions
43
83         BSP_AUDIO_OUT_Stop(), BSP_AUDIO_OUT_SetVolume(), AUDIO_OUT_SetFrequency() BSP_AUDIO_OUT_SetOutputMode and BSP_AUDIO_OUT_SetMute().
44
84     + The driver API and the callback functions are at the end of the stm32f4_discovery_audio.h file.

von Thomas K. (thomas_k502)


Lesenswert?

Ok also sind die Module zu denen des stm32f4  1:1 kompatibel

von Please fill in this field (Gast)


Lesenswert?

Thomas K. schrieb:
> Ok also sind die Module zu denen des stm32f4  1:1 kompatibel

Woraus schliesst Du das?


Andere Quelle -- STM32 Forum:
https://community.st.com/community/stm32-community/stm32-forum/content?query=BSP_AUDIO_IN_OUT_Init

z.B.
https://community.st.com/thread/29960

Warum suchst Du nicht selber?

von Thomas K. (thomas_k502)


Lesenswert?

Hallo und danke für die schnellen Antworten,

ich habe meine Frage etwas falsch formuliert. Ich wollte mit der 
besagten Funktion die Audiodaten des Onboard-Miko ausgeben. Allerdings 
gibt es wenig Dokumentation über diese Funktion im Netz aber ich hatte 
noch nicht die Zeit mir den Code anzuschauen. Heute werde ich mir die 
Sache mal genauer anschauen.

von Thomas K. (thomas_k502)


Lesenswert?

Kann mir jemand sagen, wie ich prüfen kann, ob der  STM Audiodaten 
empfangen hat? Abspielen eines im RAM liegenden Buffer funktioniert, 
sogar für kleine Felder (kleiner 70 byte), was bei dem stm32f4 nicht 
möglich war. Beim einlesen der Daten und abspeichern in einem Feld habe 
ich jedoch keinen Erfolg. Wenn ich mit dem Debugger prüfe, welche Daten 
im Buffer liegen, bekomme ich nur Nullen.

von here (Gast)


Lesenswert?

Thomas K. schrieb:
> Kann mir jemand sagen, wie ich prüfen kann, ob der  STM Audiodaten
> empfangen hat?
Ich hätte mir eine kleine Konsole im STM programmiert, und dort die 
nötigen Befehle zum (high-level-)Debugging untergebracht...

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.