Copy RAM to flash

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Copy RAM to flash

1,454件の閲覧回数
lpcware
NXP Employee
NXP Employee
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);
}



ラベル(1)
0 件の賞賛
返信
2 返答(返信)

1,326件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by robin48gx on Mon Dec 02 08:41:58 MST 2013
Thanks very much that precisely what the problem was!
:D
0 件の賞賛
返信

1,326件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by cfbsoftware on Fri Nov 29 18:52:03 MST 2013
Error 9 is 'sector not prepared'. You need to call PrepareSectors before CopyRAMToFlash as well as before EraseSectors. From the User Manual:

Quote:
This command must be executed before executing "Copy RAM to Flash" or
"Erase Sector(s)" command. Successful execution of the "Copy RAM to Flash" or
"Erase Sector(s)" command causes relevant sectors to be protected again.

0 件の賞賛
返信