Problem Getting Embedded Codegen To Generate Code For ARM CMSIS-DSP

2 次查看(过去 30 天)
I've tested the "Verify FIR Filter on ARM Cortex-M Processor in MATLAB" example, which works fine and generates CMSIS-DSP function calls so I'm fairly certain all of the dependent packages are installed correctly: https://uk.mathworks.com/help/supportpkg/armcortexm/ref/Verify-FIR-Filter-on-ARM-Cortex-M-Processor-in-MATLAB-example.html
I've modified it to use a 256 point FFT, using DSP.fft() and abs(), and I'm hoping to generate code calling arm_rfft_fast_f32() and arm_abs_f32().
I'm observing two problems, with the compiled code, that I've been going round in circles trying to resolve, for days.
1/ arm_rfft_fast_f32() and arm_abs_f32() are not being called.
2/ The return array (X) is being declared as the maximum stack allocation size (65536), even if I pre-declare it using zeros() or coder.nullcopy(), so is eating up too much memory:
void ec_fft(const double x[256], double X[65536])
{
static creal_T Y0[65536];
The test code is listed below. Its very short but the full source code is in the attachment.
Any help would be most appreciated.
Thanks very much,
John
FFT Function: (ec_fft.m)
function [X]=ec_fft(x) %#codegen
% X=zeros(256);
persistent ft;
if isempty(ft)
ft = dsp.FFT('FFTLengthSource','Property','FFTLength',256);
end
X = abs(ft(x));
end
Test App: (ec_fft_test.m)
Fs = 1000;
L = 256;
t = (0:L-1)'/Fs;
x = cos(2*pi*250*t);
X = coder.nullcopy(x);
X = ec_fft(x);
plot(Fs/2*linspace(0,1,128), X(1:128))
title('Single-sided amplitude spectrum of noisy signal y(t)')
xlabel('Frequency (Hz)'); ylabel('|X(f)|')
Script For Creating Library (run_codegen_arm.m):
ec_fft_test
cfgEx = coder.config('lib');
cfgEx.CodeReplacementLibrary = 'ARM Cortex-M';
cfgEx.HardwareImplementation.ProdHWDeviceType = 'ARM Compatible->ARM Cortex-M';
cfgEx.GenCodeOnly = true;
codegen -d ec_fft_lib ec_fft.m -report -rowmajor -config cfgEx -args {zeros(1,256)}
  1 个评论
John Edwards
John Edwards 2022-7-1
Attached, version that solves the output array size declaration problem.
Solution: Use:
types = coder.getArgTypes('ec_fft_test', 'ec_fft');
and:
-args types
Also uses single precision, which is the supported precision in codegen/CMSIS-DSP.
Just need to get DSP.fft() working with codegen now :-)
Best,
John

请先登录,再进行评论。

采纳的回答

John Edwards
John Edwards 2022-7-8
Thanks to the excellent, Mathworks support, I have a solution.
Essentially, DSP.fft() only supports complex input data, not real.
For reference, the following are the CRL conditions for dsp.FFT:
Input specifications:
  1. Complex values
  2. Data type: single
  3. Single channel (input should be column vector)
  4. Input length must equal FFT length (As per dsp.FFT property values requirements)
Property values requirement for dsp.FFT to replace:
  1. FFTImplementation:  Radix-2 
  2. Normalize :  False 
  3. FFTLength:  16, 64, 256, 1024 
  4. FFTLengthSource :  'Property' 
  5. WrapInput :  True  or  False . Value does not matter because input length must equal FFT length
If anyone needs to do this in the future then the project files are attached with this mail with the filename project_files.zip.
Best regards,
John

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Code Generation for ARM Cortex-M and ARM Cortex-A Processors 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by