如何在hpm_sdk中使用ZCC工具链编译dsp demo程序链接terapines高性能dsp库

获取hpm_sdk

  1. 使用命令 git clone https://github.com/hpmicro/hpm_sdk.git 拉取HPMicro官方SDK

  2. git checkout 切换tag,这里我们切换到v1.6.0,如下:

lt@carina:~/work/SDK/hpmicro/v1.6.0/hpm_sdk$ git checkout v1.6.0 
Note: switching to 'v1.6.0'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 44d8bcd7 hpm sdk release v1.6.0

导入环境变量

  1. 在sdk目录执行 export GNURISCV_TOOLCHAIN_PATH=TOOLCHAIN_PATH 命令,

TOOLCHAIN_PATH为zcc工具链的路径,确保在TOOLCHAIN_PATH路径下存在bin目录,
例如:

export GNURISCV_TOOLCHAIN_PATH=/home/lt/APP/Terapines/zstudio/zstudio-linux/resources/app/resources/toolchains/zcc
  1. 执行 export HPM_SDK_TOOLCHAIN_VARIANT=zcc 命令
  2. 手动设置环境变量"HPM_SDK_BASE"指向SDK根目录, export HPM_SDK_BASE=/path/hpm_sdk
  3. 在sdk根目录下执行 source env.sh

修改CMakeList

我们本次演示的dsp例子是 samples/hpm_math/fft_perf_test,由于hmp_sdk对ZCC工具链的支持还未完全,所以我们需要修改三处CMakeList源码。

  1. middleware/hpm_math目录下的CMakeList,第10行,将 -march=${RV_ARCH}_zp052b修改为 -march=${RV_ARCH}_zp052b_xandes ,修改如下图

  2. 修改samples/hpm_math/fft_perf_test目录下的CMakeList,将第7行的rv32imafc
    修改为 rv32imafdc,将第8行的ilp32f 修改为 ilp32d,并注释掉第18行的 generate_ide_projects(),否则会出现一些报错。修改如下图:

3、 修改soc目录下的CMakeList,将第22和23行的 -march=${RV_ARCH}_xandes修改为 -march=${RV_ARCH}_zp052b_xandes。修改如下图:

编译运行

  1. 命令行进入 samples/hpm_math/fft_perf_test目录,新建一个build文件夹,进入刚刚新建的build文件夹使用命令 cmake -GNinja -DBOARD=hpm6200evk .. && ninja ,编译成功则在build/output目录下生成demo.elf程序。

  2. 关于将程序下载到hpm6200开发板和运行调试程序,请参考链接:https://1nfinite.ai/t/terapines-zcc-risc-v-mcu/78

  3. 运行结果,如下所示:

==============================
 hpm6200evk clock summary
==============================
cpu0:		 600000000Hz
cpu1:		 600000000Hz
axi:		 200000000Hz
ahb:		 200000000Hz
mchtmr0:	 24000000Hz
mchtmr1:	 24000000Hz
xpi0:		 133333333Hz
==============================

----------------------------------------------------------------------
$$\   $$\ $$$$$$$\  $$\      $$\ $$\
$$ |  $$ |$$  __$$\ $$$\    $$$ |\__|
$$ |  $$ |$$ |  $$ |$$$$\  $$$$ |$$\  $$$$$$$\  $$$$$$\   $$$$$$\
$$$$$$$$ |$$$$$$$  |$$\$$\$$ $$ |$$ |$$  _____|$$  __$$\ $$  __$$\
$$  __$$ |$$  ____/ $$ \$$$  $$ |$$ |$$ /      $$ |  \__|$$ /  $$ |
$$ |  $$ |$$ |      $$ |\$  /$$ |$$ |$$ |      $$ |      $$ |  $$ |
$$ |  $$ |$$ |      $$ | \_/ $$ |$$ |\$$$$$$$\ $$ |      \$$$$$$  |
\__|  \__|\__|      \__|     \__|\__| \_______|\__|       \______/
----------------------------------------------------------------------
cpu0:		 600000000Hz


