I am using KSDK2.0 and trying to write and read some data to the last sector of the PFlash (0x0007F000).
The relevant code looks something like:
#define BOOTFLASH_ADDRESS 0x7F000
static flash_config_t BOOTFLASH_flashDriver;
memset(&BOOTFLASH_flashDriver, 0, sizeof(flash_config_t));
result = FLASH_Init(&BOOTFLASH_flashDriver);
FLASH_Erase(&BOOTFLASH_flashDriver, BOOTFLASH_ADDRESS,0x1000, kFLASH_apiEraseKey);
FLASH_Program(&BOOTFLASH_flashDriver, BOOTFLASH_ADDRESS,(uint32_t *) BOOTFLASH_RamCopy, 0x140);
What happens is sometimes it writes correctly and I can read the contents just fine, other times it causes a reset in the middle of the "while (lengthInBytes > 0)" block in FLASH_Program.
I tried disabling interrupts during the execution of FLASH_Program and removing the watchdog, but the behaviour persists and is unpredictable. Does anyone have any suggestion on how to tackle this issue?