Skip to main content
QMa.1
Associate
January 5, 2023
Solved

How to speed up STM32G474 float number calculation?

  • January 5, 2023
  • 5 replies
  • 3323 views

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 

This topic has been closed for replies.
Best answer by GLASS

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.

5 replies

S.Ma
Principal
January 5, 2023

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....

Tesla DeLorean
Guru
January 5, 2023

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

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
GLASS
GLASSBest answer
Visitor II
January 5, 2023

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.

QMa.1
QMa.1Author
Associate
January 5, 2023

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!

MM..1
Chief III
January 5, 2023
Piranha
Principal III
January 9, 2023