dsp fft radix-4 Total samples: 64.
total times:2940 tick.
------------------------------------
DC component amplitude:10.000006.
Frequency:8.000000, Amplitude:11.000008.
Frequency:17.000000, Amplitude:18.999989.
Frequency:24.000000, Amplitude:23.000000.
------------------------------------
dsp ifft radix-4 Total samples: 64.
total times:3092 tick.
------------------------------------


dsp fft radix-4 Total samples: 256.
total times:14272 tick.
------------------------------------
DC component amplitude:9.999995.
Frequency:8.000000, Amplitude:11.000002.
Frequency:17.000000, Amplitude:18.999998.
Frequency:24.000000, Amplitude:23.000004.
------------------------------------
dsp ifft radix-4 Total samples: 256.
total times:14847 tick.
------------------------------------


dsp fft radix-4 Total samples: 1024.
total times:68832 tick.
------------------------------------
DC component amplitude:9.999996.
Frequency:8.000000, Amplitude:10.999999.
Frequency:17.000000, Amplitude:19.000000.
Frequency:24.000000, Amplitude:23.000000.
------------------------------------
dsp ifft radix-4 Total samples: 1024.
total times:71295 tick.
------------------------------------


**************************************



dsp fft radix-2 Total samples: 64.
total times:2921 tick.
------------------------------------
DC component amplitude:10.000006.
Frequency:8.000000, Amplitude:11.000008.
Frequency:17.000000, Amplitude:18.999989.
Frequency:24.000000, Amplitude:23.000000.
------------------------------------
dsp ifft radix-2 Total samples: 64.
total times:3071 tick.
------------------------------------


dsp fft radix-2 Total samples: 128.
total times:7795 tick.
------------------------------------
DC component amplitude:9.999997.
Frequency:8.000000, Amplitude:11.000002.
Frequency:17.000000, Amplitude:18.999996.
Frequency:24.000000, Amplitude:23.000004.
------------------------------------
dsp ifft radix-2 Total samples: 128.
total times:8624 tick.
------------------------------------


dsp fft radix-2 Total samples: 256.
total times:14245 tick.
------------------------------------
DC component amplitude:9.999995.
Frequency:8.000000, Amplitude:11.000002.
Frequency:17.000000, Amplitude:18.999998.
Frequency:24.000000, Amplitude:23.000004.
------------------------------------
dsp ifft radix-2 Total samples: 256.
total times:14884 tick.
------------------------------------


dsp fft radix-2 Total samples: 512.
total times:36034 tick.
------------------------------------
DC component amplitude:9.999996.
Frequency:8.000000, Amplitude:10.999999.
Frequency:17.000000, Amplitude:19.000000.
Frequency:24.000000, Amplitude:22.999998.
------------------------------------
dsp ifft radix-2 Total samples: 512.
total times:39921 tick.
------------------------------------


dsp fft radix-2 Total samples: 1024.
total times:68993 tick.
------------------------------------
DC component amplitude:9.999996.
Frequency:8.000000, Amplitude:10.999999.
Frequency:17.000000, Amplitude:19.000000.
Frequency:24.000000, Amplitude:23.000000.
------------------------------------
dsp ifft radix-2 Total samples: 1024.
total times:71298 tick.
------------------------------------


**************************************



dsp fft q31 radix-2 Total samples: 64.
total times:3412 tick.
------------------------------------
DC component amplitude:20.000011.
Frequency:8.000000, Amplitude:22.000017.
Frequency:17.000000, Amplitude:37.999977.
Frequency:24.000000, Amplitude:46.000000.
------------------------------------
dsp ifft q31 radix-2 Total samples: 64.
total times:4113 tick.
------------------------------------


