STM32 project design: music player based on STM32F4 (UCOSIII operating system, GUI control)

STM32-based music player

Insert picture description here
Bilibili video link: https://www.bilibili.com/video/BV1cp4y1678G/
Data link: https://download.csdn.net/download/mbs520/13711787
Baidu network disk link: https://pan. baidu.com/s/1G-Q1CA1Px8RSZJtTYjmELw
Extraction code: abcd

Remember to like

1. Project requirements:

Hardware driver + software tool project

Technology required for the project:

  • UCOSIII
  • GUI display
  • IIS protocol
  • Sound card driver-information and reference code provided
  • SD card driver-information and reference code provided
  • Fatfs file system
  • IIC/SPI and W25Q128 driver
  • The use of font library on MCU screen
  • Porting and use of mp3 and WAV decoding library-information and reference code provided
  • Transplantation and use of JPG and BMP decoding library-information and reference code provided
  • DMA use

The function is basically the same as the current MP3 device

①Able to scan the directory of the SD card to obtain music files (.mp3.wav, etc.) through the embedded file system of the SD card driver

②Drive the WM8978 sound card chip to use IIS to transmit the audio data read from the SD card to the sound card and control the sound card to play music

③Able to display MP3 player related information and
song name on the mcu screen . . . .

You can use the font library to display related Chinese

2. Material preparation

1. One STM32F4 development board (need audio interface support) (GEC M4 I use)
(Note that you need to buy an LCD screen that can be plugged in, preferably with onboard wm8978, if not, you can connect an audio driver module)
Function: master chip, process various data
Insert picture description here
or:
Insert picture description here
+
Insert picture description here

2. 800*480 4.3 inch capacitive touch LCD screen (the Punctual Atom screen I use)
(Note that it is not compatible with other resolution screens)
Function: display and touch control
Insert picture description here
3, an SD card below 32G and a card reader

Function: store necessary files such as mp3, wav files, picture files, etc.
Insert picture description here

2. Hardware connection

1. Just plug the screen into the development board

Three, download and debug

1. Download the relevant information.
Insert picture description here
2. Download the source code to the microcontroller.
3. Copy the SD card root directory file to the SD card root directory.
Insert picture description here
4. Power on the system and supply enough power, otherwise the screen is half bright and the sound card driver is abnormal.
The transplantation is successful if the pictures and button controls can be displayed normally.

Four, related knowledge points

(1) FATFS file system (it is used to read and write SD card files)

1. FATFS is a completely free and open source FAT file system module, specially designed for small embedded systems. It is completely
written in standard C language, so it has good hardware platform independence and can be transplanted to 8051, PIC, AVR, SH,
Z80, H8, ARM and other series of microcontrollers with simple modifications. It supports FATl2, FATl6 and FAT32, and supports multiple storage media;

2. Why do I need a file system?
Because the SD card is only a kind of memory, ordinary read and write operations can only be read for addresses. The data read is all character data, and there is no concept of files. SD cards that have added a file system can use FATFS files. The system manages, for example, if you want to store a picture, you only need to store it in the form of a file, while ordinary reading and writing can only store the picture data byte by byte in a designated memory. Reading must be strictly based on Address location read

3. Punctuality Atom provides a relatively easy-to-use FATFS source code that can be directly transplanted. The
code file can be downloaded from the Punctuality Atom official website.
The following are the main API functions: Perform a series of operations such as reading and writing files, similar to C language file IO Similar, you should know the general purpose by looking at the file name

Insert picture description here

(2) MP3 player

Write next time, I'm sleepy~o~

(3) Picture display
Write next time, I'm sleepy~o~

(4) GUI interface
Write next time, I'm sleepy~o~

Five, program display

Show some key codes:


#include "stm32f4xx.h"


/*  开始任务  */
//任务优先级
#define START_TASK_PRIO		3
//任务堆栈大小	
#define START_STK_SIZE 		128
//任务控制块
OS_TCB StartTaskTCB;
//任务堆栈	
CPU_STK START_TASK_STK[START_STK_SIZE];
//任务函数
void start_task(void *p_arg);

/*  主任务  */
//任务优先级
#define MAIN_TASK_PRIO		6
//任务堆栈大小	
#define MAIN_STK_SIZE 		512
//任务控制块
OS_TCB MainTaskTCB;
//任务堆栈	
CPU_STK MAIN_TASK_STK[MAIN_STK_SIZE];
//任务函数
void main_task(void *p_arg);



//系统初始化
void sys_init(void)
{
    
    
	u8 key;
	
	uart_init(115200);  //串口初始化
	LED_Init();         //LED初始化
	KEY_Init();
	LCD_Init();					//LCD初始化  
	
	FSMC_SRAM_Init();			//SRAM
	tp_dev.init();			//触摸初始化	
	W25QXX_Init();				//初始化W25Q128
	gui_init();          //gui初始化
	
	my_mem_init(SRAMIN);		//初始化内部内存池 
	my_mem_init(SRAMEX);		//初始化外部内存池 
	my_mem_init(SRAMCCM);		//初始化CCM内存池 
	exfuns_init();				//为fatfs相关变量申请内存  
  	f_mount(fs[0],"0:",1); 		//挂载SD卡 
 	f_mount(fs[1],"1:",1); 		//挂载FLASH.
	piclib_init();										//初始化画图	  
	
	while(font_init()) ;			//检查字库
	while(WM8978_Init());//检查音频芯片是否正常
}

int main(void)
{
    
    
	OS_ERR err;
	CPU_SR_ALLOC();
	
	delay_init(168);  	//时钟初始化
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//中断分组配置
	
	sys_init();    //系统初始化
	delay_ms(150);   
	LCD_Clear(GRAY);//清屏
	
	
	OSInit(&err);		//初始化UCOSIII
	OS_CRITICAL_ENTER();//进入临界区
	//创建开始任务
	OSTaskCreate((OS_TCB 	* )&StartTaskTCB,		//任务控制块
				 (CPU_CHAR	* )"start task", 		//任务名字
                 (OS_TASK_PTR )start_task, 			//任务函数
                 (void		* )0,					//传递给任务函数的参数
                 (OS_PRIO	  )START_TASK_PRIO,     //任务优先级
                 (CPU_STK   * )&START_TASK_STK[0],	//任务堆栈基地址
                 (CPU_STK_SIZE)START_STK_SIZE/10,	//任务堆栈深度限位
                 (CPU_STK_SIZE)START_STK_SIZE,		//任务堆栈大小
                 (OS_MSG_QTY  )0,					//任务内部消息队列能够接收的最大消息数目,为0时禁止接收消息
                 (OS_TICK	  )0,					//当使能时间片轮转时的时间片长度,为0时为默认长度,
                 (void   	* )0,					//用户补充的存储区
                 (OS_OPT      )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR, //任务选项
                 (OS_ERR 	* )&err);				//存放该函数错误时的返回值
	OS_CRITICAL_EXIT();	//退出临界区	 
	OSStart(&err);  //开启UCOSIII
	while(1);
}

//主任务
void main_task(void *pdata)
{
    
    
	while(1)
	{
    
    
		audio_play();//音乐播放器
		LCD_Clear(WHITE);
		delay_ms(1000);
	}
} 

Guess you like

Origin blog.csdn.net/mbs520/article/details/111313042