Adapt9s12XD512 non-functioning caused by function call

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Adapt9s12XD512 non-functioning caused by function call

9,021件の閲覧回数
ODUIEEECarTeam
Contributor I
I wrote a function for use in my program that does nothing more than loop through an int array[683] a few times making comparisons in order to analyze sensor data. It does nothing more than test for different cases and save some integers in a global array.  It runs fine on the computer using a C compiler. It is, however, perhaps a little lengthy to post here(but i will do so in the following post).  It compiles fine in code warrior with no errors, but I get a warning: L1912: Object _vectab overlaps with another (last addr: 0xEB5F, object addr: 0xCF00)
Anyway, here is the problem:
 
When I load the function but don't call it, everything works fine, but when I call the function, the microcontroller does NOTHINGIt doesn't run any of the code before the function call, or after it, or at least not correctly, as the code does several things that can be observed (like flash an onboard LED).  I can't find any indication that the program is too big, or does anything that the microcontroller can't handle. 
 
I will try to clean up the code (lots of things commented out left in it) for the following post.
 
Why does the following function cause the microcontroller not to function at all?


Message Edited by ODU IEEE Car Team on 2008-03-26 12:46 PM
ラベル(1)
0 件の賞賛
返信
31 返答(返信)

1,975件の閲覧回数
ODUIEEECarTeam
Contributor I
No special reason for asking, I just didn't quite understand everything that was said so I wanted to double check I was using the right statements for everything.  Thanks for all of you guys' help on this topic.  I got my program functioning and I learned a little about this topic. Thanks.
0 件の賞賛
返信

1,975件の閲覧回数
CompilerGuru
NXP Employee
NXP Employee
What was the problem?

Daniel
0 件の賞賛
返信

1,975件の閲覧回数
JimDon
Senior Contributor III
If you are using Special Edition you have a 32K limit, so if this is the case, I would go back to a non-banked project and fore go the headaches. You can get a full 32K of code without using banked model.
0 件の賞賛
返信

1,975件の閲覧回数
ODUIEEECarTeam
Contributor I
First of all, ignore the previously posted code for future reference to this thread.  It has been fixed and besides the few errors (a result of cleaning the code up for the post),  it is not the problem. 
We have torn apart and rebuilt our project several times, adding each verified function or set of verified functions piece by piece.  into the new project, confirming functionality at each step. 

The problem that consistently stops our progress is that it seems to get to large.  and we get warnings: L1912: Object <obj> overlaps with another (last addr: <addr>, object address: <objadr>)
(the object is usually _vectab)

I am completely unfamiliar with most things related to solving this problem and we only have a few days left (I remember the meaning banked memory from it's mention in class, but that's about it), so I have a series of questions:

I am using the special edition of code warrior, which should give me 32k to run my program without messing with changing my "#pragma CODE_SEG __NEAR_SEG NON_BANKED" statements right?

– 512K byte Flash EEPROM
– 4K byte EEPROM
– 32K byte RAM
These are the specs of my controller, but I can't seem to figure out what is saved where.  and what numbers mean what.  When I comment out a large sections of logical tests, my program runs correctly, and I can find 3 numbers that relate to size: 

At the bottom of the project:
code: 11k, data: 8k
In the bin folder:
Full_Chip_Simulation.abs          296KB
Full_Chip_Simulation.abs.glo    10KB
Full_Chip_Simulation.abs.s19   10KB
Full_Chip_Simulation.map         219KB

When I uncomment all the code that works independently (it is I can comment out different parts and the other parts will work, but not all of them in one) I get total, or almost total non-functioning including code before the overlapping objects are used:

At the bottom of the project:
code: 12k, data: 8k
In the bin folder:
Full_Chip_Simulation.abs          297KB
Full_Chip_Simulation.abs.glo    11KB
Full_Chip_Simulation.abs.s19   11KB
Full_Chip_Simulation.map         220KB

I can't seem to find anything that relates this increase in these numbers to why my code loses functionality.
What is significant about this specific increase?

What can I do to avoid this apparent running out of space without reducing the size of my code (which still needs to get bigger)?

Also, I talked to a grad student experienced in this sort of thing briefly, who dismissed this and said I had plenty of space, and based on the numbers I see, he appears to be right, but based on the problems I'm getting, he appears to be wrong.  We're totally stuck.

Thanks to everyone for your help. 
0 件の賞賛
返信

1,975件の閲覧回数
bigmac
Specialist III
Hello,
 
I am not sure whether the following issue has already been alluded to -
 
