Using flash memory for non volatile variables

I want to write some variables to non-volatile flash. I am using a ADuC7022. The address is 0x80000 to flash memory. My hex file is 6450 bytes. The first 2k byes of flash is firmware. Can I just write near the end of flash memory so it will never get erased? Memcpy( &addr, &myVar). Were addr is 0x8FFA0. I assume the read from flash would be memcpy( &myVar, &addr). How do I set addr up in C++? Const unsigned integer addr=0x8FFA0?

  • 0
    •  Analog Employees 
    on Mar 11, 2013 9:30 AM

    One extra thing I would like to add to ADUzer's post is that you can use a pointer to read back the value after using the flash controller to write to it.

    #define          flashLocation                                    (*(volatile unsigned short int *) 0xYYYYYYYY)

    myVar = flashLocation;

  • I'd be surprised if the memcpy function supports writing to flash. You have to write via the flash controller. Look at the section "NONVOLATILE FLASH/EE MEMORY" in the manual for an explanation and to see how this is done. You'll most likely need to erase the page before writing to it. The top 2K of 64K is for the kernel and can't be accessed. There's also an errata saying you shouldn't access the top of the 62K.