uint32_t test = 123456; printf("prepare: %u\n", u32IAP_PrepareSectors(16, 16)); printf("written: %u\n", u32IAP_CopyRAMToFlash(0x00010000, (uint32_t) test, 256)); |
uint32_t u32IAP_PrepareSectors(uint32_t u32StartSector, uint32_t u32EndSector) { uint32_t u32Status; uint32_t au32Result[5]; uint32_t au32Command[5]; if (u32EndSector < u32StartSector) { u32Status = IAP_STA_INVALD_PARAM; } else { au32Command[0] = IAP_CMD_PREPARE_SECTORS; au32Command[1] = u32StartSector; au32Command[2] = u32EndSector; IAP_EXECUTE_CMD(au32Command, au32Result); u32Status = au32Result[0]; } return u32Status; } uint32_t u32IAP_CopyRAMToFlash(uint32_t u32DstAddr, uint32_t u32SrcAddr, uint32_t u32Len) { uint32_t au32Result[5]; uint32_t au32Command[5]; au32Command[0] = IAP_CMD_COPY_RAM_TO_FLASH; au32Command[1] = u32DstAddr; au32Command[2] = u32SrcAddr; au32Command[3] = u32Len; au32Command[4] = SystemCoreClock / 1000UL; /* Core clock frequency in kHz */ IAP_EXECUTE_CMD(au32Command, au32Result); return au32Result[0]; } |
printf("written: %u\n", u32IAP_CopyRAMToFlash(0x00010000, (uint32_t) &test, 256)); |
#ifdef __USE_CMSIS #include "LPC17xx.h" #endif #include <cr_section_macros.h> #include <NXP/crp.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; #include <stdio.h> #include "IAP/IAP.h" int main(void) { SystemCoreClockUpdate(); uint32_t test = 123456; __disable_irq(); printf("prepare: %u\n", u32IAP_PrepareSectors(16, 16)); // success printf("erase: %u\n", u32IAP_EraseSectors(16, 16)); // success printf("prepare: %u\n", u32IAP_PrepareSectors(16, 16)); // success printf("written: %u\n", u32IAP_CopyRAMToFlash(0x00010000, (uint32_t) &test, 256)); // "SRC_ADDR_NOT_MAPPED" __enable_irq(); while (1) { } return 0; } |
/* IAP Command Status Codes */ #define IAP_STA_CMD_SUCCESS 0 #define IAP_STA_INVALID_COMMAND 1 #define IAP_STA_SRC_ADDR_ERROR 2 #define IAP_STA_DST_ADDR_ERROR 3 #define IAP_STA_SRC_ADDR_NOT_MAPPED 4 #define IAP_STA_DST_ADDR_NOT_MAPPED 5 #define IAP_STA_COUNT_ERROR 6 #define IAP_STA_INVALID_SECTOR 7 #define IAP_STA_SECTOR_NOT_BLANK 8 #define IAP_STA_SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION 9 #define IAP_STA_COMPARE_ERROR 10 #define IAP_STA_BUSY 11 #define IAP_STA_INVALD_PARAM 12 /* Define the flash page size, this is the minimum amount of data can be written in one operation */ #define IAP_FLASH_PAGE_SIZE_BYTES 256 #define IAP_FLASH_PAGE_SIZE_WORDS (IAP_FLASH_PAGE_SIZE_BYTES >> 2) /* IAP Command Definitions */ #define IAP_CMD_PREPARE_SECTORS 50 #define IAP_CMD_COPY_RAM_TO_FLASH 51 #define IAP_CMD_ERASE_SECTORS 52 #define IAP_CMD_BLANK_CHECK_SECTORS 53 #define IAP_CMD_READ_PART_ID 54 #define IAP_CMD_READ_BOOT_ROM_VERSION 55 #define IAP_CMD_COMPARE 56 #define IAP_CMD_REINVOKE_ISP 57 #define IAP_CMD_READ_SERIAL_NUMBER 58 /* IAP boot ROM location and access function */ #define IAP_ROM_LOCATION 0x1FFF1FF1UL #define IAP_EXECUTE_CMD(a, b) ((void (*)())(IAP_ROM_LOCATION))(a, b) |