Hey Carlos,
I have tried erasing only sector0, and all for flash, as well as portions of flash. I verify the IAP command return after every command to ensure CMD_SUCCESS.
Here is a detailed breakdown of my current programming algorithm:
*Initialization
Power Chip
Reset Low
Wait 300uS
Reset High
Wait 300uS
Reset TAP
Read IDCODE DP
Request Power CTRLSTAT
Verify Power CTRLSTAT
Read AP IDR starting with AP 0 untill I find AHB_AP(MEM_AP) (Is normally AP0 and is on LPC1754)
Write CSW 0x23000042 (No INC, 32BIT)
Write TAR CCLKCFG_Addr (0x400FC10C)
Write DRW 0x3 (sets clock divider to 3+1 of 4MHz resulting in 1MHz core clock)
Write TAR CCLKCFG_Addr (0x400FC104)
Write DRW 0x0 (Just to ensure we are using default (PLL0)
---From here I will just say write to address, with writes to TAR, DRW, and CSW for auto INC being implied---
***Erase Chip
*Move Vector Table
Write DHCSR 0xA05F0003 (to stop core)
Verify DHCSR (core stopped)
Copy data from 0x0-0x1F to 0x10000200
Write VOTR to 0x10000200
*Prepare Sectors
Write 0xFFFFFFFF to 0x10000380
Write 50 to 0x10000300 (IAP prepare sector)
Write 0x0 to 0x10000304 (Start Sector Number)
Write 0x11 to 0x10000308 (End Sector Number)
Write 0x10000300 to r0 (Done through DCRDR)
Write 0x10000380 to r1 (Done through DCRDR)
Write 0x1FFF1FF0 to PC (Done through DCRDR)
Write DHCSR 0xA05F0001 (to start core)
Verify 0x0 at 0x10000380
Write DHCSR 0xA05F0003 (to stop core)
*Erase Sectors
Write 0xFFFFFFFF to 0x10000380
Write 52 to 0x10000300 (IAP erase sectors)
Write 0x0 to 0x10000304 (Start Sector Number)
Write 0x11 to 0x10000308 (End Sector Number)
Write 1000 (0x3EB) to 0x1000030C (Core Clock FREQ)
Write 0x10000300 to r0 (Done through DCRDR)
Write 0x10000380 to r1 (Done through DCRDR)
Write 0x1FFF1FF0 to PC (Done through DCRDR)
Write DHCSR 0xA05F0001 (to start core)
Verify 0x0 at 0x10000380
Write DHCSR 0xA05F0003 (to stop core)
--When I read data at this point from 0x0-0x1FF it has not been erased. Data at 0x200-end of flash is erased--
*Reset
Write 0x05FA0004 to ARICR_Addr (0xE000ED0C) (Request reset)
Wait 1000uS
Write 0x05FA0000 to ARICR_Addr (0xE000ED0C) (Unrequest reset)
Write VOTR to 0x10000200
***Write Page (Values used are for sector0 sectors are incremented for sector being written to)
*Write Ram Stack
Write DHCSR 0xA05F0001 (to start core)
Write data to be programmed into RAM starting at 0x10000400
Write DHCSR 0xA05F0003 (to stop core)
*Prepare Sector
Write 0xFFFFFFFF to 0x10000380
Write 50 to 0x10000300 (IAP prepare sector)
Write 0x0 to 0x10000304 (Start Sector Number)
Write 0x11 to 0x10000308 (End Sector Number)
Write 0x10000300 to r0 (Done through DCRDR)
Write 0x10000380 to r1 (Done through DCRDR)
Write 0x1FFF1FF0 to PC (Done through DCRDR)
Write DHCSR 0xA05F0001 (to start core)
Verify 0x0 at 0x10000380
Write DHCSR 0xA05F0003 (to stop core)
*Copy RAM to Flash
Write 0xFFFFFFFF to 0x10000380
Write 51 to 0x10000300 (IAP copy RAM to Flash)
Write 0x0 to 0x10000304 (Addr of Target Location)
Write 0x10000400 to 0x10000308 (Addr of RAMStack)
Write 256 to 0x10000308 (Bytes to write)
Write 1000 (0x3EB) to 0x10000310 (Core Clock FREQ)
Write 0x10000300 to r0 (Done through DCRDR)
Write 0x10000380 to r1 (Done through DCRDR)
Write 0x1FFF1FF0 to PC (Done through DCRDR)
Write DHCSR 0xA05F0001 (to start core)
Verify 0x0 at 0x10000380
Write DHCSR 0xA05F0003 (to stop core)
--When I read data at this point from 0x0-0x1FF it has been partially programmed. Some areas have correct data but many do not. Most words have at least one bit error, some have several. Data at 0x200-end of flash is programmed correctly and has no errors--
Thanks for your assistance.
Best Regards,
Peter