Copy RAM to FLASH in order to save an array

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

Copy RAM to FLASH in order to save an array

1,449件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Lamborghini on Tue May 10 08:42:40 MST 2011
Hi everybody,
I'm using a LPC1114 and I would like to wite an [COLOR=Green]uint32_t [/COLOR][COLOR=Green]flash_memory[64] [/COLOR]  ( 256 bytes in size ) to flash memory (equal to the minimun block size),
using it as eeprom, because i need to save some calibration values and then read this array elements anytime i initialize the microcontroller after power on.

I searched for info about the IAP code sequence to use for writing
and consequently code sequence for reading  flash,
but at the moment  i don't have a clear idea how to procede.

Anyone have some code suggestion?

Thanks
0 件の賞賛
返信
5 返答(返信)

1,308件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by robin48gx on Fri Nov 29 08:07:30 MST 2013
#define COMM_BK_MAX_BUFFER_SIZE 512
volatile  unsigned char  *COMMBKBuffer = 0x78000;                /* Buffer used by application : copied from lpcxx_pinsel.c 28NOV2013  */

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);
}



This code give the following from its printfs':

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
.

What am I doing wrong. ec 9 appears to be a PARAM_ERROR but I cannot see what I have done wrong.

0 件の賞賛
返信

1,308件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcxpresso-support on Fri Oct 11 06:05:07 MST 2013
That link is from the old LPCXpresso forum, which has now migrated to LPCware. Unfortunately, although the content from the old forum is now available here, links to the old address no longer work.

However if you use the "Search the forums" box (top right of the main forum page) for 'IAP' or "data in flash" you will find lots of previous threads (including answers and weblinks) on this subject.

For example:
http://www.lpcware.com/content/forum/lpc11u14-flash-data-storage

Regards,
LPCXpresso Support
0 件の賞賛
返信

1,308件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by AmitTank on Fri Oct 11 04:55:18 MST 2013
hey, can u please send the link again ....
Dat previous one is not working  ...

I am also looking for the similar issue ... to save test data from ram to flash ....
Can you help me out ??

You have working code ??
0 件の賞賛
返信

1,308件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Lamborghini on Wed May 11 07:46:45 MST 2011

Quote:
TheFallGuy                       See: http://knowledgebase.nxp.com/showthread.php?t=160

Thank you TheFallGuy.
I studied the link you posted and adapted the code to be more readable for me and my collegues.
It seems to work properly so now I'm able to store my calibration values :)
0 件の賞賛
返信

1,308件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheFallGuy on Tue May 10 10:00:07 MST 2011
See: http://knowledgebase.nxp.com/showthread.php?t=160
0 件の賞賛
返信