IAP sector erase problem in LPC17xx

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 18, 2016 by lpcware
Content originally posted in LPCWare by mostafanfs on Wed Apr 06 03:03:57 MST 2016
I've been working with IAP flash programming and I encountered a problem I couldn't figure out.
I'm using IAR on a LPC1778 board and I have written a function and I've placed it in the last sector which is sector #29 (out of sector #0 to sector #29) so it would be able to read new firmware from an external flash and write it to sectors #1 to #28 after erasing them. (sector #0 is not affected in the whole process)

Problem is when I erase sector #1 before copying RAM to Flash the program execution gets messed up and it just blows (I'm in IAR debugger with connected jlink performing step by step debugging) and therefore it does not return a Return Code and I'm not able to figure out the problem.

But if I determine sector #2 as the first sector to be erased it works just well and I can copy entire new firmware into flash starting from sector #2 .
But I want to begin with sector #1 .
Obviously it has something to do with the sector #1 when it comes to erasing sectors before copying to flash.

This is my icf (linker) file. I have edited some addresses :

/*###ICF### Section handled by ICF editor, don't touch! ****/
/*-Editor annotation file-*/
/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */
define symbol __ICFEDIT_intvec_start__ = 0x00001000;
define symbol __ICFEDIT_version_start__ = 0x00002000;
/*-Memory Regions-*/
define symbol __BOOTLOADER_START__ = 0x00078000;
define symbol __BOOTLOADER_END__ = 0x0007FFFF;
define symbol __ICFEDIT_region_UPDATE_IMAGE_ROM_start__ = 0x00001000;
define symbol __ICFEDIT_region_UPDATE_IMAGE_ROM_end__   = 0x00067FFF;
define symbol __ICFEDIT_region_RAM_start__ = 0x10000000;
define symbol __ICFEDIT_region_RAM_end__   = 0x1000FFFF;
define symbol __ICFEDIT_size_cstack__ = 0x800;
define symbol __ICFEDIT_size_heap__   = 0x5000;
/**** End of ICF editor section. ###ICF###*/

define symbol __RAM1_start__  = 0x20000000;
define symbol __RAM1_end__    = 0x20002FFF;
define symbol __RAM2_start__  = 0x20003000;
define symbol __RAM2_end__    = 0x20007FFF;

define memory mem with size = 4G;
define region BOOTLOADER_region   = mem:[from __BOOTLOADER_START__ to __BOOTLOADER_END__];
define region UPDATE_IMAGE_ROM_region   = mem:[from __ICFEDIT_region_UPDATE_IMAGE_ROM_start__ to __ICFEDIT_region_UPDATE_IMAGE_ROM_end__];
define region RAM_region   = mem:[from __ICFEDIT_region_RAM_start__   to __ICFEDIT_region_RAM_end__];
define region RAM1_region  = mem:[from __RAM1_start__ to __RAM1_end__];
define region RAM2_region  = mem:[from __RAM2_start__ to __RAM2_end__];

define block CSTACK    with alignment = 8, size = __ICFEDIT_size_cstack__   { };
define block HEAP      with alignment = 8, size = __ICFEDIT_size_heap__     { };

initialize by copy { readwrite };
do not initialize  { section .noinit };

place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec };
place at address mem:__ICFEDIT_version_start__  { section .rodata object version.o };
place in UPDATE_IMAGE_ROM_region   { readonly };
place in BOOTLOADER_region   { section BOOTLOADER_SECTOR };
place in RAM_region   { readwrite, block CSTACK };
place in RAM1_region  { section .sram, section PERRAM };
place in RAM2_region  { block HEAP };

Where does interrupt vectors are located?
Could it be the reason ? (of course I've disabled all interrupts before playing around with IAP)