Running the SAI Low Power Audio Example using GStreamer - Using the i.MX 8M Plus

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Running the SAI Low Power Audio Example using GStreamer - Using the i.MX 8M Plus

Running the SAI Low Power Audio Example using GStreamer - Using the i.MX 8M Plus

1. Intro

 

This document contains instructions to run run the SAI low power audio demo on the i.MX 8M Plus EVK.

Here, the  RPSMG to allows audio to be passed from the A53 cluster running Linux to the M7 core. The latter controls the on board WM8960 audio codec,  which is connected to a 3.5 mm audio jack that allow us to play music using headphones.

I will show the necessary steps to make the demo work and will add some GStreamer examples to demonstrate the demo's capabilities.

 

TBD: update this with a nice diagram that depicts the A53 and M7 RPMSG channel.

2. Requirements

 

Hardware 

  • MX 8M Plus EVK
  • Headphones with 3.5 mm audio jack
  • Type-C power supply for i.MX 8M Plus EVK
  • Micro USB to USB adapter cable

Software 

3. Reference documentation for this example

 

MCUXpresso SDK

 

[1] Getting Started with MCUXpresso SDK for EVK-MIMX8MP

    Available within the MCUXpresso SDK package:  \{INSTALL PATH}\SDK_X_X_X_EVK-MIMX8MP\docs 

 

[2] SAI low power audio README file

Contains instructions for the SAI Low Power Audio Demo.

 Available within the MCUXpresso SDK package: \{INSTALL PATH}\SDK_X_X_X_EVK-MIMX8MP\boards\evkmimx8mp\demo_apps\sai_low_power_audio

 

4. Downloading a pre-built Linux BSP image for the i.MX 8M Plus

 

I will make use of the prebuilt Linux Image for the i.MX 8M Plus EVK for demonstrating the demo works.  At the moment of writing this time, I used the 5.15.32 release, although there are older releases like 5.10.5 that I tested and proved to work with no issues.

This SAI Low Power Audio Demo shall work for other processors on the i.MX 8M family. Although specific instructions ( e.g. load address for M-core binary load) might require some adaptation. For M-core load address, please refer to the specific MCUXpresso SDK documentation for each processor.

The prebuilt Linux image (5.15.32) for the i.MX 8M Plus EVK can be downloaded from here:
https://www.nxp.com/webapp/Download?colCode=L5.15.32_2.0.0_MX8MP&appType=license

You can download other releases from here: Embedded Linux for i.MX Applications Processors | NXP Semiconductors . Select a version and a board and select download.

5. Flashing the BSP image

 

If you are using an Ubuntu 20.04 workstation, I recommend you to flash the image using dd. For this, you can refer to the i.MX Linux User's Guide:

Section - 4.3.2 Copying the full SD card image - https://www.nxp.com/docs/en/user-guide/IMX_LINUX_USERS_GUIDE.pdf

sudo dd if=.wic of=/dev/sdx bs=1M && sync

NOTE: when using dd, ALWAYS, double check the of device that you are about to writing. Messing up with another location or partition will harm your system

 

If you are following this document on a Windows machine:

You can use the Universal Update Utility (UUU) to flash your image on either the board's eMMC or SD card.

Document named UUU.pdf shall serve as your reference guide for further instructions and flashing examples. It is available along with UUU binary here: https://github.com/NXPmicro/mfgtools/releases

Two examples are shown below for your convenience:

                                    SD card flash

                                                uuu -b sd_all bootloader rootfs.sdcard.bz2

                                    eMMC flash

                                                uuu -b emmc_all bootloader rootfs.sdcard.bz2

       uuu uuu.auto

NOTE: UUU is also compatible with Ubuntu

NOTE: there are other engineers who like to use BalenaEtcher for flashing their BSP images. I have tested it and works on both Ubuntu and Windows 10 machines.

 

6. Preparing the BSP and booting up M7 core  using U-Boot

 

I am writing this upon the instructions contained on the README file for the low power audio example  [2]. Instructions ready to copy and paste will follow:

 

