MC9RS08KA2 Newbie I need to declare a far array C language CodeWarrior

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

MC9RS08KA2 Newbie I need to declare a far array C language CodeWarrior

Jump to solution
2,432 Views
BooleanBob
Contributor IV

Hello friends.

Can anybody tell me how to declare a

 

static const char array[10]

 

...in C, for KA2 chip ?

The linker is complaining with an L1023 ... "L1023: Object array spans multiple pages"

I remember this happens also with QE128 when the paged memory boundaries are exceeded.

I don't think that the same sintax could be used for KA2.

Do I also have to add some segment declaractions for the linker .prm file ?

I can't find any C examples for accessing an array this way. The AN3266 gives assembler examples but are not enough.

The online help in

http://www.freescale.com/infocenter/Codewarrior/index.jsp?topic=/com.freescale.doc.mcu.hcs08_compile...

just gives the definition for far pointers.

 

Thanks in advance

Bob

Labels (1)
0 Kudos
1 Solution
919 Views
BooleanBob
Contributor IV

Daniel:

 

Thank you so much for your explanation and the code examples.

 

First I would like to make clear that I am perfectly aware that trying to program a tiny chip such as the KA2 using a C compiler could sound rather strange to many colleagues, but I know that there is no reason not for doing it. I have lot of good reasons to do so and you know them well ( consistency, self documentation of the written code, efficiency, math libraries online, portability, etc.)

 

I had learn about managing the paged memory code in my projects with QE128, but in this case there are reasonably good documents to read and code examples that comes with the evaluation board of this chip. To my surprise, there is practically no information about KA2 and C language coming with the Softec kit. Yes, this could be the case of a chip that "likes" more assembly language than C. I understand the reasons but I don't agree with this because it should perfectly be done with a good compiler such as CodeWarrior.

 

You are a compiler guru and I don't really know if you probably work for some compiler company as Metrowerks/Freescale, but I would like to ask you how did you get this information ? Could you please be so kind to enlighten me ? Because I have read the documentation of the compiler and linker ( many times ) and it doesn't come clear from there. I was about to declare the segments for the pages in the .PRM file and try to make some weird thing splitting the arrays and some other ugly C destructive practice ( Aghhh ! ) . Did I missed some literature or should I had search some other place ?

 

I've been using Freescale chips fully programmed in C for years and I think that I have almost everything I need to program the regular S08 chips. But I couldn't find information about C examples for declaring far objects for the KA chips from the RS08 family ( intensive use of Google these days )

 

Again many thanks my friend, I will report results later.:smileywink:

 

Greetings from Buenos Aires, Argentina.

 

Roberto

View solution in original post

0 Kudos
9 Replies
919 Views
CompilerGuru
NXP Employee
NXP Employee

First a short answer. You can probably safely ignore the warning, details below. The result is not as efficient as it could be, but works.

 

Now the more detailed response Smiley Happy.

For the RS08 in extended (meaning non zero page) memory, the compiler supports 2 kind of accesses.

Paged (segment qualifier __SEG_PAGED, pointer qualifier __paged) and far (segment qualifier __FAR_SEG, pointer qualifier __far).

Far accesses/variables can be located anywhere, they may cross page (meaning multiple of 64) boundaries. For __paged accesses the compiler assumes that there is no page boundary inside of an object.

If an object is bigger than the page size (64), then it has to be __far as there is always a page boundary somewhere. For all object objects though using __paged access is MUCH more efficient, therefore I would suggest to use always __paged with the single exception of objects > 64 bytes, where __far is mandatory.

Back to the warning, the warning if for __paged accesses, but as by default there are no paged accesses (default is the safe but slow and huge __far), the code works. Just not as efficient as it could be.

Also the warning cannot be avoided as far as I know for objects > 64 bytes (I personally find the warning a bit unfortunate, well it is as it is).

For using paged, the requirement that nothing must cross a page boundary is best implemented in the prm file by listing 

the used flash as 64 byte blocks.

A sample helps I hope:

 

 

#pragma push#pragma CONST_SEG __PAGED_SEG MY_PAGED_SECconst int test0[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};const int test1[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};const int test2[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};#pragma CONST_SEG __FAR_SEG MY_FAR_SECconst int test_far[100] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};#pragma popvolatile int sum;void main(void) {  unsigned char i = 0;  for (;;)  {   i++;   i %= sizeof(test0)/sizeof(test0[0]);   sum = test0[i] + test1[i] + test2[i] + test_far[i];   __RESET_WATCHDOG();  }}

 

