Problem in flash writing and reading

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

Problem in flash writing and reading

1,359 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ramesh@spatika on Tue Dec 07 06:47:43 MST 2010
As an initial step first i am erasing all the sectors which i am going to use and also i am  writing some format text on to them.

In the next step i am reading the flash and substitute the value for that particular time and then the same is written to the flash.

I am using a struct variable for writing and reading from the flash.

So when i am trying to read the flash i found that in addition to the data i am writing to the flash i am also noticing  some other values in the flash in a different position.

kindly let me know if someone is facing the same problem or otherwise suggest me someway to get out of this problem

Original Attachment has been moved to: 1100891_dma.txt.zip

0 Kudos
Reply
6 Replies

1,274 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ramesh@spatika on Mon Dec 13 00:20:50 MST 2010
1.Code for prepare sector

short int Prepare_Sector(int Start_Sec_No, int End_Sec_No) {
    command_iap[0] = 50;
    command_iap[1] = Start_Sec_No;
    command_iap[2] = End_Sec_No;
    iap_entry = (IAP) IAP_LOCATION;
    iap_entry(command_iap, result_iap);
    return (result_iap[0]);
}

2.Code for erase sector

short int Erase_Sector(int Start_Sec_No, int End_Sec_No) {
    command_iap[0] = 52;
    command_iap[1] = Start_Sec_No;
    command_iap[2] = End_Sec_No;
    command_iap[3] = XOSC;
    iap_entry = (IAP) IAP_LOCATION;
    iap_entry(command_iap, result_iap);
    return (result_iap[0]);
}

3.Code for write sector

short int Write_Sector(unsigned int Dest_Addr, unsigned int Source_Addr,
        int Bytes) {
    command_iap[0] = 51;
    command_iap[1] = Dest_Addr;
    command_iap[2] = Source_Addr;
    command_iap[3] = Bytes;
    command_iap[4] = XOSC;
    iap_entry = (IAP) IAP_LOCATION;
    iap_entry(command_iap, result_iap);
    return (result_iap[0]);
}

These are the code i am using for low level flash operations.
xosc frequency is 100000
kindly review the same and let me know if u find any problems in them.
0 Kudos
Reply

1,274 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by NXP_USA on Fri Dec 10 09:19:05 MST 2010
What do the functions Prepare_Sector, Write_Sector, and Erase_Sector do? Those seem to be called by the code you posted to do the low-level flash operations but without seeing the code it is hard to review them.

-NXP
0 Kudos
Reply

1,274 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gbm on Thu Dec 09 08:18:11 MST 2010
My guess is - the problem may lie in the definition of your data structures, Reading_def and monthly_log in particular.
0 Kudos
Reply

1,274 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by shailesh on Wed Dec 08 18:11:04 MST 2010
I have observed one problem while programming the internal flash memory of LPC1765
1) First i erased all the sectors in flash.
2) I wrote Data to RAM.
2) Using IAP command CopytoRAMToFlash(flash_addr,ramaddr,len) i wrote image into the flash.
3)But the data in flash is data along with garbage.

Kindly let me know if someone is facing the same problem or otherwise suggest me someway to get out of this problem
0 Kudos
Reply

1,274 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ramesh@spatika on Wed Dec 08 01:06:56 MST 2010
Every 15 minute i am logging the data into the flash using the following function

void Log_Data_In_Flash(void)
{
    int iCount,sample;
    char test[40];
    int i;
    if((giDom!=(xMonthly_Log[giMoy]->xdaily_log[giDom].idd))||(giMoy!=(xMonthly_Log[giMoy]->xdaily_log[giDom].imm))||(giYy!=(xMonthly_Log[giMoy]->xdaily_log[giDom].iyy)))
    {
        Erase_n_Format(giYy, giMoy, giDom);//Mismatch Erase the entire months space
    }
    //now let us read the daily space
    Read_Daily_Data(&local_daybuf_4_log, giMoy, giDom);

    sample=(giHh*60+giMin)/15;//position of the data to be written for the time

    vPrintStringAndNumber("sample",sample);
    local_daybuf_4_log.irf[sample]=siRain_Log;
    local_daybuf_4_log.itemp[sample]=siTemp_Log;
    local_daybuf_4_log.ihumi[sample]=siHumi_Log;
    local_daybuf_4_log.iws[sample]=siWs_Log;
    local_daybuf_4_log.iwd[sample]=siWd_Log;


    //now log the data on the flash by writing
    Write_Daily_Data(&local_daybuf_4_log,giMoy, giDom);
    sample=(giHh*60+giMin)/15;//position of the data to be written for the time

}

