lpcware

IAP write - weird problem?

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by jb111 on Tue Aug 04 23:29:17 MST 2015
Hi,

I am writing a bootloader for the LPC11A13. Ive followed the example code given in the AN10995 documentation. So far it has been working.
[color=#f00][/color]
However during my testing i came across a weird occurrence....

Once an application has been written to flash I do a CRC over the whole application and write this CRC to the last address in the allocated app area (just like the example code). As stated this has worked fine, until I made my application code take up the entire available space (i.e. My whole allocated app area minus the last address which is saved for the CRC).

When the app takes up its full space the CRC write corrupts another memory cell, and the CRC is written just fine.

The IAP call to copy ram to flash returns successful. The IAP call to compare buffers fails.

Another oddity is that if i only copy the second half of my application (i.e. from the middle to the end, to the correct addresses) this issue doesn't arise.




Here is a copy of the memory at the offending location:
        
Before IAP write:
0x00004FF0    -------------   FFFFFEF4  02DC6C00  FFFFFFFF  FFFFFFFF         
After IAP write:
0x00004FF0    -------------   FF[color=#f00]D[/color]FFEF4  02DC6C00  FFFFFFFF  00008054         
     
As you can see the last location the CRC has been writen (correctly), but the cell at 0x4FF0 has also changed.

Here is the function that writes the CRC. As stated it works exceot in this specific case:


uint32_t BOOT_WriteCRC2(uint16_t u16CRC){

uint32_t i;
uint32_t u32Result = 0;
uint32_t a32DummyData[BOOT_IAP_FLASH_PAGE_SIZE_WORDS];
uint32_t *pu32Mem = (uint32_t *)(BOOT_APP_END_ADDR  -      BOOT_IAP_FLASH_PAGE_SIZE_BYTES);



for (i = 0 ; i < BOOT_IAP_FLASH_PAGE_SIZE_WORDS; i++)
{
a32DummyData = *pu32Mem++;
}

a32DummyData[BOOT_IAP_FLASH_PAGE_SIZE_WORDS - 1] = (uint32_t)u16CRC;

int return_val = 0;
BOOT_iap_PrepareSectors(BOOT_APP_END_SECTOR, BOOT_APP_END_SECTOR);
BOOT_iap_CopyRAMToFlash((BOOT_APP_END_ADDR - BOOT_IAP_FLASH_PAGE_SIZE_BYTES), (uint32_t)a32DummyData, 256);
return_val = BOOT_iap_Compare((BOOT_APP_END_ADDR - BOOT_IAP_FLASH_PAGE_SIZE_BYTES), (uint32_t)a32DummyData, 256, 0);
return (return_val);


}

I hope my issue is clear.
I will continue to investigate.
Thanks in advanced.


Outcomes