And here the prm parts (for a ka2, adapt to your chip:

 

SEGMENTS /* Here all RAM/ROM areas of the device are listed. Used in PLACEMENT below. */    TINY_RAM                 =  READ_WRITE   0x0005 TO 0x000D;    RAM                      =  READ_WRITE   0x0020 TO 0x004F;    RESERVED_RAM             =  NO_INIT      0x0000 TO 0x0004;    MY_PAGED_SEG0            =  READ_ONLY    0x3800 TO 0x383F;    MY_PAGED_SEG1            =  READ_ONLY    0x3840 TO 0x387F;    MY_PAGED_SEG2            =  READ_ONLY    0x3880 TO 0x38BF;    ROM                      =  READ_ONLY    0x38C0 TO 0x3FF7;ENDPLACEMENT /* Here all predefined and user segments are placed into the SEGMENTS defined above. */    RESERVED                 INTO RESERVED_RAM;    TINY_RAM_VARS            INTO TINY_RAM;    DIRECT_RAM_VARS          INTO RAM, TINY_RAM;    DEFAULT_RAM              INTO RAM, TINY_RAM;    MY_FAR_SEC, DEFAULT_ROM  INTO ROM;    MY_PAGED_SEC INTO MY_PAGED_SEG0, MY_PAGED_SEG1, MY_PAGED_SEG2;END

 

Daniel

 

0 Kudos
920 Views
BooleanBob
Contributor IV

Daniel:

 

Thank you so much for your explanation and the code examples.

 

First I would like to make clear that I am perfectly aware that trying to program a tiny chip such as the KA2 using a C compiler could sound rather strange to many colleagues, but I know that there is no reason not for doing it. I have lot of good reasons to do so and you know them well ( consistency, self documentation of the written code, efficiency, math libraries online, portability, etc.)

 

I had learn about managing the paged memory code in my projects with QE128, but in this case there are reasonably good documents to read and code examples that comes with the evaluation board of this chip. To my surprise, there is practically no information about KA2 and C language coming with the Softec kit. Yes, this could be the case of a chip that "likes" more assembly language than C. I understand the reasons but I don't agree with this because it should perfectly be done with a good compiler such as CodeWarrior.

 

You are a compiler guru and I don't really know if you probably work for some compiler company as Metrowerks/Freescale, but I would like to ask you how did you get this information ? Could you please be so kind to enlighten me ? Because I have read the documentation of the compiler and linker ( many times ) and it doesn't come clear from there. I was about to declare the segments for the pages in the .PRM file and try to make some weird thing splitting the arrays and some other ugly C destructive practice ( Aghhh ! ) . Did I missed some literature or should I had search some other place ?

 

I've been using Freescale chips fully programmed in C for years and I think that I have almost everything I need to program the regular S08 chips. But I couldn't find information about C examples for declaring far objects for the KA chips from the RS08 family ( intensive use of Google these days )

 

Again many thanks my friend, I will report results later.:smileywink:

 

Greetings from Buenos Aires, Argentina.

 

Roberto

0 Kudos
919 Views
BooleanBob
Contributor IV

Daniel:


Here are my .PRM file for the KA2 and a portion of the sample code.

I have added some page segments.

The __PAGED_SEG works fine, but the compiler screams with the __FAR_SEG declaration of the array even with an object size that matches the page segment size. Attached is the error output. What am I doing wrong ?

Thank you again


 

#pragma push
#pragma CONST_SEG __PAGED_SEG MY_PAGED_SEC


const unsigned char simtab[64]  = {0,1,2,3,4,5,6,7,8,9};
const unsigned char simtab1[64] = {0,1,2,3,4,5,6,7,8,9};
const unsigned char simtab2[64] = {0,1,2,3,4,5,6,7,8,9};

#pragma CONST_SEG __FAR_SEG MY_FAR_SEC

const unsigned char simtab3[64] = {0,1,2,3,4,5,6,7,8,9};

#pragma pop

 

===========================================================

/* This is a linker parameter file for the mc9rs08ka2 */

NAMES END /* CodeWarrior will pass all the needed files to the linker by command line. But here you may add your own files too. */

SEGMENTS /* Here all RAM/ROM areas of the device are listed. Used in PLACEMENT below. */
    
    TINY_RAM                 =  READ_WRITE   0x0005 TO 0x000D;
    RAM                      =  READ_WRITE   0x0020 TO 0x004F;
    RESERVED_RAM             =  NO_INIT      0x0000 TO 0x0004;

    MY_PAGED_SEG0            =  READ_ONLY    0x3800 TO 0x383F;
    MY_PAGED_SEG1            =  READ_ONLY    0x3840 TO 0x387F;
    MY_PAGED_SEG2            =  READ_ONLY    0x3880 TO 0x38BF;
    MY_PAGED_SEG3            =  READ_ONLY    0x38C0 TO 0x38FF;
    MY_PAGED_SEG4            =  READ_ONLY    0x3900 TO 0x393F;
    MY_PAGED_SEG5            =  READ_ONLY    0x3940 TO 0x397F;
    MY_PAGED_SEG6            =  READ_ONLY    0x3980 TO 0x39BF;
    MY_PAGED_SEG7            =  READ_ONLY    0x39C0 TO 0x39FF;

    ROM                      =  READ_ONLY    0x3A00 TO 0x3FF7;

END

PLACEMENT /* Here all predefined and user segments are placed into the SEGMENTS defined above. */
    
    RESERVED                INTO     RESERVED_RAM;
    TINY_RAM_VARS           INTO     TINY_RAM;
    DIRECT_RAM_VARS         INTO     RAM, TINY_RAM;
    DEFAULT_RAM             INTO     RAM, TINY_RAM;
    MY_FAR_SEC, DEFAULT_ROM INTO     ROM;
    MY_PAGED_SEC            INTO     MY_PAGED_SEG0, MY_PAGED_SEG1,
MY_PAGED_SEG2,MY_PAGED_SEG3,
                                     MY_PAGED_SEG4, MY_PAGED_SEG5, MY_PAGED_SEG6,MY_PAGED_SEG7;

END

STACKSIZE 0x00 /* no stack for RS08 */
//VECTOR 0 _Startup     /* Reset vector: this is the default entry point for an application. */

========================================================================


 

0 Kudos
919 Views
CompilerGuru
NXP Employee
NXP Employee

 

The prm file does not enforce that simtab3 is not allocated across a page boundary, so linker message in this case can be safely ignored. It is similar to the case of a >64 byte far variable, where the warning cannot be avoided as well :smileysad:.

 

The best location in the manual I saw was the chapter,

CodeWarrior for Microcontrollers V10.0 > HCS08/RS08 for Microcontrollers > RS08 Build Tools Reference Manual > Generating Compact Code - Relocatable Data  

 

but even in those samples it is not enforced that the paged variables were allocated without crossing a page boundary :smileysad:.

 

I do know the tools because I worked on the compiler many years ago, but that was before the RS08 came up.

 

Daniel

 

0 Kudos
919 Views
Navidad
Contributor III

Hello BooleanBob,

 

You are not doing anything wrong (but you could have :smileywink:). The linker warns you that one of your objects goes from one page to another, meaning that it is only safe to access it if it is placed in a far segment (or accessed with a far pointer). Of course, you already placed your object is a far segment, but this information is not really available at link time. I know that this may get a bit annoying, but I think it is the type of information that may just save some debugging time since this system of extending ANSI-C for these small MCUs tends to be rather complicated. You can also disable the message if you do not find it useful any more (pass -WmsgSd1023 to the RS08 linker). 

0 Kudos
919 Views
BooleanBob
Contributor IV

Thank you too, Navidad.


You are right. But I try not to disable any messages, unless they are those that really bother as "Result of function called is not used" or "Asignment in condition".


This is why it bothers to have some warning hanging but in this case, no problem.


Kind regards


Roberto

 

0 Kudos
919 Views
BooleanBob
Contributor IV

Yes my dear friend, I was tired when I read your first post and skipped something very important. You have explained perfectly well. For some reason I had always read this linker warning as an error :smileytongue:


Understood, I can live with this warning. I will return with confirmation of problem solved.


Please, I am curious: where is this information stored ?


Very kind regards !


Roberto

0 Kudos
919 Views
Navidad
Contributor III

You mean where is all that documented ? Generally speaking it is in the compiler manual. However, I have to agree that it is a bit spread out, you have to put together quite many pieces. Freescale is putting it all together in a brief document (an application note) that targets exactly this subject: accessing RS08 upper memory. This is obviously not of much use to you any more, but for other people out there trying to do the same job I guess it will come handy. I'm not sure yet when this will make it on freescale.com, but I will come back with a link here.

 

0 Kudos
919 Views
BooleanBob
Contributor IV

Yes Navidad, everything counts when you navigate in solitude !

I will wait for your return.

I appreciate your contribution.


Kind regards


Roberto


 

0 Kudos