On the ADuC7060 - How do I write data to the flash?

I am having trouble writing to the User flash space on the ADuC7060.

Any hints on how to write to flash location 0x87400?

Also, I want to reliably read this location after I have written to it - how do I do this?

  • 0
    •  Analog Employees 
    on Dec 2, 2010 5:28 PM

    Appended is a very simple piece of code that works.

    I call the write to flash from the external interrupt handler.

    I read the flash memory location in the while loop.

    For a flash read, there is no need to use the flash controller registers (FEECON) – just setup a pointer to the memory location and read it directly.

    Using this code, flash address 0x87400 will contain 0xFFFF55A1 after the external interupt 0 is asserted.

    #define uiMemAddress  (*(volatile unsigned long      *) 0x87400)

    #include<aduc7060.h>

    int main(void)

    {

                    POWKEY1 = 0x1;

                    POWCON0 = 0x78;                              // Set core to max CPU speed of 10.24Mhz

                    POWKEY2 = 0xF4;

                    uiTest = 0x55A1;

                    IRQCONE = BIT1;                                              // Rising edge

                    IRQEN = BIT4 + BIT13;                                     // Enable Timer 1 IRQ

                    while(1)

                    {

                       uiTest2 =  uiMemAddress;

                    }

    }

    void IRQ_Handler(void) __irq

    {

       unsigned long IRQSTATUS = 0;

        IRQSTATUS = IRQSTA;                   // Read off IRQSTA register

                    if ((IRQSTATUS & BIT13) == BIT13)            //External Interrupt0 source

                    {

                                    IRQCLRE = BIT13;                                                 // Clear External Interrupt 0

                                    FEEMOD = FEEMOD|0x8; // Disable protection : enable the erase and write commands.

                                    FEEADR = 0x7400 ;

                                    FEEDAT = uiTest ;

                                    FEECON = 0x03 ; // erase page + write

                    }

    }

  • for example: i have 3 data cells in program memory (const int data[3] = {1,2,3})

    question:

    how to overwrite the date[1] without changing the date[0] and date[2]?

    if i call func (with adr = 1, data = 2):

    flash_write(data,adr){

         FEEADR = (uint16_t)(&data[adr]); (or (uint16_t)((&data[1]) & (0xFFFF))

         FEEDAT = data;

         FEEMOD |= 0x08;

         FEECON = 0x03;

    }

    ceases to operate the program

    documentation on ADuC7060 says erasing the page.
    and the page size is 512 bytes.
    ie at FEECON = 3 ->

    1) 512 bytes is erased indexed by FEEADR

    2) written 16bit data from FEEDAT.

  • 0
    •  Analog Employees 
    on Mar 18, 2011 9:31 AM

    Hi dezna,

    this is not possible, it is not EEPROM, it is Flash.

    Others use this so that they have at the start of the page some index pointers If the index is not 0, that it points to the next valid data block.

    For each change of the data-block they use the next block in memory and write 0 to the current index and the address of the actual valid data-block into the next index location. Usually they use 2 512-Byte-Blocks and if the first is full they start the next and erase the first one and  so on....

  • Hello, MikeL.

    I would like to recomend you to check FLASH/EE controller busy bit to ensure that previous operation finished. Command status bits are helpful too.

    If your interrupt occurs with period less than ~24ms command  will be fail.