Using Flash Memory
Adapted from Using flash memory.
Classic Spectranet has 128K of flash memory. It is paged into the Z80 address space like SRAM, but writing it is different from writing RAM.
Flash versus RAM
Flash is non-volatile and keeps its contents after power off. It behaves like ROM during normal reads, and ordinary memory writes do not change it.
Important flash properties:
- erased bits read as
1 - programming can change bits from
1to0 - changing
0back to1requires erasing a whole sector - the Am29F010 used by classic Spectranet has eight 16K erase sectors
- each byte write or sector erase requires a command sequence
RAM is volatile and can be written byte by byte without an erase step.
Spectranet flash layout
Flash occupies pages 0x00 to 0x1F. Pages 0x00 to 0x03 are reserved by Spectranet, and the last 256 bytes of page 0x1F store configuration such as MAC address, IP settings, and DHCP preference.
Erasing flash
Because sectors are 16K, rewriting one 4K page requires preserving the other pages in the same sector, erasing the whole sector, and writing the required data back.
Erase and write code must run from RAM. If the CPU fetches instructions from flash during the command sequence, the operation can be disturbed or aborted. Classic Spectranet utilities copy flash programming code to RAM before executing it.
The sector erase sequence is:
- write
0xAAto address0x555 - write
0x55to address0x2AA - write
0x80to address0x555 - write
0xAAto address0x555 - write
0x55to address0x2AA - write
0x30to the lowest address of the sector
Completion can be detected by polling the flash status bits, especially DQ7 and DQ5.
Writing flash
Programming one byte uses this sequence:
- write
0xAAto address0x555 - write
0x55to address0x2AA - write
0xA0to address0x555 - write the byte to the target address
Each byte requires its own command sequence. Existing 0 bits cannot be changed back to 1 without erasing the sector, but additional 1 bits in the same byte can still be programmed to 0.