Skip to main content
diego ambroggi
Associate III
Apr 9, 2020 7:12 AM UTC
Solved

Debug problems using Optimization settings.

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

This topic has been closed for replies.
waclawek.jan
waclawek.janBest answer
Super User
Apr 9, 2020 8:36 AM UTC

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

6 replies

waclawek.jan
Super User
Apr 9, 2020 7:57 AM UTC

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
Apr 9, 2020 8:04 AM UTC

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

Tesla DeLorean
Guru
Apr 9, 2020 8:18 AM UTC

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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
diego ambroggi
Associate III
Apr 9, 2020 8:29 AM UTC

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

waclawek.jan
waclawek.janBest answer
Super User
Apr 9, 2020 8:36 AM UTC

> "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
Apr 9, 2020 9:23 AM UTC

Great, Thanks

I'll try to take your advice

Happy Easter