cancel
Showing results for 
Search instead for 
Did you mean: 

I have a certain macro in a header file. After compilation, STM IDE generates the .hex file. Is it possible to have the name of the .hex file from the value of the macro definition?

SSoha.2
Associate

For example: if the macro is defined as follows:

#define CUST_NAME ivec

Then, after compilation, the hex file should be named as ivec.hex

3 REPLIES 3
ABlac.3
Associate

Yes, it is possible to have the name of the .hex file derived from the value of the macro definition. You can achieve this by defining a custom build rule or script that renames the output file after it has been generated by the compiler.

Assuming you are using the STM32CubeIDE, you can modify the build settings to include a custom build command that renames the output file. Here are the steps:

  1. Open the project properties dialog by right-clicking on the project and selecting "Properties".
  2. Select the "C/C++ Build" category and go to the "Settings" tab.
  3. Expand the "Build Steps" section and add a custom build step by clicking on the "Add" button.
  4. In the "Command" field, enter a command that renames the output file based on the value of the CUST_NAME macro. For example:
  5. mv ${BuildArtifactFileBaseName}.hex ${CUST_NAME}.hex
  6. This command renames the output file from its original name to the value of the CUST_NAME macro followed by the .hex extension.
  7. Click "OK" to save the build step and close the dialog.

After making these changes, the IDE should generate a .hex file with the name derived from the value of the CUST_NAME macro. Note that this approach assumes that the macro is defined consistently across all source files in the project, and that the output file is always a .hex file.

It's not working...

this is my Command:

arm-none-eabi-objcopy -O ihex ${ProjName}.elf ${BuildArtifactFileBaseName}.hex mv ${BuildArtifactFileBaseName}.hex ${CUST_NAME}.hex

this is the output on the console

"

Finished building: Chg_C0.2.hex

Finished building: Chg_C0.2.bin

Finished building: Chg_C0.2.list

arm-none-eabi-objcopy -O ihex Chg_C0.2.elf Chg_C0.2.hex mv Chg_C0.2.hex .hex

Usage: arm-none-eabi-objcopy [option(s)] in-file [out-file]

"

So, I observe that the macro was not read and the file name was empty. (.hex)

this was the macro definition

#define CUST_NAME MICRO

I also tried the following macro definition

#define CUST_NAME "MICRO"

nothing works..

In your example, CUST_NAME must be a "build variable" defined in the project options.

It is not a C preprocessor definition. But you can add a C preprocessor definition using a build variable.