the Page problem with  MC9S08DZ128

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

the Page problem with  MC9S08DZ128

1,381 Views
wlm
Contributor I

 I built a project with Banked mode for a  MC9S08DZ128. My program larger than 64Kb, and plus with some LCD chart data, which was labeled with  #pragma CONST_SEG PAGED_ROM.  To verify the validness, I dump the LCD chart data to RAM, the data was read begin with the address of 0x8000.  I read it's .map file, the LCD chart data was assigned at the address begin with  0x68000, and some function was assigned at page 5 and page 6. I debug the program by step, find the process would loss the control, and the Register show the status of  PC:8297 IP:68297  PPAGE:6  LAP:0, contrast whit the PC:BE9F IP:2BE9F PPAGE:2  LAP:0 in normal status. If the function wasn't assigned at Page 5 and Page 6, the program can run correctly.
Please tell me what is wrong? and how to solve the problem? How could I use the flash section which larger than 64Kb?

Labels (1)
0 Kudos
9 Replies

686 Views
kef
Specialist I

Wrong is that compiler (I mean V6.3  and don't know if it was improved in 10.x) is unable to handle data from paged flash directly. It is not enough to change default constants segment. You need to deal with linear address of your data or do other tricks to access paged data.

 

1) It would be the best to not use paged flash for your data.

 

2) You may try making paged data access routines NON_BANKED, then, provided P-page of your data is known, you may switch PPAGE register before you access to your data. To make page of data known, you may edit prm and make data allocated not to PAGED_ROM, but to specific page of flash.

 

3) Of course you should consider this CW example, which allows to access paged data using LAP from any code, both banked and nonbanked

 

CodeWarrior for Microcontrollers V6.3\(CodeWarrior_Examples)\HCS08\Evaluation Board Examples\DEMOQE128\DEMOQE128_LAP_Dictionary

0 Kudos

686 Views
wlm
Contributor I

My program larger than 64Kb,and some function was assigned at page 5 and page 6 automaticly, how can I change this?In you  repaly "switch PPAGE register before you access to your data",But  the program was assigned at page 5 and page 6 automaticly.

 

 

 

0 Kudos

686 Views
kef
Specialist I

Regarding "2)". I meant you may force allocating your paged data to specific page. For example you may force allocation to page 7, adding this line to PLACEMENT section in PRM file:

 

    PAGEDDATA                           INTO  PPAGE_7;

 

Now, you define your data in C like this:

 

#pragma CONST_SEG PAGEDDATAconst char mydata[] = "mydata";#pragma CONST_SEG DEFAULT

 

Now you do NON_BANKED mydata access routine. It may be either a copy routine, or some data manipulation routine. Let ir for example copy mydata[] to RAM:

#pragma CODE_SEG __NEAR_SEG NON_BANKEDvoid copymydatatoRAM(char *destination){const char *src;char oldppage;   oldppage = PPAGE; // we have restore PPAGE on exit   PPAGE = 7; // mydata allocated to page 7, see prm file   //you can't library copy functions here, since they are paged    // and will manipulate PPAGE      // don'y do here strcpy(destination, mydata);    src=mydata;   while(*src != '\0')   {      *destination++ = *src++;   }   PPAGE = oldppage;}#pragma CODE_SEG DEFAULT

 Usage example:

