41 #include "lpc17xx_iap.h"
45 #ifndef FLASH_PROG_AREA_START
46 #define FLASH_PROG_AREA_START 0x0000
50 #define BUFF_SIZE ((int)IAP_WRITE_1024)
54 #ifndef INTERNAL_SRAM_BUFF_ADRESS
55 #define INTERNAL_SRAM_BUFF_ADRESS (LPC_RAM_BASE+0x8000-BUFF_SIZE)
59 #define NO_ALIGNED_ACCES -10001
65 #define sbuffer ((const void *) INTERNAL_SRAM_BUFF_ADRESS)
71 uint32_t flash_prog_area_prev_sect,flash_prog_area_curr_sect =-1;
74 if (error != 0)
return error;
76 error = ReadBootCodeVer(&error, &br);
77 if(error != CMD_SUCCESS)
return error;
81 flash_prog_area_prev_sect = flash_prog_area_curr_sect;
85 flash_prog_area_curr_sect = GetSecNum (free_area_adress - 1) + 1;
87 free_area_adress = GetSecAddr(flash_prog_area_curr_sect);
88 if (flash_prog_area_prev_sect != flash_prog_area_curr_sect ) {
89 error = EraseSector(flash_prog_area_curr_sect,flash_prog_area_curr_sect);
90 if (error != CMD_SUCCESS)
break;
91 error = BlankCheckSector(flash_prog_area_curr_sect,
92 flash_prog_area_curr_sect,
NULL,
NULL);
93 if(error != CMD_SUCCESS)
break;
95 error = CopyRAM2Flash((
void *)dest_adress,
sbuffer,IAP_WRITE_1024);
96 if (error != CMD_SUCCESS)
break;
97 error = Compare((
void *)dest_adress,
sbuffer,IAP_WRITE_1024);
99 if (error != CMD_SUCCESS)
break;
102 if (error || br == 0)
break;
115 if (error != 0)
return error;