The STM32 series microcontroller uses the latest Cortex-M3 core of ARM. The VSl003 audio decoder chip is the third generation product of the VSlOxx series. It is a single-chip MP3/WMA/MIDI decoder and ADPCM encoder chip produced by VLSI Solution of Finland. This paper uses the STM32 series microcontroller, combined with the decoder chip VSl003, SD card, LCD and other peripherals to design and implement an MP3 player. Its main functions are: play all audio files supported by VSl003, such as MP3, WMA, WAV files, and the sound quality is very good; control the previous/next song, volume increase and decrease, etc. through the joystick; display the song name and playback status through the LCD; this system also implements the card reader function, and the PC can directly read and write the SD card on the development board through the USB interface to facilitate the copying of audio files.
1 STM32 processor
Cortex-M3 is the latest processor core based on ARMv7 architecture launched by ARM. It has the characteristics of high performance, low cost and low power consumption, and is specially designed for embedded applications.
ARMv7 architecture adopts Thumb-2 technology, which is developed on the basis of ARM's Thumb code compression technology and maintains complete code compatibility with existing ARM solutions. Thumb-2 technology uses 31% less memory than pure ARM code, reduces system overhead, and can provide 38% higher performance than Thumb technology.
In terms of interrupt processing, Cortex-M3 integrates Nested Vectored Interrupt Controller NVIC (Nested Vectored Interrupt Controller). NVIC is a tightly coupled part of Cortex-M3 processor, which can configure 1 to 240 physical interrupts with 256 priorities and 8 levels of preemption priority, providing excellent exception handling capabilities for the processor. At the same time, the use of preemption, tail chaining and late arrival technology greatly shortens the response time of abnormal events. During the Cortex-M3 exception handling process, the processor state is automatically saved and restored by hardware, which further shortens the interrupt response time and reduces the complexity of software design.
The Cortex-M3 architecture proposes a new single-line debugging technology. The trace debugging of the Cortex-M3 processor is implemented through the debug access port (Debug Access Port, DAP). The DAP port can be used as a serial wire debug port (SW-DP) or a serial JTAG debug port (SWJ-DP, allowing JTAG or SW protocol). Among them, SW-DP only needs two pins, clock and data, to achieve low-cost trace debugging, avoid using multiple pins for JTAG debugging, and fully support RealView compiler and RealView debugging products. In addition, Cortex-M3 also has the characteristics of high integration, which greatly reduces the chip area. It integrates many tightly coupled system peripherals internally, reasonably utilizes the chip space, and enables the system to meet the control requirements of the next generation of products.
The STM32 series is a microcontroller based on the Cortex-M3 core. It expands high-performance peripherals on the basis of the Cortex-M3 core.
2 VS1003 MP3/WMA audio codec
VS1003 contains a high-performance, low-power DSP processing core (VSDSP), a working memory, a 5.5KB RAM for user programs, a serial SPI bus interface, a high-quality oversampling DAC with adjustable sampling frequency, and a 16-bit sampling ADC. The internal structure of VS1003 is shown in Figure 1.
The MP3 playback process is that STM32 takes data from the SD card through the SPI1 interface, and then sends it to the decoding chip VS1003 for decoding and playback through the SPI2 interface. Here, the decoding module uses a separate SPI interface to reduce interference and noise and improve sound quality.
3 System hardware design
The system is divided into 6 modules in terms of hardware: microcontroller STM32F103, decoding module VSl003, storage module SD card, control joystick, USB interface and display LCD. The system hardware framework is shown in Figure 2.
The following describes the hardware connection between the system's storage module SD card, decoding chip VSl003 and STM32.
3.1 Connection between SD card and STM32
The system uses the STM32 internal interface SPIl to communicate with the SD card. The following describes its pin connection.
PE3: Low level is valid, connected to the chip select pin CD/DAT3 of the SD card. When SPI communicates with the SD card, PE3 needs to be pulled low to operate the SD card.
PA7: Mapped to the master output slave input (MOSI) signal line of the STM32 internal interface SPIl. Here STM32 is the master device and the SD card is the slave device. The data flow is transmitted from STM32 to the SD card. This signal line is used to transmit some control commands to complete SD card operations, such as reading and writing.
PA5: Connected to the clock (SCLK) signal line of the STM32 internal interface SPIl. The SPI clock frequency can be set to adjust the speed of reading SD card data.
PA6: Connected to the master input slave output (MISO) signal line of the STM32 internal interface SPIl. The data transmission direction is from the SD card to the STM32, mainly returning some states of the SD card, internal register values, etc.
PCI2: used to detect whether the SD card is fully inserted. When the SD card is fully inserted, PCl2 is low level, otherwise it is high level.
3.2 Connection between VSl003 and STM32
The system uses the STM32 internal interface SP12 to communicate with VSl003. The following describes its pin connection.
PA3: Interrupt request pin of VSl003. When the internal data of VSl003 has been processed and new data is required, DREQ is pulled high. STM32 sends a new data stream to VSl003 based on this signal.
PBl3: The clock (SCLK) signal line connected to the STM32 internal interface SPI2.
PBl4: The master input slave output (MISO) signal line connected to the STM32 internal interface SPI2. Here STM32 is the master device and VSl003 is the slave device. The data stream is transmitted from VSl003 to STM32. Mainly used to read some states and internal register values of VSl003, such as the value of the internal register returned by the register test.
PBl5: Connected to the master output slave input (MOSI) signal line of the STM32 internal interface SPl2. Here STM32 is the master device and VSl003 is the slave device. The data flow direction is from STM32 to VSl003, mainly transmitting some control commands, MP3/WMA data streams, etc. to VSl003.
PA1: Low level is valid. If this pin is pulled low, the control signal is transmitted through SPI. The control signal includes reading and writing the internal registers of VSl003, initializing VSl003, setting the volume of left and right channels, etc. PA2: Low level is valid. If this pin is pulled low, the data signal is transmitted through SPI. For example, this pin needs to be pulled low when transmitting MP3/WMA data stream to VSl003.
PA0: Low level is valid. Pulling this pin low will reset VSl003 by hardware. [page]
4 System software design
The software of this system is developed by the integrated development tool RealView MDK Professional Edition, which has powerful compiling, linking and debugging functions. The software structure is shown in Figure 3. The working process of this system is roughly as follows: STM32 reads MP3/WMA files from the SD card through SPI1, and sends the read data stream to the VS1003 decoder through SPl2 for playback; the PC can read and write the contents of the SD card through the USB bus, and transfer MP3/WMA and other files; the LCD display is used to display the file name and playback status of the MP3. The five-dimensional joystick is shaken left and right to control the previous/next song, shaken up and down to control the volume, and pressed to control play/pause.
Since the speed of SPI1 reading SD card files is much faster than the speed of VS1003 playing data streams, SPI1 can read the data required for the next playback from the SD card while VS1003 is playing the data stream from SPI2, and there will be no discontinuous sound. Since two SPI interfaces are used, there is no interference between them, and the efficiency of the file system is improved, so this system can obtain very high-quality music.
Due to space limitations, only two core modules of the software are introduced below.
4.1 SD module
The SD module mainly provides SD card drivers and functions for operating the FAT file system. The FAT file system supports long file names. This module mainly contains two files, msd.c and fat16.c. The functions of their main functions are introduced below.
4.1.1 msd.c
This file is used to provide SD card drivers and mainly includes the following functions.
SPI_Config: Configure SPI1 and related GPIOs connected to the SD card.
MSD_Init: Initialize SD card communication.
Get_Medium_Characteristics: Get relevant information such as the capacity and block size of the SD card.
MSD_GoIdleState: Put the SD card in idle state.
MSD_SendCmd: Send a command to the SD card.
MSD_GetResponse: Get a response from the SD card.
MSD_GetStatus: Get the status of the SD card.
MSD_WriteBlock: Write 1 block of data to the SD card.
MSD_ReadBlock: Read 1 block of data from the SD card.
The following is the implementation of the function MSD_ReadBlock:
4.1.2 fat16.c
This file provides support for FAT16 file system, mainly including the following functions.
ReadMBR: Read MBR data structure.
ReadBPB: Read BPB data structure.
ReadFAT: Read the specified item of file allocation table.
ReadBloek: Read a sector of SD card.
FAT_Init: Get the basic information of FAT16 file system.
DirStartSec: Get the starting sector number of root directory.
DataStartSec: Get the starting sector number of data area.
ClusConvLBA: Get the starting sector number of a cluster.
LBAConvClus: Convert the relationship between sector number and cluster number.
GetFileName: Get the first sector number of the specified file.
ListDateTime: List the date and time when the file or subdirectory is created.
SearchFoler: Search for files or subdirectories in the specified range.
ListDir: List files or subdirectories and related information in the specified range.
FAT_FileOpen: Open the specified file.
FAT_FileRead: Read file data.
4.2 VSl003 module
The VSl003 module mainly provides the driver for the decoding chip VSl003, and provides a basic interface for the application layer to play audio data, control volume channels, etc. This module mainly contains the file vsl003.c. The functions of its main functions are as follows.
The vsl003.c file mainly provides the driver for the VSL003 chip, including the following main functions.
VSL003_Config: Configure the relevant pins connected between STM32 and VSl003, including SPl2, PA0, PA1, PA2, and PA3.
SPIGetChar: Read 1 byte from VSl003 via SPI.
SPIPutChar: Write 1 byte to VSl003 via SPI. If it is an MP3/WMA data stream, VSl003 will start decoding and playing.
Mp3ReadRegister: Read the value of the VSl003 register.
Mp3WriteRegister: Write the VSl003 register.
Mp3Reset: Reset VSl003, including software reset and hardware reset.
Mp3SoftReset: VSl003 software reset, set the clock, sampling rate, emphasis, volume, stereo and other parameters. Generally, a software reset is required between two songs.
VsSineTest: Play sine sound waves to test whether the connection between VSl003 and STM32 is intact.
Conclusion
This article proposes a design scheme for an MP3 player based on STM32, and uses the ARM development tool RealView MDK to implement a prototype of the scheme. Although this scheme cannot be used as a general MP3 solution, it has a certain reference value for industrial control, automotive electronics, medical electronics and other solutions that require certain audio. In addition, this system uses multiple peripheral interfaces of the STM32 processor, which can also be used as a reference for readers.
Previous article:Design of Embedded Web Server Based on Cortex-M3 Core Processor
Next article:Research on the Exception Handling Mechanism of Cortex-M3
Recommended ReadingLatest update time:2024-11-16 23:43
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Very pleasantly surprised, let me show you the winning nail clipper set.
- SensorTile.box accelerometer IIS3DHHCTR test project
- AD When viewing in 3D, the color cannot be changed in any way, it is just one color.
- Jiuxing shares - causes and hazards of motor bearing heating
- After the medical equipment is completed, how can we protect the security of our programs?
- How to select external clock and external memory for TI DSP?
- Can UST_OTG1 be used with a USB flash drive?
- Altium Designer 20.0.9.164
- "Introduction to Arduino Interactive Design with Perfect Illustrations" - Getting Started with Microcontrollers from Scratch
- TI wM-Bus 169MHz RF Subsystem with Receiver for Smart Gas and Water Meters