i.MX 8M Mini sai_low_power_audio

NXP提供 sai_low_power_audio程序,主要功能:A53核负责解码音乐文件然后放入内存中,最后通过SRTM(Simplified Real Time Messaging)通知M4核去内存中获取数据到TCM中,使用SDMA方式把数据传输到SAI和音频解码芯片进行播放。

编译

安装编译链和SDK:见上一篇imx8mm hello world编译

进入目录:SDK_2.5.0_EVK-MIMX8MM/boards/evkmimx8mm/demo_apps/sai_low_power_audio/armgcc

运行脚本:./build_all.sh

运行

拷贝sai_low_power_audio.bin文件出来,打开TFTP工具。

下载demo并运行

M4核打印显示

设置m4 dts并启动内核

测试

A53核播放音乐到SAI3 wm8524:

M4串口输入s启动sai_low_power_audio:

A53播放音乐文件到M4核:

可以看到M4核已经处于run的状态,这时候耳机里面听不到音乐的,因为M4核使用的是SAI1和I2C3通过FPC接口输出到底板外面,需要额外使用ak4497解码器盒子进行音乐的播放,且支持HIFI功能;由于手里没有ak4497解码器,所以不能验证M4播放音乐是否正常。

电路图

A53核对应的SAI3核WM8524图,可以正常的播放音乐文件。

M4核对应的SAI1 和I2C3,这里接ak4497解码器。

DTS

wm8524对应到sai3,没有挂I2C

ak4497d对应sai1,ak4497是挂载I2C3下面的。

代码

SDK_2.5.0_EVK-MIMX8MM/boards/evkmimx8mm/demo_apps/sai_low_power_audio/sai_low_power_audio.c

void Peripheral_RdcSetting(void)
{
    rdc_domain_assignment_t assignment = {0};
    rdc_periph_access_config_t periphConfig;

    assignment.domainId = BOARD_DOMAIN_ID;
    RDC_SetMasterDomainAssignment(RDC, kRDC_Master_SDMA3_PERIPH, &assignment);
    RDC_SetMasterDomainAssignment(RDC, kRDC_Master_SDMA3_BURST, &assignment);
    RDC_SetMasterDomainAssignment(RDC, kRDC_Master_SDMA3_SPBA2, &assignment);

    RDC_GetDefaultPeriphAccessConfig(&periphConfig);
    /* Do not allow the A53 domain(domain0) to access the following peripherals. */
    periphConfig.policy = RDC_DISABLE_A53_ACCESS;
    periphConfig.periph = kRDC_Periph_SAI1;
    RDC_SetPeriphAccessConfig(RDC, &periphConfig);
    periphConfig.periph = kRDC_Periph_UART4;
    RDC_SetPeriphAccessConfig(RDC, &periphConfig);
    periphConfig.periph = kRDC_Periph_I2C3;
    RDC_SetPeriphAccessConfig(RDC, &periphConfig);
    periphConfig.periph = kRDC_Periph_GPT1;
    RDC_SetPeriphAccessConfig(RDC, &periphConfig);
    /* Do not allow the m4 domain(domain1) to access SAI3.
     * The purpose is to avoid system hang when A core to access SAI3 once M4 enters STOP mode.
     */
    periphConfig.policy = RDC_DISABLE_M4_ACCESS;
    periphConfig.periph = kRDC_Periph_SAI3;
    RDC_SetPeriphAccessConfig(RDC, &periphConfig);
}

可以看到M4核设置的是SAI3。

疑问

可以把A53的SAI1关闭,然后M4使用SAI1可以进行播放音乐吗?【单独修改M4使用SAI1不行】

如果不使用m4 dts启动内核报下面错误:

应该是报I2C初始化冲突了,见下面m4 dts文件内容:

arch/arm64/boot/dts/freescale/fsl-imx8mm-evk-m4.dts 

/*
 * Copyright 2018 NXP
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#include "fsl-imx8mm-evk.dts"

/ {
	reserved-memory {
		#address-cells = <2>;
		#size-cells = <2>;
		ranges;

		m4_reserved: m4@0x80000000 {
			no-map;
			reg = <0 0x80000000 0 0x1000000>;
		};

	};

	rpmsg_i2s: rpmsg-i2s {
		compatible = "fsl,imx8mq-rpmsg-i2s";
		/* the audio device index in m4 domain */
		fsl,audioindex = <0> ;
		fsl,dma-buffer-size = <0x6000000>;
		fsl,enable-lpa;
		status = "okay";
	};

	sound-rpmsg {
		compatible = "fsl,imx-audio-rpmsg";
		model = "ak4497-audio";
		cpu-dai = <&rpmsg_i2s>;
		rpmsg-out;
	};

};

/*
 * ATTENTION: M4 may use IPs like below
 * ECSPI0/ECSPI2, GPIO1/GPIO5, GPT1, I2C3, I2S3, WDOG1, UART4, PWM3, SDMA1
 */

