Embedded Studio本身有直接导入Keil工程文件的功能,导入也很方便。但今天我们试直接创建一个用ARMCC来编译的Embedded Studio工程文件。

Embedded Studio工程文件结构

一个.emProject文件包含一个解决方案,每个解决方案可以包含多个工程和多个配置。每个工程又包含多个配置,工程中的配置是可以继承解决方案中的同名配置的。

图 1

创建一个新工程

点击 File>>New Project...,选择将工程添加到一个新的解决方案中,还是添加到当前解决方案中。我们这儿选择创建一个全新的解决方案。

图 3

选择外部编译可执行文件,设置好工程名及存储路径。点击Next后选择目标设备及调试接口以及默认创建的配置文件即可。

默认创建了一个Debug配置文件和一个隐藏的common配置。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<!DOCTYPE CrossStudio_Project_File>
<solution Name="LPC1752" target="8" version="2">
<project Name="Periphals">
<configuration
Name="Common"
arm_architecture="v7M"
arm_core_type="Cortex-M3"
arm_endian="Little"
arm_fpu_type=""
arm_target_device_name="LPC1752"
arm_target_interface_type="SWD"
debug_start_from_entry_point_symbol="No"
debug_target_connection="Simulator"
linker_section_placements_segments="FLASH1 RX 0x00000000 0x00010000;RAM1 RWX 0x10000000 0x00004000"
project_directory=""
project_type="Externally Built Executable" />
</project>
<configuration
Name="Debug"
c_preprocessor_definitions="DEBUG"
gcc_debugging_level="Level 3"
gcc_omit_frame_pointer="Yes"
gcc_optimization_level="None" />
</solution>

配置Keil编译器路径

我们刚刚创建的解决方案中,所有工程都是基于LPC1752的且都采用ARMCC进行编译。所以选择直接在解决方案中的common配置中对公共参数进行设置,这样所有工程的配置都可以继承这些配置。(导入keil工程自动生成的emProject文件是新创建了一个External Keil ARMCC的配置)

图 4

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<!DOCTYPE CrossStudio_Project_File>
<solution Name="LPC1752" target="8" version="2">
<project Name="Periphals">
<configuration
Name="Common"
arm_architecture="v7M"
arm_core_type="Cortex-M3"
arm_endian="Little"
arm_fpu_type=""
arm_target_device_name="LPC1752"
arm_target_interface_type="SWD"
debug_start_from_entry_point_symbol="No"
debug_target_connection="Simulator"
linker_section_placements_segments="FLASH1 RX 0x00000000 0x00010000;RAM1 RWX 0x10000000 0x00004000"
project_directory=""
project_type="Externally Built Executable" />
</project>
<configuration
Name="Debug"
c_preprocessor_definitions="DEBUG"
gcc_debugging_level="Level 3"
gcc_omit_frame_pointer="Yes"
gcc_optimization_level="None" />
<configuration
Name="Common"
c_preprocessor_definitions="CORE_M3;CHIP_LPC175X_6X"
c_user_include_directories=".;../../Common/board;../../Common/chip;../../Common/CMSIS;../../Hardware/;../../Hardware/config_175x_6x"
macros="KEIL_TOOLKIT_DIR=D:/Keil_v5/ARM" />
</solution>

KEIL_TOOLKIT_DIR=D:/Keil_v5/ARM就是配置本地Keil编译器路径。
注: 一定要在解决方案上右键选择Options...,在弹出的对话框中选择Common配置文件进行配置。

配置外部编译器为ARMCC

图 5

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<!DOCTYPE CrossStudio_Project_File>
<solution Name="LPC1752" target="8" version="2">
<project Name="Periphals">
<configuration
Name="Common"
arm_architecture="v7M"
arm_core_type="Cortex-M3"
arm_endian="Little"
arm_fpu_type=""
arm_target_device_name="LPC1752"
arm_target_interface_type="SWD"
debug_start_from_entry_point_symbol="No"
debug_target_connection="Simulator"
linker_section_placements_segments="FLASH1 RX 0x00000000 0x00010000;RAM1 RWX 0x10000000 0x00004000"
project_directory=""
project_type="Externally Built Executable" />
<configuration
BUILD_OPTIONS="ARM CC"
Name="Debug"
build_generic_options_file_name="$(StudioDir)/targets/ARMCC_build_options.xml" />
</project>
<configuration
Name="Debug"
c_preprocessor_definitions="DEBUG"
gcc_debugging_level="Level 3"
gcc_omit_frame_pointer="Yes"
gcc_optimization_level="None" />
<configuration
Name="Common"
c_preprocessor_definitions="CORE_M3;CHIP_LPC175X_6X"
c_user_include_directories=".;../../Common/board;../../Common/chip;../../Common/CMSIS;../../Hardware/;../../Hardware/config_175x_6x"
macros="KEIL_TOOLKIT_DIR=D:/Keil_v5/ARM" />
</solution>

