STM32 not behaving after optimization

Sysprogs forums Forums VisualGDB STM32 not behaving after optimization

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #23487
    Johanan
    Participant

    I have a project rather large project using STM32F4, which works OK with no optimization. When I optimize to speed, it starts to misbehave. It does not crash, but there are some glitches on LCD display, some other variables display incorrect etc.

    I assume ARM GCC is a very well tested compiler, so it is probably due to my poor programming style. In particular I suspect forgetting to declare global and static as volatile when needed.  I wonder what should I be looking for, and if there is some tool to scan the code (it is a lot of lines) and point on possible problems.

    Thanks

     

    #23488
    kurta999
    Participant

    The problem can be in HAL too. Eg: USB CDC doesn’t work for me with “optimize for speed”, I had to lower it  to “optimize more”. (i’m not going to fix a driver myself which ST has f*cked up..)

    #23494
    Johanan
    Participant

    Actually I am using USB host.

    Wonder what will happen if I remove it for testing.

    • This reply was modified 5 years, 3 months ago by Johanan.
    #23496
    support
    Keymaster

    Hi All,

    The GCC itself it very stable (it’s used to build the Linux kernel that powers most of the servers nowadays), so the problem is likely caused by either your code or some libraries.

    The only advice we could give is to try changing optimization level on specific files (it’s easy to do via VS Project Properties for MSBuild-based projects) in order to pinpoint the exact one. You can also try using the #pragma optimize to override optimization for specific functions (the #pragma will affect the rest of the source file unless you put another #pragma optimize there).

    #23497
    Johanan
    Participant

    Will try that.

    Of course, I could berry my head in the sand, and leave it without optimization.

    I am concerned that this is a bad sign, and if not taken care of, it will hit me bad sometime later down the road…

    Thanks

    • This reply was modified 5 years, 3 months ago by Johanan.
    #27953
    Johanan
    Participant

    Well, After a long time I had to reduce code size, and found that stm32f1xx_hal_gpio.c is the only problematic one.

    I remove optimization from it and now it works, my code size shrieked by about 30 %.

    No idea what is the problem in that file, however.

    Johanan

     

    #27956
    support
    Keymaster

    It is hard to say why optimization of the GPIO driver would cause any problems, but in case you want to look deeper into it, you can try overriding optimization level for individual functions by marking them with __attribute__((optimize(“O2”))).

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.