Paul Flory
Paul Flory

Reputation: 11

STM32CubeIDE's post-build step to convert to hex or bin

I'm using the STM32CubeIDE for the project build but trying to do post build steps as a method to put the application checksum/crc into the .hex file. I read that the below command should work with the STM32CubeIDE builder.

first to convert .elf to .bin arm-none-eabi-objcopy -O binary main.elf main.tmp.bin

and then .bin to .hex after the checksum is done... arm-none-eabi-objcopy -I binary -O ihex
--change-addresses 0x08020000 main.bin hex2.tmp

but I get error that it's not a recognizable command...see attached image enter image description here

Am I missing a path variable or something?

Upvotes: 0

Views: 3230

Answers (3)

deadParrot
deadParrot

Reputation: 146

On Linux, from the command line. Having installed STM32CubeIDe in /opt the bin\arm-none-eabi-objcopy lives in:

very_long_path="/opt/st/stm32cubeide_1.15.0/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.12.3.rel1.linux64_1.0.100.202403111256/tools"

Which I symlinked as follows

ln -s ${very_long_path} /opt/st-cc-arm-xx-eabi

Then whenever I want to convert an elf to hex I can invoke

/opt/st-cc-arm-xx-eabi/bin/arm-none-eabi-objcopy -O ihex ./Debug/blinky.elf "blinky.hex"

Upvotes: 0

Hemjal
Hemjal

Reputation: 300

I assume you are using a Windows system and trying to convert the .elf file to hex. I did this using the following command:

arm-none-eabi-objcopy  -O ihex  LSM1x0A_SDK_LoRaWAN_Sigfox.elf  "LSM1x0A_SDK_LoRaWAN_Sigfox.hex"
  • Remember to change the elf file name and the target hex file name.

In addition, if you need to execute a python script then you can combine multiple commands as follows:

arm-none-eabi-objcopy  -O ihex  LSM1x0A_SDK_LoRaWAN_Sigfox.elf  "LSM1x0A_SDK_LoRaWAN_Sigfox.hex" & cd D:/cf_firmwares/LRWN_dev/LSM1x0A_dev/Projects/NUCLEO-WL55CC/Applications/LoRaWAN_Sigfox/LSM100A/STM32CubeIDE/Release & ls & python D:/cf_firmwares/LRWN_dev/LSM1x0A_dev/Utilities/1_SJITools/1_FW_Merge_Tool/main.py

Above command, I tried to following stuff:

  • convert elf to hex
  • moving to a new directory
  • check what is there in that directory
  • executing a python script

Observation:

  • Post-build commands might be executed in a random manner
  • Works like a Ubuntu terminal

result demo_cmd

enter image description here

Hope this will help

Upvotes: 0

pmacfarlane
pmacfarlane

Reputation: 4317

Yes, you can make this part of CubeIDE's build process, with some caveats.

Firstly, you can't just type these commands (e.g. for testing) into a Windows command prompt window. Your PATH environment variable will not include the directory where the GNU tools are stored. You'd need to manually add the correct paths to your PATH. You can see which directories CubeIDE uses by opening your project's Properties window, and going to C/C++ Build -> Environment.

enter image description here

Next, note that CubeIDE can automatically generate a .bin file for your program already. Go to Properties -> C/C++ Build -> Settings -> [Tool settings] -> MCU Post build outputs and you can select Convert to binary file:

enter image description here

Lastly, you can enter one user-defined post-build step at Properties -> C/C++ Build -> Settings -> [Build steps].

enter image description here

This would be the place to invoke whatever command generates and inserts the CRC. CubeIDE will use the correct path so you don't need to specify it here.

I don't think there is a way to add yet another post-build step, but a .bin file should be ok for programming. If you really need a .hex file you might have to make a script that does the CRC and final objcopy to achieve that, and call the script as your post-build step.

Upvotes: 2

Related Questions