F28335

您所在的位置:网站首页 esp32c3f F28335

F28335

#F28335| 来源: 网络整理| 查看: 265

一、CMD文件详解

为了方便之后对CMD文件的修改,先大致了解和学习一下CMD文件。

1、两个伪指令

MEMORY和SECTIONS

MEMORY 指令:主要用来建立目标存储器的模型 ,规定各种类型的存储器的容量 SECTIONS指令:根据这个模型来安排各个段的位置,给段分配相应的存储器

1)MEMORY指令相关

MEMORY { PAGE 0: /* Program Memory */ /* Memory (RAM/FLASH/OTP) blocks can be moved to PAGE1 for data allocation */ ZONE0 : origin = 0x004000, length = 0x001000 /* XINTF zone 0 */ RAML0 : origin = 0x008000, length = 0x001000 /* on-chip RAM block L0 */ RAML1 : origin = 0x009000, length = 0x001000 /* on-chip RAM block L1 */ RAML2 : origin = 0x00A000, length = 0x001000 /* on-chip RAM block L2 */ RAML3 : origin = 0x00B000, length = 0x001000 /* on-chip RAM block L3 */ ZONE6 : origin = 0x0100000, length = 0x100000 /* XINTF zone 6 */ ZONE7A : origin = 0x0200000, length = 0x00FC00 /* XINTF zone 7 - program space */ FLASHH : origin = 0x300000, length = 0x008000 /* on-chip FLASH */ FLASHG : origin = 0x308000, length = 0x008000 /* on-chip FLASH */ FLASHF : origin = 0x310000, length = 0x008000 /* on-chip FLASH */ FLASHE : origin = 0x318000, length = 0x008000 /* on-chip FLASH */ FLASHD : origin = 0x320000, length = 0x008000 /* on-chip FLASH */ FLASHC : origin = 0x328000, length = 0x008000 /* on-chip FLASH */ FLASHA : origin = 0x338000, length = 0x007F80 /* on-chip FLASH */ CSM_RSVD : origin = 0x33FF80, length = 0x000076 /* Part of FLASHA. Program with all 0x0000 when CSM is in use. */ BEGIN : origin = 0x33FFF6, length = 0x000002 /* Part of FLASHA. Used for "boot to Flash" bootloader mode. */ CSM_PWL : origin = 0x33FFF8, length = 0x000008 /* Part of FLASHA. CSM password locations in FLASHA */ OTP : origin = 0x380400, length = 0x000400 /* on-chip OTP */ ADC_CAL : origin = 0x380080, length = 0x000009 /* ADC_cal function in Reserved memory */ IQTABLES : origin = 0x3FE000, length = 0x000b50 /* IQ Math Tables in Boot ROM */ IQTABLES2 : origin = 0x3FEB50, length = 0x00008c /* IQ Math Tables in Boot ROM */ FPUTABLES : origin = 0x3FEBDC, length = 0x0006A0 /* FPU Tables in Boot ROM */ ROM : origin = 0x3FF27C, length = 0x000D44 /* Boot ROM */ RESET : origin = 0x3FFFC0, length = 0x000002 /* part of boot ROM */ VECTORS : origin = 0x3FFFC2, length = 0x00003E /* part of boot ROM */ PAGE 1 : /* Data Memory */ /* Memory (RAM/FLASH/OTP) blocks can be moved to PAGE0 for program allocation */ /* Registers remain on PAGE1 */ BOOT_RSVD : origin = 0x000000, length = 0x000050 /* Part of M0, BOOT rom will use this for stack */ RAMM0 : origin = 0x000050, length = 0x0003B0 /* on-chip RAM block M0 */ RAMM1 : origin = 0x000400, length = 0x000400 /* on-chip RAM block M1 */ RAML4 : origin = 0x00C000, length = 0x001000 /* on-chip RAM block L1 */ RAML5 : origin = 0x00D000, length = 0x001000 /* on-chip RAM block L1 */ RAML6 : origin = 0x00E000, length = 0x001000 /* on-chip RAM block L1 */ RAML7 : origin = 0x00F000, length = 0x001000 /* on-chip RAM block L1 */ ZONE7B : origin = 0x20FC00, length = 0x000400 /* XINTF zone 7 - data space */ FLASHB : origin = 0x330000, length = 0x008000 /* on-chip FLASH */ }

PAGE 0 will be used to organize program sections PAGE 1 will be used to organize data sections CSM_RSVD :Code Security Module_reserved 代码安全模块,不能放程序代码或者数据块,必须初始化为0X0000 BEGIN :程序启动的开始地址 CSM_PWL : password locations 存放密码的地方

2)SECTIONS指令相关

