This is another article about the NXP MCUXpresso IDE (see “MCUXPresso IDE: Unified Eclipse IDE for NXPs ARM Cortex-M Microcontrollers“), this time it is about Post-build steps. Post-build steps are custom actions which can be executed after the build (or link phase), and are typically used to generate S-Record, Binary or Intel Hex files (see “S-Record, Intel Hex and Binary Files“).
MCUXpresso IDE Series
This article is part of a series to get up to speed using the new NXP MCUXpresso IDE. Published so far are:
- MCUXpresso IDE: Unified Eclipse IDE for NXPs ARM Cortex-M Microcontrollers
- MCUXpresso IDE: S-Record, Intel Hex and Binary Files
- MCUXpresso IDE: Adding the Eclipse Marketplace Client
- MCUXpresso IDE: Importing Kinetis Design Studio Projects
- MCUXpresso IDE: Installing Processor Expert into Eclipse Neon
- MCUXpresso IDE: Terminate and Disconnect a Debug Session
- MCUXpresso IDE: Blinky the NXP LPC800-DIP Board
Outline
Post Build Steps are part of the Eclipse CDT build tool integration. If using the GNU ARM Eclipse plugins as in Kinetis Design Studio, then it offers check boxes to run pre-configured post build steps e.g. for creating flash image files or printing the code size.
This post shows how to do the same in MCUXpresso IDE, either using post build steps or using a context menu on the executable file.
Post-Build Steps
The Post-build steps can be found under the C/C++ Build project settings, under the ‘Build Steps’ tab.
Pressing the ‘Edit’ button opens a dialog where I can edit the actions:
The default probably shows the following:
arm-none-eabi-size "${BuildArtifactFileName}" # arm-none-eabi-objcopy -v -O binary "${BuildArtifactFileName}" "${BuildArtifactFileBaseName}.bin" # checksum -p ${TargetChip} -d "${BuildArtifactFileBaseName}.bin"
The first command (arm-none-eabi-size) prints code size information (see “text, data and bss: Code and Data Size Explained“), with an output something like this in the console view:
text data bss dec hex filename 540764 344 37032 578140 8d25c MK64FN1M0xxx12_Project_Demo.axf
If there is a line starting with ‘#’, then everything following that will be ignored: that line plus all the lines which follow. Remove the ‘#’ to have the command executed.
To generate a binary file, use
arm-none-eabi-objcopy -v -O binary "${BuildArtifactFileName}" "${BuildArtifactFileBaseName}.bin"
To generate a S19/Motorola S-Record, use the following:
arm-none-eabi-objcopy -v -O srec "${BuildArtifactFileName}" "${BuildArtifactFileBaseName}.s19"
To generate Intel Hex, use the following:
arm-none-eabi-objcopy -v -O ihex "${BuildArtifactFileName}" "${BuildArtifactFileBaseName}.hex"
A description of all options for the GNU objcopy program can be found in https://sourceware.org/binutils/docs/binutils/objcopy.html
To change the length of S19 lines, the option
--srec-len <length>
is useful, e.g. –srec-len 128. See “S-Record Manipulation with GNU objcopy and Burner Utility“.
I can use multiple commands, such as the example below will produce S19, Intel Hex and Binary files:
The command execution can be checked in the console view:
The files get generated into the build output folder:
Other than that, have a look at the (excellent) electronic documentation, using the menu Help > MCUXpresso IDE User Guide:
Then you search for what you are looking for:
Binary Utilities
If I only need a binary or Intel Hex file right away without using a post build step, I can use the ‘Binary Utilities’ menu. It does not have the ability to generate S19 files, but is otherwise very useful:
Update: later IDE version (e.g. v11.3.0) have added the menu to create S19 files.
💡 Make sure you select a binary (ELF/Dwarf .axf) file, otherwise the menu does not show up.
The interesting thing is that these menus are configurable, under the menu Window > Preferences > MCUXpresso IDE > Utilities:
Update: later IDE version (e.g. v11.3.0) have added the the setting for creating S19 files.
I cannot add more menu entries, and I cannot change the menu name. But I can change the menu action. So if I would like to create the S19 file instead of the Intel hex, I can change that entry. Or I can execute multiple commands separated by a semicolon:
arm-none-eabi-objcopy -O ihex "${FileName}" "${FileBaseName}.hex"; arm-none-eabi-objcopy -v -O srec "${FileName}" "${FileBaseName}.s19"
💡 Make sure to use a semicolon *plus a space* as separator. A semicolon alone will give an error message.
💡 The settings are part of the workspace settings, so if you want this for multiple workspace, you have to export/import the settings or do it in each workspace.
Summary
The MCUXpresso IDE has a versatile way to generate binary, S19 or Intel Hex files using post-build steps. For creating hex and binary files ‘ad-hoc’, I can use the Binary context menu on the ELF/Dwarf executable file. As a bonus feature, I can change the Binary Utilities commands.
And if you want to generate more advanced files or generating complex checksums, have a look at the ‘SRecord’ tool described in my other article: “CRC Checksum Generation with ‘SRecord’ Tools for GNU and Eclipse”
Happy Hexing 🙂
Links
- MCUXpresso IDE web page: http://www.nxp.com/mcuxpresso/ide
- MCUXpresso IDE community: http://www.nxp.com/mcuxpresso/ide/forum
- MCUXpresso Config tools and SDK: https://mcuxpresso.nxp.com/
- GNU Objcopy: https://sourceware.org/binutils/docs/binutils/objcopy.html
Pingback: MCUXpresso IDE: Unified Eclipse IDE for NXPs ARM Cortex-M Microcontrollers | MCU on Eclipse
Pingback: MCUXpresso IDE: Adding the Eclipse Marketplace Client | MCU on Eclipse
Pingback: MCUXpresso IDE: Importing Kinetis Design Studio Projects | MCU on Eclipse
Pingback: MCUXpresso IDE: Installing Processor Expert into Eclipse Neon | MCU on Eclipse
Hi Erich, if someone, like me, prefers the SystemV list (-A) instead of Berkeley (-B) format:
arm-none-eabi-size -A “${BuildArtifactFileName}”
Michael
LikeLike
Have you tried to flash a binary or hex file generated with this procedure? I am trying to do this and I’m having problems. I am trying with a K22F freedom board and the SDK 2.0 led_output example. I try to flash the .bin by dragging it to the FRDM-K22FJ drive and it doesn’t work. I just tried the same process using KDS 3.0 with the same SDK example (targeted for KDS) and it works. I compared the binaries but they are very different. The KDS generated binary is 1KB bigger. Not sure if something is missing in the McuXpresso binary.
I have also tried with other procedures and file formats (hex, srec, J-link commander, etc).
Any ideas?
Thanks,
Carlos
LikeLike
Hi Carlos,
I’m not using the .bin file loader on the FRDM boards, but I have used the bin and S19 files with the debugger and I have not seen any problems?
I will try that tomorrow with a K64F board if this is helpful?
LikeLike
Hi Erich,
Thank you for the fast reply. Sure if you can try it it would be great.
I just found something, though. If I set SDK_DEBUGCONSOLE=1 the binary works. Any ideas?
Thanks,
Carlos
LikeLike
Hi Carlos,
the ‘SDK_DEBUGCONSOLE’ setting should not matter. Unless you are using semihosting? If so, it can block your target if you are not attaching a debugger. So using semihosting in general is a bad idea.
I quickly tried bin files, and I can load them with the SEGGER MSD bootloader on the FRDM-K64F without any issues.
Erich
LikeLike
Hi Erich,
I am using the SDK 2.0 led_output example as-is. It does use semihosting (I believe most SDK examples do). As you pointed out this seems to be the issue. I can program bin files now.
Thanks a lot for your help!
Carlos
LikeLike
Pingback: Using Eclipse to Program Binary Files to an Embedded Target | MCU on Eclipse
Pingback: MCUXpresso IDE: Terminate and Disconnect a Debug Session | MCU on Eclipse
Pingback: MCUXPresso IDE: Blinky the NXP LPC800-DIP Board | MCU on Eclipse
Pingback: MCUXpresso IDE v10.0.2 – Updated Eclipse based IDE for LPC and Kinetis | MCU on Eclipse
Pingback: Converting a Raw Binary File into an ELF/Dwarf File for Loading and Debugging | MCU on Eclipse
Pingback: Flash-Resident USB-HID Bootloader with the NXP Kinetis K22 Microcontroller | MCU on Eclipse
Pingback: Tutorial: Booting the NXP i.MX RT from Micro SD Card | MCU on Eclipse
Pingback: Generating Intel Hex Files with a given Length using srec_cat | MCU on Eclipse
Pingback: Listing Code and Data Size for all Files with the GNU size Utility in a Post-Build Action | MCU on Eclipse
Pingback: Touch & Build: Auto-Update of Firmware Date and Time | MCU on Eclipse