Problem in using D-Flash for XS128, Need help

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

Problem in using D-Flash for XS128, Need help

2,724 Views
nandu
Contributor III
Good day everyone,
 
I am working on MC9S12XS128 MCU.
 
I know that this MCU has the new feature of D-Flash. I am facing a problem in using this and executing its commands on it. I am not very clear about this D-Flash and have the following questions
 
I do not want to use the Global address in my project, so after reviewing the datasheets, i am thinking that a 1Kbyte D-flash is available for XS128 mcu in the local memory map in the range 0x0C00 to 0x0FFF. so, i want to perform program/erase commands in this memory area
 
This is my sample code
 
 
Code:
void Init_Project(void){   /* Init Flash module */  
   FCLKDIV = 0x07;  /* FDIV generates an FCLK frequency of 1.05 MHz */   DFPROT  = 0x10;  /* Disables D-Flash memory protection from program and erase */}void Erase_DFlash_Sector(void){    if(FSTAT_CCIF == 0) /* Is command not completed — */      {        return;         /* Break current process */    }    FSTAT = 48;         /* ESTAT: PVIOL=1,ACCERR=1, clear error flags */            FCCOBIX =  0x00;    FCCOBHI =  0x12;    /* Erase D-Flash sector command */    FCCOBLO =  0x00;    /* Global address = 0 */        FCCOBIX =  0x01;    FCCOB   =  0x0C00;  /* Local D-Flash address, 0x0C00 */        FSTAT_CCIF = 1;     /* Clear command complete flag to start new command */          while(!FSTAT_CCIF); /* wait for command to complete */}void main(void){    Init_Project();    Erase_DFlash_Sector();}  

But after downloading the code and run in the Codewarrior debugger, i can see the memory from
 
0x0800 to 0x0BFF is filled with all " rr rr rr rr rr .... rr"   and
0x0C00 to 0x0FFF is filled with all " -- -- -- -- -- ....--"
 
and i always see the ACCERR bit of FSTAT register is set. that means some acces error.
 
I have the following doubts....
 
1. Do i need to specailly enable the D-Flash and Initialize the D-Flash before running the commands to the memory 0x0C00 to 0x0FFF... (like in case of MC9S12DG128, or D64.. etc.. we will configure the EEPROM with "INITEE" and enable the EEPROM using "MISC")......??
 
2. And am I writing the correct values to the registers FCCOBIX and FCCOB  in my function "Erase_DFlash_Sector()"... ???
 
3. The data sheet mentioned, the FCCOB parameters for this command should contains the Global address [22:16]  to identify D-Flash blocks to be erased... and I dont want to use global memory.. is this creates any problem...
 
Finally, I am confused how to configure the 1KByte D-Flash from 0x0C00 to 0x0FFF and how to run the commands on this memory area.. specially how to write the FCCOB registers if I am not using global memory model..
 
Any kind of suggestions will be greatly helpful to me.,.
 
Nandu

 
 
 
 
 
 
Labels (1)
0 Kudos
3 Replies

663 Views
DPB
NXP Employee
NXP Employee
Hello

The global addresses are required. i.e. 0x10_0C00 must be used in this case
    FCCOBIX =  0x00;
    FCCOBHI =  0x12;    /* Erase D-Flash sector command */
->  FCCOBLO =  0x10;    /* Global address = 10 */
   
To disable D-Flash protection DFPROT[7] must be set. i.e. DFPROT = 0x80 instead of DFPROT = 0x10.
-> DFPROT  = 0x80;  /* Disables D-Flash memory protection from program and erase */
No further configuration of the sort mentioned (INITEE and MISC) is neccesary.
 
DPB

0 Kudos

663 Views
nandu
Contributor III
Hi DPB sir...
 
Thank you very very much ...
 
Now, I can run the D-Flash commands using the global address.
 
I can Erase/Program the D-Flash from 0x10_0000 to 0x10_1FFF i.e in a total of 8kbytes (Since MC9S12XS128 has 8K bytes of D-Flash)
 
But, if I also want to read the data that is present in those locations by directly accessing those memory locations...but I couldn't able to do it..
 
