CCSv9 Static Lib 静态库封装及使用
Written By Tomy Stark.
E-mail: ro7enkranz@qq.com
Ver 1.0.0Note:
默认已将 controlSUITE 安装在 "C:\ti\" 目录下
Code Composer Studio Version: 9.0.1.00004
1. 创建工程
通过 Project -> New CCS Project 分别创建两个工程:
工程1 - 应用工程
Target: TMS320F28027
Project Name:
A_F28027_TestCase
Tool-chain:
Output type:
Executable
Output format:
legacy COFF
Linker command file:
1
C:\ti\controlSUITE\device_support\f2802x\v230\f2802x_common\cmd\F28027.cmd
Runtime support library: <automatic>
Project templates and examples:
- Empty Project (with main.c)
工程2 - 静态库工程
- Target: TMS320F28027
- Connection: Texas Instruments XDS100v3 USB Debug Probe
- Project Name:
A_F28027_TestCase_Lib
- Tool-chain:
- Output type:
Static Library
- Output format:
legacy COFF
- Output type:
- Project templates and examples:
- Empty Project
2. 工程设置
工程1 - 应用工程
添加 Linker File(*.cmd)
如下图所示,将以下目录下的链接文件
F2802x_Headers_nonBIOS.cmd
拖动到工程目录下,此时弹出对话框File Operation
,选择Link to files
,之后下拉列表框内选择TI_PRODUCTS_DIR
,接着单击OK
即可。该链接文件用于将外设寄存器映射到正确的内存地址。1
C:\ti\controlSUITE\device_support\f2802x\v230\f2802x_headers\cmd
添加 controlSUITE 库源文件(*.asm, *.c)
分别将以下目录下的文件添加到工程当中
(相对路径添加法)
。1
2C:\ti\controlSUITE\device_support\f2802x\v230\f2802x_common\source\
C:\ti\controlSUITE\device_support\f2802x\v230\f2802x_headers\source\
1. 具体步骤
右键单击工程名 -> New -> Folder:
选择本工程: A_F28027_TestCase
Folder name: F2802x_Common
单击 Advanced
选择 Link to alternate location (Linked Folder)
方法一:编辑框直接输入以下地址
1
TI_PRODUCTS_DIR/controlSUITE/device_support/f2802x/v230/f2802x_common/source
- 方法二:Variables -> TI_PRODUCTS_DIR -> Extend -> controlSUITE -> device_support -> f2802x -> v230 -> f2802x_common -> source -> OK
Finish
2. 以同样方法添加其余目录下的源文件
1 | TI_PRODUCTS_DIR/controlSUITE/device_support/f2802x/v230/f2802x_headers/source |
添加 controlSUITE 库头文件(*.h)
Project -> Properties -> CCS Build -> C2000 Compiler -> Include Options -> Add dir to #include search path(–include_path, -I)
1
2
3
4${PROJECT_ROOT}
${CG_TOOL_ROOT}/include
${TI_PRODUCTS_DIR}/controlSUITE/device_support/f2802x/v230/f2802x_common/include
${TI_PRODUCTS_DIR}/controlSUITE/device_support/f2802x/v230/f2802x_headers/include添加全局宏
Project -> Properties -> CCS Build -> C2000 Compiler -> Predefined Symbols -> Pre-define NAME(–define, -D)
- _DEBUG
- LARGE_MODEL
- FLASH
- DEBUG
编译后的错误(Error)解决
1. 编译后报很多重名错误,类似如下
symbol "_DSP28x_DisableInt" redefined: first defined in "./F2802x_Common/f2802x_asmfuncs.obj"; redefined in "./F2802x_Common/f2802x_disint.obj"
解决方法:
右键单击对应源文件 -> Exclude from Build
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15/* A. 如下源文件二组择一组排除编译 */
/* Exclude 如下2个文件 */
f2802x_swprioritizeddefaultisr.c
f2802x_swprioritizedpievect.c
/* 或如下2个文件 */
f2802x_defaultisr.c
f2802x_pievect.c
/* B. 如下源文件二组择一组排除编译 */
/* Exclude 如下1个文件 */
f2802x_asmfuncs.asm
/* 或如下3个文件 */
f2802x_usdelay.asm
f2802x_dbgier.asm
f2802x_disint.asm
编译后的报警(Warning)解决
1. #10210-D null: creating “.esysmem” section with default size of 0x400; use the -heap option to change the default size
解决方法:
Project -> Properties -> CCS Build -> C2000 Linker -> Basic Options:
Heap size for C/C++ dynamic memory allocation (–heap_size, -heap) = 0x400
3. 创建源文件
通过 New -> Header File 或 Source File 分别创建头文件和源文件
Step 1. 工程2 - 静态库工程
创建
LIB_MathFuncs.h
和LIB_MathFuncs.c
LIB_MathFuncs.h 1
2
3
4
5
6
7
8
uint32_t LIB_Math_Add(uint32_t x, uint32_t y);LIB_MathFuncs.c 1
2
3
4
5
6
7
8
9
10
11
12
/*******************************************************************************
* @name : LIB_Math_Add
* @brief : 创建一个加法函数,仅做演示。
* @param : uint32_t x, uint32_t y
* @retval : uint32_t
*******************************************************************************/
uint32_t LIB_Math_Add(uint32_t x, uint32_t y)
{
return (x + y);
}编译静态库工程
编译之后即可发现本工程的
Debug
目录下生成了A_F28027_TestCase_Lib.lib
库文件。
Step 2. 工程1 - 应用工程
复制库文件
将
A_F28027_TestCase_Lib.lib
和LIB_MathFuncs.h
复制到应用工程下,如图:添加 A_F28027_TestCase_Lib 库头文件(*.h)
Project -> Properties -> CCS Build -> C2000 Compiler -> Include Options -> Add dir to #include search path(–include_path, -I)
1
${PROJECT_ROOT}/DTek_LIB
添加 A_F28027_TestCase_Lib 库引用(*.lib)
Project -> Properties -> CCS Build -> C2000 Linker -> File Search Path -> Include library file or command file as input (–library, -l)
1
${PROJECT_ROOT}/DTek_LIB/A_F28027_TestCase_Lib.lib
创建
main.h
和main.c
main.h 1
2
3
4main.c 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
volatile uint32_t resultVal = 0U;
/*******************************************************************************
* @name : main
* @brief :
* @param : void
* @retval : int
*******************************************************************************/
int main(void)
{
resultVal = LIB_Math_Add(0, 1);
while (resultVal)
{
/* TODO: Do something here... */
}
return 0;
}
4. 调试
进入调试模式验证 静态库
函数是否能够被正常调用并执行