This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

28035自编写SCI bootloader函数,MCU无法运行,反复进入CodeStartBranch.asm,MCU重启

你好:

      我是自编写SCI_BOOTLoader程序,MCU复位后先进入flash模式,执行主函数,在man函数中调用InitBoot()函数,发现程序每次执行到自动波特率检测中的DELAY_US(100);时,MCU会重新进入CodeStartBranch.asm,像是MCU复位重启动了。

但是我将主函数中的InitBoot();屏蔽掉,整个系统可以正常运行。

个人感觉是CMD文件设置有问题,但尝试过修改没有效果,麻烦帮我看一下有什么问题。

void main(void)
{
// Disable CPU interrupts
DINT;
// Disable CPU interrupts and clear all CPU interrupt flags:
IFR = 0x0000;
IER = 0x0000;

/***restart***/
if(InitSysCtrl_POINT == 0)
{
InitBoot();
}

}

        我的cmd文件是:

MEMORY
{
PAGE 0: /* Program Memory */
/* Memory (RAM/FLASH/OTP) blocks can be moved to PAGE1 for data allocation */
BEGIN_M0 : origin = 0x000000, length = 0x000002 /* Part of M0SARAM. Used for "Boot to M0" bootloader mode. */

RAML0 : origin = 0x008000, length = 0x00800 /* on-chip RAM block L0 */
OTP : origin = 0x3D7800, length = 0x000400 /* on-chip OTP */
FLASH : origin = 0x3E8000, length = 0x00FF80 /* on-chip FLASH */

CSM_RSVD : origin = 0x3F7F80, length = 0x000076 /* Part of FLASHA. Program with all 0x0000 when CSM is in use. */
BEGIN_FLASH : origin = 0x3F7FF6, length = 0x000002 /* Part of FLASHA. Used for "boot to Flash" bootloader mode. */
PASSWORDS : origin = 0x3F7FF8, length = 0x000008 /* Part of FLASH Sector A. CSM password locations. */

IQTABLES : origin = 0x3FE000, length = 0x000B50 /* IQ Math Tables in Boot ROM */

IQTABLES2 : origin = 0x3FEB50, length = 0x00008C /* IQ Math Tables in Boot ROM */
IQTABLES3 : origin = 0x3FEBDC, length = 0x0000AA /* IQ Math Tables in Boot ROM */
IQMATH : origin = 0x3FEC86, length = 0x00082A

ROM : origin = 0x3FF4B0, length = 0x000B10,
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 = 0x000002, length = 0x00004E /* Part of M0, BOOT rom will use this for stack */
M0SARAM : origin = 0x000050, length = 0x0003b0 /* on-chip RAM block M0 */
M1SARAM : origin = 0x000400, length = 0x000400 /* on-chip RAM block M1 */
RAML123 : origin = 0x008800, length = 0x001800 /* on-chip RAM block L0 L1 L2 */


}

/* Allocate sections to memory blocks.
Note:
codestart user defined section in DSP28_CodeStartBranch.asm used to redirect code
execution when booting to flash
ramfuncs user defined section to store functions that will be copied from Flash into RAM
*/

SECTIONS
{

/* Allocate program areas: */
/* Program memory (PAGE 0) sections */
.text : > FLASH, PAGE = 0
.cinit : > FLASH, PAGE = 0
.const : > FLASH, PAGE = 0
.econst : > FLASH, PAGE = 0
.pinit : > FLASH, PAGE = 0
.reset : > RESET, PAGE = 0, TYPE = DSECT /* We are not using the .reset section */
.switch : > FLASH, PAGE = 0
vectors : > VECTORS PAGE = 0, TYPE = DSECT

/* Data Memory (PAGE 1) sections */
.cio : > RAML123, PAGE = 1
.bss : > RAML123, PAGE = 1
.ebss : > RAML123, PAGE = 1
.stack : > M0SARAM, PAGE = 1
.sysmem : > RAML123, PAGE = 1
.esysmem : > RAML123, PAGE = 1

/*** User Defined Sections ***/
codestart : > BEGIN_FLASH, PAGE = 0 /* Used by file CodeStartBranch.asm */
csm_rsvd : > CSM_RSVD, PAGE = 0 /* Used by file passwords.asm */
passwords : > PASSWORDS, PAGE = 0 /* Used by file passwords.asm */

/* Allocate IQ math areas: */
IQmath : > FLASH PAGE = 0 /* Math Code */
IQmathTables : > IQTABLES, PAGE = 0, TYPE = NOLOAD

ramfuncs : LOAD = FLASH,
RUN = RAML0,
LOAD_START(_RamfuncsLoadStart),
LOAD_END(_RamfuncsLoadEnd),
RUN_START(_RamfuncsRunStart),
PAGE = 0

}

