lpcware

Copy RAM to flash

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by robin48gx on Fri Nov 29 08:35:49 MST 2013

I have to following code to copy a RAM structure to flash.
It fails with error code == 9.

Here are the printf's this code produces:

Quote:

serial_eeprom::init_comm_backup() called
serial_eeprom::write_comm_bk entered with CRP 0x320f24c 52490828
serial_eeprom::write_comm_bk Write failed at RAM 0x10005E30 FLASHROM 0x00078000 ec 9
serial_eeprom::read_Comm Backup Read Complete
verify_count 0
Display status : 41



What am I doing wrong?



#define COMM_BK_MAX_BUFFER_SIZE 512
volatile  unsigned char  *COMMBKBuffer = 0x78000;                /* Buffer used by application : copied from lpcxx_pinsel.c 28NOV2013  */
//__CRP const unsigned int CRP_WORD = CRP_NO_CRP ;
void
write_comm_bk()
{


int start_address = (uint32_t) & comm_backup;
int received_data = 0;
int more_data=1,ec;
int crp_mode;
static int * crp_modep = 0x000002FC;

crp_mode = *crp_modep;

printf("serial_eeprom::write_comm_bk entered with CRP 0x%x %d\n", crp_mode, crp_mode);
if(u32IAP_PrepareSectors(29, 29) != IAP_STA_CMD_SUCCESS) {// 64k for fonts, at top of flash memory
printf("serial_eeprom::write_comm_bk Failed to prepare flash for erase\n");
return;
}

if (u32IAP_EraseSectors(29,29) != IAP_STA_CMD_SUCCESS) {
printf("serial_eeprom::write_comm_bk Failed to Erase flash.\n");
return;
}


    do {
         // uint32_t u32IAP_CopyRAMToFlash(uint32_t u32DstAddr, uint32_t u32SrcAddr, uint32_t u32Len)
if((ec=u32IAP_CopyRAMToFlash( (uint32_t)COMMBKBuffer+ received_data, start_address + received_data, COMM_BK_MAX_BUFFER_SIZE)) == IAP_STA_CMD_SUCCESS){
   printf("serial_eeprom::write_comm_bk Writing at %X\n",
   start_address + received_data);
   /*Verify the flash contents with the contents in RAM */
   if(u32IAP_Compare(start_address + received_data, (uint32_t)COMMBKBuffer+ received_data, COMM_BK_MAX_BUFFER_SIZE, 0) == IAP_STA_CMD_SUCCESS){
   printf("serial_eeprom::write_comm_bk Verify at %X OK\n",
   start_address + received_data);
   }
   else {
printf("serial_eeprom::write_comm_bk Verify failed at %X ec %d\n",
start_address + received_data,ec);
return;
   }
}
else {
printf("serial_eeprom::write_comm_bk Write failed at RAM 0x%8.8X FLASHROM 0x%8.8X ec %d\n",
start_address + received_data, COMMBKBuffer+ received_data,ec);
return;
}
received_data += COMM_BK_MAX_BUFFER_SIZE;

            if ( received_data >= sizeof(comm_backup) )
           more_data = 0;
            else
           more_data = 1;

} while (more_data);

//f_close(&fdr);
printf("serial_eeprom::write_comm_bk Complete reveived data is %d\n", received_data);
}



Outcomes