ST AN3997 APPLICATION NOTE

AN3997
Application note
Audio playback and recording using the STM32F4DISCOVERY

1 Introduction

This application note describes the audio (wave) playback and recording application based on the STM32F4xx microcontroller and the STM32F4-DISCOVERY board.
The audio data (wave) can be read from the internal Flash memory of the STM32F4xx microcontroller or on an external USB key (through USB FS core in Host mode). The recorded wave can be stored only in the external USB key.
The recording process is based on ST MP45DT02 MEMS microphone hardware with a PDM audio software decoding Library (converting PDM data produced by the microphone to PCM data stored in the USB key).
The document is structured as follows:
A description of the principles of the audio playback and recording firmware and how to
run the firmware demonstration are provided in Section 2: Application overview.
Section 3 describes how to get started with the software and hardware.
The source code of this application is provided in the "STM32F4-DISCOVERY board firmware package" (V1.1.0 and later) under the following path 'Project\Audio_playback_and_record.

1.1 Reference documents

STM32F4DISCOVERY high-performance Discovery board data brief
Getting started with software and firmware environments for the
STM32F4DISCOVERY Kit (UM1467)
PDM audio software decoding on STM32 microcontrollers (AN3998)
STM32F40x reference manual (RM0090)
STM32F405xx STM32F407xx datasheet
The above documents are available at www.st.com/stm32f4-discovery.
October 2011 Doc ID 022390 Rev 1 1/15
www.st.com
Contents AN3997
Contents
1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1 Reference documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2 Application overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.1 Application description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.2 Firmware driver description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.3 Audio playback application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.3.1 Playback from USB key . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.3.2 Playback from internal Flash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.4 Audio record application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3 How to use the audio playback and recording application . . . . . . . . . 12
3.1 System requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.2 Running the application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2/15 Doc ID 022390 Rev 1
AN3997 List of figures
List of figures
Figure 1. Audio playback and record architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Figure 2. Audio playback and record modules. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Figure 3. Audio playback/record firmware driver flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Figure 4. Wave player procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Figure 5. Recording application procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Figure 6. Microphone connection. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Figure 7. Hardware environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Doc ID 022390 Rev 1 3/15
Application overview AN3997
MS19886V1
Codec (DAC)
I2S
Button
USB
host

2 Application overview

2.1 Application description

The audio playback and record applications support two types of mass storage media. They can play audio data in the internal Flash of the microcontroller or on an external USB key, and record data only to an external USB key. This is selected by defines in the main.h file. In the workspace toolbar, select the project configuration:
MEDIA_IntFLASH
MEDIA_USB_KEY
The firmware driver can:
Play a stored wave from an external USB key or internal Flash
Record a wave in an external USB key
Switch from play to record

Figure 1. Audio playback and record architecture

This application is based on a STM32F4xx device and an STM32F4-DISCOVERY board.
The main features of the application are:
MEMS microphone
Audio Codec DAC
Headphone
USB key (if this the storage media used)
MEMS accelerometer
4/15 Doc ID 022390 Rev 1
AN3997 Application overview
MS19887V1
I2C
Buttons
DMA
I2S
I2S
Internal
Flash
I/Os
USB host
Codec (DAC)
STM32
The main STM32 modules used by this application are:
USB peripheral: configured in Host mode. Mass Storage Class (MSC) is implemented
to transmit and receive audio data from/to USB key.
I2S peripheral: configured in Master Transmitter mode and used to transmit audio data
to the external audio codec (DAC). It is also used as a Master Receiver as an input clock for the MEMS microphone.
DMA: is used to transmit data from the buffers to the I2S peripheral. This significantly
reduces the CPU load.
I2C peripheral: is used to control several external devices like the audio Codec and to
obtain data from this device.
SPI peripheral: used to control the MEMS accelerometer.
User button: is used to monitor the applications (playback or record).

Figure 2. Audio playback and record modules

Note: This application note is based on the STM32 USB On-The-Go (OTG) host and device
library. For more details about the USB Host stack and a mass storage demonstration, please refer to the “STM32F105/7, STM32F2xx and STM32F4xx USB On-The-Go host and device library” user manual (UM1021).
Doc ID 022390 Rev 1 5/15
Loading...
+ 10 hidden pages