Skip to main content
TheBigBelarusian
Associate II
July 23, 2024
Solved

How to change STM32CubeIDE environment variable through script

  • July 23, 2024
  • 1 reply
  • 2846 views

Hi all.

Please tell me, for example, CubeIDE has environment variables and I can create my own by setting their values ​​through CubeIDE itself and passing them to the target assembly, but can I somehow change the value of my environment variable using additional scripts?
Here's the situation. I create an environment variable and bring it to the assembly definition. I also create a .bat script where I import it and change it, and add the script call to PREBUILD, but unfortunately, when assembling the project, I see that the change has not been changed. Is it actually possible to implement the scenario I described in CubeIDE?
Yes, I understand that I can use make/cmake directly or create a separate .h file. My scenario is more of a sporting interest.
I will be very glad to help and advice

Best answer by TheBigBelarusian

Hi, thanks for the advice.

I tried with bash and the situation is similar. I can import a variable, change it, see the new value, but during assembly the old value is applied. I analyzed the project's system files and found the file .settings/org.eclipse.cdt.core.prefs. This is where my variables are declared. And everything looks like the data from this file is already overwriting my new data before assembly. I wrote a simple script that will change the value of a variable in this file before assembly and everything worked. In fact, this is, of course, a crapshoot, and if you were to write a script, then, in principle, do not become attached to the CubeIDE environment, but use other approaches, and as I said earlier, this was just a matter of sport. If anyone knows a more elegant solution, I would be glad to hear your advice.

1 reply

Pavel A.
Super User
July 23, 2024

 I also create a .bat script where I import it and change it, and add the script call to PREBUILD

You can change (set) environment variable in a bat file but it won't propagate outside after the bat file exits. Try a .sh script and the "source" command... not sure if the CubeIDE's busybox shell supports it ...

 

TheBigBelarusian
TheBigBelarusianAuthorBest answer
Associate II
July 24, 2024

Hi, thanks for the advice.

I tried with bash and the situation is similar. I can import a variable, change it, see the new value, but during assembly the old value is applied. I analyzed the project's system files and found the file .settings/org.eclipse.cdt.core.prefs. This is where my variables are declared. And everything looks like the data from this file is already overwriting my new data before assembly. I wrote a simple script that will change the value of a variable in this file before assembly and everything worked. In fact, this is, of course, a crapshoot, and if you were to write a script, then, in principle, do not become attached to the CubeIDE environment, but use other approaches, and as I said earlier, this was just a matter of sport. If anyone knows a more elegant solution, I would be glad to hear your advice.