char data[100];void main(void) {  copymydatatoRAM(data);

 

 BTW maybe LAP is not very convenient to use, especially if you don't like pointers, but it is very effective to access data from paged memory. LAP registers are allocated in zero page, also they allow to autoincrement pointer on access, which helps making and speeds up copy routines.
 

0 Kudos

686 Views
wlm
Contributor I

Hi kef:

 

First, I have seen CodeWarrior for Microcontrollers V6.3\(CodeWarrior_Examples)\HCS08\Evaluation Board Examples\DEMOQE128\DEMOQE128_LAP_Dictionary.But I found if my chart data was defined like this ,const char *__linear const keys[]={1,2,3,4,5}  it was wrong. wheather I must define like this const char *__linear const keys[]={"1","2","3","4","5"} .

How can I use number instead of string?

 

I mean you answer can slove the Data problem, But how can I run functions  which were assigned at page 5 and page 6 automaticly. Because  the program was assigned at page 5 and page 6 automaticly. And the *__linear  can only slove the problem of data.

 

 

The program was assigned at page 5 and page 6 automaticly. So I don't konw the exactly page of it , I cannot change PPage.

 

for example

 

void main(void) {

  copymydatatoRAM(data);

}

 

but the function   copymydatatoRAM(data)  was saved in the page 6,how can I use it.

0 Kudos

686 Views
kef
Specialist I

No, copymydatatoRAM is assigned to the outside of PPAGE window 0x8000-0xBFFF. In my experimental project this function landed at 0x4097. Maybe you ignored CODE_SEG pragma from my example or did something to  NON_BANKED placement in your PRM file?

 

All other functions can be allocated to any page. Normally you should not bother what page specific function is allocated to. But what you did to allocate data in paged flash is not enough. Yes, switching CONST_SEG allocation makes data allocated in paged flash, but you should either use LAP pointer to access paged data, or care about 1) switching PPAGE  to access paged data and 2) care about NOT switching PPAGE while CPU is executing paged function within PPAGE window, since it would unmap memory with current code from PPAGE window and CPU will runaway. Paged functions are executed from PPAGE window 0x8000-0xBFFF. Having data in different page than code, you need to switch PPAGE, but you can't do it while CPU program counter is within page window. So you need to jump to NON_BANKED routine and switch PPAGE there.

 

> My program larger than 64Kb,How can I change one Page to another page for program or function?

 

 Do you mean you won't some paged code allocated to specific page? This may be done switching CODE_SEG to specific placement, which is restricted to specific page. You need to define new placement in PLACEMENT section of PRM file. Then use CODE_SEG to switch to this placement.

BTW you may place both paged data access routine and access routine to the same page switching both CODE_SEG and CONST_SEG to the same PLACEMENT INTO PPAGE_x. This way you wouldn eliminate the need to switch PPAGE for data access. But you still can't call functions like strcpy or memcpy, because they may be allocated to different page and won't be able access data properly.

 

const char *__linear const keys[]={1,2,3,4,5} ;  --- Of course this is wrong. Original code defined array of strings. It looks like you want to define either array of chars or array of ints.

 

#include <mmu_lda.h>#pragma CONST_SEG  __LINEAR_SEG PAGED_ROMconst char myconstchars[] = {1,2,3,4,5};const int myconstints[] = {0x101,2,3,4,5};#pragma CONST_SEG  DEFAULTvoid main(void) {char c;int i;  __LOAD_LAP_ADDRESS(myconstchars);   __ADJUST_LAP_IMM_16BIT( 2/* access 3rd element of myconstchars*/);  // ^^ _IMM  is for immediate constant argument  // ^^ _16BIT - width of index variable/constant.   __LOAD_BYTE(c);  __LOAD_LAP_ADDRESS(myconstints);   __ADJUST_LAP_IMM_16BIT( 3*2/* access 4th element of myconstints*/);  __LOAD_WORD_INC(i);

 

It requires a lot of writing in proper English(, which I'm not good at) to explain it all. Hope you'll manage to get it working.

 

 

0 Kudos

686 Views
wlm
Contributor I

Hi kef: What I mean is that wheather Data in Paged Flash should be changed  PPAGE  before reBut  the data,

 

What is the way to solve one function to another function in different paged Flash? It will changed automatic or by myself?

0 Kudos

686 Views
kef
Specialist I

I'm not sure I understand your request. Do you wonder how banked calls are made by CPU? It is made by CALL and RTC CPU instructions.

0 Kudos

686 Views
wlm
Contributor I

Hi kef

 

I want to know wheather if the function can not be assigned at Page 5 and Page 6 or other?

 

My program larger than 64Kb,How can I change one Page to another page for program or function?

 

All methods you have said were stated for  data which were saved in page?

 

Thang you

 

0 Kudos

686 Views
wlm
Contributor I
Hi kef
,
 
Thank you for your answer.
Without your help, it would have taken a long time for me to solve the problem 
Thank you again!
 
wlm
0 Kudos