By default, a breakpoint is placed at main when debugging. When a breakpoint is hit, an editor is opened with the cursor at the relevant line. This may be why your startup code is opened. As far as I know, STM32CubeIDE has no option to prevent opening editors on breakpoints.
You can disable this "hidden" breakpoint in the Debug Configuration, accessible through the Run menu. Select your configuration in the left column and go to the Startup tab on the right. Towards the bottom, deselect the checkbox before "Set breakpoint at: main".
If this doesn't help, and assuming you have no normal breakpoints active, you could check STLink's documentation for similar options. I have no experience with that specific debugger.
Screenshot of STM32CubeIDE's Debug Config. dialog, with "breakpoint at main" circled in red
Edit below. Thanks, oromoiluig, for clarifying the issue further in your comment.
There is also a known bug in the IDE that might affect you. An ST employee comfirmed that it "Sounds like unexpected behavior" and suggests to:
- Start a new workspace
- Create a new test project
- Use the "Run" button to download code.
One user reported that it helped. Many more report the issue persists, even today in version 1.9.0.
To answer your question directly: No. You likely cannot stop STMCubeIDE from opening startup.s or other rource files in this situation. It is up to ST to fix their IDE.
main()
is normally inmain.c
. I am experiencing a similar issue as the OP where STM32CubeIDE opens files seemingly at random when starting, pausing or restarting a program in debug mode. My guess is it opens the file/line that is being executed at that very moment, but it's really useless unless it's when pausing the program, in which it could be OK. – Apostolate