Constant declarations @ fixed flash address via template?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Constant declarations @ fixed flash address via template?

3,351 Views
FTSolutions
Contributor III
Hello,
I understand from searching older threads that CW for DSP56F8xxx does NOT support declarations of constants @ fixed address - for example, I would like the generated S-Record Code image of my application code to have its revision information stored into fixed location in dataflash, e.g., for application firmware revision "1.2.3":
UInt16 FWMajorRev@0x7B00 = 1;
UInt16 FWMinorRev@0x7B01 = 2;
UInt16 FWMaintRev@0x7B02 = 3;

I obviously do not want to have application code write this to flash every time it runs as
that is time consuming and could contribute to flash wear issues.   I know I can define a section in the linker .cmd file for the project to store this info, but if I allow CW to generate new linker file (as future code changes, variable additions cause expansion of .bss sections, etc.) it will overwrite my modified .cmd file with the special section.
.x_AppFWRev (R) : ORIGIN=0x7B00, LENGTH=0x0003
...
...
.AppFWRevision :
{
  #Major Rev
WRITEH(1);
 #Minor Rev
WRITEH(2);
 #Maint Rev
 WRITEH(3)
} > .x_AppFWRev

 IS there a way to create a "template" with CW that would use my specially coded cmd file as a template or not eliminate my special section, but still allow it to create the .cmd file to accomodate future code changes ?  

I am trying to avoid having to document procedure for copying older .cmd files, writing code, generating new linker .cmd file, and copying /pasting from older .cmd files into new .cmd file and disabling the automatic linker file generation in PE repeatedly.

Any advice/help is appreciated !

Labels (1)
Tags (1)
0 Kudos
8 Replies

593 Views
trytohelp
NXP Employee
NXP Employee
Hi,
 
there is a way to specify object to an address.
See below.
 

Specifying Variable Addresses in C

The user can tell the compiler to specify the address of a variable in a C file using the :

operator. The constant value following the : operator is the word address of the global

variable (i.e., int OneReg : 0xBCD ; specifies that the global variable OneReg

resides at word address 0xBCD).

NOTE

The Linker does not reserve space for global variables declared with the :

operator.

Hopte this will help you.
 
Regards
Pascal
0 Kudos

593 Views
FTSolutions
Contributor III
Hello Pascal,

thank you but I already know this, and it is only part of what I want to do.
I want to compile a constant value into that fixed address location, not just define a pointer/variable at the location, which can be done in other ways in C.

Basically I want to be able to compile in word constants at specific data flash addresses, without having to add in all the dataflash code beans to have the program erase&write the values in dataflash on its own.

The CW compiler does this for itself in that it generates the start address/entry point for a program, that is then loaded at the top long word location in dataflash (Motorola S7 record).   I would like to know if there is any way that we can get it to do similar function for the user specified constant.  Other compilers do support this, as has been discussed on other threads, and I am hoping that someone has some sort of work-around to the limitation in CW for 56F8xxx.   Otherwise one must write more code into their application to check these locations and program them with the values.
0 Kudos

593 Views
trytohelp
NXP Employee
NXP Employee
Hi,
 
If you don't receive feedbackvia the forum, I recommend you to contact the Freescale support team.
Please use Freescale on line support web page.
  - Go to following URL: http://www.freescale.com/TechSupport
  - Click on Submit a Service Request. You will come to a login page.
  - You can submit your request through the web from there.
 
Regards
Pascal
0 Kudos

593 Views
J2MEJediMaster
Specialist I
Try taking a look at FAQ-28651. Although the target MCU was a HCS12X, the technique used to facilitate the embedding of a serial number into Flash appears to similar to what you're trying to do. HTH.

---Tom

0 Kudos

593 Views
FTSolutions
Contributor III
Yes, that (as mentioned in FAQ) is what I would like to do, but this compiler for 56F8xxx does NOT support the "@" symbol operator nor does it support "_at_", so it will not compile.

I did not want to have to incorporate the dataflash beans and extra code, but perhaps this is the only way to do it with CW for 56F8xxx.   I also can do what I want to do by making explicit section and instructions in the .cmd linker command file for the project as noted in my first post, but the IDE regenerates the linker file and just over-writes the entire file and does not keep the sections that I add to embed the numbers, so I have to do it over again.

If I tell the IDE to not regenerate the linker file, I don't lose my changes, but then if another programmer adds variables or code to the project and requires increase in .bss section or code section, the stack has to move and the project will not run correctly until the .cmd file is regenerated to account for the larger sizes.  Once it is regenerated, I go back to have to re-entering my section changes all over again.

So, my original question: Is there a way to save /create a new project template that would use a user-defined .cmd file as the default (and thus, I could make my special sections in the .cmd file, and the IDE would know not to remove it all )? Or when it does regenerate the .cmd file, it would recreate the special section that I added).   IT does this same sort of thing when one uses the defined stationery templates - the bootloader .cmd files and the application .cmd files have different sections defined and recreated in the .cmd file. This would be a good feature to have, I think.  It would also enable a work around to this very basic problem about constants at defined addresses, which is common enough in embedded systems.
0 Kudos

593 Views
J2MEJediMaster
Specialist I
The FAQ also presented an ANSI-C specific way to declare a variable at an address, to wit:

#define serial_number (*(const unsigned char*)0xC000);


That didn't work, either?

---Tom

0 Kudos

593 Views
FTSolutions
Contributor III
The #define statement will compile. 
#define serialnumber (*(UInt16 *)0x7FFB)
 If I put an assignment statement such as:
serialnumber = 0x123;
inside my program function code, it will compile and link.  The compiler will not accept an assignment or initialization of the value outside of function scope (meaning, if I put the assignment outside of the main() function, the compiler rejects it.  If I put it inside main(), it is happy.   This is not want I want.

I want the compiler to compile into the output file a specific constant value at a specific location.   Since the location is in dataflash, if I want the value to be initialized by the program code I must include all the dataflash bean/support code to write the value, which is something that I do not wish to do as I don't need the dataflash bean to just READ the value, and don't want to add the extra code space, etc, for the bean.
0 Kudos

593 Views
trytohelp
NXP Employee
NXP Employee
Hi,
 
To answer to your question:
is it possible to create your own stationnery project ?
Yes you can.
To that you must create a project and add your changes like new cmd file and your configuration you need.
When this project is create you must copy the folder under \stationery.
Now it will appear in the wizard: File ¦ New.
 
Hope this will help you.
Regards
Pascal
0 Kudos