TI의 C2000 Delfino 시리즈의 32비트 마이크로컨트롤러로, 모터 제어(motor control), 전력 변환(power conversion), 실시간 제어 애플리케이션(real-time control applications)에 최적화되어 있습니다 (TI's 32-bit microcontroller of the C2000 Delfino series, optimized for motor control, power conversion, and real-time control applications). CMD 파일(Linker Command File)은 Code Composer Studio(CCS)에서 프로젝트를 빌드할 때 메모리 할당과 섹션 배치를 제어하는 핵심 파일입니다 (The CMD file (Linker Command File) is a critical file that controls memory allocation and section placement when building projects in Code Composer Studio (CCS)). 이 문서는 CMD 파일의 역할, 구조, 작성 방법, 그리고 다양한 실용적인 예제를 상세히 설명하여 초보자와 숙련된 개발자 모두가 C2000의 메모리 관리(memory management)를 효과적으로 수행할 수 있도록 돕습니다 (This document provides a detailed explanation of the CMD file's role, structure, writing methods, and various practical examples to help both beginners and experienced developers effectively manage memory for C2000).
1. CMD 파일 개요 (Overview of CMD File)
CMD 파일은 TI의 링커가 소스 코드와 오브젝트 파일을 결합하여 실행 가능한 이미지(.out)를 생성할 때 사용하는 스크립트 파일입니다 (The CMD file is a script used by TI's linker to combine source code and object files to create an executable image (.out)). TMS320F28377D와 같은 C2000 디바이스는 복잡한 메모리 구조(complex memory structure)를 가지므로, CMD 파일은 메모리 맵(memory map)을 정의하고 코드 및 데이터를 적절한 메모리 영역에 배치하는 데 필수적입니다 (For C2000 devices like the TMS320F28377D, which have a complex memory structure, the CMD file is essential for defining the memory map and placing code and data in appropriate memory regions).
1.1 CMD 파일의 역할 (Role of CMD File)
- 메모리 정의 (Memory Definition): 디바이스의 물리적 메모리(Flash, RAM, OTP 등)를 주소와 크기로 정의합니다 (Defines the device's physical memory regions such as Flash, RAM, and OTP with addresses and sizes).
- 섹션 배치 (Section Placement): 컴파일러가 생성한 섹션(.text, .data, .bss 등)을 메모리 영역에 매핑합니다 (Maps compiler-generated sections like .text, .data, and .bss to memory regions).
- 링크 제어 (Link Control): 스택/힙 크기, 엔트리 포인트, 초기화 루틴을 지정합니다 (Specifies stack/heap sizes, entry points, and initialization routines).
- 특수 섹션 처리 (Special Section Handling): Flash API, IQmath, CLA(Control Law Accelerator)용 섹션을 관리합니다 (Manages sections for Flash API, IQmath, and CLA).
- 디버깅 지원 (Debugging Support): 메모리 배치를 명확히 하여 CCS에서 메모리 상태를 쉽게 확인할 수 있습니다 (Clarifies memory placement for easy memory state inspection in CCS).
1.2 TMS320F28377D 메모리 구조 (TMS320F28377D Memory Structure)
TMS320F28377D의 메모리 구조는 CMD 파일 작성의 기반입니다 (The memory structure of the TMS320F28377D forms the basis for writing CMD files). 주요 메모리 영역은 다음과 같습니다 (The main memory regions are as follows):
- Flash:
- 크기 (Size): 512KB (256K x 16)
- 주소 (Address): 0x080000 ~ 0x0BFFFF
- 용도 (Purpose): 프로그램 코드(program code), 상수(constants), Flash API 저장.
- RAM:
- M0 RAM: 2KB (0x000080 ~ 0x0007FF), CPU1/CPU2 공용(shared), 스택/데이터(stack/data).
- M1 RAM: 2KB (0x000800 ~ 0x000FFF), CPU1/CPU2 공용(shared), 스택/데이터(stack/data).
- LS0~LS5 RAM: 각 8KB (0x008000 ~ 0x00FFFF), 로컬 공유 RAM(local shared RAM), 코드/데이터(code/data).
- GS0~GS15 RAM: 각 4KB (0x00C000 ~ 0x01BFFF), 글로벌 공유 RAM(global shared RAM), 데이터/버퍼(data/buffer).
- Boot ROM:
- 크기 (Size): 32KB (0x3F8000 ~ 0x3FFFFF)
- 용도 (Purpose): 부트로더(bootloader), 기본 루틴(basic routines), 읽기 전용(read-only).
- OTP (One-Time Programmable):
- 크기 (Size): 1KB (0x078000 ~ 0x0783FF)
- 용도 (Purpose): 보안 설정(DCSM), 캘리브레이션 데이터(calibration data), 읽기 전용(read-only).
- CLA RAM:
- CLAL0RAM: CLA 프로그램용(program), 1KB.
- CLAMSGxRAM: CLA 데이터/메시지용(data/message), 1KB.
- Peripheral Registers:
- 주소 (Address): 0x000000 ~ 0x007FFF
- 용도 (Purpose): 주변 장치 제어 레지스터(peripheral control registers).
- Reset Vector:
- 주소 (Address): 0x3FFFC0 ~ 0x3FFFC1
- 용도 (Purpose): 부트 시 프로그램 시작 지점(program start point at boot).
1.3 CMD 파일의 중요성 (Importance of CMD File)
- 정확한 메모리 관리 (Accurate Memory Management): 잘못된 메모리 배치는 런타임 오류(runtime errors)나 비효율적인 실행을 초래합니다 (Incorrect memory placement can cause runtime errors or inefficient execution).
- 성능 최적화 (Performance Optimization): 자주 실행되는 코드를 RAM에 배치하여 속도를 향상시킵니다 (Placing frequently executed code in RAM improves speed).
- 프로덕션 대비 (Production Readiness): Flash 기반 CMD는 배포용, RAM 기반 CMD는 디버깅용으로 사용됩니다 (Flash-based CMDs are used for production, while RAM-based CMDs are used for debugging).
- CLA 및 Flash API 지원 (CLA and Flash API Support): 고급 기능 활용 시 특수 섹션 정의가 필요합니다 (Special section definitions are required for advanced features).
2. CMD 파일의 구조 (Structure of CMD File)
CMD 파일은 두 가지 주요 섹션으로 구성됩니다 (The CMD file consists of two main sections):
- MEMORY 섹션 (MEMORY Section): 디바이스의 물리적 메모리 영역을 정의합니다 (Defines the device's physical memory regions).
- SECTIONS 섹션 (SECTIONS Section): 코드 및 데이터 섹션을 메모리 영역에 매핑합니다 (Maps code and data sections to memory regions).
2.1 MEMORY 섹션 (MEMORY Section)
MEMORY 섹션은 디바이스의 메모리 영역을 정의합니다 (The MEMORY section defines the device's memory regions). 각 영역은 이름, 시작 주소, 크기, 속성을 지정합니다 (Each region specifies a name, start address, size, and attributes).
구문 (Syntax):
MEMORY
{
NAME : origin = ADDRESS, length = SIZE, attr = [R|W|X]
}
- NAME: 메모리 영역의 고유 이름 (예: FLASH, RAMM0) (Unique name of the memory region, e.g., FLASH, RAMM0).
- origin: 시작 주소 (16진수) (Start address in hexadecimal).
- length: 메모리 크기 (16진수, 워드 단위) (Memory size in hexadecimal, word units).
- attr: 속성 (R: 읽기, W: 쓰기, X: 실행 가능) (Attributes: R for read, W for write, X for executable).
예시 (Example):
MEMORY
{
RESET : origin = 0x3FFFC0, length = 0x000002
FLASH : origin = 0x080000, length = 0x040000 /* 256KB */
RAMM0 : origin = 0x000080, length = 0x000780 /* 2KB */
RAMM1 : origin = 0x000800, length = 0x000800 /* 2KB */
RAMLS0 : origin = 0x008000, length = 0x002000 /* 8KB */
RAMLS1 : origin = 0x00A000, length = 0x002000 /* 8KB */
RAMGS0 : origin = 0x00C000, length = 0x001000 /* 4KB */
BOOTROM : origin = 0x3F8000, length = 0x008000 /* 32KB */
OTP : origin = 0x078000, length = 0x000400 /* 1KB */
CLAL0RAM : origin = 0x008000, length = 0x001000 /* CLA Program RAM */
CLAMSGxRAM : origin = 0x009000, length = 0x001000 /* CLA Message RAM */
}
설명 (Description): 이 예시는 TMS320F28377D의 주요 메모리 영역을 정의합니다 (This example defines the main memory regions of the TMS320F28377D). Flash, RAM, OTP, CLA RAM 등 각 영역의 주소와 크기를 정확히 명시하여 정확한 메모리 배치를 보장합니다 (Each region, such as Flash, RAM, OTP, and CLA RAM, is specified with its address and size to ensure accurate memory placement).
2.2 SECTIONS 섹션 (SECTIONS Section)
SECTIONS 섹션은 컴파일러가 생성한 섹션(.text, .data 등)을 메모리 영역에 매핑합니다 (The SECTIONS section maps compiler-generated sections like .text and .data to memory regions).
구문 (Syntax):
SECTIONS
{
.SECTION_NAME :> MEMORY_NAME
}
- .SECTION_NAME: 컴파일러가 생성한 섹션 이름 (예: .text, .data) (Name of the compiler-generated section, e.g., .text, .data).
- MEMORY_NAME: MEMORY 섹션에서 정의한 메모리 영역 (Memory region defined in the MEMORY section).
주요 섹션 (Main Sections):
- .text: 실행 가능한 코드 (Executable code).
- .data: 초기화된 전역/정적 변수 (Initialized global/static variables).
- .bss: 초기화되지 않은 전역/정적 변수 (Uninitialized global/static variables).
- .const: 읽기 전용 상수 (Read-only constants).
- .econst: C2000 전용 읽기 전용 상수 (C2000-specific read-only constants).
- .ebss: C2000 전용 초기화되지 않은 변수 (C2000-specific uninitialized variables).
- .stack: 스택 메모리 (Stack memory).
- .cinit: C 초기화 테이블 (C initialization table).
- .pinit: C++ 초기화 테이블 (C++ initialization table).
- .switch: 스위치 문 테이블 (Switch statement table).
- codestart: 프로그램 시작 지점 (Program start point).
- ramfuncs: Flash에서 로드되고 RAM에서 실행되는 함수 (Functions loaded from Flash and executed in RAM).
- Fapi_Flash: Flash API 함수 (Flash API functions).
- .Cla1Prog: CLA 프로그램 코드 (CLA program code).
- Cla1DataRam: CLA 데이터 (CLA data).
예시 (Example):
SECTIONS
{
.text :> FLASH
.const :> FLASH
.cinit :> FLASH
.pinit :> FLASH
.switch :> FLASH
.data :> RAMLS0
.bss :> RAMLS0
.ebss :> RAMLS0
.econst :> RAMLS0
.stack :> RAMM0
codestart :> FLASH
ramfuncs : LOAD = FLASH,
RUN = RAMLS1,
LOAD_START(_RamfuncsLoadStart),
LOAD_SIZE(_RamfuncsLoadSize),
RUN_START(_RamfuncsRunStart)
table(RAM)
}
2.3 고급 기능 (Advanced Features)
- LOAD/RUN 분리 (LOAD/RUN Separation): 섹션을 Flash에서 로드하고 RAM에서 실행하도록 설정합니다 (Sets sections to load from Flash and run in RAM).
- LOAD_START, LOAD_SIZE, RUN_START: 복사 프로세스를 위한 심볼 정의 (Symbols for the copy process).
- table(RAM): 복사 테이블 생성 (Creates a copy table).
- ramfuncs : LOAD = FLASH, RUN = RAMLS1, LOAD_START(_RamfuncsLoadStart), LOAD_SIZE(_RamfuncsLoadSize), RUN_START(_RamfuncsRunStart) table(RAM)
- 스택/힙 설정 (Stack/Heap Configuration):
- --stack_size=0x400 /* 1KB 스택 (1KB Stack) */ --heap_size=0x200 /* 512B 힙 (512B Heap) */
- 엔트리 포인트 (Entry Point):
- --entry_point=code_start
3. CMD 파일 작성 절차 (CMD File Writing Procedure)
CMD 파일을 작성하는 단계는 다음과 같습니다 (The steps for writing a CMD file are as follows):
- 디바이스 메모리 맵 확인 (Check Device Memory Map):
- 레퍼런스 매뉴얼(SPRUI25)에서 메모리 주소와 크기를 확인합니다 (Check memory addresses and sizes in the Reference Manual (SPRUI25)).
- C2000Ware: device_support\f2837xd 폴더의 CMD 템플릿을 활용합니다 (Use CMD templates from the device_support\f2837xd folder in C2000Ware).
- 주요 메모리 영역(Flash, RAM, OTP, CLA RAM)별 주소와 크기를 기록합니다 (Record addresses and sizes for main memory regions like Flash, RAM, OTP, and CLA RAM).
- MEMORY 섹션 작성 (Write MEMORY Section):
- 메모리 영역의 시작 주소와 크기를 정확히 정의합니다 (Define start addresses and sizes for memory regions accurately).
- 실행 코드(Flash, RAMLSx)와 데이터(RAMLSx, RAMGSx)를 구분합니다 (Distinguish between executable code (Flash, RAMLSx) and data (RAMLSx, RAMGSx)).
- OTP와 Boot ROM은 읽기 전용으로 설정합니다 (Set OTP and Boot ROM as read-only).
- SECTIONS 섹션 작성 (Write SECTIONS Section):
- 코드(.text, .const 등)는 Flash 또는 RAMLSx에 배치합니다 (Place code sections like .text and .const in Flash or RAMLSx).
- 데이터(.data, .bss 등)는 RAMLSx 또는 RAMGSx에 배치합니다 (Place data sections like .data and .bss in RAMLSx or RAMGSx).
- 스택(.stack)은 RAMM0 또는 RAMM1에 배치합니다 (Place the stack (.stack) in RAMM0 or RAMM1).
- CLA 및 Flash API 섹션은 필요 시 추가합니다 (Add CLA and Flash API sections as needed).
- 특수 섹션 처리 (Handle Special Sections):
- ramfuncs: Flash에서 로드, RAM에서 실행 (Load from Flash, run in RAM).
- Fapi_Flash: Flash API용 섹션 (Section for Flash API).
- . Cla1Prog, Cla1DataRam: CLA 프로그램/데이터 (CLA program/data).
- codestart: 부트 시 시작 지점 (Program start point at boot).
- 링커 옵션 설정 (Set Linker Options):
- 스택 크기(--stack_size), 힙 크기(--heap_size)를 설정합니다 (Set stack size (--stack_size) and heap size (--heap_size)).
- 엔트리 포인트(--entry_point)를 지정합니다 (Specify the entry point (--entry_point)).
- 필요 시 --args로 명령줄 인수를 전달합니다 (Pass command-line arguments with --args if needed).
- 검증 및 디버깅 (Validation and Debugging):
- 빌드 후 .map 파일을 통해 섹션 배치를 확인합니다 (Check section placement in the .map file after building).
- 메모리 오버플로우 또는 충돌 시 MEMORY 크기와 SECTIONS 매핑을 수정합니다 (Modify MEMORY sizes and SECTIONS mapping if memory overflow or conflicts occur).
- CCS의 Memory Browser로 메모리 상태를 점검합니다 (Inspect memory state using CCS's Memory Browser).
4. CMD 파일 작성 고려사항 (Considerations for Writing CMD Files)
- 메모리 최적화 (Memory Optimization):
- 실행 속도가 중요한 코드는 RAMLSx 또는 RAMM0/M1에 배치합니다 (Place performance-critical code in RAMLSx or RAMM0/M1).
- 상수와 초기화 코드는 Flash에 배치하여 저장 공간을 절약합니다 (Place constants and initialization code in Flash to save space).
- CLA 프로그램은 CLAL0RAM, 데이터는 CLAMSGxRAM에 배치합니다 (Place CLA programs in CLAL0RAM and data in CLAMSGxRAM).
- 스택과 힙 (Stack and Heap):
- 기본 스택 크기: 0x400 (1KB) (Default stack size: 0x400 (1KB)).
- 힙은 동적 메모리 할당이 필요한 경우 적절히 설정합니다 (Set heap size appropriately for dynamic memory allocation).
- Flash 프로그래밍 (Flash Programming):
- Flash API 사용 시 Fapi_Flash 섹션을 추가합니다 (Add the Fapi_Flash section when using Flash API).
- 부트 시 RAM으로 복사하는 초기화 코드를 작성합니다 (Write initialization code to copy to RAM at boot).
- 보안 및 OTP (Security and OTP):
- OTP는 보안 설정(DCSM) 및 캘리브레이션 데이터에 사용됩니다 (OTP is used for security settings (DCSM) and calibration data).
- CMD에서 OTP를 읽기 전용으로 설정합니다 (Set OTP as read-only in the CMD file).
- 디버깅 vs. 프로덕션 (Debugging vs. Production):
- 디버깅: RAM 기반 CMD로 빠른 테스트를 수행합니다 (Debugging: Use RAM-based CMD for quick testing).
- 프로덕션: Flash 기반 CMD로 배포합니다 (Production: Use Flash-based CMD for deployment).
- C2000Ware 활용 (Using C2000Ware):
- C:\ti\c2000\C2000Ware_x_xx_xx_xx\device_support\f2837xd\linker_cmd의 템플릿을 사용합니다 (Use templates from C:\ti\c2000\C2000Ware_x_xx_xx_xx\device_support\f2837xd\linker_cmd).
5. 실용적인 CMD 파일 예제 (Practical CMD File Examples)
아래는 TMS320F28377D를 위한 다양한 CMD 파일 예제입니다 (Below are various CMD file examples for the TMS320F28377D). 각 예제는 특정 애플리케이션 시나리오를 고려하여 작성되었습니다 (Each example is tailored to specific application scenarios).
5.1 예제 1: 기본 Flash 기반 CMD 파일 (Example 1: Basic Flash-Based CMD File)
/* File: F28377D_Flash_lnk.cmd */
/* Description: TMS320F28377D Flash 기반 기본 CMD 파일 (Basic Flash-based CMD file for TMS320F28377D) */
/* Compiler: Code Composer Studio (TI C2000 Compiler) */
/* Target: TMS320F28377D */
--stack_size=0x400 /* 스택 크기 1KB (Stack size 1KB) */
--heap_size=0x200 /* 힙 크기 512B (Heap size 512B) */
--entry_point=code_start /* 프로그램 시작 지점 (Program start point) */
MEMORY
{
RESET : origin = 0x3FFFC0, length = 0x000002
FLASH : origin = 0x080000, length = 0x040000 /* 256KB */
RAMM0 : origin = 0x000080, length = 0x000780 /* 2KB */
RAMM1 : origin = 0x000800, length = 0x000800 /* 2KB */
RAMLS0 : origin = 0x008000, length = 0x002000 /* 8KB */
RAMLS1 : origin = 0x00A000, length = 0x002000 /* 8KB */
RAMGS0 : origin = 0x00C000, length = 0x001000 /* 4KB */
BOOTROM : origin = 0x3F8000, length = 0x008000 /* 32KB */
OTP : origin = 0x078000, length = 0x000400 /* 1KB */
}
SECTIONS
{
codestart :> FLASH
.text :> FLASH
.cinit :> FLASH
.pinit :> FLASH
.switch :> FLASH
.const :> FLASH
.data :> RAMLS0
.bss :> RAMLS0
.ebss :> RAMLS0
.econst :> RAMLS0
.stack :> RAMM0
ramfuncs : LOAD = FLASH,
RUN = RAMLS1,
LOAD_START(_RamfuncsLoadStart),
LOAD_SIZE(_RamfuncsLoadSize),
RUN_START(_RamfuncsRunStart)
table(RAM)
}
설명 (Description):
- 목적 (Purpose): 기본적인 Flash 기반 애플리케이션 (Basic Flash-based application).
- 메모리 배치 (Memory Placement):
- 코드(.text, .const 등)는 Flash에 저장 (Code sections like .text and .const are stored in Flash).
- 데이터(.data, .bss 등)는 RAMLS0에 배치 (Data sections like .data and .bss are placed in RAMLS0).
- 스택은 RAMM0에 배치 (Stack is placed in RAMM0).
- ramfuncs는 Flash에서 로드되고 RAMLS1에서 실행 (ramfuncs are loaded from Flash and executed in RAMLS1).
- 특징 (Features):
- 부트 시 ramfuncs를 RAM으로 복사하여 실행 속도를 최적화 (Optimizes execution speed by copying ramfuncs to RAM at boot).
- 스택 크기 1KB, 힙 크기 512B (Stack size 1KB, heap size 512B).
5.2 예제 2: RAM 기반 CMD 파일 (디버깅용) (Example 2: RAM-Based CMD File for Debugging)
/* File: F28377D_RAM_lnk.cmd */
/* Description: TMS320F28377D RAM 기반 디버깅용 CMD 파일 (RAM-based CMD file for debugging TMS320F28377D) */
/* Compiler: Code Composer Studio (TI C2000 Compiler) */
/* Target: TMS320F28377D */
--stack_size=0x400 /* 스택 크기 1KB (Stack size 1KB) */
--heap_size=0x200 /* 힙 크기 512B (Heap size 512B) */
--entry_point=code_start /* 프로그램 시작 지점 (Program start point) */
MEMORY
{
RESET : origin = 0x3FFFC0, length = 0x000002
RAMM0 : origin = 0x000080, length = 0x000780 /* 2KB */
RAMM1 : origin = 0x000800, length = 0x000800 /* 2KB */
RAMLS0 : origin = 0x008000, length = 0x002000 /* 8KB */
RAMLS1 : origin = 0x00A000, length = 0x002000 /* 8KB */
RAMGS0 : origin = 0x00C000, length = 0x001000 /* 4KB */
}
SECTIONS
{
codestart :> RAMLS0
.text :> RAMLS0
.cinit :> RAMLS0
.pinit :> RAMLS0
.switch :> RAMLS0
.const :> RAMLS0
.data :> RAMLS1
.bss :> RAMLS1
.ebss :> RAMLS1
.econst :> RAMLS1
.stack :> RAMM0
}
설명 (Description):
- 목적 (Purpose): 디버깅 시 빠른 코드 실행을 위한 RAM 기반 설정 (RAM-based configuration for fast code execution during debugging).
- 메모리 배치 (Memory Placement):
- 모든 코드와 데이터는 RAMLS0과 RAMLS1에 배치 (All code and data are placed in RAMLS0 and RAMLS1).
- 스택은 RAMM0에 배치 (Stack is placed in RAMM0).
- 특징 (Features):
- Flash를 사용하지 않아 빠른 빌드 및 테스트 가능 (No Flash usage enables fast build and test cycles).
- 프로덕션 환경에서는 Flash 기반 CMD로 전환 필요 (Switch to Flash-based CMD for production).
5.3 예제 3: CLA 및 Flash API 포함 CMD 파일 (Example 3: CMD File with CLA and Flash API)
/* File: F28377D_CLA_Flash_lnk.cmd */
/* Description: TMS320F28377D CLA 및 Flash API 포함 CMD 파일 (CMD file with CLA and Flash API for TMS320F28377D) */
/* Compiler: Code Composer Studio (TI C2000 Compiler) */
/* Target: TMS320F28377D */
--stack_size=0x400 /* 스택 크기 1KB (Stack size 1KB) */
--heap_size=0x200 /* 힙 크기 512B (Heap size 512B) */
--entry_point=code_start /* 프로그램 시작 지점 (Program start point) */
MEMORY
{
RESET : origin = 0x3FFFC0, length = 0x000002
FLASH : origin = 0x080000, length = 0x040000 /* 256KB */
RAMM0 : origin = 0x000080, length = 0x000780 /* 2KB */
RAMM1 : origin = 0x000800, length = 0x000800 /* 2KB */
RAMLS0 : origin = 0x008000, length = 0x002000 /* 8KB */
RAMLS1 : origin = 0x00A000, length = 0x002000 /* 8KB */
RAMGS0 : origin = 0x00C000, length = 0x001000 /* 4KB */
CLAL0RAM : origin = 0x008000, length = 0x001000 /* CLA Program RAM */
CLAMSGxRAM : origin = 0x009000, length = 0x001000 /* CLA Message RAM */
}
SECTIONS
{
codestart :> FLASH
.text :> FLASH
.cinit :> FLASH
.pinit :> FLASH
.switch :> FLASH
.const :> FLASH
.data :> RAMLS0
.bss :> RAMLS0
.ebss :> RAMLS0
.econst :> RAMLS0
.stack :> RAMM0
Fapi_Flash :> FLASH
.Cla1Prog : LOAD = FLASH,
RUN = CLAL0RAM,
LOAD_START(_Cla1ProgLoadStart),
LOAD_SIZE(_Cla1ProgLoadSize),
RUN_START(_Cla1ProgRunStart)
table(RAM)
Cla1DataRam :> CLAMSGxRAM
}
설명 (Description):
- 목적 (Purpose): CLA와 Flash API를 사용하는 고급 애플리케이션 (Advanced application using CLA and Flash API).
- 메모리 배치 (Memory Placement):
- 코드와 상수는 Flash에 배치 (Code and constants are placed in Flash).
- CLA 프로그램은 Flash에서 로드되고 CLAL0RAM에서 실행 (CLA program is loaded from Flash and executed in CLAL0RAM).
- CLA 데이터는 CLAMSGxRAM에 배치 (CLA data is placed in CLAMSGxRAM).
- Flash API는 Flash에 배치 (Flash API is placed in Flash).
- 특징 (Features):
- CLA를 활용한 고속 연산 지원 (Supports high-speed computation with CLA).
- Flash 프로그래밍을 위한 API 포함 (Includes API for Flash programming).
5.4 예제 4: IQmath 및 대용량 데이터 처리 CMD 파일 (Example 4: CMD File for IQmath and Large Data Handling)
/* File: F28377D_IQmath_lnk.cmd */
/* Description: TMS320F28377D IQmath 및 대용량 데이터 처리 CMD 파일 (CMD file for IQmath and large data handling for TMS320F28377D) */
/* Compiler: Code Composer Studio (TI C2000 Compiler) */
/* Target: TMS320F28377D */
--stack_size=0x600 /* 스택 크기 1.5KB (Stack size 1.5KB) */
--heap_size=0x400 /* 힙 크기 1KB (Heap size 1KB) */
--entry_point=code_start /* 프로그램 시작 지점 (Program start point) */
MEMORY
{
RESET : origin = 0x3FFFC0, length = 0x000002
FLASH : origin = 0x080000, length = 0x040000 /* 256KB */
RAMM0 : origin = 0x000080, length = 0x000780 /* 2KB */
RAMM1 : origin = 0x000800, length = 0x000800 /* 2KB */
RAMLS0 : origin = 0x008000, length = 0x002000 /* 8KB */
RAMLS1 : origin = 0x00A000, length = 0x002000 /* 8KB */
RAMGS0 : origin = 0x00C000, length = 0x001000 /* 4KB */
RAMGS1 : origin = 0x00D000, length = 0x001000 /* 4KB */
}
SECTIONS
{
codestart :> FLASH
.text :> FLASH
.cinit :> FLASH
.pinit :> FLASH
.switch :> FLASH
.const :> FLASH
.data :> RAMLS0
.bss :> RAMLS0
.ebss :> RAMGS0
.econst :> RAMLS0
.stack :> RAMM0
ramfuncs : LOAD = FLASH,
RUN = RAMLS1,
LOAD_START(_RamfuncsLoadStart),
LOAD_SIZE(_RamfuncsLoadSize),
RUN_START(_RamfuncsRunStart)
table(RAM)
IQmath :> FLASH
IQmathTables :> FLASH
}
설명 (Description):
- 목적 (Purpose): IQmath 라이브러리를 사용하는 고정소수점 연산 애플리케이션 (Fixed-point arithmetic application using the IQmath library).
- 메모리 배치 (Memory Placement):
- 코드와 IQmath 라이브러리는 Flash에 배치 (Code and IQmath library are placed in Flash).
- 대용량 데이터(.ebss)는 RAMGS0에 배치 (Large data (.ebss) is placed in RAMGS0).
- ramfuncs는 RAMLS1에서 실행 (ramfuncs are executed in RAMLS1).
- 특징 (Features):
- IQmath를 활용한 고속 수학 연산 지원 (Supports high-speed mathematical operations with IQmath).
- 대용량 데이터 처리를 위해 RAMGS0 사용 (Uses RAMGS0 for large data handling).
- 스택과 힙 크기를 증가(1.5KB, 1KB)하여 복잡한 연산 지원 (Increased stack and heap sizes (1.5KB, 1KB) to support complex computations).
5.5 예제 5: 다중 CPU (CPU1/CPU2) 지원 CMD 파일 (Example 5: CMD File for Multi-CPU Support (CPU1/CPU2))
/* File: F28377D_DualCPU_lnk.cmd */
/* Description: TMS320F28377D CPU1 및 CPU2 지원 CMD 파일 (CMD file for CPU1 and CPU2 support for TMS320F28377D) */
/* Compiler: Code Composer Studio (TI C2000 Compiler) */
/* Target: TMS320F28377D (CPU1) */
--stack_size=0x400 /* 스택 크기 1KB (Stack size 1KB) */
--heap_size=0x200 /* 힙 크기 512B (Heap size 512B) */
--entry_point=code_start /* 프로그램 시작 지점 (Program start point) */
MEMORY
{
RESET : origin = 0x3FFFC0, length = 0x000002
FLASH : origin = 0x080000, length = 0x040000 /* 256KB */
RAMM0 : origin = 0x000080, length = 0x000780 /* 2KB */
RAMM1 : origin = 0x000800, length = 0x000800 /* 2KB */
RAMLS0 : origin = 0x008000, length = 0x002000 /* 8KB */
RAMLS1 : origin = 0x00A000, length = 0x002000 /* 8KB */
RAMGS0 : origin = 0x00C000, length = 0x001000 /* 4KB */
RAMGS1 : origin = 0x00D000, length = 0x001000 /* 4KB */
IPC_MSGRAM : origin = 0x0003F8, length = 0x000008 /* IPC Message RAM */
}
SECTIONS
{
codestart :> FLASH
.text :> FLASH
.cinit :> FLASH
.pinit :> FLASH
.switch :> FLASH
.const :> FLASH
.data :> RAMLS0
.bss :> RAMLS0
.ebss :> RAMGS0
.econst :> RAMLS0
.stack :> RAMM0
ramfuncs : LOAD = FLASH,
RUN = RAMLS1,
LOAD_START(_RamfuncsLoadStart),
LOAD_SIZE(_RamfuncsLoadSize),
RUN_START(_RamfuncsRunStart)
table(RAM)
.ipc_msgram :> IPC_MSGRAM
}
설명 (Description):
- 목적 (Purpose): CPU1과 CPU2 간 통신(IPC)을 지원하는 CMD 파일 (CMD file supporting Inter-Processor Communication (IPC) between CPU1 and CPU2).
- 메모리 배치 (Memory Placement):
- 기본 코드는 Flash에 배치 (Base code is placed in Flash).
- 데이터는 RAMLS0과 RAMGS0에 배치 (Data is placed in RAMLS0 and RAMGS0).
- IPC 메시지용 메모리(IPC_MSGRAM)를 추가 (Adds IPC_MSGRAM for IPC messaging).
- 특징 (Features):
- CPU1과 CPU2 간 데이터 교환을 위한 IPC 메모리 지원 (Supports IPC memory for data exchange between CPU1 and CPU2).
- 다중 CPU 환경에서 동기화 및 통신 최적화 (Optimizes synchronization and communication in a multi-CPU environment).
5.6 예제 6: 고속 PWM 애플리케이션용 CMD 파일 (Example 6: CMD File for High-Speed PWM Application)
/* File: F28377D_PWM_lnk.cmd */
/* Description: TMS320F28377D 고속 PWM 애플리케이션용 CMD 파일 (CMD file for high-speed PWM application for TMS320F28377D) */
/* Compiler: Code Composer Studio (TI C2000 Compiler) */
/* Target: TMS320F28377D */
--stack_size=0x500 /* 스택 크기 1.25KB (Stack size 1.25KB) */
--heap_size=0x300 /* 힙 크기 768B (Heap size 768B) */
--entry_point=code_start /* 프로그램 시작 지점 (Program start point) */
MEMORY
{
RESET : origin = 0x3FFFC0, length = 0x000002
FLASH : origin = 0x080000, length = 0x040000 /* 256KB */
RAMM0 : origin = 0x000080, length = 0x000780 /* 2KB */
RAMM1 : origin = 0x000800, length = 0x000800 /* 2KB */
RAMLS0 : origin = 0x008000, length = 0x002000 /* 8KB */
RAMLS1 : origin = 0x00A000, length = 0x002000 /* 8KB */
RAMLS2 : origin = 0x00C000, length = 0x002000 /* 8KB */
RAMGS0 : origin = 0x00E000, length = 0x001000 /* 4KB */
}
SECTIONS
{
codestart :> FLASH
.text :> FLASH
.cinit :> FLASH
.pinit :> FLASH
.switch :> FLASH
.const :> FLASH
.data :> RAMLS0
.bss :> RAMLS0
.ebss :> RAMGS0
.econst :> RAMLS0
.stack :> RAMM0
ramfuncs : LOAD = FLASH,
RUN = RAMLS1,
LOAD_START(_RamfuncsLoadStart),
LOAD_SIZE(_RamfuncsLoadSize),
RUN_START(_RamfuncsRunStart)
table(RAM)
pwmfuncs : LOAD = FLASH,
RUN = RAMLS2,
LOAD_START(_PwmfuncsLoadStart),
LOAD_SIZE(_PwmfuncsLoadSize),
RUN_START(_PwmfuncsRunStart)
table(RAM)
}
설명 (Description):
- 목적 (Purpose): 고속 PWM 애플리케이션(예: 모터 제어)을 위한 CMD 파일 (CMD file for high-speed PWM applications, e.g., motor control).
- 메모리 배치 (Memory Placement):
- 기본 코드는 Flash에 배치 (Base code is placed in Flash).
- PWM 관련 함수(pwmfuncs)는 Flash에서 로드되고 RAMLS2에서 실행 (PWM-related functions (pwmfuncs) are loaded from Flash and executed in RAMLS2).
- 데이터는 RAMLS0과 RAMGS0에 배치 (Data is placed in RAMLS0 and RAMGS0).
- 특징 (Features):
- PWM 제어 함수를 RAMLS2에 배치하여 고속 실행 보장 (Places PWM control functions in RAMLS2 for high-speed execution).
- 스택과 힙 크기를 증가(1.25KB, 768B)하여 PWM 데이터 처리 지원 (Increased stack and heap sizes (1.25KB, 768B) to support PWM data processing).
6. CMD 파일 사용 방법 (How to Use CMD Files)
6.1 환경 설정 (Environment Setup)
- C2000Ware 설치 (Install C2000Ware):
- C:\ti\c2000\C2000Ware_x_xx_xx_xx에서 라이브러리 및 CMD 템플릿을 다운로드합니다 (Download libraries and CMD templates from C:\ti\c2000\C2000Ware_x_xx_xx_xx).
- device_support\f2837xd\linker_cmd 폴더를 확인합니다 (Check the device_support\f2837xd\linker_cmd folder).
- CCS 프로젝트 설정 (CCS Project Setup):
- TMS320F28377D 타겟으로 프로젝트를 생성합니다 (Create a project targeting TMS320F28377D).
- F28x_Project.h 및 관련 헤더 파일을 포함합니다 (Include F28x_Project.h and related header files).
- 프로젝트 속성 > CCS Build > C2000 Linker > File Search Path에서 CMD 파일 경로를 지정합니다 (Specify the CMD file path in Project Properties > CCS Build > C2000 Linker > File Search Path).
- 빌드 설정 (Build Settings):
- Flash 기반: --flash 옵션을 추가합니다 (Flash-based: Add the --flash option).
- RAM 기반: 디버깅 시 Flash 옵션을 비활성화합니다 (RAM-based: Disable Flash option during debugging).
6.2 CMD 파일 적용 (Applying CMD Files)
- CMD 파일을 프로젝트 폴더에 추가합니다 (Add the CMD file to the project folder).
- 프로젝트 속성에서 링커 설정에 CMD 파일 경로를 지정합니다 (Specify the CMD file path in the linker settings).
- 빌드 후 .map 파일을 확인하여 섹션 배치를 점검합니다 (Check section placement in the .map file after building).
6.3 하드웨어 준비 (Hardware Preparation)
- 개발 보드 (Development Board): TI ControlCARD 또는 LaunchPad를 사용합니다 (Use TI ControlCARD or LaunchPad).
- JTAG 디버깅 (JTAG Debugging): JTAG 에뮬레이터(XDS100v2, XDS200 등)를 연결합니다 (Connect a JTAG emulator like XDS100v2 or XDS200).
- Flash 프로그래밍 (Flash Programming): CCS의 Flash 도구 또는 Flash API를 사용합니다 (Use CCS Flash tools or Flash API).
- RAM 디버깅 (RAM Debugging): RAM 기반 CMD로 빠른 테스트를 수행합니다 (Perform quick tests with RAM-based CMD).
6.4 디버깅 (Debugging)
- .map 파일 분석 (Analyze .map File):
- 빌드 후 생성된 .map 파일로 섹션 주소와 크기를 확인합니다 (Check section addresses and sizes in the .map file generated after building).
- 메모리 오버플로우 여부를 점검합니다 (Check for memory overflow).
- Memory Browser:
- CCS의 Memory Browser로 메모리 내용을 확인합니다 (Inspect memory contents using CCS's Memory Browser).
- RAMM0, RAMLSx, Flash 등의 데이터 및 코드를 검증합니다 (Verify data and code in RAMM0, RAMLSx, and Flash).
- CLA 디버깅 (CLA Debugging):
- CLAL0RAM, CLAMSGxRAM의 내용을 확인합니다 (Check contents of CLAL0RAM and CLAMSGxRAM).
- CLA 레지스터 상태를 점검합니다 (Inspect CLA register states).
- 링커 에러 (Linker Errors):
- "section overflow": MEMORY 크기를 증가하거나 SECTIONS를 재배치합니다 (Increase MEMORY sizes or rearrange SECTIONS).
- "undefined symbol": codestart 또는 엔트리 포인트를 확인합니다 (Check codestart or entry point).
7. 추가 팁 (Additional Tips)
- C2000Ware 활용 (Using C2000Ware):
- C:\ti\c2000\C2000Ware_x_xx_xx_xx\device_support\f2837xd\examples에서 CMD 파일과 예제를 확인합니다 (Check CMD files and examples in C:\ti\c2000\C2000Ware_x_xx_xx_xx\device_support\f2837xd\examples).
- F28377D_Flash_lnk_cpu1.cmd, F28377D_RAM_lnk_cpu1.cmd 템플릿을 활용합니다 (Use templates like F28377D_Flash_lnk_cpu1.cmd and F28377D_RAM_lnk_cpu1.cmd).
- 메모리 최적화 (Memory Optimization):
- 자주 실행되는 함수는 ramfuncs로 RAM에 배치합니다 (Place frequently executed functions in ramfuncs in RAM).
- 대용량 데이터는 RAMGSx에 배치하여 RAMLSx를 절약합니다 (Place large data in RAMGSx to save RAMLSx).
- IQmath, Flash API 등 라이브러리는 Flash에 배치합니다 (Place libraries like IQmath and Flash API in Flash).
- Flash 프로그래밍 (Flash Programming):
- Flash API 사용 시 Fapi_Flash 섹션을 추가합니다 (Add the Fapi_Flash section when using Flash API).
- 부트 시 memcpy로 ramfuncs를 RAM으로 복사합니다 (Copy ramfuncs to RAM using memcpy at boot).
- CLA 활용 (Using CLA):
- CLA 프로그램은 CLAL0RAM, 데이터는 CLAMSGxRAM에 배치합니다 (Place CLA programs in CLAL0RAM and data in CLAMSGxRAM).
- CLA 태스크와 메인 CPU 간 동기화를 확인합니다 (Verify synchronization between CLA tasks and the main CPU).
- 문제 해결 (Troubleshooting):
- PWM 출력 없음 (No PWM Output): ePWM 관련 코드와 CMD의 ramfuncs 배치를 확인합니다 (Check ePWM-related code and ramfuncs placement in the CMD).
- 메모리 충돌 (Memory Conflict): .map 파일에서 섹션 크기와 메모리 경계를 점검합니다 (Check section sizes and memory boundaries in the .map file).
- CLA 오류 (CLA Errors): CLA 메모리 매핑과 태스크 초기화를 확인합니다 (Check CLA memory mapping and task initialization).
- TI 리소스 (TI Resources):
- TI E2E 포럼 (TI E2E Forum): CMD 파일 및 링커 관련 질문 해결 (Resolve CMD file and linker-related questions).
- 레퍼런스 매뉴얼 (Reference Manual) (SPRUI25): 메모리 맵, 레지스터 상세 정보 (Detailed information on memory map and registers).
- C2000Ware 예제 (C2000Ware Examples): device_support\f2837xd\examples\cpu1.
8. 결론 (Conclusion)
이 문서는 TMS320F28377D의 CMD 파일의 역할, 구조, 작성 방법을 한글과 영어로 상세히 설명하고, Flash 기반, RAM 기반, CLA, Flash API, IQmath, 다중 CPU, 고속 PWM 애플리케이션 등 다양한 시나리오에 맞는 예제를 제공했습니다 (This document provides a detailed explanation of the CMD file's role, structure, and writing methods in both Korean and English, with examples for various scenarios including Flash-based, RAM-based, CLA, Flash API, IQmath, multi-CPU, and high-speed PWM applications). CMD 파일은 메모리 관리와 코드 배치를 최적화하여 안정적이고 효율적인 애플리케이션 실행을 보장합니다 (The CMD file optimizes memory management and code placement to ensure stable and efficient application execution). 초보자는 C2000Ware의 템플릿을 활용하고, 숙련된 개발자는 애플리케이션 요구사항에 따라 CMD 파일을 커스터마이징하여 사용할 수 있습니다 (Beginners can use C2000Ware templates, while experienced developers can customize CMD files based on application requirements).
키워드 (Keywords): TMS320F28377D, CMD 파일 (CMD File), C2000, 링커 스크립트 (Linker Script), 메모리 맵 (Memory Map), Flash, RAM, CLA, Flash API, IQmath, 다중 CPU (Multi-CPU), 고속 PWM (High-Speed PWM), Code Composer Studio, 섹션 배치 (Section Placement), 스택 (Stack), 힙 (Heap)
'MCU > C2000' 카테고리의 다른 글
[TMS320F28335] ADC 사용법 : Bitfield 구조 활용 예제 코드 (0) | 2025.08.18 |
---|---|
[TMS320F28335] ePWM 사용법 : Bitfield 구조 활용 예제 코드 (1) | 2025.08.18 |
[TMS320F28377D] DC-DC 변환 토포롤로지별 ePWM 생성 방법: Bitfield 구조 활용 예제 코드 (1) | 2025.08.18 |
[TI C2000]TMS320F28377D, TMS320F28379D, TMS320F28388D 비교 (2) | 2025.08.18 |
[TMS320F28377D] FPU, TMU, VCU-II 사용법 : 예제 코드 및 활용 가이드 (1) | 2025.08.18 |
[TMS320F28377D] DAC 및 Fault Trip Zones 사용법 : Bitfield 구조 활용 예제 코드 (0) | 2025.08.18 |
[TMS320F28377D] USB, I2C, McBSP, uPP 사용법 : Bitfield 구조 활용 예제 코드 (0) | 2025.08.18 |
[TMS320F28377D] SDFM 사용법 : Bitfield 구조 활용 예제 코드 (1) | 2025.08.18 |