//erasing the data and formatting


void Erase_n_Format(unsigned int iYear, unsigned int iMonth, unsigned int iDate )
{
    int day,month,year,sector;
    //Claculate the sector
    sector=START_SEC_NO_DEF+iMonth-1;
    vPrintStringAndNumber("\nSec ",sector);
     __disable_irq();
     Prepare_Sector(sector,sector);//prepare the sector
     Erase_Sector(sector,sector);//erase the sector
     __enable_irq();

     //before formatting clear the local buffer by readin the erased space
     Read_Daily_Data(&local_daybuf_4_log,iMonth,iDate);
     //format the buffer
     for(day=0;day<32;day++)
     {
         local_daybuf_4_log.idd=(short int)day;
         local_daybuf_4_log.imm=(short int)iMonth;
         local_daybuf_4_log.iyy=(short int)iYear;
         Write_Daily_Data(&local_daybuf_4_log,iMonth,day);
     }

}
//writing the data every 15 minute
void Write_Daily_Data(Reading_def *xWrite_local,unsigned int iMonth,unsigned int iDate)
{
    int sector;
    int ret;
    int i;

    sector=START_SEC_NO_DEF+iMonth-1;
     __disable_irq();
     Prepare_Sector(sector,sector);//prepare the sector
     ret=Write_Sector((unsigned int)&(xMonthly_Log[iMonth]->xdaily_log[iDate]),(unsigned int)xWrite_local,1024);//write the sector
     if(ret!=0)
         vPrintString("Error in writing");
     __enable_irq();

}



void Read_Daily_Data(Reading_def *xRead_Local,unsigned int iMonth,unsigned int iDate)
{
    int i;
    char test[40];
    xRead_Local->idd=xMonthly_Log[iMonth]->xdaily_log[iDate].idd;
    xRead_Local->imm=xMonthly_Log[iMonth]->xdaily_log[iDate].imm;
    xRead_Local->iyy=xMonthly_Log[iMonth]->xdaily_log[iDate].iyy;



    for(i=0;i<96;i++)
    {
        xRead_Local->irf=xMonthly_Log[iMonth]->xdaily_log[iDate].irf;
        xRead_Local->itemp=xMonthly_Log[iMonth]->xdaily_log[iDate].itemp;
        xRead_Local->ihumi=xMonthly_Log[iMonth]->xdaily_log[iDate].ihumi;
        xRead_Local->iws=xMonthly_Log[iMonth]->xdaily_log[iDate].iws;
        xRead_Local->iwd=xMonthly_Log[iMonth]->xdaily_log[iDate].iwd;

        if((xRead_Local->itemp!=0xffff)&&(xRead_Local->itemp!=455)){
            sprintf(test,"\nteRd %d, %d;   ",xRead_Local->itemp,i);
            vPrintString(test);
        }
        if((xRead_Local->ihumi!=0xffff)&&(xRead_Local->ihumi!=677)){
            sprintf(test,"\nhuRd %d, %d;    ",xRead_Local->ihumi,i);
            vPrintString(test);
        }


    }
    xRead_Local->imax_temp=xMonthly_Log[iMonth]->xdaily_log[iDate].imax_temp;
    xRead_Local->imin_temp=xMonthly_Log[iMonth]->xdaily_log[iDate].imin_temp;
    xRead_Local->imax_humi=xMonthly_Log[iMonth]->xdaily_log[iDate].imax_humi;
    xRead_Local->imin_humi=xMonthly_Log[iMonth]->xdaily_log[iDate].imin_humi;
    xRead_Local->imax_wind=xMonthly_Log[iMonth]->xdaily_log[iDate].imax_wind;

    for(i=0;i<24;i++)
    {
        xRead_Local->padding=xMonthly_Log[iMonth]->xdaily_log[iDate].padding;
    }


}



please see the code above for you reference.

As i told at every 15 minute i am reading the flash.

If there is no content in the flash memory i will write the text format.

I there is right contentt in the flash memory then i will read the same and substitute the value for the particular sample.



kindly guide me further.
0 Kudos
Reply

1,274 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by NXP_USA on Tue Dec 07 09:32:05 MST 2010
Can you post a code sample that shows how you are reading, erasing, and writing the flash?

Thank you,
-NXP
0 Kudos
Reply