注: 必须在工程上点击右键选择Options...,并设置Debug配置中的External Compiler为ARMCC。

添加源文件

直接将源文件夹拖动至工程目录下,就可以添加目录下的所有文件。但这样拖动添加的文件夹是没有包含子目录及子目录下的文件的。可以通过以下设置自动添加子目录及子目录下的文件。

图 6

注: 一定要在文件夹上右键选择Options...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<!DOCTYPE CrossStudio_Project_File>
<solution Name="LPC1752" target="8" version="2">
<project Name="Periphals">
<configuration
Name="Common"
arm_architecture="v7M"
arm_core_type="Cortex-M3"
arm_endian="Little"
arm_fpu_type=""
arm_target_device_name="LPC1752"
arm_target_interface_type="SWD"
debug_start_from_entry_point_symbol="No"
debug_target_connection="Simulator"
linker_section_placements_segments="FLASH1 RX 0x00000000 0x00010000;RAM1 RWX 0x10000000 0x00004000"
project_directory=""
project_type="Externally Built Executable" />
<configuration
BUILD_OPTIONS="ARM CC"
Name="Debug"
build_generic_options_file_name="$(StudioDir)/targets/ARMCC_build_options.xml" />
<folder
Name="Application"
exclude=""
filter="*.*"
path="../../Application"
recurse="Yes" />
<folder
Name="Common"
exclude=""
filter="*.*"
path="../../Common"
recurse="Yes" />
<folder
Name="Hardware"
exclude=""
filter="*.*"
path="../../Hardware"
recurse="Yes" />
</project>
<configuration
Name="Debug"
c_preprocessor_definitions="DEBUG"
gcc_debugging_level="Level 3"
gcc_omit_frame_pointer="Yes"
gcc_optimization_level="None" />
<configuration
Name="Common"
c_preprocessor_definitions="CORE_M3;CHIP_LPC175X_6X"
c_user_include_directories=".;../../Common/board;../../Common/chip;../../Common/CMSIS;../../Hardware/;../../Hardware/config_175x_6x"
macros="KEIL_TOOLKIT_DIR=D:/Keil_v5/ARM" />
</solution>

编译工程

至此已经可以通过keil的ARMCC编译工程了,但仍有一些问题。此时的编译结果如下图

图 7

只有Flash使用情况,却没有RAM使用情况。对工程的Debug配置添加如下图配置

图 8

再次新编译结果如下图

图 9

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

<!DOCTYPE CrossStudio_Project_File>
<solution Name="LPC1752" target="8" version="2">
<project Name="Periphals">
<configuration
Name="Common"
arm_architecture="v7M"
arm_core_type="Cortex-M3"
arm_endian="Little"
arm_fpu_type=""
arm_target_device_name="LPC1752"
arm_target_interface_type="SWD"
debug_start_from_entry_point_symbol="No"
debug_target_connection="Simulator"
linker_section_placements_segments="FLASH1 RX 0x00000000 0x00010000;RAM1 RWX 0x10000000 0x00004000"
project_directory=""
project_type="Externally Built Executable" />
<configuration
BUILD_OPTIONS="ARM CC"
Name="Debug"
build_generic_options_file_name="$(StudioDir)/targets/ARMCC_build_options.xml"
debug_target_connection="J-Link"
linker_additional_options="--ro_base=0x00000000;--rw_base=0x10000000;--first=__Vectors" />
<folder
Name="Application"
exclude=""
filter="*.*"
path="../../Application"
recurse="Yes" />
<folder
Name="Common"
exclude=""
filter="*.*"
path="../../Common"
recurse="Yes" />
<folder
Name="Hardware"
exclude=""
filter="*.*"
path="../../Hardware"
recurse="Yes" />
</project>
<configuration
Name="Debug"
c_preprocessor_definitions="DEBUG"
gcc_debugging_level="Level 3"
gcc_omit_frame_pointer="Yes"
gcc_optimization_level="None" />
<configuration
Name="Common"
c_preprocessor_definitions="CORE_M3;CHIP_LPC175X_6X"
c_user_include_directories=".;../../Common/board;../../Common/chip;../../Common/CMSIS;../../Hardware/;../../Hardware/config_175x_6x"
macros="KEIL_TOOLKIT_DIR=D:/Keil_v5/ARM" />
</solution>

编译后的程序下载到目标板正常运行