SECTIONS { /* Allocate program areas: */ /* The Flash API functions can be grouped together as shown below. The defined symbols _Flash28_API_LoadStart, _Flash28_API_LoadEnd and _Flash28_API_RunStart are used to copy the API functions out of flash memory and into SARAM */ .cinit : > FLASHA PAGE = 0 .pinit : > FLASHA, PAGE = 0 .text : > FLASHA PAGE = 0 codestart : > BEGIN PAGE = 0 ramfuncs : LOAD = FLASHA, RUN = RAML0, LOAD_START(_RamfuncsLoadStart), LOAD_END(_RamfuncsLoadEnd), RUN_START(_RamfuncsRunStart), PAGE = 0 csmpasswds : > CSM_PWL PAGE = 0 csm_rsvd : > CSM_RSVD PAGE = 0 /* Allocate uninitalized data sections: */ .stack : > RAMM1 PAGE = 1 .ebss : > RAML4 PAGE = 1 .esysmem : > RAMM1 PAGE = 1 /* Initalized sections go in Flash */ /* For SDFlash to program these, they must be allocated to page 0 */ .econst : > FLASHA PAGE = 0 .switch : > FLASHA PAGE = 0 /* Allocate IQ math areas: */ IQmath : > FLASHC PAGE = 0 /* Math Code */ IQmathTables : > IQTABLES, PAGE = 0, TYPE = NOLOAD IQmathTables2 : > IQTABLES2, PAGE = 0, TYPE = NOLOAD FPUmathTables : > FPUTABLES, PAGE = 0, TYPE = NOLOAD /* Allocate DMA-accessible RAM sections: */ DMARAML4 : > RAML4, PAGE = 1 DMARAML5 : > RAML5, PAGE = 1 DMARAML6 : > RAML6, PAGE = 1 DMARAML7 : > RAML7, PAGE = 1 /* Allocate 0x400 of XINTF Zone 7 to storing data */ ZONE7DATA : > ZONE7B, PAGE = 1 /* .reset is a standard section used by the compiler. It contains the */ /* the address of the start of _c_int00 for C Code. /* /* When using the boot ROM this section and the CPU vector */ /* table is not needed. Thus the default type is set here to */ /* DSECT */ .reset : > RESET, PAGE = 0, TYPE = DSECT vectors : > VECTORS PAGE = 0, TYPE = DSECT /* Allocate ADC_cal function (pre-programmed by factory into reserved memory) */ .adc_cal : load = ADC_CAL, PAGE = 0, TYPE = NOLOAD }

C语言生成的段可以分为已初始的段和未初始的段。

已初始的段:真实的指令和数据,存放在程序存储空间 page0

.text 编译C语言中的语句时,生成的汇编指令代码存放于此

.cinit 存放用来对全局和静态变量初始化的常数

.const 包含字符串常量和全局变量、静态变量(由const声明)的初始化及说明

.econst 包含字符串常量和全局变量静态变量(由far const声明)的初始化及说明

.pinit 全局构造器程序列表

.switch 存放switch语句产生的常数表格

#pragma CODE_SECTION 将程序从Flash搬运到RAM中运行,从而提高工作效率

codestart 代码启动

未初始的段:保留变量的地址空间,存放在数据存储空间 page1

.bss 未初始化的变量预留空间,程序引导过程中,C引导程序会将ROM中的.cint块中的数据复制到.bss块中

.ebss 用for声明的或大存储器模式下的全局和静态变量保留空间

.stack C系统的堆栈分配的空间,函数调用时传递参数以及局部变量分配空间

.sysmem 动态存储器分配保留空间,如果未用到malloc函数,则该块空间为0

#pragma DATA_SECTION 将变量存放到某个特定的位置

二、CODE_SECTION指令使用

利用#pragma CODE_SECTION指令将变量关联到SECTIONS"ramfuncs’’

#pragma CODE_SECTION(Example,"ramfuncs");

为链接创建相关变量

extern Uint16 RamfuncsLoadStart; extern Uint16 RamfuncsLoadEnd; extern Uint16 RamfuncsRunStart;

复制时间关键代码以及FLASH设置代码到RAM

Example_MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart);

修改CMD文件使得 映射到指定的地址空间

ramfuncs : LOAD = FLASHA, RUN = RAML0, LOAD_START(_RamfuncsLoadStart), LOAD_END(_RamfuncsLoadEnd), RUN_START(_RamfuncsRunStart), PAGE = 0 或者使用组合 Flash28_API: { -lFlash28335_API_V210.lib(.econst) -lFlash28335_API_V210.lib(.text) } GROUP { ramfuncs { -l lib/AVP32F33X_API_V210.lib} }

LOAD : 指定要加载程序在FLASH中的地址段 RUN :指定在RAM里运行程序的RAM地址段 LOAD_START 所要加载程序在FLASH里的初始地址 LOAD_END 所要加载程序在FLASH里的结束地址 RUN_START 程序运行的起始地址

三、DATA_SECTION指令使用

利用#pragma DATA_SECTION指令将变量关联到SECTIONS"ramdata’’

#pragma DATA_SECTION(Example,"ramdata");

修改CMD文件使得 "ramdata’'映射到指定的地址空间

DMARAML4 : > RAML4, PAGE = 1 DMARAML5 : > RAML5, PAGE = 1 DMARAML6 : > RAML6, PAGE = 1 DMARAML7 : > RAML7, PAGE = 1 四、依据需求修改CMD文件

因为bootloar升级需要在一块DSP芯片上烧写两个工程,两个工程的启动地址不同。一般来说,我们在bootloader工程中,保持初始设置不变,仍然使用FLASHA中的地址作为起始地址 bootloader起始地址配置 在APP工程中,起始地址可以修改为FLASHC中的地址作为起始地址,当然其他地址也是可以的。同时在APP工程的中的CMD文件中,我们要重新配置SECTION指令相关地址,即有FLASHA相关的地址全部修改为FLASHC,使得两个工程之间没有flash重叠的部分。 APP起始地址配置 在bootloader工程的main函数中的跳转汇编指令的跳转地址也要依据APP工程的起始地址进行修改,在上述的例子中,跳转地址选择0x32FFF6。



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3