Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Message

Re: Flash write errors

2006-01-26 by Guillermo Prandi

Sorry, guys, my mistake.

I was not checking the sector for being blank after my 
IAP_EraseSectors() function, and there was a typo in that function 
that prevented the correct CPU clock from getting through the IAP 
command.

It was a weird thing to watch the erase sectors command take almost 
no time, when it was supposed to take 400 mS!

Thanks everybody.

Guille


--- In lpc2000@yahoogroups.com, "Guillermo Prandi" 
<yahoo.messenger@m...> wrote:
>
> Hi, Richard. This is an excertp of my test code:
> 
> 
> #define IAP_LOCATION 0x7ffffff1
> 
> typedef void (*IAP)(unsigned int [],unsigned int[]);
> 
> static    unsigned    int    iapcmd[5];
> static    unsigned    int    iapres[3];
> 
> #define    IAP_CMD_PREPARE_FOR_WRITE   50
> #define    IAP_CMD_COPY_RAM_TO_FLASH   51
> #define    IAP_CMD_ERASE_SECTORS       52
> #define    IAP_CMD_CHECK_BLANK         53
> #define    IAP_CMD_READ_PART_ID        54
> #define    IAP_COMMAND                 0
> #define    IAP_RESULT                  0
> #define    IAP_PFW_START_SECTOR        1
> #define    IAP_PFW_END_SECTOR          2
> #define    IAP_CRTF_DST_ADDR           1
> #define    IAP_CRTF_SRC_ADDR           2
> #define    IAP_CRTF_BYTES              3
> #define    IAP_CRTF_CCLK_KHZ           4
> #define    IAP_ES_START_SECTOR         1
> #define    IAP_ES_END_SECTOR           2
> #define    IAP_ES_CCLK_KHZ             3
> #define    IAP_CB_START_SECTOR         1
> #define    IAP_CB_END_SECTOR           2
> #define    IAP_CB_NON_BLANK_FIRST      1
> #define    IAP_CB_NON_BLANK_WORD       2
> 
> ....
> } else if( !strnicmp( command, "iapw ", 5 ) )
> {
>     static    char   buf[256];
>               char*  txt = &command[5];
>               int    res;
> 
>     memset( buf, 0, sizeof(buf) );
>     strcpy( buf, txt );
> 
>     do {    // Not a loop
> 
>     res = IAP_CheckBlank( 22, 22 );
> 
>     if( res != IAP_CMD_SUCCESS )
>     {
>         printf( "Sector is not blank. Blanking sector...\r\n" );
> 
>         res = IAP_PrepareForWrite( 22, 22 );
> 
>         if( res != IAP_CMD_SUCCESS )
>         {
>             printf( "IAP_PrepareForWrite() returns error %
> d\r\n", res );
>             break;
>         }
> 
>         res = IAP_EraseSectors( 22, 22 );
> 
>         if( res != IAP_CMD_SUCCESS )
>         {
>             printf( "IAP_EraseSectors() returns error %
d\r\n", res );
>             break;
>         }
> 
>         printf( "Sector blanked.\r\n" );
>     }
> 
>     printf( "Writing onto flash...\r\n" );
> 
>     res = IAP_PrepareForWrite( 22, 22 );
> 
>     if( res != IAP_CMD_SUCCESS )
>     {
>         printf( "IAP_PrepareForWrite() returns error %d\r\n", res );
>         break;
>     }
> 
>     res = IAP_CopyRAMToFlash( buf, (void*) 0x00078000, sizeof
(buf) );
> 
>     if( res == IAP_CMD_SUCCESS )
>     {
>         printf( "Flash memory written successfully.\r\n", res );
> 
>         if( memcmp( buf, (void*) 0x00078000, sizeof(buf) ) )
>         {
>             printf
> ( "Flash and RAM buffer contents do NOT match.\r\n" );
> 
>         } else {
> 
>             printf( "Flash and RAM buffer are now identical.\r\n" );
>         }
> 
>     } else {
> 
>         printf( "IAP_CopyRAMToFlash() returns error %d\r\n", res );
>         break;
>     }
> 
>     } while(0);
> }
> 
> ....
> 
> ///////////////////////////////////////
> 
> 
> int IAP_PrepareForWrite( int start_sector, int end_sector )
> {
>     taskENTER_CRITICAL();
>     iapcmd[IAP_COMMAND] = IAP_CMD_PREPARE_FOR_WRITE;
>     iapcmd[IAP_PFW_START_SECTOR] = start_sector;
>     iapcmd[IAP_PFW_END_SECTOR] = end_sector;
>     IAP    iap_entry = (IAP) IAP_LOCATION;
>     iap_entry( iapcmd, iapres );
>     int    res = (int) iapres[IAP_RESULT];
>     taskEXIT_CRITICAL();
>     return res;
> }
> 
> int IAP_CopyRAMToFlash( void* src_addr, void* dst_addr, int bytes )
> {
>     taskENTER_CRITICAL();
>     iapcmd[IAP_COMMAND] = IAP_CMD_COPY_RAM_TO_FLASH;
>     iapcmd[IAP_CRTF_SRC_ADDR] = (unsigned long) src_addr;
>     iapcmd[IAP_CRTF_DST_ADDR] = (unsigned long) dst_addr;
>     iapcmd[IAP_CRTF_BYTES] = bytes;
>     iapcmd[IAP_CRTF_CCLK_KHZ] = GetCCLKKHz();
>     IAP    iap_entry = (IAP) IAP_LOCATION;
>     iap_entry( iapcmd, iapres );
>     int    res = (int) iapres[IAP_RESULT];
>     taskEXIT_CRITICAL();
>     return res;
> }
> 
> int IAP_EraseSectors( int start_sector, int end_sector )
> {
>     taskENTER_CRITICAL();
>     iapcmd[IAP_COMMAND] = IAP_CMD_ERASE_SECTORS;
>     iapcmd[IAP_ES_START_SECTOR] = start_sector;
>     iapcmd[IAP_ES_END_SECTOR] = end_sector;
>     iapcmd[IAP_CRTF_CCLK_KHZ] = GetCCLKKHz();
>     IAP    iap_entry = (IAP) IAP_LOCATION;
>     iap_entry( iapcmd, iapres );
>     int    res = (int) iapres[IAP_RESULT];
>     taskEXIT_CRITICAL();
>     return res;
> }
> 
> int IAP_CheckBlank( int start_sector, int end_sector )
> {
>     taskENTER_CRITICAL();
>     iapcmd[IAP_COMMAND] = IAP_CMD_CHECK_BLANK;
>     iapcmd[IAP_CB_START_SECTOR] = start_sector;
>     iapcmd[IAP_CB_END_SECTOR] = end_sector;
>     IAP    iap_entry = (IAP) IAP_LOCATION;
>     iap_entry( iapcmd, iapres );
>     int    res = (int) iapres[IAP_RESULT];
>     taskEXIT_CRITICAL();
>     return res;
> }
> 
> 
> 
> Guille
> 
> 
> --- In lpc2000@yahoogroups.com, Robert Adsett <subscriptions@a...> 
> wrote:
> >
> > My apologies if this shows up twice.  Every once in a while Yahoo 
> decides 
> > it couldn't send a piece of mail my way several days in the past 
> and shuts 
> > down delivery despite having sent mail successfully to the same 
> address 
> > since many times.
> > 
> > At 07:42 PM 1/25/06 -0500, Tom Walsh wrote:
> > >Guillermo Prandi wrote:
> > > >Hi. Are Flash write errors normal, i.e. a known issue? When
> > > >programming my LPC2138 using the isp21lpc utility, every now 
and 
> then
> > > >I get a write error; a second attempt always succeed. This 
> happens
> > > >roughly once every 100 programming attempts. I thought it 
could 
> have
> > > >been a problem with my serial cable or some other hardware 
> problem,
> > > >but now I added an IAP function to my test program and I am 
> getting
> > > >errors too (i.e., saved data differs from the source data, 
> although
> > > >the IAP copy ram to flash command returns CMD_SUCCESS). I 
checked
> > > >everything and I think I covered the normal requisites:
> > > >
> > > >
> > > >
> > >
> > >There seems to be something goofy going on with those utils.  I 
> tried
> > >using the lpc21isp (version 1.24) package on Linux, but it would
> > >sometimes error out at random locations.  Not sure why.
> > >
> > >I finally had to write an ISP loader for an LPC2138 to program an
> > >LPC2106.  This loader source I then took an hung some RS232 
> routines
> > >onto it so I could also up load into the LPC2138 from Linux.  So 
> far, my
> > >loader works flawlessly.
> > 
> > I had some similar occurrences with the Philips utility as well.  
> They seem 
> > to have disappeared about the time I started using the automatic 
> > downloading and a good cabling setup on the last few 
centimeters.  
> I've not 
> > had a similar problem with the lpc21isp program and I've not 
tried 
> > IAP.  Mind you the write errors I was seeing were not verify 
errors 
> but the 
> > protocol appearing to simply stop and it was rare enough that I 
> couldn't be 
> > certain as to its source.
> > 
> > A quick question to verify my understanding of what you are 
seeing 
> > Guillermo, is your verification source the same buffer you just 
> used to 
> > program via IAP or do you refresh it from elsewhere before you do 
> the compare?
> > 
> > Just a little more grist for the mill.
> > 
> > Robert
> > 
> > " 'Freedom' has no meaning of itself.  There are always 
> restrictions,   be 
> > they legal, genetic, or physical.  If you don't believe me, try 
to 
> chew a 
> > radio signal. "  -- Kelvin Throop, III
> > http://www.aeolusdevelopment.com/
> >
>

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.