2024-05-30 07:29 AM
Currently the extention only builds an ELF file.
How can I tell cmake to not only build an ELF file but also a HEX or BIN file?
Solved! Go to Solution.
2024-06-03 01:36 AM
So, to answer my own question, I got it working by appending the following lines to `CMakeLists.txt` in the project folder:
# Convert output to hex and binary
add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -O ihex $<TARGET_FILE:${CMAKE_PROJECT_NAME}> ${CMAKE_PROJECT_NAME}.hex
)
# Convert to bin file -> add conditional check?
add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -O binary $<TARGET_FILE:${CMAKE_PROJECT_NAME}> ${CMAKE_PROJECT_NAME}.bin
)
Snipped cortesy of https://github.com/MaJerle/stm32-cube-cmake-vscode
2024-05-30 07:37 AM - edited 2024-05-30 07:40 AM
Add the conversion as a post-build step;
https://stackoverflow.com/questions/19458031/how-to-create-a-executable-hex-from-elf-file-format
EDIT: sorry, that's for CubeIDE - I guess VSCode has something similar?
2024-05-30 08:12 AM
@Andrew Neil wrote:EDIT: sorry, that's for CubeIDE - I guess VSCode has something similar?
Thanks for your reply. But yes, I need it vor VS Code.
2024-05-30 02:43 PM
Perhaps a command line option to the linker, or use objcopy / objdump to get the output forms you want.
2024-06-03 01:36 AM
So, to answer my own question, I got it working by appending the following lines to `CMakeLists.txt` in the project folder:
# Convert output to hex and binary
add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -O ihex $<TARGET_FILE:${CMAKE_PROJECT_NAME}> ${CMAKE_PROJECT_NAME}.hex
)
# Convert to bin file -> add conditional check?
add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -O binary $<TARGET_FILE:${CMAKE_PROJECT_NAME}> ${CMAKE_PROJECT_NAME}.bin
)
Snipped cortesy of https://github.com/MaJerle/stm32-cube-cmake-vscode