2024-05-21 03:00 AM
I'm trying to use CMSIS DSP on a STM32H563, but I do not get the expected results.
In X-CUBE-ALGOBUILD.1.3.0, when I select DSP Library in STM32CubeMX, the installed arm_math.h does not list Cortex-M33 support:
#error "Define according the used Cortex core ARM_MATH_CM7, ARM_MATH_CM4, ARM_MATH_CM3, ARM_MATH_CM0PLUS, ARM_MATH_CM0, ARM_MATH_ARMV8MBL, ARM_MATH_ARMV8MML"
I also looked at X-CUBE-DSPDEMO, which only contains pre-built libraries for cortexM4/M7.
And when I just link and build the CMSIS-DSP c files and try to run a test like this:
q31_t in = 25;
q31_t out;
arm_sqrt_q31(in, &out);
the result equals 231704 instead of the expected value 5.
I am defining -DARM_MATH_HELIUM -DARM_MATH_AUTOVECTORIZE
What would be the official way to use CMSIS-DSP on the STM32H5?
Is CMSIS-DSP supported at all on Cortex-M33?
Solved! Go to Solution.
2024-05-21 06:59 AM
It actually is not an STM32H5 or cortex-m33 issue after all.
I was misinterpreting the way in which the q31/q15 dsp types should be used.
The q31_t type is a fixed point type which can be used for values between -1 and 1, so I cannot use it to calculate the square root of 25.
I think this should be the correct way to use arm_sqrt_q31:
float32_t f = 0.5;
q31_t in;
q31_t out;
arm_float_to_q31(&f, &in, 1);
arm_sqrt_q31(in, &out);
arm_q31_to_float(&out, &f, 1);
which correctly results in 0.707
2024-05-21 03:02 AM
2024-05-21 04:06 AM - edited 2024-05-21 04:07 AM
Indeed, I have tried to follow those instructions. They might work for cortex-m4 and cortex-m7, but h5 is a cortex-m33, and STM32Cube_FW_H5_V1.2.0 does not contain any pre-built dsp archive files.
So as I wrote in my post, I have added the CMSIS-DSP files to my project and I can build and link them without any errors. However, when I am executing dsp functions (such as arm_sqrt_q31) the results are wrong.
2024-05-21 06:59 AM
It actually is not an STM32H5 or cortex-m33 issue after all.
I was misinterpreting the way in which the q31/q15 dsp types should be used.
The q31_t type is a fixed point type which can be used for values between -1 and 1, so I cannot use it to calculate the square root of 25.
I think this should be the correct way to use arm_sqrt_q31:
float32_t f = 0.5;
q31_t in;
q31_t out;
arm_float_to_q31(&f, &in, 1);
arm_sqrt_q31(in, &out);
arm_q31_to_float(&out, &f, 1);
which correctly results in 0.707