cancel
Showing results for 
Search instead for 
Did you mean: 

Debug problems using Optimization settings.

diego ambroggi
Associate III

Hi everyone,

I'm developing a new one project using STM32L031K6T MCU.

It's mandatory to use a simple low cost device for massive production.

Now flash memory is almost totally consumed.

I'm tring to use compiling optimisations to reduce program dimension but there are some problems about stepping flow.

It seems that program pointer is not alligned to the file, it doesn't follow next row but it jumps randomly.

I'm using NUCLEO-L031K6 demo board and STM32CubeIde.

Thanks in advance.

Diego

1 ACCEPTED SOLUTION

Accepted Solutions

> "disable optimization locally"

If this is gcc, use the "optimize" function attribute

https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#Common-Function-Attributes

JW

View solution in original post

6 REPLIES 6

This is normal, code reordering within the C language standard constraints (see volatile and "side effects" in the standard) is one of the optimization techniques. Just get used to it.

JW

diego ambroggi
Associate III

I assumed that selection "optimized for debug" was the right way, but there are problems in this case too.

Each C line can generate many machine instructions. If you must step your code to understand the logic you'll want to step the disassembly view and perhaps need to improve your static analysis skills.

Try also to only disable optimization locally, say at a function of interest level.

Pay particular attention to variables and structures needing the volatile keyword​ if modified by interrupts or callbacks.

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

Thank you I try to "disable optimization locally". I've never done this before.

What's the right operation to do this? Tere are some tutorials?

Thanks

> "disable optimization locally"

If this is gcc, use the "optimize" function attribute

https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#Common-Function-Attributes

JW

diego ambroggi
Associate III

Great, Thanks

I'll try to take your advice

Happy Easter