SNIU028D February 2016 – September 2020 UCD3138 , UCD3138064 , UCD3138064A , UCD3138128 , UCD3138A , UCD3138A64
Data flash and Program Flash have separate flash programming circuitry, so it is possible to operate on data flash while executing from program flash. It is not possible to read from data flash while writing or erasing data flash, however. So all values that will be needed during erase/write process should be stored in RAM or program Flash.
The UCD3138 has 2048 bytes of Data flash organized in 64 blocks of 32 bytes each. Erasing can be done a block at a time. To erase a block, first write the key to the FLASHILOCK register. Then simply write to the Data Flash Control Register (DFLASHCTRL) with the block number in the low 6 bits (PAGE_SEL) and a 1 in bit 9 (PAGE_ERASE).
Then wait for the BUSY bit in the same register to go low before doing any other Data Flash Operation.
To erase the entire Data Flash, write the key, and then write to DFLASHCTRL with bit 8 (MASS_ERASE) set. The Busy wait is required for a mass erase as well.
Erasing Data Flash (or Program Flash) sets all the bits in the Flash locations.