i.MX DSP User's Guide
i.MX DSP User's Guide
Contents
1 Introduction 1 Introduction......................................1
This document provides an overall introduction to the DSP including system 2 System Architecture........................ 1
3 File organization.............................. 5
architecture, file organization, DSP-related toolchain, and so on. This
4 Building DSP Framework on Linux
document helps with the overall understanding of the DSP-related code.
OS................................................... 6
Currently, the DSP is used to decode and encode audio streams on the i.MX 5 Building DSP Framework on
8QXP, 8QuadMax, 8M Plus, and 8ULP platforms. Windows OS....................................9
The current DSP framework can support several clients. They support 6 Building DSP Wrapper and Unit Test
...................................................... 15
these codecs:
7 Usage of DSP Binary Files............15
Decoder: 8 Building Codec Wrapper and Codec
Library........................................... 16
• AAC-LC 9 Revision History............................ 18
• AAC plus(HE-AAC/HE-AACv2) 10 Appendix A. Memory Allocation for
DSP............................................... 19
• BSAC
• DAB+
• MP2
• MP3
• DRM
• SBC
• OGG
• AMR-NB
• AMR-WB
• WMA
• WAV
• OPUS
Encoder:
• SBC
2 System Architecture
Figure 1 and Figure 2 provide the overall system architecture of the DSP-related code.
NXP Semiconductors
System Architecture
Application
GStreamer Android
DSP /unit_tests/DSP/dsp_test.out
Wrapper
User
space
Kernel
space
rpmsg
/dev/rpmsgx /dev/rpmsg_ framework Dma-buf
ctrlx
Vritio framework
virtio
Remote proc
Remoteproc framework
Mailbox
Hardware SOC
MU HIFI4
DSP Framework/firmware
Rpmsg-lite (openamp)
HIFI4 Core
Execution
Memory
Library loader
Component Component
The DSP-related code includes the DSP framework, DSP remoteproc driver, DSP wrapper, unit test, DSP codec wrapper, and
DSP codec.
• The DSP framework is a firmware code which runs on the DSP core. The DSP driver is used to load the DSP firmware into
the memory and transfer messages between the user space and the DSP framework.
• The remoteproc and RPMsg framework is used to transfer messages between the Cortex-A cores and the DSP cores. The
Message Unit (MU) is used to trigger interrupts between the Cortex-A cores and DSP cores when messages are placed into
the vring buffer.
• The DSP wrapper and the unit test are the application code in the user space, which uses the rpmsg_char interface to transfer
messages between the DSP remoteproc driver and the user space. In addition, the DSP wrapper is used to provide unified
interfaces for the GStreamer.
• The DSP codec provides the actual decoding and encoding functions.
• The DSP codec wrapper is a wrapping code for the DSP codec and provides unified interfaces for the DSP framework.
3 File organization
The DSP framework, DSP wrapper, and unit test code are in the github.com/NXP imx-audio-framework repository. The DSP
remoteproc driver code belongs to the Linux OS kernel.
DSP codecs originated from Cadence are license-restricted: A license authorization is required from NXP Marketing to access
them in binary format.
cd imx-audio-toolchain/Xtensa_Tool
tar zxvf XtensaTools_RF_2016_4_linux.tgz -C ./tools
cd imx-audio-toolchain/Xtensa_Tool
tar zxvf hifi4_nxp_v3_3_1_2_dev_linux.tgz -C ./builds
cd imx-audio-toolchain/Xtensa_Tool
./ builds/RF-2016.4-linux/hifi4_nxp_v3_3_1_2_dev/install --xtensa-tools ./tools/RF- 2016.4-linux/
XtensaTools --registry ./tools/RF-2016.4-linux/XtensaTools/config
have appropriate 32-bit compatibility packages installed. If you use a 64-bit system (for example; Ubuntu 16.04), install the 32-bit
compatibility packages first. Use these commands:
&dsp {
compatible = "fsl,imx8mp-dsp-v1"; memory-region = <&dsp_reserved>; reg = <0x0 0x3B6E80000x0
0x88000>;
pinctrl-0 = <&pinctrl_uart4>;
clocks = <&audiomix_clk IMX8MP_CLK_AUDIOMIX_OCRAMA_IPG>,
…
…
<&audiomix_clk IMX8MP_CLK_AUDIOMIX_ASRC_IPG>,
<&clk IMX8MP_CLK_UART4_ROOT>,
<&clk IMX8MP_CLK_UART4_ROOT>;
clock-names =
"ocram", "audio_root", "audio_axi", "core", "debug", "mu2", "sdma_root", "sai_ipg",
"sai_mclk","asrc_ipg", "uart_ipg", "uart_per";
…
fsl,dsp-firmware = "imx/dsp/hifi4.bin"; status = "okay";
};
DSP Start.....
core initialized
Response queue: write = 0x0 / read = 0x0 Command queue: write = 0x10001 / read = 0x0 ext_msg:
[client:0]:(80008004,4,1000) Response queue: write = 0x0 / read = 0x0 Command queue: write =
0x10001 / read
= 0x10001
alloc size out: 943feff8 4104 avail mem: 16773104 Response queue: write = 0x0 / read = 0x0
Response[client: 0]:(80048000,4,1000)
Command queue: write = 0x10001 / read = 0x10001 Response queue: write = 0x10001 / read = 0x10001
Command queue: write = 0x20002 / read = 0x10001 ext_msg: [client: 0]:(80008004,80000001,15)
Response
queue: write = 0x10001 / read = 0x10001
Figure 3. i.MX8-8X-BB
Connect the RS-232 to a PC and connect the base board to the i.MX QuadXPlus board.
1. Add the UART clock and pinctrl in the DTS.
Add the UART clock and pinctrl in the DSP node as follows:
dsp: dsp@596e8000 {
clocks = ...
...
status = "disabled";
};
--- a/dsp_framework/arch/board.h
+++ b/dsp_framework/arch/board.h
#endif /*PLATF_8ULP */
Then build the DSP with “DEBUG=1” and copy it to the board.
3. Run the DSP and print the debug information.
This part is the same as on the i.MX 8M Plus board. Select the proper serial COM port and you will see the debug
information. The debug information cannot print on the i.MX 8QuadMax board, because the UART is taken.
NOTE
Log into the XPG Cadence website to download installers for the Xplorer IDE, Xtensa tools, and so on. For NXP
internal use, contact the DSP owner to get the NXP common XPG login credentials. The Xplorer 7.0.8 version is
used as an example and its default installation folder is C:\usr\xtensa.
After the download finishes, right-click the “Xtensa Tools 11.0.4 for Windows” option and select the “Install Xtensa Tools…” option
in the new dialog. The installing process takes some time.
The Xtensa Tool is installed successfully after this step. You can see this folder in the Xplorer’s installing folder if everything is OK:
C:\usr\xtensa\XtDevTools\install\tools\RF-2016.4-win32
• Add the configuration package into Xplorer.
When you have the hifi4_nxp_v3_3_1_2_dev_win32.tgz package from NXP, you can add it into Xplorer. The first thing to do is to
create a folder called build in Xplorer’s installing path if the build folder is not created already. The total path after this operation
is as follows:
C:\usr\xtensa\XtDevTools\downloads\RF-2016.4\build
• Place the hifi4_nxp_v3_3_1_2_dev_win32.tgz package into the new build folder.
C:\usr\xtensa\XtDevTools\downloads\RF-2016.4\build\ hifi4_nxp_v3_3_1_2_dev_win32.tgz
• After you have performed the above steps, you can click the refresh button in the “XPG View” panel and find the “build”
option in this panel.
• Right-click the build->hifi4_nxp_v3_3_1_2_dev_win32.tgz package and click the “Install Build…” option in the new dialog
to start the installing process. This takes some time. You can see the following folder in the Xplorer’s installing folder if
everything is OK.
C:\usr\xtensa\XtDevTools\install\builds\RF-2016.4-win32\hifi4_nxp_v3_3_1_2_dev
• Add the new memmap linker files into Xplorer.
After you add the hifi4_nxp_v3_3_1_2_dev_win32.tgz configuration package into Xplorer, you can add the new memmap linker
files. You can copy the mainsim folder into Xplorer’s install folder to finish this process. The complete folder after this process is
as follows:
C:\usr\xtensa\XtDevTools\install\builds\RF-2016.4-win32\hifi4_nxp_v3_3_1_2_dev\xtensa- elf\lib\mainsim
After you complete the above three steps, the new configuration package and the corresponding memory map linker files are
successfully added into Xplorer.
• Enter the project name and import DSP framework source code into the “New Xtensa C/C++ Project” dialog. Then click
the “Finish” button.
After the above two steps, the DSP framework project is successfully created. You can see the project in Figure 7.
• Click the “Addl” compiler to add options. Add the “-DPLATF_8m” attribute to build the firmware for i.MX8mp. Add the
“-DPLATF_8MP_LPA” attribute to build the firmware for LPA. Add the “-DDEBUG” attribute to build the firmware with the
print debug information.
• Click the “Linker” option and configure the custom LSP path as shown in Figure 10. Click the “OK” button to finish this
process.
• When you configured the memmap linker files, you can choose the dsp_framework project and the required DSP
configuration to start the building process. The configuration is as follows:
• Click the “Build Active->Build Active” option to start building the DSP framework. This takes some time.
NOTE
You must remove the file rpmsg_queue.c and directory porting in rpmsg_lite, otherwise it reports error.
• After performing the above steps, you get the binary file called dsp_framework (which is the firmware of the DSP) in the
following folder.
C:\usr\xtensa\Xplorer-7.0.8- workspaces\workspace\dsp_framework\bin\hifi4_nxp_v3_3_1_2_dev\Debug\dsp_framework
If you want to use this binary file to run on a real board, rename the dsp_framework binary file as
hifi4.bin and place it to a right place of “rootfs”.
/usr/lib/imx-mm/audio-codec/dsp/lib_dsp_bsac_dec.so
/usr/lib/imx-mm/audio-codec/dsp/lib_dsp_dabplus_dec.so
/usr/lib/imx-mm/audio-codec/dsp/lib_dsp_drm_dec.so
/usr/lib/imx-mm/audio-codec/dsp/lib_dsp_mp2_dec.so
/usr/lib/imx-mm/audio-codec/dsp/lib_dsp_sbc_dec.so
/usr/lib/imx-mm/audio-codec/dsp/lib_dsp_sbc_enc.so
• Add DSP NXP codec wrapper library (WMA10 library requires authorization from NXP Marketing, others are on the Yocto
Mirror Server):
/usr/lib/imx-mm/audio-codec/dsp/lib_mp3d_wrap_dsp.so
/usr/lib/imx-mm/audio-codec/dsp/lib_aacd_wrap_dsp.so
/usr/lib/imx-mm/audio-codec/dsp/lib_vorbisd_wrap_dsp.so
/usr/lib/imx-mm/audio-codec/dsp/lib_wma10d_wrap_dsp.so
/usr/lib/imx-mm/audio-codec/dsp/lib_nbamrd_wrap_dsp.so
/usr/lib/imx-mm/audio-codec/dsp/lib_wbamrd_wrap_dsp.so
7.3.1 dsp_test
After placing the binary files into the correct location of the rootfs, you can decode or encode audio streams directly using the unit
test binary file. To decode one *.mp3 file, use this command:
./dsp_test -f1 -d16 -itest.mp3 -otest.pcm
To play one music file using the GStreamer and DSP wrapper, use this command:
gplay-1.0 test.mp3
The dsp_test also supports compress playback. This feature is now usable on i.MX 8MP board, after this change the dtb filename
is: imx8mp-evk-dsp.dtb, you can hear the sound by running the command:
./dsp_test -f1 -c33 -d16 -isyz.mp3
A position-independent library can be loaded and run at any address that supports both code and data, like a normal system RAM.
Alternatively, you can use the “pisplitload” LSP to load the code and data into separate memory blocks located in local RAMs. The
library location must be decided before the runtime.
The Xtensa development toolchain must be installed before making a loadable library. After that, you can follow the steps below.
/* replace all calls to printf with calls through the pointer */ #define printf printf_ptr
/* This is the function provided by the library */ char * interface_func(unsigned int input)
printf_ptr = printf_func;
/* The main application wants to call the function interface_func, but can’t directly reference it.
Therefore, this function returns a pointer to it, and the main application will be able to call it via this
pointer. */
return interface_func;
The main application calls the “_start” function, passes a pointer to “printf”, and takes a pointer to interface_func() in return. If the
library and the main program must communicate a value of more than one symbol, then the “_start” function call can return arrays
of pointers, rather than single pointers.
After finishing your source code, you can use “xt-xcc” of the Xtensa development toolchain to compile the code. Because the
position-independent libraries can be loaded at any address, make sure that the code in the library is position-independent using
the “-fpic” flag along with your normal compile options, as shown here:
xt-xcc -O3 -o library.o -c library.c
After this command, you can get a position-independent library with the code and data loadable separately. If you want to get a
contiguous position-independent library, you can use this command.
xt-xcc -mlsp=piload -Wl,--shared-pagesize=128 -Wl,-pie -lgcc -lc -o library.so library.o
After the linking stage, you can get a loadable library which can be loaded by the DSP framework. The current DSP framework
only supports loading the code and data sections separately.
9 Revision History
The following table provides the revision history for this document.
1 01/2019 Added details about using the sound card feature that allows users to
play mp3 files over ALSA compressed interface.
3 09/2020 Added support for the i.MX8 MP board. Added support for *.wav files
playback by the ALSA compressed interface. Added details about DSP
framework building.
4 01/2021 Updated the version of the toolchain. Added details about the firmware
generation and the LPA.
LF5.10.72_2.2.0 12/2021 This document is published with the Linux software document
package from this release.
Currently, the Linux OS kernel reserves the memory for the DSP in the SDRAM separately. The range of the reserved
memory is 0x92400000 ~ 0x943fffff (32 MB). You may set this reserved memory by changing the imx8x-mek.dtsi file in the
linux-kernel/arch/arm64/boot/dts/freescale folder.
reserved-memory {
…………….
dsp_reserved: dsp@92400000 {
reg = <0 0x92400000 0 0x1000000>;
no-map;
};
dsp_reserved_heap: dsp_reserved_heap {
reg = <0 0x93400000 0 0xef0000>;
no-map;
};
dsp_vdev0vring0: vdev0vring0@942f0000 {
reg = <0 0x942f0000 0 0x8000>;
no-map;
};
dsp_vdev0vring1: vdev0vring1@942f8000 {
reg = <0 0x942f8000 0 0x8000>;
no-map;
};
dsp_vdev0buffer: vdev0buffer@94300000 {
compatible = "shared-dma-pool";
reg = <0 0x94300000 0 0x100000>;
no-map;
};
………….....
}
The DSP remoteproc driver splits the current reserved memory into five parts. One part is used to store the DSP firmware and the
other part is a scratch memory for the DSP framework. The detailed information about these five parts is shown in Table 3.
NOTE
If you make changes in the memory map linker files of the Xtensadevelopment toolchain, make the related changes
for the DSP remoteproc driver.
Right to make changes - NXP Semiconductors reserves the right to make changes to information published in this document, including
without limitation specifications and product descriptions, at any time and without notice. This document supersedes and replaces all
information supplied prior to the publication hereof.
Security — Customer understands that all NXP products may be subject to unidentified or documented vulnerabilities. Customer
is responsible for the design and operation of its applications and products throughout their lifecycles to reduce the effect of these
vulnerabilities on customer’s applications and products. Customer’s responsibility also extends to other open and/or proprietary
technologies supported by NXP products for use in customer’s applications. NXP accepts no liability for any vulnerability. Customer
should regularly check security updates from NXP and follow up appropriately. Customer shall select products with security features
that best meet rules, regulations, and standards of the intended application and make the ultimate design decisions regarding its
products and is solely responsible for compliance with all legal, regulatory, and security related requirements concerning its products,
regardless of any information or support that may be provided by NXP. NXP has a Product Security Incident Response Team
(PSIRT) (reachable at [email protected]) that manages the investigation, reporting, and solution release to security vulnerabilities of
NXP products.
NXP, the NXP logo, NXP SECURE CONNECTIONS FOR A SMARTER WORLD, COOLFLUX,EMBRACE, GREENCHIP, HITAG,
ICODE, JCOP, LIFE, VIBES, MIFARE, MIFARE CLASSIC, MIFARE DESFire, MIFARE PLUS, MIFARE FLEX, MANTIS, MIFARE
ULTRALIGHT, MIFARE4MOBILE, MIGLO, NTAG, ROADLINK, SMARTLX, SMARTMX, STARPLUG, TOPFET, TRENCHMOS,
UCODE, Freescale, the Freescale logo, AltiVec, CodeWarrior, ColdFire, ColdFire+, the Energy Efficient Solutions logo, Kinetis,
Layerscape, MagniV, mobileGT, PEG, PowerQUICC, Processor Expert, QorIQ, QorIQ Qonverge, SafeAssure, the SafeAssure logo,
StarCore, Symphony, VortiQa, Vybrid, Airfast, BeeKit, BeeStack, CoreNet, Flexis, MXC, Platform in a Package, QUICC Engine, Tower,
TurboLink, EdgeScale, EdgeLock, eIQ, and Immersive3D are trademarks of NXP B.V. All other product or service names are the
property of their respective owners. AMBA, Arm, Arm7, Arm7TDMI, Arm9, Arm11, Artisan, big.LITTLE, Cordio, CoreLink, CoreSight,
Cortex, DesignStart, DynamIQ, Jazelle, Keil, Mali, Mbed, Mbed Enabled, NEON, POP, RealView, SecurCore, Socrates, Thumb,
TrustZone, ULINK, ULINK2, ULINK-ME, ULINK-PLUS, ULINKpro, µVision, Versatile are trademarks or registered trademarks of Arm
Limited (or its subsidiaries) in the US and/or elsewhere. The related technology may be protected by any or all of patents, copyrights,
designs and trade secrets. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. The Power
Architecture and Power.org word marks and the Power and Power.org logos and related marks are trademarks and service marks
licensed by Power.org. M, M Mobileye and other Mobileye trademarks or logos appearing herein are trademarks of Mobileye Vision
Technologies Ltd. in the United States, the EU and/or other jurisdictions.