2023-06-12
08:18 PM
- last edited on
2023-07-11
12:34 AM
by
Laurids_PETERSE
We are developing STM32H757 Firmware using STM32CubeIDE (V 1.10.1, GNU Tools for STM32 (10.3-2021.10)). We have encapsulated an SPI read function based on ST's BSP. When tested on CM7 with optimization options turned off (-O0), the function can run normally and return. However, when the optimization option is set to -O2, the function becomes abnormal. We tried the following:
1. Debug with the emulator. With the same code and compilation options, the code can run normally.
2. The problem cannot be reproduced with the emulator. We added two logs before the exception jump, compiled an image, wrote it into flash, and the image can run normally.
3. We added a volatile modifier to the control loop variable, compiled an image, wrote it into flash, and the image can run normally.
It seems that none of the three experimental phenomena can be explained. The attachment contains the function code and modification instructions, as well as the flag options of the compiler and linker.
Please help to analyze.
2023-06-12 09:48 PM
So it could be a combination of STLink connected to the target AND optimisations.
If your toolchain can, try to activate each compiler option progressively to find out which one(s) is the culprit (use binary seach way instead of one by one).
Could be timings, SW coding bug....