Skip to main content
diego ambroggi
Associate III
April 9, 2020
Solved

Debug problems using Optimization settings.

  • April 9, 2020
  • 4 replies
  • 2693 views

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.
Best answer by waclawek.jan

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

4 replies

waclawek.jan
Super User
April 9, 2020

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
April 9, 2020

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

Tesla DeLorean
Guru
April 9, 2020

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 VenmoUp vote any posts that you find helpful, it shows what's working..
diego ambroggi
Associate III
April 9, 2020

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
April 9, 2020

> "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
April 9, 2020

Great, Thanks

I'll try to take your advice

Happy Easter