Instruct U-Boot to pass to the kernel the rpmsg device tree to enable communication between the A53 cluster and the M7 one:

u-boot=>setenv fdtfile imx8mp-evk-rpmsg.dtb
u-boot=>saveenv

Load the M7 example:

u-boot=>setenv mmcargs 'setenv bootargs ${jh_clk} console=${console} root=${mmcroot} snd_pcm.max_alloc_per_card=134217728'
u-boot=>saveenv

Now, we need to load the M4 with the demo. Refer to [1] for further information. If running the BSP on an SD card, make sure the example binary is listed on the boot partition as follows:

fatls mmc 1:1

You shall see something similar to this:

            imx8mp_m7_TCM_sai_low_power_audio.bin

Open the serial terminal emulator for the M7. Out of the fourth ports listed when we plug the i.MX 8M Plus serial debug cable to the PC, the M7 is typically the last one listed.

 

All the serial ports available to the workstation when the i.MX 8M Plus serial cable is connected to it. NOTE: you may require to install addtitional COM drivers if you are running on Windows.All the serial ports available to the workstation when the i.MX 8M Plus serial cable is connected to it. NOTE: you may require to install addtitional COM drivers if you are running on Windows.

I like doing the previous step so I can see the result of the next commands issued in U-boot to load the M7 image.

fatload mmc 1:1 0x48000000 imx8mp_m7_TCM_sai_low_power_audio.bin;
cp.b 0x48000000 0x7e0000 20000;
bootaux 0x7e0000

Here is an screenshot that shows how the U-Boot's response should look:

U-Boot response when loading the SAI low power audio example to the Cortex M7U-Boot response when loading the SAI low power audio example to the Cortex M7

That should have prompted the following message on the M7 terminal:

M7-core is up!M7-core is up!

 

Now, let’s move to user space!

u-boot=> boot

7. Testing the example using a simple GStreamer pipeline

 

As soon as the O.S. finishes booting. We can see that M7 terminal prompts the following:

M7 is now in STOP mode; waiting for some audio to beat the room!M7 is now in STOP mode; waiting for some audio to beat the room!

Confirm that the WM8960 is listed as audio card as follows:

 cat /proc/asound/cards

           Listing avaialable audio cards. WM8960 should be present.Listing avaialable audio cards. WM8960 should be present.

Make note of the list. The wm8960 is listed a the third sound card.

This is where I like to differ a bit from [2] and I suggest a quicker test in case of not having an audio file ready. We just simply use GStreamer to play an audiotest source. Please make sure to plug in your headphones onto the board’s 3.5 mm jack before.

 

The following GStreamer pipeline is using the WM8960 as an audiosink. 

gst-launch-1.0 audiotestsrc ! alsasink device=hw:3
 

NOTE: please be cautious and not put the headphones directly in your head at the first attempt. The sound can be too loud to some people.

This is what you should see on the M7 side:

Picture6.png

Stop the GStreamer pipeline issuing CTRL + C. M7 shall warn you about that:

Picture7.png

NOTE: you can use the aplay command to play audio as shown on [2]. However, I consider using a testsrc is much quicker and flexible for a quick test. 

8. Additional information

 

Feel free to go ahead and tweak the GStreamer pipeline to change audio test source properties. audiotest src.

This command will let you know the available options:           

 gst-inspect-1.0 audiotestsrc

           
            NOTE: you can navigate through the displayed list using the “d”key. Press “q’’ to quit.

For example:

 

Picture8.png

Picture9.png

Picture10.png

 

For example, I am reproducing sound using a different setup based on the list above:

gst-launch-1.0 audiotestsrc freq=4000 volume=0.8 wave=8 ! alsasink device=hw:3

9.  Errata and future updates

 

TBD:  

  •   Add an example on how to define the default audio card and play the audio either using gst-play or building the pipeline using filesrc
  • Comment on the limitations of the M7 core regarding sample rate and audio formats

 

100% helpful (1/1)
Version history
Last update:
‎07-07-2022 05:46 PM
Updated by: