#ifdef __USE_CMSIS #include "LPC13Uxx.h" #endif #include <cr_section_macros.h> #include <NXP/crp.h> #include "IAP.h" #include <stdio.h> // Variable to store CRP value in. Will be placed automatically // by the linker when "Enable Code Read Protect" selected. // See crp.h header for more information __CRP const unsigned int CRP_WORD = CRP_NO_CRP ; /* Flash offset where the configuration is stored */ #define CONFIG_FLASH_OFFSET 0x1000 #define CONFIG_FLASH_SECTOR (CONFIG_FLASH_OFFSET >> 12) #define CONFIG_FLASH_SECTOR_SIZE 1 // TODO: insert other definitions and declarations here static uint8_t demo_messg[] = "IAP flash data"; static uint8_t demo_messg2[64]; void writeDATA(void); void readDATA(void); int main(void) { writeDATA(); readDATA(); volatile int i = 0; while(1) { i++; } } void readDATA(void) { } void writeDATA(void) { __e_iap_status iap_status; /* Prepare the sector for erase */ iap_status = (__e_iap_status) u32IAP_PrepareSectors(CONFIG_FLASH_SECTOR, (CONFIG_FLASH_SECTOR + CONFIG_FLASH_SECTOR_SIZE)); if (iap_status != CMD_SUCCESS) while(1); /* Erase the sector */ iap_status = (__e_iap_status) u32IAP_EraseSectors(CONFIG_FLASH_SECTOR, (CONFIG_FLASH_SECTOR + CONFIG_FLASH_SECTOR_SIZE)); if (iap_status != CMD_SUCCESS) while(1); /* Prepare the sector for writing */ iap_status = (__e_iap_status) u32IAP_PrepareSectors(CONFIG_FLASH_SECTOR, (CONFIG_FLASH_SECTOR + CONFIG_FLASH_SECTOR_SIZE)); if (iap_status != CMD_SUCCESS) while(1); /* write data to flash */ iap_status = (__e_iap_status) u32IAP_CopyRAMToFlash(&demo_messg, (void *)CONFIG_FLASH_OFFSET, 256); if (iap_status != CMD_SUCCESS) while(1); } |