I am using this (ADCuC7060) microcontroller first time.
I want to save some value in memory which should be intact whenever
goes off just like extenal memory(AT24C02 etc.).
How can I do in this controller.
You are correct, the key to write in FEEADR is 0xFFC3 for a mass erase command as shown in the code example.
The datasheet needs to be updated.
You may reserve two or more FLASH pages (512 byte each) for data storage and you can erase and program this from your application code via the Flash-Controller MMRs (FEECON i.e.). Depending on your requirements one or more blocks of information may fit into a 512 byte page and before you erase a page you program your next block of data into the next page.
Attached is some code example to demonstrate how to erase a page of the Flash and store parameters at the erased locations.
Please check this example ("Command Sequence for Executing a Mass Erase", ADuC7060 Data Sheet, Rev. C, page 26):
FEEDAT = 0x3CFF;FEEADR = 0x77C3;FEEMOD = FEEMOD|0x8; //Erase key enableFEECON = 0x06; //Mass erase command
FEEDAT = 0x3CFF;
FEEADR = 0x77C3;
FEEMOD = FEEMOD|0x8; //Erase key enable
FEECON = 0x06; //Mass erase command
0x77C3 −> 0xFFC3?
These four lines of code describe the sequence to perform a mass erase of the flash. See description of the mass erase command in table 15.
The value to write in the FEEADR register is not a valid Flash address that would be used for other commands such as a page erase or a write. This value (0x77C3) is a 32-key value for the mass erase command.
Similar sequence is required for setting permanent Flash protection, where the 32-key value to write to FEEADR is not a valid Flash address.
Thank you for your reply!
But please verify the value of this key, it must be 0xFFC3 instead of 0x77C3. I think, it's error in the datasheet. For example, Masserase function (flash.c.zip from second answer) uses 0xFFC3 constant.
The functions in the code example seem to have an unnecessary +0x80000 when writing to the 16 bit MMR FEEADR, that will be truncated. The flash address range will be 0x0000 to 0x77FF with no need to map to 0x80000 to 0x877FF as far as I can see.
You are correct, the 0x80000 offset is not necessary.
FEEADR contains the address used by the Flash controller. The Flash controller can only address the 32kB of Flash.
The fact that the Flash starts at address 0x80000 is irrelevant to the Flash controller.
Retrieving data ...