Skip to main content
QMa.1
Associate
Jan 5, 2023 1:12 AM UTC
Solved

How to speed up STM32G474 float number calculation?

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.
GLASS
GLASSBest answer
Visitor II
Jan 5, 2023 5:37 AM UTC

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.

6 replies

S.Ma
Principal
Jan 5, 2023 2:49 AM UTC

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
Jan 5, 2023 3:18 AM UTC

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

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
GLASS
GLASSBest answer
Visitor II
Jan 5, 2023 5:37 AM UTC

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
Jan 5, 2023 5:38 PM UTC

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
Super User
Jan 5, 2023 6:18 AM UTC
Piranha
Principal III
Jan 9, 2023 1:39 AM UTC