ST STM32F103 Series Application Note

How to use the high-density microcontroller to play audio files with an external i2s audio codec
Hide thumbs Also See for STM32F103 Series:

Advertisement

How to use the high-density STM32F103xx microcontroller
Introduction
This application note describes how to use the high-density STM32F103xx I
play audio files using an external codec.
2
The I
S protocol is widely used to transfer audio data from a microcontroller/DSP to an
audio codec in order to play melodies (stored in a memory) or, to capture analog sound
(from a microphone).
The high-density STM32F103xx allows I
and implements specific functionalities for this communications mode.
The first, preliminary section of this application note may be skipped by advanced users.
Note:
Throughout this document, and unless otherwise specified, the term of I
refer to the I
STM32F103xx microcontrollers.
May 2008
to play audio files with an external I²S audio codec
2
S feature of the SPI peripheral that is implemented in high-density
Application note
2
S audio communications using the SPI peripheral,
Rev 1
AN2739
2
S feature to
2
S will be used to
1/26
www.st.com

Advertisement

Table of Contents
loading

Summary of Contents for ST STM32F103 Series

  • Page 1 Note: Throughout this document, and unless otherwise specified, the term of I S will be used to refer to the I S feature of the SPI peripheral that is implemented in high-density STM32F103xx microcontrollers. May 2008 Rev 1 1/26 www.st.com...
  • Page 2: Table Of Contents

    Contents AN2739 Contents S general description ........5 S protocol .
  • Page 3 AN2739 List of tables List of tables Table 1. Driver library description ........... 11 Table 2.
  • Page 4 List of figures AN2739 List of figures Figure 1. S Phillips protocol waveforms 16/32-bit ........5 Figure 2.
  • Page 5: S General Description

    AN2739 S general description S general description S protocol S (IC-to-IC sound) is an audio data transfer standard using a three-line bus for serial and synchronous data transmission. Data are transmitted on the SD line (Serial Data) in Little Endian format (MSB first). Data length is not limited (usually 16/20/24/32/64 bits).
  • Page 6: Stm32F103Xx I

    S general description AN2739 Figure 2. S protocol signal description and configuration Transmitter Receiver Transmitter Receiver Transmitter = Master Receiver = Master Controller Transmitter Receiver Controller = Master ai15113 STM32F103xx I S feature presentation The STM32F103xx implements the I S feature as a mode included in the SPI peripheral. The user has to choose either the SPI mode or the I S mode (software configuration).
  • Page 7 AN2739 S general description To decide if MCLK should be generated or not, the following facts have to be taken into consideration: ● The external I S device requirements (codec/DAC). In general these devices need a master clock (usually at the rate 256 × F ) to perform internal and sampling operations.
  • Page 8: Implementation Example

    Implementation example AN2739 Implementation example General overview The example presented in this application note aims at providing typical hardware and software implementation basics for an audio application like portable audio players, sound synthesis systems, speech recorders, cell phones or interactive control boards. Typically, the system embeds: –...
  • Page 9: Audio Codec

    AN2739 Implementation example Other board resources are used to interface the application: ● Audio codec: AK4343 implemented on the STM3210E-EVAL and connected to the I2S2 interface (and to relative passive components). ● Stereo audio speaker and audio jack connected to the audio codec and implemented on the STM3210E-EVAL.
  • Page 10: Stm32F103Xx And Board Configuration

    Implementation example AN2739 When the MCLK clock is enabled (by configuring the relative configuration register), MCKI jumper (JP18) should be configured in the 2<>3 position in order to drive the MCLK signal from the STM32F103xx I S interface to the codec MCLKI pin. The default codec configuration used in this application note is: ●...
  • Page 11: Firmware Description

    AN2739 Implementation example For more details, refer to the STM3210E-EVAL evaluation board user manual on www.st.com. Firmware description This application note is based on: ● the STM32F10xxx firmware library ● the I2S_CODEC driver firmware (offering the main functions required to control the...
  • Page 12: I2S_Codec_Init Function

    Implementation example AN2739 Table 2. I2S_CODEC driver high-level functions (continued) Function name Description Increments the audio file pointer by a fixed step (percentage of the I2S_CODEC_ForwardPlay file length) then continues playing. Decrements the audio file pointer by a fixed step (percentage of I2S_CODEC_RewindPlay the file length) then continues playing.
  • Page 13: Configuration Parameters List

    AN2739 Implementation example Table 4 lists all the parameters that have to be set in order to correctly configure the application (some are automatically set by the I2S_CODEC_Init function, others are constants defined in the driver files). Table 4. Configuration parameters list Parameters Values Location...
  • Page 14: I2S_Codec_Play Function

    Implementation example AN2739 ● I2S_CODEC_Play function This function starts playing the audio file from a programmable position. Table 6. I2S_CODEC_Play function Function name I2S_CODEC_Play Prototype u32 I2S_CODEC_Play(u32 AudioStartPosition) Sets the memory read address to AudioStartPosition and enables the I Behavior description interrupt to begin sending audio data to the codec.
  • Page 15: I2S_Codec Medium-Level Driver Functions

    AN2739 Implementation example Medium-level functions Medium-level functions are used to better control some basic functionality and the audio stream. Table 8 presents these functions. Table 8. I2S_CODEC medium-level driver functions Function name Description Sends the audio data using the SPI2 peripheral and checks the audio play status (if a (Pause/Stop) command is pending) by calling the I2S_CODEC_UpdateStatus function.
  • Page 16: I2S_Codec Low-Level Driver Functions

    Implementation example AN2739 Low-level functions Some low-level functions provide flexible management of the memory (SPI Flash/NOR, etc.). Other types of memories can be supported simply by replacing the body of these low- level functions by the corresponding functions for the memory. Example: the Media_Init function should contain the entire memory initialization procedure.
  • Page 17 AN2739 Implementation example Figure 6. Driver’s functional flowchart 2 I2S_CODEC_Data End of stream Transfer Codec configuration AudioReplay ==0 phase Audio file Send dummy Read data from AudioReplayCount data on I2S2 memory > 0 Send data on I2S2 AudioReplayCount-- Stop Increment AudioReplayCount = data index Play...
  • Page 18: Demo Firmware Description

    Implementation example AN2739 2.3.2 Demo firmware description The demo uses the i2s_codec driver functions to control the audio stream. Other functions are implemented to make the application interactive. Two main functions are handled by the application: ● Joystick and push-button input control ●...
  • Page 19: Table 12. Lcd_Update Function

    AN2739 Implementation example LCD_Update function The LCD configuration and the current audio stream information display operations are performed by the LCD_Update function as detailed in Table Table 12. LCD_Update function Function name LCD_Update Prototype void LCDUpdate(u32 Status) Updates the information displayed on the LCD according to the parameter Behavior description Status.
  • Page 20 Implementation example AN2739 Demo firmware flowcharts Figure 7 presents the overall function flowchart. Figure 7. Demo’s functional flowchart 1 SystemTick event Main.c Up/down push-putton pressed Configure SystemTick Key push-button pressed LCD configuration and welcome screen display Right/Left push-button pressed Joystick and Key configuration SEL push-button pressed...
  • Page 21 AN2739 Implementation example Figure 8. Demo’s functional flowchart 2 Up/Down Key push-button Right/Left push-button SEL push-button push-button pressed pressed pressed pressed Current status = Current status = LCD_Update Forward/rewind Playing Playing (STOP) LCD_Update LCD_Update LCD_Update LCD_Update LCD_Update Stop (ALL) (VOL) (PAUSE) (PLAY) (FRWRWD)
  • Page 22: Timing Considerations

    Implementation example AN2739 ● Use the STMicroelectronics DFU demonstration firmware to compile any audio file and load it into the memory (for more details, refer to the DFU section in the STM3210E- EVAL evaluation board demonstration user manual). Once this DFU image is loaded, the file address has to be set (using the AUDIO_FILE_ADDRESS constant in the main.h file) and the application note firmware can then run correctly.
  • Page 23: General, Allowed Parameters

    AN2739 Implementation example General, allowed parameters Audio file Supported audio configuration is: ● Format: PCM ● Channel number: Stereo/Mono ● Data length: 16 bits ● Frequency: 8 kHz, 16 kHz, 22.05 kHz, 44.1 kHz, 48 kHz (depending on the system clock frequency) ●...
  • Page 24: Conclusion

    Conclusion AN2739 Conclusion This application note explains the basics to build an interactive audio playing application using the STMicroelectronics evaluation board with an audio codec, a speaker, a headphone jack and an optional LCD. The application may be enhanced by adding/removing some options depending on the requirements.
  • Page 25: Revision History

    AN2739 Revision history Revision history Table 13. Document revision history Date Revision Changes 30-May-2008 Initial release. 25/26...
  • Page 26 No license, express or implied, by estoppel or otherwise, to any intellectual property rights is granted under this document. If any part of this document refers to any third party products or services it shall not be deemed a license grant by ST for the use of such third party products or services, or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoever of such third party products or services or any intellectual property contained therein.

Table of Contents