wiki:CPC-CompactFlash

Version 3 (modified by pulkomandy, 10 years ago) ( diff )

--

CPC-CompactFlash

This very simple interface (only 2 74LSxx chips) allows the use of a CompactFlash memory card on the CPC. It uses the 8 bit mode of the compact flash, making it even simpler than the IDE interfaces you can find elsewhere.

Schematics

http://www.circuitbee.com/circuit/view/0000000374

Also available (with PCB routing) in the SVN repository.

Programming information

The interface maps the registers at addresses FEF0-FEFF :

AddressReadWrite
FEF0DataData
FEF1ErrorFeature
FEF2Sector countSector count
FEF3LBA 0LBA 0
FEF4LBA 1LBA 1
FEF5LBA 2LBA 2
FEF6Drive/LBA 3Drive/LBA 3
FEF7StatusCommand

Sector are accessed using 28-bit sector numbers in registers FEF3-FEF6. Only the 4 low bits of FEF6 are used, the 4 high bits must be set to E to enable LBA mode on the master drive.

Initializing

First of all, set the compact flash card to 8-bit mode:

	OUT &FEF6,&E0 ' Select master drive in LBA mode
	OUT &FEF2,1 ' Sector count = 1
	OUT &FEF3,0 ' Select first sector on drive
	OUT &FEF4,0
	OUT &FEF5,0

	OUT &FEF1,1 ' 8bit mode feature code
	OUT &FEF7,&EF ' execute SET FEATURE command

You can then identify the card:

	OUT &FEF6,&E0 ' Select master drive in LBA mode
	OUT &FEF2,1 ' Sector count = 1
	OUT &FEF3,0 ' Select first sector on drive
	OUT &FEF4,0
	OUT &FEF5,0

	OUT &FEF7,&EC ' Send IDENTIFY command

	' Wait for the card to become ready to send data
loop	A = IN &FEF7
	IF A > &7F GOTO loop

	' Get the drive identification in IDENT array
	FOR i = 0 to 512
		IDENT(i) = IN &FEF0
	NEXT i

The identification data is 512 bytes long and has information about the card (manufacturer id, model number, ...) and its capacity and format, and a few other less important things.

You can also read sectors:

	OUT &FEF6,&E0 ' Select master drive in LBA mode
	OUT &FEF2,1 ' Sector count = 1
	OUT &FEF3,0 ' Select first sector on drive
	OUT &FEF4,0
	OUT &FEF5,0

	OUT &FEF7,&20 ' Send READ SECTOR WITH RETRY command

loop	A = IN &FEF7
	IF A > &7F GOTO loop

	' Get the sector in DATA array
	FOR i = 0 to 512
		DATA(i) = IN &FEF0
	NEXT i

Using a filesystem

Currently, no filesystem is available. Write one or wait for AmélieDOS to be released! Meanwhile, you can have fun with reading and writing sectors.

Note: See TracWiki for help on using the wiki.