Skip to main content
Associate III
May 21, 2024
Solved

STM32H5 DSP support

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?

This topic has been closed for replies.
PieterGBest answer
Associate III
May 21, 2024

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

3 replies

Andrew Neil
Super User
May 21, 2024
A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
PieterGAuthor
Associate III
May 21, 2024

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.

PieterGAuthorBest answer
Associate III
May 21, 2024

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