TMS320F28335 添加了一句程序后,编译没有问题,但ILLEGAL_ISR报错
<p>在初始化阶段,我的程序需要读取文件中的数据,因此添加了一条“fscanf(p1, "%f", &ry); ”程序。</p><p>在未添加之前,程序可以正常运行;添加之后,编译没有问题,但是运行时程序就会跳转到ILLEGAL_ISR报错。通过设置断点,发现跳转报错前执行的最后一条指令是void InitSpiaGpio()里的EALLOW。如果将fscanf这两句程序注释掉,那么程序正常运行。下面贴上初始化阶段的程序。</p>
<pre>
<code class="language-cpp">/*
* INIT.c
*
*Created on: 2023年5月29日
* Author: gy
*/
#include "main.h"
void SYSTERM_INIT()
{
InitSysCtrl();
//初始化PIE控制寄存器和PIE中断向量表
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
LED_Init();
DAC8563_Init();
EQEP1_Init();
init_zone67();
//// -------------读取u_ff数据------------
int i=0;
FILE *p1 = fopen("C:\\Users\\Saturday\\Desktop\\data_4000\\ry_init.dat", "r");//1.dat文件放在.c文件所在的文件夹中
FILE *p2 = fopen("C:\\Users\\Saturday\\Desktop\\data_4000\\uff_init.dat", "r");//1.dat文件放在.c文件所在的文件夹中
// FILE *p1 = fopen("C:\\Users\\Saturday\\Desktop\\data_4000\\ry_4000_1v1.dat", "r");//1.dat文件放在.c文件所在的文件夹中
// FILE *p2 = fopen("C:\\Users\\Saturday\\Desktop\\data_4000\\uff_4000_1v1.dat", "r");//1.dat文件放在.c文件所在的文件夹中
if (p1==NULL)//检测是否成功打开
printf("Open failed\n");
if (p2==NULL)//检测是否成功打开
printf("Open failed\n");
for (i = 0; i<20000; i++)
{
fscanf(p1, "%f", &ry); //读入1.dat数据给数组c
fscanf(p2, "%f", &u_ff);
if(i%1000==0){
printf("%f\t%d\n", u_ff,i);}
}
fclose(p1);//释放指针
fclose(p2);//释放指针
printf("load memory over");
////---------------------------------------------
//
//-------------------开机复位程序-----------------------
while(GpioDataRegs.GPADAT.bit.GPIO12 == 1){ //
Dac8563_reg_write(0x1F,31000);//第三个参数为复位时的电压 设置的小一些
SET_SYNC;
DELAY_US(1);
// if(GpioDataRegs.GPADAT.bit.GPIO12 == 0) break;
}
if(GpioDataRegs.GPADAT.bit.GPIO12 == 0){
Dac8563_reg_write(0x1F,33500); // 往正方向走一点,使得限位开关变为未触发状态
SET_SYNC;
DELAY_US(1);
DELAY_US(3000000); //延时1s
}
//
Dac8563_reg_write(0x1F,32768);
SET_SYNC;
DELAY_US(1);
DELAY_US(2000000); //延时2s
// --------------------------
//------------------------光栅尺计数清零-------------------------
EALLOW;// This is needed to write to EALLOW protected registers
EQep1Regs.QPOSCNT = 0;
EDIS;
//-----------------------初始换定时器和串口-------------------------
// TIM1_Init(150,200);
UARTb_Init(230400);
TIM0_Init(150,200);
}
</code></pre>
<p> </p>
<p>在网上搜索了一些关于此问题的解决方案:</p>
<p>1.晶振出现问题;换了一个28335开发板,问题仍然存在,排除晶振问题。</p>
<p>2.CMD配置 堆栈.stack分配空间太小;<img data-mce-src="/resized-image/__size/640x480/__key/communityserver-components-multipleuploadfilemanager/7a574403_2D00_d405_2D00_4e42_2D00_b667_2D00_e6bd99ab703d-142850-complete/pastedimage1725263764886v1.png" data-mce-style="max-height: 240px; max-width: 320px;" src="https://e2echina.ti.com/resized-image/__size/640x480/__key/communityserver-components-multipleuploadfilemanager/7a574403_2D00_d405_2D00_4e42_2D00_b667_2D00_e6bd99ab703d-142850-complete/pastedimage1725263764886v1.png" />,但memory allocation中显示是够用的。下面是CMD配置文件。</p>
<pre>
<code>MEMORY
{
PAGE 0 :
/* BEGIN is used for the "boot to SARAM" bootloader mode */
BEGIN : origin = 0x000000, length = 0x000002 /* Boot to M0 will go here */
RAMM0 : origin = 0x000050, length = 0x0003B0
RAML0L1L2: origin = 0x008000, length = 0x005000
RAML3 : origin = 0x00D000, length = 0x001000
CSM_RSVD : origin = 0x33FF80, length = 0x000076 /* Part of FLASHA.Program with all 0x0000 when CSM is in use. */
CSM_PWL : origin = 0x33FFF8, length = 0x000008 /* Part of FLASHA.CSM password locations in FLASHA */
ADC_CAL : origin = 0x380080, length = 0x000009
RESET : origin = 0x3FFFC0, length = 0x000002
IQTABLES : origin = 0x3FE000, length = 0x000b50
IQTABLES2: origin = 0x3FEB50, length = 0x00008c
FPUTABLES: origin = 0x3FEBDC, length = 0x0006A0
BOOTROM : origin = 0x3FF27C, length = 0x000D44
PAGE 1 :
/* BOOT_RSVD is used by the boot ROM for stack. */
/* This section is only reserved to keep the BOOT ROM from */
/* corrupting this area during the debug process */
BOOT_RSVD: origin = 0x000002, length = 0x00004E /* Part of M0, BOOT rom will use this for stack */
RAMM1 : origin = 0x000400, length = 0x000400 /* on-chip RAM block M1 */
RAML4 : origin = 0x00C000, length = 0x001000
RAML5 : origin = 0x00D000, length = 0x001000
RAML6 : origin = 0x00E000, length = 0x001000
RAML7 : origin = 0x00F000, length = 0x001000
ZONE7 : origin = 0x200000, length = 0x100000
}
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 : > RAML0L1L2, PAGE = 0
.text : > RAML0L1L2, PAGE = 0
.InitBoot : > RAML0L1L2, PAGE = 0
.cinit : > RAML0L1L2, PAGE = 0
.pinit : > RAML0L1L2, PAGE = 0
.switch : > RAML0L1L2, PAGE = 0
.cio : > RAML4, PAGE = 1
.sysmem : > RAML4, PAGE = 1
.stack : > RAML4, PAGE = 1
.ebss : > RAML4, PAGE = 1
.econst : > RAML5, PAGE = 1
.esysmem : > RAMM1, PAGE = 1
IQmath : > RAML0L1L2, PAGE = 0
IQmathTables : > IQTABLES,PAGE = 0, TYPE = NOLOAD
FPUmathTables : > FPUTABLES, PAGE = 0, TYPE = NOLOAD
DMARAML4 : > RAML4, PAGE = 1
DMARAML5 : > RAML5, PAGE = 1
DMARAML6 : > RAML6, PAGE = 1
DMARAML7 : > RAML7, PAGE = 1
ZONE7DATA : > ZONE7, PAGE = 1
.reset : > RESET, PAGE = 0, TYPE = DSECT /* not used */
csm_rsvd : > CSM_RSVD PAGE = 0, TYPE = DSECT /* not used for SARAM examples */
csmpasswds : > CSM_PWL PAGE = 0, TYPE = DSECT /* not used for SARAM examples */
/* Allocate ADC_cal function (pre-programmed by factory into TI reserved memory) */
.adc_cal : load = ADC_CAL, PAGE = 0, TYPE = NOLOAD
}
/*
//===========================================================================
// End of file.
//===========================================================================
*/
</code></pre>
<p>3.数组指针问题。由于我用到的数据量较大,使用了外扩SRAM,在CMD中也可以看到定义了ZONE7DATA空间。INIT.c文件中使用的两个数组通过以下方式定义的</p>
<pre>
<code>#pragma DATA_SECTION(u_ff,"ZONE7DATA");
volatile float u_ff = {0.0};
#pragma DATA_SECTION(ry,"ZONE7DATA");
volatile float ry = {0.0};</code></pre>
<p>这个问题困扰我很久了,实在找不到解决方案,希望看到的各位大佬伸出援手,非常感谢!!</p>
<p>仔细检查新添加的程序代码,尤其是中断相关的代码,确保没有错误的ISR指针赋值。<br />
排除是否晶振问题。<br />
如果可能,尝试增大.stack段的大小,然后重新编译和测试。</p>
页:
[1]