Using Build Variables in debug Initialization Commands
The problem is a bit more complex; the debugger always put the code where the link editor decides to put it, so changing where the code is placed (RAM or FLASH) has to be done by edititing the link editor script.
The default link editor script places code in FLASH, not in SRAM, so starting a debug session will flash your program on the board; I don’t know what makes you think the program was placed in RAM.
Note that there is also a “Target” submenu in the project context menu where you can clear or flash the target board with your program.
Bernard (Ac6)