How to create HEX or BIN file for separate flashing?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-05-30 7: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.
- Labels:
-
VSCode for STM32
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-06-03 1: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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-05-30 7:37 AM - edited ‎2024-05-30 7: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?
A complex system designed from scratch never works and cannot be patched up to make it work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-05-30 8: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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-05-30 2:43 PM
Perhaps a command line option to the linker, or use objcopy / objdump to get the output forms you want.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-06-03 1: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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-12-10 2:46 AM - last edited on ‎2024-12-10 3:04 AM by Andrew Neil
Hello
I had the same question and I ended up with this path, which I share with you:
From CubeIDE screen with a project OPEN
I select: Project > Properties and then C/C++ Build.
From the drop down of the C/C++build I select <Settings> and then, on the tab <Tool Settings> I select <MCU/MPU post build outputs>.
I check the boxes Convert to binary and Convert to hex
Finish by pressing APPLY AND CLOSE
On the next BUILD, the .hex and .bin files are present inside RELEASE folder of the project.
Hope this helped.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-12-10 4:17 AM
@Cats You did realise that I ask vor a VS Code and not for an Eclipse solution?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-12-10 6:33 AM
Hmmmm :) Nope!
You are right!
Actually my "discovery" concerns CubeIDE...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-12-10 6:46 AM - edited ‎2024-12-10 6:46 AM
Need to add something to the build commands defined in the json file? Google for description of that json file.
