‎2020-03-25 11:30 AM
I am using a nucleo-f401re board.
Solved! Go to Solution.
‎2020-03-26 02:01 AM
Hi,
To change the code optimization level (in a general sense) do the following:
Right-click the project under Project Explorer
Select properties
Go to C/C++ Build->Settings
On the right hand side of the window, select "Tool Settings"
There, under corresponding compiler, you have the options for debugging and optimisation. Under these two menus, you should be able to change debuggin and optimization level for the compiler.
I have attached a picture of one of my example projects to show what you are looking for.
Best regards.
‎2020-03-25 12:05 PM
Do you really expect a helpful answer to this (non-)question ?
You missed any necessary context of your problem, right ;)
‎2020-03-26 02:01 AM
Hi,
To change the code optimization level (in a general sense) do the following:
Right-click the project under Project Explorer
Select properties
Go to C/C++ Build->Settings
On the right hand side of the window, select "Tool Settings"
There, under corresponding compiler, you have the options for debugging and optimisation. Under these two menus, you should be able to change debuggin and optimization level for the compiler.
I have attached a picture of one of my example projects to show what you are looking for.
Best regards.
‎2020-03-26 05:59 AM
Thank You, that worked, while watching the how to videos the guy says change the optimization level, but he was using Keil, that didn't do me any good when I was using STM32 Cube IDE, I looked for a user manual but ST didn't seem to have much.
‎2020-10-04 01:57 AM
I found that, if you have a specific function that must be optimized for speed, it works better to do it in your code like this:
#pragma GCC push_options
#pragma GCC optimize ("-Ofast")
void MyFunction()
{
// The code for your function goes here...
}
#pragma GCC pop_options
The "#pragma" statements instructs the GCC compiler to optimize your function for speed.
‎2020-10-04 03:15 AM
Or alternatively and when using GCC attribute feature for a dedicated function:
void MyFunction() __attribute__((optimize("-Ofast")))
just for completeness
‎2020-10-04 06:23 AM
Thanks for the alternative hs2.
However in STM32CubeIDE that format gives the error: "attributes should be specified before the declarator in a function definition".
So I tried it like this >>
__attribute__((optimize("-Ofast"))) void MyFunction()
{
// Code here
}
That worked perfectly. :)
‎2022-05-03 12:50 AM
i have the same question and this post helped me
‎2022-11-17 07:29 AM
aaaaand it helped me again
‎2023-09-06 08:28 AM
As stated in solution,
Note that there are 2 build configurations, Debug and Release. You select the configurations under Project/Build Configuration/Set Active.
Levels are apparently universal to all GCC compilers. From https://stackoverflow.com/questions/1778538/how-many-gcc-optimization-levels-are-there
For debugging, I have been using the default (none) and have had no trouble with debugging. But if I do, I'll try -Og.