【电路笔记 TMS320F28335DSP】CCS将数据或代码放置到指定的内存空间 #pragma CODE_SECTION和#pragma DATA_SECTION

.bss 和 .usect 指令创建未初始化的节;.text、.data 和 .sect 指令创建初始化的节。

  • 汇编器如何处理 Sections中,链接器脚本和编译器指令用于定义程序的不同部分如何被放置到目标设备的存储器中。.bss.data.text等是这些指令的一部分,它们告诉编译器或链接器如何组织代码和数据。

1. .usect 指令

  • 创建用户自定义的未初始化节.usect 允许程序员创建特定名称的未初始化数据节,这对于需要将某些变量或数组放在特定位置的应用非常有用。
  • 特点:与.bss类似,.usect也用于存放未初始化的数据,但提供了更细粒度的控制。
#pragma DATA_SECTION(mySpecialArray, ".mySection")
volatile int mySpecialArray[10];

2. .sect 指令

  • 创建用户自定义的初始化节:类似于.usect,但是用于存放已经初始化的数据。可以用来创建特定名称的初始化数据节,以满足特殊的内存布局需求。
  • 特点:允许开发者指定特定的数据段,并确保这些数据按照预期的方式被初始化和放置。
#pragma DATA_SECTION(mySpecialData, ".myInitSection")
int mySpecialData = 123;

DATA_SECTION 将数据放置到指定的内存空间

  • 在源文件配置DATA_SECTION:#pragma DATA_SECTION(变量名,“CMD地址段”); 编译为.usect
// https://downloads.ti.com/docs/esd/SPRUHV7/the-set-code-section-and-set-data-section-pragmas-stdz0556071.html
#pragma DATA_SECTION(bufferB, "my_sect")
char bufferA[512];
char bufferB[512]:

CODE_SECTION 将函数放置到指定的内存空间

  • 示例来自 Example_2833xGpioSetup。
  • 在源文件配置CODE_SECTION:#pragma CODE_SECTION(函数名,“CMD地址段”);编译为.sect
#pragma CODE_SECTION(InitFlash, "ramfuncs");
  • 函数定义:
//---------------------------------------------------------------------------
// Example: InitFlash:
//---------------------------------------------------------------------------
// This function initializes the Flash Control registers

//                   CAUTION
// This function MUST be executed out of RAM. Executing it
// out of OTP/Flash will yield unpredictable results

void InitFlash(void)
{
   EALLOW;
   //Enable Flash Pipeline mode to improve performance
   //of code executed from Flash.
   FlashRegs.FOPT.bit.ENPIPE = 1;

   //                CAUTION
   //Minimum waitstates required for the flash operating
   //at a given CPU rate must be characterized by TI.
   //Refer to the datasheet for the latest information.
#if CPU_FRQ_150MHZ
   //Set the Paged Waitstate for the Flash
   FlashRegs.FBANKWAIT.bit.PAGEWAIT = 5;

   //Set the Random Waitstate for the Flash
   FlashRegs.FBANKWAIT.bit.RANDWAIT = 5;

   //Set the Waitstate for the OTP
   FlashRegs.FOTPWAIT.bit.OTPWAIT = 8;
#endif

#if CPU_FRQ_100MHZ
   //Set the Paged Waitstate for the Flash
   FlashRegs.FBANKWAIT.bit.PAGEWAIT = 3;

   //Set the Random Waitstate for the Flash
   FlashRegs.FBANKWAIT.bit.RANDWAIT = 3;

   //Set the Waitstate for the OTP
   FlashRegs.FOTPWAIT.bit.OTPWAIT = 5;
#endif
   //                CAUTION
   //ONLY THE DEFAULT VALUE FOR THESE 2 REGISTERS SHOULD BE USED
   FlashRegs.FSTDBYWAIT.bit.STDBYWAIT = 0x01FF;
   FlashRegs.FACTIVEWAIT.bit.ACTIVEWAIT = 0x01FF;
   EDIS;

   //Force a pipeline flush to ensure that the write to
   //the last register configured occurs before returning.

   asm(" RPT #7 || NOP");
}
  • 在CMD文件中,需要对ramfuncs这个段进行配置。如:
MEMORY
{
    RAML0 : origin = 0x008000, length = 0x001000
}
SECTIONS
{
    ramfuncs : LOAD = FLASHD, RUN = RAML0, LOAD_END(_RamfuncsLoadEnd), RUN_START(_RamfuncsRunStart), PAGE = 0
}


SECTIONS
{
   /* Setup for "boot to SARAM" mode:
      The codestart section (found in DSP28_CodeStartBranch.asm)
      re-directs execution to the start of user code.  */
   codestart        : > BEGIN,     PAGE = 0
   ramfuncs         : > RAML0,     PAGE = 0
   .text            : > RAML1,     PAGE = 0
   .cinit           : > RAML0,     PAGE = 0
   .pinit           : > RAML0,     PAGE = 0
   .switch          : > RAML0,     PAGE = 0

   .stack           : > RAMM1,     PAGE = 1
   .ebss            : > RAML4,     PAGE = 1
   .econst          : > RAML5,     PAGE = 1
   .esysmem         : > RAMM1,     PAGE = 1
}

CG

  • http://www.ti.com/cn/lit/pdf/spraa85
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值