Trying to use CMSIS DSP

Hi,
looking at using the CMSIS DSP lib functionality. Tried to include the lib.

#include "arm_math.h"

Got,

fatal error: ARMCM4.h: No such file or directory

Looks like "ARM_MATH_CM3" is not defined.

Tried,

#define ARM_MATH_CM3
#include "arm_math.h"

to a series of #define conflicts with "spark_wiring.h" along the lines of,

../inc/spark_wiring.h:86:12: error: expected unqualified-id before numeric constant
#define A0 10
^
../../core-common-lib/CMSIS/Include/arm_math.h:1715:11: note: in expansion of macro 'A0'
q15_t A0; /**< The derived gain, A0 = Kp + Ki + Kd . */
^

Can someone shed light on this, and the state of the CMSIS DSP lib in general?

Thx.

What math function are you missing?
Does #include "math.h" not suffice fir your needs?

@ScruffR I’m fairly certain that math.h does not have more DSP specific functions like FIR and FFTs, so that is why I’m looking into the CMSIS DSP lib.

1 Like

Hi @L_L

CMSIS is whole suite of libraries–I am not sure you can pick and choose just some. Don’t you also need the HAL layer etc. from CMSIS?

@bko
I'll take the whole thing, I'm not picky. :wink:

However, the CMSIS library already looks developed for the Cortex-M3, as indicated on their site.

http://www.keil.com/pack/doc/CMSIS/General/html/index.html

1.00 Initial release of CMSIS-CORE for Cortex-M3 processor

And they are now on ver 4.2 for M7.

Anymore suggestions? Should I re-post this in the Troubleshooting section?

Hi @L_L

I think you are underestimating the amount of work to get this going–this is not simple troubleshooting. Have a look at this picture I borrowed from the ARM website:

Look how the DSP library depends on the CMSIS-CORE and the CMSIS-RTOS, which in turn depends on a 3rd party kernel. It looks to me like you need all of those parts to make this work.

If you want to do this, I think you will have to completely get rid of the Spark firmware environment and program the Spark Core at the bare-metal level with a new RTOS.

This is not impossible but would be a fair chunk of work. There is precedence since there has been a NUTX port to the core. This also might get easier in the Photon environment in the future.

Maybe @mdma or @zachary can comment too.

@bko
Right, I have seen that strata diagram. I’m not intending to imply that integration of the CMSIS library is trivial, but it is part of the spark/core-common-lib. I just want information about its state. Hopefully, you referring others will draw enough attention. Thanks for that.

I’m a bit puzzled, since the M3 doesn’t have DSP instructions. The M4 has DSP, and the name of the header at the top of the thread seems to indicate it’s for the M4. If the library has software implementations of DSP algorithms then it might be ok.

The A0 problem you are seeing is due to macros conflicting. After including “application.h”, add “#undef A0” before including the CMSIS headers.

Interesting. Never looked into it before. With latest firmware master built locally I was able to at least instantiate and manipulate one of the structs in “arm_math.h”.

In my application, I had to add the following:

#define ARM_MATH_CM3
#undef A0
#undef A1
#undef A2
#include "arm_math.h"

Also, there are 4 warnings in compiling arm_math.h about comparison of signed and unsigned variables. In each case there’s a local index variable that’s an int32_t, and the warning is fixed by changing to uint32_t.

There are some static inline functions with software implementations, for example this one that AFAICT don’t require DSP hardware, but I don’t know whether that’s true of the whole file.

Good luck!

2 Likes

Thanks all for the feedback! The posted errors are resolved, but now it looks like there is missing implementation code.

C:\Spark\core-firmware\build/../src/application.cpp:32: undefined reference to `
arm_rfft_init_f32'

I'll go swim through the CMSIS library, and see what I can do. Maybe @satishgn could offer some frustration reducing hints, being the contributor.

@L_L Were you able to use CMSIS DSP on Photon/Core? Has there been any development on this? I too am looking at using the CMSIS DSP functionality in my application.

[I know this is an old post, and hence the query to see if there have been any updates, as of today]

1 Like

I got till this point. Trying to figure out, how to compile assembly file along with my .c files.

I have a similar issue. Opened a new thread: https://community.particle.io/t/arm-math-perform-fft/44314