Working with mc56f84xxx
Theory Introduction
So, to start with the theory. You should at least roughly understand this to work with these memory controllers. This does not concern the usual ProgrammFlash (P_Flash) - here everything works as usual.
The 56F844x/5x/7x controllers have what is called EEE (Enhanced EEPROM) or, in Russian, an EEPROM emulator in flash memory, implemented with an interesting wear leveling mechanism.
Apparently, the solution from Motorola engineers has migrated to Freescale-NXP (the same solution is found in MKE and others).
It works as follows: There are two physical memory segments: FlexNVM (Data Flash or D-Flash) - special flash memory and FlexRAM (special RAM).
There are three purposes for the memory:
- D-Flash - data memory, not EEPROM. Just constants in flash memory.
- EEE - EEPROM emulation, a mirror of EEPROM in FlexRAM.
- EEPROM_backup - a compressed backup of EEPROM, with no direct access for the user or programmer.
Theory Algorithm
The sizes of these sections by purpose are not known in advance. To determine or change the sizes (segmentation), a set of registers called EepromConfig has been created. Now the manufacturer's engineers built the system as follows:
- Upon the first write to the controller, we perform segmentation, determining the sizes of the three areas. By default (if you erase the processor), we have full access to D-Flash (for example, f565 - 32 kilobytes) and no EEPROM or backup (0 bytes).
- Now the size of D-Flash is, for example, 24KB, while the size of EEE is, for example, 256 bytes.
- To write to EEPROM, we write not to the EEPROM itself but to FlexRAM (EEE), then the controller internally copies what was written to FlexRAM, compresses it, and saves it to EEPROM_backup.
- For reading, a command is given to unload from EEPROM_backup into FlexRAM (EEE).
- DataFlash can only be read up to the size that was segmented.
- Anything that goes beyond the segmentation limits will not be read from the sections and should not be. MultiProg fills these leftovers with zeros = 0x0.
- What you should understand by this point is that if you did not save the EepromConfig (the segmentation data) when reading the controller from the board, then when writing to a clean controller, you will never be able to write D-Flash & EEPROM normally. Before writing, of course, it must be recorded first.
Practice
Now for the practice.
Select controller 84565 (or another with this type of memory). A button EEP_CONFIG has appeared. It is currently inactive.
After connecting to the controller, it will become active. We also see a line in the log
[SUCCESS] Read EEP_Config: EEESIZE : 0x6, Depart : 0x1, FlexRAM EEP size : 256 bytes, D-Flash size 24576 bytes
We read the segmentation registers.
For now, we do nothing and click on EEP_CONFIG.
A window like this has appeared.
The window is only active after connecting; to access the button-window, you need to make a connection. It is recommended that if we plan to do something (write-read), we first perform all operations with the config right after connecting.
If we plan to read this controller, we first need to save the EEPROM config (segmentation settings). Click Save to file.
Now, if we plan to write after connecting, we need to load the controller config that we previously read.
Then (after Load from File of the new config) the Apply button (to write a new config-segmentation) will become active.
Pressing Close does not perform any writing.
After erasing, the configuration inside the controller resets to default.
For this 565, there are 32KB of DataFlash and 0 EEPROM emulator.