Running from stack, using TN235 that will not compile

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Running from stack, using TN235 that will not compile

4,189 次查看
AndersJ
Contributor IV
CW 3.1 HCS12
 
I need to run code from stack to erase and program flash.
 
I have implemented TN235, thinking it will allow me to write programs in C,
put the code on the stack and execute from there. Although not absolutely
necessary, I would prefer to be able to call functions also located in banked memory.
 
TN235 seems to resolve all this... BUT, the compiler complains about:
#pragma CODE_SEG NEAR PIC ToCopyToStack /* near and position independent */
issuing warning C3802: Segment pragma incorrect
 
All help much appreciated
 
Anders J
 
 

 
 
标签 (1)
标记 (1)
0 项奖励
回复
5 回复数

1,590 次查看
AndersJ
Contributor IV
Daniel,
 
Your pragma suggestions removed the warnings.
Thank you. This was a great help, moving me forward.
Strange that TN235 does not mention this issue.
 
I do not understand how to "Check how your pragma looks..."
Can you please explain this in some more detail, as I cannot find the "context menu".
 
My stack is not banked and after your help I am now able to execute from RAM.
 
I need to execute out of RAM, because I am reprogramming the flash with a new program.
In order to do that I need to erase the flash that is running the current program,
including non-banked flash, so I can put my new program in those banks.
 
I cannot erase memory that I am executing from, so I need to move som programming
functions onto the stack and run it from there, now being able to erase and reprogram.
After all is said and done, I'll let the COP reset, and I'm up and running the new program.
 
This is my plan. I'm not there yet.
 
Thanks for your help,
Anders J
 
 
 
 
 
 
 
0 项奖励
回复

1,590 次查看
J2MEJediMaster
Specialist I
Have you tried looking at the application note AN2548.pdf, which describes a serial bootloader that can download to Flash? Perhaps that might be of help.

---Tom

Message Edited by J2MEJediMaster on 2006-11-20 11:39 AM

 

AN2548.pdf

Message Edited by t.dowe on 2009-09-16 10:40 AM
0 项奖励
回复

1,590 次查看
AndersJ
Contributor IV
Does this also mean that the code that copies the function to stack,
and then also "jumps to the stack" to execute it, must be in NON-banked memory?
 
Anders
 
0 项奖励
回复

1,590 次查看
CompilerGuru
NXP Employee
NXP Employee
I would start by checking why you do get this C3802
message. My guess, the NEAR you are using is defined by a macro to __near.
Check how your pragma looks after preprocessing, there is a context menu entry to do this.
If this is the problem, try this:

#pragma CODE_SEG __NEAR_SEG __PIC_SEG ToCopyToStack

Daniel

(if ToCopyToStack needs to be non banked depends on how you copy it to the stack. I hope you stack is non banked tough :smileyhappy:
And calling other functions in flash should work as long as the accessed flash is accessible. However why do you execute the code out of RAM if you have flash which stays accessible?

Daniel
0 项奖励
回复

1,590 次查看
J2MEJediMaster
Specialist I
The restrictions section at the bottom of TN235 states:

"The code copied to stack needs to be position independent and therefore must not contain runtime calls."

Put another way, the PIC code is PC relative, using 16 bit addressing. If you're trying to access a function in another memory bank, you not using PIC code. To prove this, try commenting out your calls to functions in banked memory and see if the code compiles and links without errors.

---Tom
0 项奖励
回复