dsp fft q31 radix-2 Total samples: 128.
total times:8576 tick.
------------------------------------
DC component amplitude:19.999992.
Frequency:8.000000, Amplitude:22.000004.
Frequency:17.000000, Amplitude:37.999992.
Frequency:24.000000, Amplitude:46.000008.
------------------------------------
dsp ifft q31 radix-2 Total samples: 128.
total times:9589 tick.
------------------------------------


dsp fft q31 radix-2 Total samples: 256.
total times:17432 tick.
------------------------------------
DC component amplitude:19.999989.
Frequency:8.000000, Amplitude:22.000006.
Frequency:17.000000, Amplitude:38.000000.
Frequency:24.000000, Amplitude:46.000011.
------------------------------------
dsp ifft q31 radix-2 Total samples: 256.
total times:20162 tick.
------------------------------------


dsp fft q31 radix-2 Total samples: 512.
total times:42257 tick.
------------------------------------
DC component amplitude:19.999989.
Frequency:8.000000, Amplitude:22.000004.
Frequency:17.000000, Amplitude:38.000008.
Frequency:24.000000, Amplitude:46.000004.
------------------------------------
dsp ifft q31 radix-2 Total samples: 512.
total times:46294 tick.
------------------------------------


dsp fft q31 radix-2 Total samples: 1024.
total times:85953 tick.
------------------------------------
DC component amplitude:19.999981.
Frequency:8.000000, Amplitude:22.000013.
Frequency:17.000000, Amplitude:38.000008.
Frequency:24.000000, Amplitude:46.000004.
------------------------------------
dsp ifft q31 radix-2 Total samples: 1024.
total times:97280 tick.
------------------------------------


**************************************



Software fft  cooley tukey Total samples: 64.
total times:7039 tick.
------------------------------------
DC component amplitude:10.000006.
Frequency:8.000000, Amplitude:11.000006.
Frequency:17.000000, Amplitude:18.999989.
Frequency:24.000000, Amplitude:22.999994.
------------------------------------
Software fft  cooley tukey Total samples: 128.
total times:14090 tick.
------------------------------------
DC component amplitude:9.999997.
Frequency:8.000000, Amplitude:10.999998.
Frequency:17.000000, Amplitude:18.999992.
Frequency:24.000000, Amplitude:22.999996.
------------------------------------
Software fft  cooley tukey Total samples: 256.
total times:29825 tick.
------------------------------------
DC component amplitude:9.999995.
Frequency:8.000000, Amplitude:10.999998.
Frequency:17.000000, Amplitude:18.999996.
Frequency:24.000000, Amplitude:22.999996.
------------------------------------
Software fft  cooley tukey Total samples: 512.
total times:63827 tick.
------------------------------------
DC component amplitude:9.999996.
Frequency:8.000000, Amplitude:10.999996.
Frequency:17.000000, Amplitude:19.000000.
Frequency:24.000000, Amplitude:22.999996.
------------------------------------
Software fft  cooley tukey Total samples: 1024.
total times:139698 tick.
------------------------------------
DC component amplitude:9.999996.
Frequency:8.000000, Amplitude:10.999996.
Frequency:17.000000, Amplitude:19.000000.
Frequency:24.000000, Amplitude:22.999994.
------------------------------------
**************************************



------------------------------------
convert data from float to q31, nums:128.
total times:639 tick.
convert data from q31 to float, nums:128.
total times:543 tick.
------------------------------------
------------------------------------
convert data from float to q31, nums:256.
total times:1211 tick.
convert data from q31 to float, nums:256.
total times:1002 tick.
------------------------------------
------------------------------------
convert data from float to q31, nums:512.
total times:2372 tick.
convert data from q31 to float, nums:512.
total times:1961 tick.
------------------------------------
------------------------------------
convert data from float to q31, nums:1024.
total times:4670 tick.
convert data from q31 to float, nums:1024.
total times:3888 tick.
------------------------------------
------------------------------------
convert data from float to q31, nums:2048.
total times:9331 tick.
convert data from q31 to float, nums:2048.
total times:7722 tick.
------------------------------------
PASS.
----------------END--------------------```