cancel
Showing results for 
Search instead for 
Did you mean: 

How to speed up STM32G474 float number calculation?

QMa.1
Associate

Hello,

I am new to STM32 MCU and right now using a 170MHz STM32G474 MCU for my project. I did a test today and found out the float number calculation speed of the MCU is quite slow.

It takes 6.3us to finish the calculation in Fig.1. (I set a GPIO pin high before the calculation starts and set it to low after the calculation). ADC_Value[] is integer and the rest variables are float. The speed is just too slow to believe.

0693W00000Y7RFXQA3.png 

The clock is set to be 170MHz. Am I missing something in the project setting (shown in Fig2 and Fig3)? Is this the real calculation speed for the MCU?

I know that in TI C2000 DSP, we can include a Scalar Factor Optimizer Library header to speed up the float calculation (SFO_V8.h). Does the STM32 DSP have the similar headers? Thanks.

0693W00000Y7RFmQAN.png0693W00000Y7RG1QAN.png 

1 ACCEPTED SOLUTION

Accepted Solutions
GLASS
Senior

Try to change ALL const value to float as said by Tesla...​

For example​ use 0.2f instead of 0.2 (the Last one is a double !)

If the real app work on large buffer of adc value, consider loop unrolling coding optimisa​tion instead of calling Adc_management() for each set of sample.

View solution in original post

6 REPLIES 6
S.Ma
Principal

If you don't need mantisse, why not stick to fractional binary like Q31, or calculate with pre.multiplied values by 1024? FMAC I guess is an IP to contemplate.

Otherwise, check your project settings, use of FPU vs sw emulated library, compiler optimisatipn mode, etc....

Check the generated code, check it's using float constants

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
GLASS
Senior

Try to change ALL const value to float as said by Tesla...​

For example​ use 0.2f instead of 0.2 (the Last one is a double !)

If the real app work on large buffer of adc value, consider loop unrolling coding optimisa​tion instead of calling Adc_management() for each set of sample.

MM..1
Chief III

Thanks for the example. I changed all the numbers to float format and used the -Ofast optimizer in the GCC Compiler Optimization setting. The calculation time length is reduced by 85% -- a much reasonable number. Thanks!

Piranha
Chief II