C equivalent to ORG

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

C equivalent to ORG

1,498件の閲覧回数
DSbob
Contributor III
Peg suggested I search for answers to my questions here, as the answers may be tool dependent.  OK, I'm using Codewarrior IDE v5.7.0, and just switched successfully from USB to demo board, to USB-Cyclone Pro-demo board (application hardware I designed arrives next week, but I've hooked a prototype to the demo board).   But I'm not sure of the terms.  In the 8-bit microcontrollers forum, I posted:
 
"I've spent years programming HC05 in asm.  New to C and Flash, using S08QG8.  I need to store a calibration value in flash.
 
With help from this forum [8-bit uC], I have it written to second to last page, 0xFC00.
 
Memory write protection starts at last page and works toward lower pages, right?  So with a flash writer in my application, I sure want to protect program memory! 
 
I want to write the calibration value at 0xE000, and make sure the complier/linker starts the application program at 0xE200, the second page of flash.  I've studied Segments and Sections in the linker prm file but don't see how to force that.  Any suggestions?
 
Writing this, I've come to realize each debug session will probably overwrite the calibration value through mass erase.  I think that can be delt with, have used command files.  Will a w(rite bytes, words, etc) post load command actually write to flash, so I can debug normal operation?"
 
Search terms "calibrate", "calibration", and "eeprom flash" turned up some interesting things, but I have not found anything specific to the compliler / linker, yet.
 
Thanks Alban for your reply in microcontrollers.  I'm a little confused about what is meant by "emplacement".  I think you are working with a different memory map too.  I'll be sure to study the QG8 memory map and flash page specs real close!  OK, I see the PLACEMENT part of the PRM file.  I think you are saying break the segment named ROM into ROMsomething and ROMsomethingelse (ROM1 looks like config register space or something).  Then the new INTO, maybe the #pragmas you suggest.  But the calibration value writer I adapted from the uC forum accepts an absolute address, and I was going to figure how to read the calibration value back that way (C pointer to absolute address?  In line assembly, MOV firstbyte, TPMC0VH, nextbyte to ...L?  If FFFF your erased, not calibrated!)
 
It is a simple application, perfect for finally forcing me to learn a little C.  Display peak absolute value of magnetic strength a hall sensor is exposed to, DC-400 hz, 0.1-1.5T.  Auto zero and normal operation are easy.  So should binary to LED segments conversion and multiplexing.  Self calibration-searching for sensor stimulation that measures strength of a DC calibration field, is the tricky part, but nearly operational.
 
I'll post a reply to this one, if I get into trouble!
ラベル(1)
タグ(1)
0 件の賞賛
返信
2 返答(返信)

459件の閲覧回数
DSbob
Contributor III
CrasyCat,
 
Your assumption is not quite correct.  Actually I do start with a constant, but that gets stored and altered in volatile memory, actually a timer register.  The timer register result is the number that the uC stores in its own NV memory, as the calibration value, preferrably without aid of a debugger.  In production it is not constant at all but varies by sensor sensitivity.  But in a given product, the sensor is stable enough to assume the value valid for a year or so.  I have all that coded and operational.
 
From the S08QG datasheet "block protection begins at any 512 byte boundary below the last address of FLASH [and working toward lower addresses]".  That is my reason for wanting to store the value in the first 512 byte NV page.  So the firmware can be protected, and can write the calibration value it finds.  That is why executable code should not start until the second block from the lowest ROM address, where it can be protected.
 
That was the hardware part of my original post.  Between your answer, CrasyCat, and Alban's to my original post in 8-bit uC forum, I think the answer to the subject is clear enough.  I'm putting out a fire, may take days to try it.
 
Thanks all.
0 件の賞賛
返信

459件の閲覧回数
CrasyCat
Specialist III
Hello
 
I assume you want to define a constant and allocate it at an absolute address.
Am I right?
 
If you are using CodeWarrior compiler you can use the @ operator in this purpose.
For example following instruction will allocate a 2 byte object at address 0xFFA0 and initialize it with 0x10.
 
   const int toto @0xFFA0 = 0x10 ;
 
If you wish to tell that he application should start at a specific address:
  - Create a function which will be used as application entry point.
     Make sure you do not define the function as static in the ANSI C source file.
  - Place the function in a user defined code section using pragma CODE_SEG
    Example
    #pragma CODE_SEG MyEntrySection
    void MyEntryCode(void) {
    /* Insert Code Here*/
    }
    #pragma CODE_SEG MyEntrySection
  - In the PRM file indicate you want to use the function MyEntryCode as application entry code.
    This is done using the command INIT
       INIT MyEntryCode
 - As you want your code to start at address 0xE200, modify the line
    ROM                      =  READ_ONLY    0xE000 TO 0xFFAD;
   into
    ROM                      =  READ_ONLY    0xE200 TO 0xFFAD;
 - Finally place the function at the appropriate location. As the function is the application entry point, it will
    be placed in predefined section .init
   So modify the line
       DEFAULT_ROM, ROM_VAR, STRINGS       INTO  ROM; 
    into
     .init, DEFAULT_ROM, ROM_VAR, STRINGS INTO  ROM; 
That should be it.
 
CrasyCat
0 件の賞賛
返信