Sysprogs forums › Forums › VisualGDB › STM32 not behaving after optimization
- This topic has 6 replies, 3 voices, and was last updated 5 years, 6 months ago by support. 
- 
		AuthorPosts
- 
		
			
				
January 16, 2019 at 08:44 #23487Johanan ParticipantI 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 January 16, 2019 at 09:51 #23488kurta999 ParticipantThe 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..) January 16, 2019 at 17:38 #23494Johanan ParticipantActually I am using USB host. Wonder what will happen if I remove it for testing. - 
		This reply was modified 6 years, 9 months ago by Johanan. 
 January 16, 2019 at 18:10 #23496support KeymasterHi 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). January 16, 2019 at 18:58 #23497Johanan ParticipantWill 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 6 years, 9 months ago by Johanan. 
 April 25, 2020 at 19:02 #27953Johanan ParticipantWell, 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 April 27, 2020 at 00:46 #27956support KeymasterIt 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”))). 
- 
		This reply was modified 6 years, 9 months ago by 
- 
		AuthorPosts
- You must be logged in to reply to this topic.