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

Reading/Writing data to flash with IAP

I am using the LPC2300 (2378) board.

I need to permanently store a variety of settings so that they are available from startup to startup. These are stored in a struct. I have done the following for storing them:

  // prep sector 9 (0x00010000) for writing

  command[0] = 50;  // IAP Prepare Sectors for Write operation
  command[1] = 9;   // Controller variables stored in sector 9
  command[2] = 9;   // (end sector is same - only use 1 sector)
  iap_entry=(IAP) IAP_LOCATION;

  // copy ram to flash

  command[0] = 51;  // IAP Copy Ram to flash operation
  command[1] = 0x00010000;   //  address of sector 9
  command[2] = (unsigned long)&parms;   // parms location
  command[3] = sizeof(parms);
  command[4] = 12000;  // clock speed
  iap_entry=(IAP) IAP_LOCATION;

I am accessing the data with a simple memcpy

  memcpy(  (void *)&gParms, (void *)0x00010000, sizeof(gParms) );

When I do a write and then do the memcpy the data isn't being stored/retrieved correctly.

What am I missing/ doing wrong?

Any help is greatly appreciated.

Thanks

Dave

Parents
  • No. I take it I have to?

    Do I have to remove the interrupts or can i suspend them with something like this

      VICIntEnClr = 1 << IntNumber;   /* Disable Interrupt */
    

    Sorry if these seem a little basic. I am new to the whole microController thing and I am a little overwhelmed at this point.

Reply
  • No. I take it I have to?

    Do I have to remove the interrupts or can i suspend them with something like this

      VICIntEnClr = 1 << IntNumber;   /* Disable Interrupt */
    

    Sorry if these seem a little basic. I am new to the whole microController thing and I am a little overwhelmed at this point.

Children
  • If you look at chapter 27 in the lpc23xx user manual, you will notice paragraph 4.2.7 which says:

    The on-chip flash memory is not accessible during erase/write operations. When the user application code starts executing the interrupt vectors from the user flash area are active. The user should either disable interrupts, or ensure that user interrupt vectors are active in RAM and that the interrupt handlers reside in RAM, before making a flash erase/write IAP call. The IAP code does not use or disable interrupts.

    I recommend that you read through all of chapter 27.

  • OK I have read it - that's how I have gotten this far.

    I need to disable the interrupts or move the code to RAM. Since I can't find anything yet on how to move the code to RAM I am trying to go with the disabling. The only thing I can find for disabling the interrupts is VICIntEnClr. My understanding of this is that if I do the following I should disable the irqs

    unsigned long irqStatus;
    irqStatus = VICIntEnable;
    VICIntEnClr = irqStatus; // disable the active irqs
    
    // write data as I did above
    
    VICIntEnable = irqMask; /* reEnable Interrupt */
    
    

    Am I hopelessly lost?