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();}
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.
#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 */ }}
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.