&i2c3 {
	status = "disabled";
};

&rpmsg{
	/*
	 * 64K for one rpmsg instance:
	 * --0xb8000000~0xb800ffff: pingpong
	 */
	vdev-nums = <1>;
	reg = <0x0 0xb8000000 0x0 0x10000>;
	status = "okay";
};

&sdma1{
	status = "disabled";
};

&uart4 {
	status = "disabled";
};

&sdma3 {
	status = "disabled";
};

&sai1 {
	status = "disabled";
};

&flexspi {
	status = "disabled";
};

可以看到只支持AK4497解码器,对A53使用的一些功能进行关闭避免冲突。

附readme.txt

Overview
========
In this demo, A core decoded music data and put it to DDR buffer and informs M4 with the related information. 
Then M4 will take the ownership of consuming the buffer, it will copy buffer from DDR to TCM, manipulating SDMA to transfer the data to SAI and codec for playback. 
It gives DDR and A core opportunity to do power saving for rather long time frame. M4 core will also take ownership of codec initialization.
SRTM(Simplified Real Time Messaging) protocol is used to communicate between A core an M4 core. 
The protocol provides various commands for A core and M4 core to communicate with each other. 
If there is no audio palyback, M4 will enter the STOP mode, and the whole SOC system would enter deep sleep mode(DSM) once A core enter low power status.

Toolchain supported
===================
- IAR embedded Workbench 8.30.2
- GCC ARM Embedded 7-2017-q4-major

Hardware requirements
=====================
- Micro USB cable
- MIMX8MM6-EVK  board
- J-Link Debug Probe
- 12V power supply
- Personal Computer
- Headphone

Board settings
==============
No special settings are required.

#### Note! ####
1.  This case does not support flash targets because of SDMA3 burst DMA not supporting for accessing flexspi.
2.  This case does not support ddr target because of the mass of the music data decoded by A core will be placed in DDR. 

Prepare the Demo
================
1.  Connect 12V power supply and J-Link Debug Probe to the board, switch SW101 to power on the board
2.  Connect a USB cable between the host PC and the J901 USB port on the target board.
3.  Open a serial terminal with the following settings:
    - 115200 baud rate
    - 8 data bits
    - No parity
    - One stop bit
    - No flow control
4.  Download the program to the target board.
5.  Launch the debugger in your IDE to begin running the demo.

******************
NOTE
******************
1.  The 48/96/192/384/768kHz, stereo, 16/24/32bit for PCM and DSD64/128/256/512 Music stream are supported
2.  Only ak4497 codecs on the audio board supported.
3.  Since the  DSD files are typically large, users could create a new large size patition in the SD card to place the music files.
4.  After M4 running, please make sure the linux kernel is boot up, then press "s" or "S" to start the demo.
5.  If there is no audio playback, the M4 will enter the STOP mode, then the whole system would enter DSM mode once A53 suspend.
    Press the ON/OFF button on the EVK board, could wakeup A53 core;
6.  Please make sure here exists xxx.wav file in the SD card.
    If the music file is placed at the Windows FAT32 paritions, after the linux kernel boot up and logged as root,
    using the "mount /dev/mmcblk1p1 /mnt" and then go to "/mnt" folder to playabck the music using the playback command.
    If the music file is placed at the Linux paritions, eg "/home", could playback the music dirctly using the playback command. 

******************
Playback command
******************
When playback the .wav file:
1.  If want to test free run, could use command: 
    aplay -Dhw:1 xxx.wav;
2.  If want to test pause command, could use command: 
    aplay -Dhw:1 -i xxx.wav -N;
    press space key on the keyboard to pause, and press the space key again to resume.
3.  If want to test play back for specified period-size, could use command:
    aplay -Dhw:1 -i --buffer-size=xxx --period-size=xxx xxx.wav -N &;
4.  Support music playabck when A core enters suspend.
    
When playback the .dsd/.dff file: 
1.  Enter folder where the DSD execution procedure exists, using command:
     "cd /unit_tests/ALSA_DSD"
2.  Then playback the DSD file, using command:
      "./mxc_alsa_dsd_player hw:1 music path"
    Please note that the "music path" means where the DSD file exists.
3.  Does not support the specified period-size by linux side; 
4.  Does not support music playabck when A core enters suspend; 

Running the demo
================
When the demo runs successfully, the log would be seen on the terminal like:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
####################  LOW POWER AUDIO TASK ####################

    Build Time: Sep 17 2018--09:32:59 
********************************
Please:
  1) Boot A53 kernel first to create the link between M core and A core;
  2) Then press "s" or "S" to start the demo.
********************************
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
M4 is running now, please boot the linux kernel and use the command to playback music.




Customization options
=====================

猜你喜欢

转载自blog.csdn.net/TSZ0000/article/details/90442624