for example:
 
Code:
#define U32_GLOBAL_DFLASH_START_ADDR    0x100000unsigned char DFlash_Data[10];
void my_function(void){    for(i=0; i<10; i++)    {            DFlash_Data[i]  = *(uint8_t *)(U32_GLOBAL_DFLASH_START_ADDR + i);         /* byte access */             }}

After I download the source code, I can see that the whole D-Flash memory contains the value of 0xFF.
(i.e. D-flash memory from 0x10_0000 to 0x10_1FFF is completely erased). But when I read those memory locations by directly accessing as shown in the above sample code, it always returns 'zero' instead of 0xFF.
i.e. the variable "DFlash_Data[ ]" always receives the value of '0' from the D-Flash memroy.
 
1. Can I direclty access the global address as shown above...??
2. why does the routine always a value zero to the variable 'DFlash_Data[ ]' ..??

Could you please suggest me the solution to read the data that is store in the D-Flash memory locations from 0x10_0000 to 0x10_1FFF
 
Thank you very much agian
Nandu
 
 
0 Kudos

663 Views
nandu
Contributor III

Hi DPB sir

I think my problem was solved as off now.. i.e. to read/access the memory locations from D-Flash for MC9S12XS128 MCU.

After going through several threads in this forum and the Codewarrior documents like TN238.pdf, TN240.pdf, AN2734.pdf. I am now in a position to understand some of the familiar terms of the XS family memory organization like Logica addressing, Global addressing, __far,__pptr etc. So, I would like to share my views here, please have a look at it and kindly correct me if I am wrong any where

In case of XS128 MCU, I think the D-Flash memory can be viewed as 3 pictures... Please reffer to the attachment 

1. Local Address Map    (General 64Kbytes of memory)

2. Logical Address Map (Memory locations which can be accessed usign the respective memory block pages like RPAGE, EPAGE, PPAGE)

3. Global Address Map  (The whole Memory locations which can be accessed using a single global page called GPAGE)

All the three address maps are logically same, but it depends on the user how he will tell the compiler to access those locations...So, he can tell the compiler either to access the memory locally, or logically (using EPAGE) or gloabally (using GPAGE).

And to use each access, we can use different schemes.

1. Inorder to access/read the memory from global map, I use the following method...

-------------------------------------------------------------------------------------------------------------

#define U32_GLOBAL_DFLASH_START_ADDR    0x100000

unsigned char DFlash_Data[10];

void my_function(void)
{
    for(i=0; i<10; i++)
    {   
        DFlash_Data[i]  = *(uint8_t* __far)(U32_GLOBAL_DFLASH_START_ADDR + i);         /* byte access */        
    }
}

i.e. we should use the '__far' pointer access to tell compiler to access data from the Global memory

2. Inorder to access/read the memory from logical map, I use the following method...

-----------------------------------------------------------------------------------------------------------

#define U16_LOGICAL_DFLASH_START_ADDR    0x00800

unsigned char DFlash_Data[10];

void my_function(void)
{
    for(i=0; i<10; i++)
    {   
        DFlash_Data[i]  = *(uint8_t* __eptr)(U16_LOGICAL_DFLASH_START_ADDR + i);         /* byte access */        
    }
}

i.e. we should use the '__eptr' pointer access to tell compiler to access data from the Logical memory map

3. Inorder to access/read the memory from local map, I use the following method...

-----------------------------------------------------------------------------------------------------------

#define U16_LOCAL_DFLASH_START_ADDR    0x0C00

unsigned char DFlash_Data[10];

void my_function(void)
{
    for(i=0; i<10; i++)
    {   
        DFlash_Data[i]  = *(uint8_t* )(U16_LOCAL_DFLASH_START_ADDR + i);         /* byte access */        
    }
}

I think, here there is no need to use any pointer access since 0x0C00 is the non-paged D-Flash memroy area

and Finally, since global addressing is used mainly where the very large size data structure are required to improve the speed a little, I use the Logical address scheme in my code, as my data in the D-Flash is not bigger than a size of D-Flash (i.e. 1Kbytes). i.e I use the 2nd scheme.

0 Kudos