This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Copy function in RAM

Hi!

I hope that you still fine.

I use the LPC2138,and i know that all functions which i write stay in ROM.
Now i triying to copy one of these functions to the RAM,but i don't find the solution.
I have triying with memcpy,but unsuccessfully.
Can anyone help me?

Thanks
Best regard

Parents
  • Hallo every body!

    Can somebody tell me whether i need the RAM address of the function for IAP programming in this example?
    And the definition of the function from sector number
    i don't realy understand that.Can you try to explain to me?.

     unsigned int get_secnum (unsigned int addr)  {
      unsigned int n;
    
      n = ((unsigned int) addr >> 13) & 0x1F;        // pseudo sector number
    
      if (n >= (0x30000 >> 13))  {
        n -= 14;                                    // high small 8kB Sectors (
      }
      else if (n >= (0x10000 >> 13))  {
        n  = 7 + (n >> 3);                          // large 64kB Sectors
      }
      return (n);                                   // sector number
    }
    
     unsigned int program (unsigned int flash_addr, unsigned char *data, unsigned int size)  {
      struct iap_in  iap;                      // IAP input parameters
      unsigned int result[16];                 // IAP results
      unsigned int save_VicInt;                // for saving of interrupt enable register
    
      save_VicInt = VICIntEnable;              // save interrupt enable status
      VICIntEnClr = 0xFFFFFFFF;                // disable all interrupts
    
    #ifdef BYPASS_IAP
      stop_pll();                              // IAP requires to run without PLL
    #endif
    
      iap.cmd = 50;                            // IAP Command: Prepare Sectors for Write
      iap.par[0] = get_secnum (flash_addr);    // start sector
      iap.par[1] = iap.par[0];                 // end Sektor
      iap_entry (&iap, result);                // call IAP function
      if (result[0])  goto exit;               // an error occured?
    
      iap.cmd = 51;                            // IAP Command: Copy RAM to Flash
      iap.par[0] = (unsigned int) flash_addr;  // destination-addr
      iap.par[1] = (unsigned int) data;        // source-addr
      iap.par[2] = size;                       // number of bytes
      iap.par[3] = 12000;                       // CPU clock  in kHZ
      iap_entry (&iap, result);                // call IAP function
    
    exit:
    
    

    char var[512];

     int main(void){
       erase   (0x30000, 0x31FFF);
     program (0x30000, var, sizeof (var)); }
    

    please i realy need your Help.

    tanks.

Reply
  • Hallo every body!

    Can somebody tell me whether i need the RAM address of the function for IAP programming in this example?
    And the definition of the function from sector number
    i don't realy understand that.Can you try to explain to me?.

     unsigned int get_secnum (unsigned int addr)  {
      unsigned int n;
    
      n = ((unsigned int) addr >> 13) & 0x1F;        // pseudo sector number
    
      if (n >= (0x30000 >> 13))  {
        n -= 14;                                    // high small 8kB Sectors (
      }
      else if (n >= (0x10000 >> 13))  {
        n  = 7 + (n >> 3);                          // large 64kB Sectors
      }
      return (n);                                   // sector number
    }
    
     unsigned int program (unsigned int flash_addr, unsigned char *data, unsigned int size)  {
      struct iap_in  iap;                      // IAP input parameters
      unsigned int result[16];                 // IAP results
      unsigned int save_VicInt;                // for saving of interrupt enable register
    
      save_VicInt = VICIntEnable;              // save interrupt enable status
      VICIntEnClr = 0xFFFFFFFF;                // disable all interrupts
    
    #ifdef BYPASS_IAP
      stop_pll();                              // IAP requires to run without PLL
    #endif
    
      iap.cmd = 50;                            // IAP Command: Prepare Sectors for Write
      iap.par[0] = get_secnum (flash_addr);    // start sector
      iap.par[1] = iap.par[0];                 // end Sektor
      iap_entry (&iap, result);                // call IAP function
      if (result[0])  goto exit;               // an error occured?
    
      iap.cmd = 51;                            // IAP Command: Copy RAM to Flash
      iap.par[0] = (unsigned int) flash_addr;  // destination-addr
      iap.par[1] = (unsigned int) data;        // source-addr
      iap.par[2] = size;                       // number of bytes
      iap.par[3] = 12000;                       // CPU clock  in kHZ
      iap_entry (&iap, result);                // call IAP function
    
    exit:
    
    

    char var[512];

     int main(void){
       erase   (0x30000, 0x31FFF);
     program (0x30000, var, sizeof (var)); }
    

    please i realy need your Help.

    tanks.

Children
  • Somebody tall me that it is not possible to use IAP programming with the evalution version of the RealView.Is that true?

    Best regards

  • Theirs should not be any problem in using IAP function in evaluation version.
    You dont need to copy any code to RAM for IAP.

    Just be sure your IAP execute routine is their.
    If its in assembly normally it will hve .

    Store your present registers along with return address.

    a call to location (0x7FFFFFF1). This will give a call in thumb mode.*** This is a branch to the IAP function.

    Relaoad values of registers from stack Return to mail program.

    Also be sure your buffer (RAM) is word alligned.

    Suvidh