// IAP Calls typedef void (*IAP) (uint32_t [],uint32_t []); #define IAP_LOCATION0x1fff1ff1 // IAP Commands #define PREPARE_SECTORS50 #define COPY_RAM_TO_FLASH51 #define ERASE_SECTORS52 #define BLANK_CHECK_SECTORS53 #define COMPARE56 #define READ_UID58 #define ERASE_PAGE59 uint32_t retVal0, retVal1, retVal2, retVal3, retVal4, retVal5; int32_t i; // TEST __disable_irq(); // since Flash is unavailable during operations, disable ALL IRQs to avoid crashing retVal0 = prepareSectors(8, 8); retVal1 = erasePages(128, 128); // addr 0x8000 __enable_irq(); for (i = 0; i < 256 / 4; i++) { buf0.chunk = 0xaaFFFF55; } for (i = 256 / 4; i < 512 / 4; i++) { buf0.chunk = 0xFFaaFFFF; } for (i = 0; i < 1; i++) { __disable_irq(); // since Flash is unavailable during operations, disable ALL IRQs to avoid crashing retVal2 = prepareSectors(8, 8); retVal3 = writePages(0x8000, (uint32_t) &buf0.chunk, 256); retVal4 = prepareSectors(8, 8); retVal5 = writePages(0x8000, (uint32_t) &buf0.chunk[256/4], 256); __enable_irq(); } // Prepares sectors for write/erase. // Will prepare both start and end sectors. They should both be the same to prepare a single sector uint32_t prepareSectors(int32_t startSector, int32_t endSector) { command[0] = PREPARE_SECTORS; command[1] = startSector; command[2] = endSector; iapEntry(command, result); return result[0]; } // Erases a page or multiple pages in the flash memory. // Use the same start and end page to erase only one page. uint32_t erasePages(int32_t startPage, int32_t endPage) { command[0] = ERASE_PAGE; command[1] = startPage; command[2] = endPage; command[3] = PLL_FREQ * 1000; // clock in kHz iapEntry(command, result); return result[0]; } // Programs the flash memory. Sectors must be prepares first, then erased (set to 0xFF) before being able to be programmed. // The boot sector can not be written by this command. // flashDestinationAddr: Destination flash address where data bytes are to be written. This address should be a 256 byte boundary. // ramSourceAddr: Source RAM address from which data bytes are to be read. This address should be a word boundary. // size: Number of bytes to be written. Should be 256 | 512 | 1024 | 4096. uint32_t writePages(uint32_t flashDestinationAddr, uint32_t ramSourceAddr, uint32_t size) { command[0] = COPY_RAM_TO_FLASH; command[1] = flashDestinationAddr; command[2] = ramSourceAddr; command[3] = size; command[4] = PLL_FREQ * 1000; // clock in kHz iapEntry(command, result); return result[0]; } |
It seems like I am facing the same issue, with an LPC11C24.
If I understand 'LPC WARE' correctly, an sector erase should always be executed prior to writing to flash.
However in the UM10398 (26.5.7) point 3 states that an erase should be executed after 16 writes.
This is kind of confusing, now it this seems like it is contradicting one-another.
Can someone please explain the correct procedure on how to write to flash?
Kind regards,
Harrie