IAP question

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

IAP question

1,546 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by killua on Tue Feb 28 16:48:45 MST 2012
Hi.

How do I know which address can I write when I am doing IAP (writing RAM to flash memory)? I am working on LPC 1343.

Thanks
0 Kudos
Reply
14 Replies

1,368 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Thom314 on Tue Aug 07 01:40:44 MST 2012
Hi Killua !

Can you please share the code that works ?

Thank you !

Thomas
0 Kudos
Reply

1,368 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by killua on Tue Mar 06 14:30:58 MST 2012
It's working... thanks for your help :)
0 Kudos
Reply

1,368 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by killua on Mon Mar 05 14:22:34 MST 2012
I reserved top 32 bytes but I getthis error:

undefined reference to `__irq_disable'

and for enable too...?

EDIT: I tried writing at lower sectors (1 and 2) and now I can print some random number...
0 Kudos
Reply

1,368 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by killua on Mon Mar 05 14:11:12 MST 2012

Quote: gbm
It must be a miracle then, as the code written, observing the rules I outlined works for me on LPC17xx and 11xx.
We cannot help you any better until we see the whole code. Also, you haven't confirmed the reservation of 32 bytes at the end of RAM.



Sorry, how do I do that?

You mean this : http://support.code-red-tech.com/CodeRedWiki/ReserveIAPRam
0 Kudos
Reply

1,368 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gbm on Mon Mar 05 13:30:00 MST 2012
It must be a miracle then, as the code written, observing the rules I outlined works for me on LPC17xx and 11xx.
We cannot help you any better until we see the whole code. Also, you haven't confirmed the reservation of 32 bytes at the end of RAM.
0 Kudos
Reply

1,368 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by killua on Mon Mar 05 12:59:46 MST 2012
No, it doesn't print anything. It looks like a code for writing/preparing/erasing is not working..???
0 Kudos
Reply

1,368 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gbm on Mon Mar 05 04:56:44 MST 2012
Actually LPC1343 has 8 sectors. Sector 6 starts at 0x6000, sector 7 at  0x7000
Make sure that 32 bytes are reserved at end of RAM and that interrupts are blocked during IAP calls - place the proper instructions around IAP calls in your routines (presumably __irq_disable(); and __irq_enable();)

How about:



#define FLASH_DATA_ADDR 0x7000

int test;
// prepare sector 7 for write/erase
// erase sector 7
// prepare sector 7 for write again, then:

u32IAP_CopyRAMToFlash(FLASH_DATA_ADDR,&timer1,256);

test = *((int *) FLASH_DATA_ADDR);
0 Kudos
Reply

1,368 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by killua on Mon Mar 05 01:54:20 MST 2012

Quote: gbm
1. How many Flash sectors are present in your device?
2. What is the definition of START_SECTOR?
3. How is "point" declared?



1. 7

2. #DEFINE START_SECTOR 0x00007000 //sector 6
#DEFINE END_SECTOR 0x00007FFF //sector 7

3.int *point;
point=START_SECTOR;
0 Kudos
Reply

1,368 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gbm on Mon Mar 05 01:51:46 MST 2012
1. How many Flash sectors are present in your device?
2. What is the definition of START_SECTOR?
3. How is "point" declared?
0 Kudos
Reply

1,368 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by killua on Sun Mar 04 16:59:22 MST 2012
After a few days of trying to get writing and reading to memory to work, I concluded I need help.

So these are the functions I am using for preparing and writing data to flash memory (I am using code I found in zip posted on this site called an11071.zip):

/*****************************************************************************
** Function name:u32IAP_PrepareSectors
**
** Description:Prepares sector(s) for erasing or write operations. This
** command must be executed before executing the "Copy RAM to
** Flash" or "Erase Sector(s)" commands.
**
** Parameters:u32StartSector - Number of first sector to prepare.
** u32EndSector - Number of last sector to prepare.
**
** Returned value:Status code returned by IAP ROM function.
**
******************************************************************************/
uint32_t u32IAP_PrepareSectors(uint32_t u32StartSector, uint32_t u32EndSector)
{
uint32_t u32Status;
uint32_t au32Result[5];
uint32_t au32Command[5];

if (u32EndSector < u32StartSector)
{
u32Status = IAP_STA_INVALD_PARAM;
}
else
{
au32Command[0] = IAP_CMD_PREPARE_SECTORS;
au32Command[1] = u32StartSector;
au32Command[2] = u32EndSector;

IAP_EXECUTE_CMD(au32Command, au32Result);

u32Status = au32Result[0];
}
return u32Status;
}

/*****************************************************************************
** Function name:u32IAP_CopyRAMToFlash
**
** Description:Program the flash memory with data stored in RAM.
**
** Parameters:   u32DstAddr - Destination Flash address, should be a 256
**                               byte boundary.
** u32SrcAddr - Source RAM address, should be a word boundary
** u32Len     - Number of 8-bit bytes to write, must be 256
** 512, 1024, or 4096.
*
** Returned value:Status code returned by IAP ROM function.
**
******************************************************************************/
uint32_t u32IAP_CopyRAMToFlash(uint32_t u32DstAddr, uint32_t u32SrcAddr, uint32_t u32Len)
{
uint32_t au32Result[5];
uint32_t au32Command[5];

au32Command[0] = IAP_CMD_COPY_RAM_TO_FLASH;
au32Command[1] = u32DstAddr;
au32Command[2] = u32SrcAddr;
au32Command[3] = u32Len;
au32Command[4] = SystemFrequency / 1000UL;/* Core clock frequency in kHz */

IAP_EXECUTE_CMD(au32Command, au32Result);

return au32Result[0];
}



Ok, and here is a part of my main program I am using to write data:

if(u32IAP_PrepareSectors(6,7)==IAP_STA_CMD_SUCCESS)
LCDPutStr("Prepared", 17, 30, 2, COLOR_FORE , COLOR_BACKROUND);
else
LCDPutStr("PrepFail", 17, 30, 2, COLOR_FORE , COLOR_BACKROUND);
Delay(260);
LCDSetRect(16, 40, 80, 92, 1, COLOR_BACKROUND);
if(u32IAP_CopyRAMToFlash(START_SECTOR,&timer1,256)==IAP_STA_CMD_SUCCESS)
LCDPutStr("Written", 17, 30, 2, COLOR_FORE , COLOR_BACKROUND);
else
LCDPutStr("WriteFail", 17, 30, 2, COLOR_FORE , COLOR_BACKROUND);


The program tells me the sectors are prepared and that I have written succesfully in them.

So here is the last part of my program, where I am trying to read written data (at the start of the program I defined "int *point"):

point=START_SECTOR;
get_timer[0]=*point;

and when I try to write get_timer[0] it doesnt print anything???? Why??? (note that the code for printing works just fine)

Thanks
0 Kudos
Reply

1,368 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gbm on Wed Feb 29 13:46:28 MST 2012
Not "randomly", contiguous area starting from 0 unless you were fiddling with linker control files.

Look at the section of .map file reporting memory usage - check the last address of ROM used.
0 Kudos
Reply

1,368 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by killua on Wed Feb 29 13:39:46 MST 2012

Quote: gbm
Check the size of your ROM image - it is reported by the linker (the last build step). In LPC134x Flash is divided into 4 KiB blocks (sectors). If there is at least one whole free block left in the uC Flash - you may use it for your nonvolatile data storage.



My ROM image is 18 kB, but if I understand this correctly it doesn't mean that only first 18kB of 32 kb of flash memory is filled, but that is filled "randomly".


Quote: yanvasilij
Look in .map file which sector is free



My .map file is HUGE... is there any easier way to look for filled and free part of my flash memory or am I supposed to do it manualy (that will take a while)...

Is there any way that I can tell my builder to not fill the last 4 kB of memory?

Thanks
0 Kudos
Reply

1,368 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by yanvasilij on Wed Feb 29 05:26:50 MST 2012
Look in .map file which sector is free
0 Kudos
Reply

1,368 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gbm on Wed Feb 29 03:24:15 MST 2012
Check the size of your ROM image - it is reported by the linker (the last build step). In LPC134x Flash is divided into 4 KiB blocks (sectors). If there is at least one whole free block left in the uC Flash - you may use it for your nonvolatile data storage.
0 Kudos
Reply