cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeIDE: output (bin) file name depending on preprocessor define?

LCE
Principal

Bonjour,

I'm currently prototyping with a H735-DK and a H723-Nucleo.

From pinout to functionality I have "separated" the differences with preprocessor declarations, so that's working.

Right now I get the same *.bin file name and have to rename it manually.
Now I would like to improve the workflow even more, so that STM32CubeIDE somehow detects that definition (or I add / change it in the project properties) and names the output files accordingly.

Is that possible?
If yes, how?

Thanks in advance!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Pavel A.
Evangelist III

Bonne soirée!

In Eclipse IDE the natural way for this is using project configurations. You create two (or more) configurations per board and customize preprocessor definitions for each. Then you customize linker settings  per configuration and redefine artifact (output file) names. You can also customize build variables per configuration and use these variables everywhere - in include directories, preprocessor defines, pre/post build commands.

View solution in original post

5 REPLIES 5

From a makefile perhaps a macro/environment variable type expansion of the command line to objcopy.

Alternatively as a post link user command, scanning the ELF for a symbol or define in the debug output, establishing name and then doing job of objcopy or spawning it.

For the STLDR files I have a batch file, recovers naming from StorageInfo removes junk from ELF file and saves compacted .STLDR with build options dependent naming.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ramprakash13
Associate II

Based on the context provided, it seems you are looking to automate the naming of your output binary files in STM32CubeIDE based on preprocessor definitions. Unfortunately, STM32CubeIDE does not provide a built-in feature to customize the output binary file name based on preprocessor definitions.

However, you can create a post-build step to rename the output file. This can be done by adding a script in the project properties under C/C++ Build > Settings > Build Steps > Post-build steps. This script can use the preprocessor definitions to rename the output file accordingly.

Here is a simple example of a post-build script that renames the output file based on a preprocessor definition:

 

 if [ '$DEFINITION' == 'H735_DK' ] then     mv output.bin output_H735_DK.bin elif [ '$DEFINITION' == 'H723_NUCLEO' ] then     mv output.bin output_H723_NUCLEO.bin fi 

 

This script checks the value of the preprocessor definition and renames the output file accordingly. You would need to replace 'DEFINITION' with the actual name of your preprocessor definition, and 'output.bin' with the actual name of your output file.

Please note that this solution assumes that you are using a Unix-like operating system or have a Unix-like environment available on your system, as the script uses Unix commands. If you are using a different operating system, you would need to adjust the script to use the equivalent commands for your system.

Very impressive for chatgpt .... or was it the MS Edge bot?

Pavel A.
Evangelist III

Bonne soirée!

In Eclipse IDE the natural way for this is using project configurations. You create two (or more) configurations per board and customize preprocessor definitions for each. Then you customize linker settings  per configuration and redefine artifact (output file) names. You can also customize build variables per configuration and use these variables everywhere - in include directories, preprocessor defines, pre/post build commands.

LCE
Principal

@Pavel A. Thanks, that's way better than manual setting the define and renaming the bin file.

Now I just have to keep in mind to switch build configuration. ;)