In embedded development, Keil MDK (Microcontroller Development Kit) is a preferred integrated development environment (IDE) for many developers. It supports various ARM Cortex-M microcontrollers and provides powerful debugging and compilation features. In actual development, we often need to generate a Bin format file from the compiled code for firmware flashing or OTA upgrades. This article will detail how to generate a Bin format file in the Keil MDK development environment.
01
What is a Bin File?
A Bin file (binary file) is a file format that contains raw binary data, typically used for storing microcontroller firmware. Compared to Hex files, Bin files are more compact and directly reflect memory data distribution, making them commonly used for production flashing or remote upgrades.
02
Why Generate a Bin File?
- Firmware Flashing: Many flashing tools (such as J-Link and ST-Link) support direct Bin file flashing.
- OTA Upgrades: Bin files are commonly used as transmission formats in over-the-air (OTA) upgrades.
- Space Efficiency: Bin files are smaller than Hex files, making them suitable for storage and transmission.
03
Steps to Generate a Bin File in Keil MDK
1. Open the Project
Launch Keil MDK and open your target project. If you don’t have a project yet, create a new one first.
2. Configure Output Options
Open the Options for Target dialog and navigate to the User tab.
In the Run User Programs After Build/Rebuild section, check Run #1.
In the Run #1 input box, enter the following command:
Go to the Project menu and select Options for Target (or press the shortcut key Alt+F7).
In the pop-up dialog, switch to the Output tab.
Check Create HEX File to ensure the generation of a Hex file. Although this step does not directly generate a Bin file, the Hex file serves as the basis for Bin file generation.
3. Use the fromelf Tool to Generate a Bin File
Keil MDK includes a tool called fromelf, which can convert Hex or ELF files to Bin files. The specific configuration steps are as follows:
C:\Keil_v5\ARM\ARMCC\bin\fromelf.exe --bin -o ..\MDKBOOT.bin ..\MDKObjects\BOOT_MDK.axf
4. Compile the Project
After saving the settings, click Build (F7) or Rebuild (Ctrl+Alt+F7) to compile the project.
Once compilation is complete, the fromelf tool will automatically generate the Bin file and save it to the specified path.
5. Verify the Output
Open the output directory (e.g., .Output
) and check if the project.bin
file has been generated.
If the file exists, the generation was successful.
Related:
- EXT4, SquashFS, JFFS2 & More: File System Comparison
- Why Is Space Occupied on Hard Drives with No Files?
Disclaimer:
- This channel does not make any representations or warranties regarding the availability, accuracy, timeliness, effectiveness, or completeness of any information posted. It hereby disclaims any liability or consequences arising from the use of the information.
- This channel is non-commercial and non-profit. The re-posted content does not signify endorsement of its views or responsibility for its authenticity. It does not intend to constitute any other guidance. This channel is not liable for any inaccuracies or errors in the re-posted or published information, directly or indirectly.
- Some data, materials, text, images, etc., used in this channel are sourced from the internet, and all reposts are duly credited to their sources. If you discover any work that infringes on your intellectual property rights or personal legal interests, please contact us, and we will promptly modify or remove it.