SCI_Boot的函数为:

Uint32 SCI_Boot()
{
Uint32 EntryAddr;
Uint16 i=1;

EALLOW;
SysCtrlRegs.WDCR = 0x0028; // Enable watchdog module
SysCtrlRegs.WDKEY = 0x55; // Clear the WD counter
SysCtrlRegs.WDKEY = 0xAA;
EDIS;

// Enable the SCI-A clocks
EALLOW;

// At reset we are in /4 mode. Change to /2
SysCtrlRegs.PLLSTS.bit.DIVSEL = 2;
SysCtrlRegs.PCLKCR0.bit.ADCENCLK = 1;
(*Device_cal)();
SysCtrlRegs.PCLKCR0.bit.ADCENCLK = 0;

GpioCtrlRegs.GPBPUD.bit.GPIO34 = 0;
GpioCtrlRegs.GPBPUD.bit.GPIO37 = 0;

// Set MUX for BOOT Select
GpioCtrlRegs.GPBMUX1.bit.GPIO34 = 0;
GpioCtrlRegs.GPBMUX1.bit.GPIO37 = 0;

// Set DIR for BOOT Select
GpioCtrlRegs.GPBDIR.bit.GPIO34 = 0;
GpioCtrlRegs.GPBDIR.bit.GPIO37 = 0;


EDIS;


EALLOW;
SysCtrlRegs.WDCR = 0x0068;
EDIS;
// Assign GetWordData to the SCI-A version of the
// function. GetWordData is a pointer to a function.
GetWordData = SCIA_GetWordData;

SCIA_Init();
i = SCIA_AutobaudLock();
if( i!= 0)
{
InitSysCtrl_POINT=(Uint32)main;//InitSysCtrl;
return InitSysCtrl_POINT;
}
// If the KeyValue was invalid, abort the load
// and return the flash entry point.
if(SCIA_GetWordData() != 0x08AA)return FLASH_ENTRY_POINT;

ReadReservedFn();

EntryAddr = GetLongData();
CopyData();


//EALLOW;
//SysCtrlRegs.WDCR = 0x0028; // Enable watchdog module
//SysCtrlRegs.WDKEY = 0x55; // Clear the WD counter
//SysCtrlRegs.WDKEY = 0xAA;
//EDIS;


return EntryAddr;
}

INT16S SCIA_AutobaudLock()
{
Uint16 i=0,j=0;
Uint16 byteData;

// Must prime baud register with >= 1
SciaRegs.SCILBAUD = 1;
// Prepare for autobaud detection
// Set the CDC bit to enable autobaud detection
// and clear the ABD bit
SciaRegs.SCIFFCT.bit.CDC = 1;
SciaRegs.SCIFFCT.bit.ABDCLR = 1;
// Wait until you correctly read an
// 'A' or 'a' and lock
while(SciaRegs.SCIFFCT.bit.ABD != 1)
{
DELAY_US(100);

if(++i >= 20000)
{
i=0;
if(++j >= 2)
{
j= 1000;
SciaRegs.SCIFFCT.bit.CDC = 0;
return -1;
}
}

}
// After autobaud lock, clear the CDC bit
SciaRegs.SCIFFCT.bit.ABDCLR = 1;
SciaRegs.SCIFFCT.bit.CDC = 0;
while(SciaRegs.SCIRXST.bit.RXRDY != 1) { }
byteData = SciaRegs.SCIRXBUF.bit.RXDT;
SciaRegs.SCITXBUF = byteData;
return 0;
}