cancel
Showing results for 
Search instead for 
Did you mean: 

STM32Cube IDE vs Arduino IDE

pbcal
Associate II

Hi,

I have used different micro-controller boards for many years, Arduino, STM32 and ESP32. I have always used Arduino IDE for all my developments. Recently I have downloaded STM32Cube IDE to see how it works compared to Arduino IDE. I started porting different programs and they went pretty well.

In the past I have developed a program to test the speed of different micro-controller boards. The program starts with a larger prime number and checks if its a prime or not. then it does it over and over to see how many times it can checks in 60 seconds. Though it does only arithmetician integer operation, it gives me an idea how fast a board is.

So I ported the code from Arduino IDE to STM32Cube IDE, and compared the results for a blue pill STM32 board (STM32F103C8T6 ). I got very different results. Code compiled in Arduino IDE goes through many more loops than the Cube IDE. If I start with a prime number 1990661, with Arduino IDE code can check 589632 times if its a prime or not. For the same code on the same board flashed through STM32Cube IDE only can check 169176 times. This is about 3.5 times slower. I get similar speed difference when I start with a different prime number.

 

I have attached both Arduino and Cube IDE code and few picture for reference. Is there anything I am doing wrong that is causing STM32Cube IDE to run slower? I am new to Cube IDE and do not know much. Any help will be appreciated.

 

1 ACCEPTED SOLUTION

Accepted Solutions
AScha.3
Chief III

Hi,

>Is there anything I am doing wrong

Yes. You didnt use a optimizer setting (i suppose).

In Arduino somewhere in the linked libs and defines and everything, there is optimizer set to -O2 or 3.

So try again in IDE, with optimizer set to -O2 (my usual setting), or -Ofast , for best speed.

here:

AScha3_0-1719074104190.png

 

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

5 REPLIES 5
AScha.3
Chief III

Hi,

>Is there anything I am doing wrong

Yes. You didnt use a optimizer setting (i suppose).

In Arduino somewhere in the linked libs and defines and everything, there is optimizer set to -O2 or 3.

So try again in IDE, with optimizer set to -O2 (my usual setting), or -Ofast , for best speed.

here:

AScha3_0-1719074104190.png

 

If you feel a post has answered your question, please click "Accept as Solution".
pbcal
Associate II

Great. I changed the setting to -Ofast and the loop count jumped to 609835 which is higher than Arduino IDE. Thanks for your suggestion.

Do you have aggressive settings for Optimization, ie -Os for speed

Does the clock start properly? HSE & PLL ?

printf("\n\nCore=%d, %d MHz\n", SystemCoreClock, SystemCoreClock / 1000000);

 

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

@Tesla DeLorean  , your sure about : "ie -Os for speed" ?

In my GCC compiler here, its for size, -Ofast is for speed.

If you feel a post has answered your question, please click "Accept as Solution".

:)

But you dont compare "IDEs" here - you compare the optimizer settings, using same compiler (both use GCC).

So to learn/see , what compiler doing, look here :

 https://godbolt.org/

Try different compiler on different cpu...then you see, what can happen. 

 

If you feel a post has answered your question, please click "Accept as Solution".