for (i = 0; i < 682; i++) {
  if( (alldata[i]>10) && alldata[i+1]<10) {
    alldata[i+1] = (alldata[i] + 2);
  }
If the array size is 682 words, valid indices are from 0 to 681.  However, since i will have a maximum value of 681, a reference to alldata[i+1] would be invalid for this case.  The upper bound of the for loop should be limited to i<681.
 
If the value of the local variable i happened to be over-written because of this error, it is possible that the function would never exit.
 
What attempts have you made to simulate the operation?  This may better show what is happening as you run the function.
 
Regards,
Mac
 


Message Edited by bigmac on 2008-03-27 02:03 PM
0 件の賞賛
返信

1,975件の閲覧回数
JimDon
Senior Contributor III
Code:
int desiredtargetsloc[10];

 Only happens 6 times????
 What did I miss?

for (i=0;i<682;i++){  if( (alldata[i]>10) && alldata[i+1]<10)  {   alldata[i+1] = (alldata[i] + 2);  }  alldata[i]=alldata[i+1];  desiredtargetsloc[i] = i;}

 
0 件の賞賛
返信

1,975件の閲覧回数
ODUIEEECarTeam
Contributor I
nvm. this is a problem. I messed up, there used to be something different there, sorry.  It was already fixed after I pasted that code, so I didn't look at what I posted closely.


Message Edited by ODU IEEE Car Team on 2008-03-26 10:02 PM

Message Edited by ODU IEEE Car Team on 2008-03-26 10:04 PM
0 件の賞賛
返信

1,975件の閲覧回数
ODUIEEECarTeam
Contributor I
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void FIND_TARGET()

int alldata[682]={99};
int desiredtargets[10]={99};
int desiredtargetsloc[10]={99};
int i=0;
int c=0;
for(i=0;i<682;i++)
{
alldata[i]=_array1[i];
}
for (i=0;i<682;i++)
{
  if( (alldata[i]>10) && alldata[i+1]<10)
  {
   alldata[i+1] = (alldata[i] + 2);
  }
alldata[i]=alldata[i+1];
desiredtargetsloc[i] = i;
}
  for (i=0;i<682;i++)
  { 
 if ( alldata[i]>10) //all data greater than 10
 {
  if((alldata[i+1]< alldata[i]) && (alldata[i+1]>10) )
  {
   if (!( alldata[i+1] > (alldata[i] -50) ))
   { 
   desiredtargets[c] = alldata[i+1];
   desiredtargetsloc[c] = i+3;
   c++;
   }
  }  
  }
  alldata[i]=alldata[i+1];
 }
for (i=0;i<c;i++) //searches for closest distance angle
{
if (desiredtargets[i]<desiredtargets[i+1])
 {
  desiredtargetsloc[i+1]=desiredtargetsloc[i];
 desiredtargets[i+1]=desiredtargets[i];
 }
targetdist=desiredtargets[i];
targetloc=desiredtargetsloc[i];
}
}     //end of gettarget
0 件の賞賛
返信

1,975件の閲覧回数
allawtterb
Contributor IV
You have a very large amount of local variables in the function.  You need to make sure you have enough stack space to accomadate for this, this function alone requires 1408 bytes on the stack!  Also, you are then initializing 704 int's on the stack to 99.  Is this really necessary?  The compiler doesn't make a for loop to do this initialization, it does it all in line.  This means it adds more than 704 lines of asm to do this.  This isn't needed with alldata as it is initialized with the first for loop. 
 
Also, a quick check showed a few problems like with desiredtargetsloc in the second for loop.  You try to set 682 values of desiredtargetsloc to 1-682 but this array only contains 10 bytes. You might want to look over the rest of the function for anymore problems like these. 
0 件の賞賛
返信

1,975件の閲覧回数
ODUIEEECarTeam
Contributor I
Also, When I open the debugger, my assembly code is "[hex] staa 0x5A" like a million times or so, and that's all, except for a few statements before the seemingly infinite staa 0x5A.
0 件の賞賛
返信

1,975件の閲覧回数
JimDon
Senior Contributor III
For what's worth:

int alldata[682]={99};

Only initializes  alldata[0] to 99. However the compiler will then 0 fill the reset of the array, and it will cost you about 4 * 682 bytes in flash with the HC12 compiler.

As stated above, the line
desiredtargetsloc[i] = i;
in the first for loop, which in invariant (meaning it will go from 0 to 681 always) will be crash the stack, even if it was large enough to begin with.
Also the index variable c is unbounded, and depending on the data in the arrays may also exceed the bounds of the array.   (desiredtargets[c] = alldata[i+1];    desiredtargetsloc[c] = i+3:smileywink:

If you never call the function, then the linker will not include it, which is why it works when you don't call it, so I would say that it is indeed over running something just due to it's size which is about 2728 bytes JUST for the local variable initialization.

If you ran this else where, you must have lucked out and what ever you ran it on failed to detect the apparent stack crash.
 



.

0 件の賞賛
返信