在KEIL中生成bin文件的方法

生成hex文件

KEIL中默认生成的是axf文件。

如果想要生成hex文件,则只需要简单地勾一下:

在KEIL中生成bin文件的方法_第1张图片

 

生成bin文件

要生成bin文件,则需要用到fromelf。

Keil自带了一个小工具,可以通过执行指令来将AXF文件转换为BIN文件这就需要调用一个外部程序fromelf.exe来将AXF文件转换为BIN格式文件。

fromelf.exe文件的位置在安装目录 Keil_v5\ARM\ARMCC\bin 或者 Keil_v5\ARM\ARMCLANG\bin 目录下。

在Options -> User -> After Build/Rebuild -> Run#1中输入:

C:\Keil_v5\ARM\ARMCLANG\bin\fromelf.exe --bin -o  ./Objects/Demo.bin ./Objects/Demo.axf

其中-o后面的要输出目标bin文件的路径和文件名;最后面的是生成的axf文件的路径及文件名。

这个方法网上有很多例子可以参考。

在KEIL中生成bin文件的方法_第2张图片

 

fromelf详解

首先参考KEIL官网的手册:

fromelf Command-line Options

http://www.keil.com/support/man/docs/armutil/armutil_pge1362128884798.htm

 

主要内容如下:

ARM 映像转换工具
fromelf [options] input_file
选项:
--help 显示帮助信息
--vsn 显示版本信息
--output file 输出文件名. (默认输出 -text 格式)
--nodebug 不要输出调试信息到映像文件中
--nolinkview 不要输出段信息到映像文件中

二进制输出格式:
--bin 普通二进制
--m32 摩托罗拉32位Hex码
--i32 英特尔32位Hex码
--vhx 定向字节的 Hex 格式
--base addr 为 m32,i32设置基地址(可选的)

输出格式要求的调试信息
--fieldoffsets Structures/Classes的汇编描述
--expandarrays Arrays inside and outside structures are expanded

其他输出格式:
--elf ELF格式
--text 文本信息
文本信息的标志
-v 详细信息
-a 打印数据的地址信息 (得到的.axf映像文件)
-c 汇编码
-d 打印数据的段内容
-e 打印例表
-g 打印调试表
-r 打印重定位信息
-s 打印符号表
-t 打印字符表
-y 打印段内容分析
-z 打印代码与数据的大小信息

 

可移植的方法

上述方法有一个不好的问题,就是在一个项目组里面多人同时开发一个项目时,如果大家安装KEIL开发环境时的路径不一样,则无法共享同一个配置。另外,当完成一个项目的开发后,再开始一个新的项目时,生成的axf文件的文件名也需要重新配置。为了解决这个问题,可以使用以下的命令行:

fromelf --bin -o "[email protected]" "#L"

或者

$K\ARM\ARMCC\bin\fromelf.exe  --bincombined [email protected] !L

自动生成跟工程名称相同的bin文件。

在KEIL中生成bin文件的方法_第3张图片

 

说明:

符号代号(Key Code)
$ 扩展为 指定文件的路径名
@ 表示 Output -> Name of Exectable:定义的工程名,比如test1
build工程后,最终生成的bin文件名称将是test1.bin

当前目录下的扩展路径

!L 编译(Build)后,就是 .\obj\xx.axf文件

文件代号(File Code)
K  keil develop chaintool 工具链(fromelf.exe)
L

Linker output file

L.bin 编译后,生成的就是最终的xx.bin文件

参考:

Key Sequence for Tool Parameters
http://www.keil.com/support/man/docs/uv4/uv4_ut_keysequence.htm

Use Key Sequences to pass arguments from µVision to external user programs. Key Sequences are combinations of a Key Code and a File Code. Key sequences can be used, for example, in the dialogsToolsSVCSOptions for Target — User, or from the command line. The following rules apply:

  • Certain Key Codes have to be duplicated when used from the command line.
    To use the symbols $, #, %, @, ~, ^
    escape them with $$, ##, %%, @@, ~~, ^^.
  • Enclose Key Sequences within quotes (" ") when using folder names that might contain special characters (space~, or #).

Key Codes and File Codes are listed in the tables below:

Key Code Description
% File name with extension (PROJECT1.UVPROJ)
# File name with extension and complete path specification (C:\MYPROJECT\PROJECT1.UVPROJ)
@ File name without extension or path specification (PROJECT1)
$ Path name of a file. Path names get extended with a backslash. For example, $P could generate C:\MYPROJECT\.
! File name with extension and relative path specification to the current folder (.\SRC\TEST.C)
~ 1 Line number of the current cursor position
^ 1 Column number of the current cursor position
File Code Description
$D Device name as selected from the Device Database.
E Editor file name currently in focus.
F

Depending on the context, this File Code returns:

  • The file selected in the window Project.
  • The currently active editor file.
  • The file that is currently translated by a build process.
H Application HEX file name (PROJECT1.H86).
$J Absolute compiler system include folder. Compiler base folders are listed in the fieldProject — Manage — Project Items — Folder/Extensions - ARMCC Folder. The include path depends on the compiler selected in Options for Target - Code Generation - ARM Compiler.
K Absolute root folder of the development toolchain, regardless of the Key Code used.
L Linker output file. Typically the executable file used for debugging (PROJECT1).
$M CPU mask revision number.
P Current project file name.
X µVision executable program file (..\UV4\UV4.EXE). Works for For Key Code %, # @.
$X XTAL clock frequency in MHz as specified in Options for Target — Target — XTAL.
^X XTAL clock frequency in kHz as specified in Options for Target — Target — XTAL.

 

 

 

 

 

 

你可能感兴趣的:(KEIL-MDK开发环境)