AnsweredAssumed Answered

FLASH update using IAP and __RAMFUNC

Question asked by tim99 on Feb 25, 2017
Latest reply on Jul 24, 2017 by Juan Abelaira


I am trying to make a routine for updating my firmware without using ISP. So fare I am downloading my firmware to a free location in FLASH and I am now trying to copy this firmware to the first part of the FLASH memory. I am aware that to do this, the function copying the firmware cannot also be in the FLASH section being written to, so I am trying to place this function in RAM using __RAMFUNC. I have attached the code for my function below. However, I am experiencing that the execution is halted after executing the "Erase sectors" IAP command. So it seems to me that the code is not executed from RAM. Anyone have any idea of what I am doing wrong? (I am using LPC1549)

__RAMFUNC(RAM2) void flashing(uint8_t sectors)

     unsigned int command[5];                         // Command
     unsigned int result[4];                              // Result
     typedef void (*IAP)(unsigned int[], unsigned int[]);          // IAP Pointer
     IAP iap_Entry = (IAP) IAP_LOCATION;

     uint8_t ret_code,i;
     uint16_t ii;
     uint8_t data[1024];

     /* Disable interrupt mode */

     /* Prepare to write/erase the sector */
     command[0] = IAP_PREWRRITE_CMD;
     command[1] = 0;                                   // strSector
     command[2] = sectors;                                 // endSector
     iap_entry(command, result);

     /* Erase Sectors */
     command[0] = IAP_ERSSECTOR_CMD;
     command[1] = 0;                                   //strSector;
     command[2] = sectors;                                 //endSector;
     command[3] = SystemCoreClock / 1000;
     iap_entry(command, result);
        /* Copy 1024 bytes at a time. Sectors = number of sectors to copy */
          for(ii=0; ii<1024;ii++)
               /* First read date to RAM before writing to FLASH */
                        data[ii] = *(uint8_t*)(START_ADDR_SECTOR+i*1024+ii);
          /* Prepare sector for write */
          command[0] = IAP_PREWRRITE_CMD;
          command[1] = 0;                              // strSector
          command[2] = sectors;                         // endSector
          iap_entry(command, result);

          /* Write to FLASH */
          command[0] = IAP_WRISECTOR_CMD;
          command[1] = i*1024;
          command[2] = (uint32_t) &data;
          command[3] = 1024;
          command[4] = SystemCoreClock / 1000;
          iap_entry(command, result);
     NVIC_SystemReset();  //#TODO