Correct initialization sequence CF-cards

180 views
Skip to first unread message

Nick Brok

unread,
Apr 13, 2022, 1:33:03 AM4/13/22
to retro-comp
Hi, probably Wayne
I experimented a lot with several CF-cards and discovered a lot of differences in the way a cf-card is initialized. I looked in the ROMWBW code for a correct initialization of a cf-card, but I couldn't find it. Can you point me to the code where the initialization sequence is done? I discovered also that less then 512 MB cards works differently than the 512 MB cards and bigger. I have a 4MB card and it reads 256 bytes of a sector only.
Is there any difference between this  'low" capacity cards and the bigger ones?

Alan Cox

unread,
Apr 13, 2022, 6:57:55 AM4/13/22
to Nick Brok, retro-comp
All CF cards are 512 byte/sector all I/O is 512 bytes. If you are getting 256 bytes only then you've not put it into 8bit mode, or it may not be an actual CF compliant card and support 8 bit mode, but if so then you'd get an error from the set features command.

There is no initialization as such for an IDE device. They power up with the registers set up so you can issue a normal read of CHS 0,0,1 without reloading them, so you can use them to bootstrap with a tiny ROM.

If you are not forcing a hardware reset and EDD sequence (which really isn't worth it and needs the ALT regs decoded anyway) then there is no set up. The drive is in a normal state from power up. It'll not show as ready for a moment (up to a minute or so on really ancient drives!).

The usual sequence for a simple 8bit micro is

Write AA 55 to the sector low 2 registers, check it reads back the same
Write 55 AA to the sector low 2 registers,  ditto

(That checks a card is present)

Send a set features for 8bit, and check if it worked. If it errors you have a 16bit only device
Send an identify and check for LBA support if you don't also handle CHS

And that's basically it.

The history of the commands is something like this

Ancient ancient devices (MFM and RLL) support CHS and other sector sizes. They don't have anything but the basic I/O commands (WD1010) at 16bit width.

The earliest IDE is just WD1010 but with the controller equivalent logic on the drive and only 16bit wide  512 bytes/sector allowed. These are rare, if not pretty much non-existent.

By IDE 2 they started adding commands for modes, IDENTIFY and the like.

Later devices add LBA support.

Very large devices support LBA48 (needed for drives over 2TB) but support LBA as well for accessing blocks below 2TB

CHS v LBA is just a bit flag
LBA48 is a whole extra command mode

All the ATA draft specs (the last draft before ANSI standardisation) are on t13.org. Everything you need is in ATA-3 or ATA-4 or so. The standard gets bigger, more verbose, more standards committee jargonspeak each release so the older ones are by far the best to look at unless you are using recent features like SATA.

It's all back compatible until the later SATA stuff. You can issue WD1010 commands to a last generation PATA drive and it'll just work !

Alan

Phillip Stevens

unread,
Apr 13, 2022, 8:03:54 AM4/13/22
to retro-comp
Nick  wrote:
Hi, probably Wayne
I experimented a lot with several CF-cards and discovered a lot of differences in the way a cf-card is initialized. I looked in the ROMWBW code for a correct initialization of a cf-card, but I couldn't find it. Can you point me to the code where the initialization sequence is done? I discovered also that less then 512 MB cards works differently than the 512 MB cards and bigger. I have a 4MB card and it reads 256 bytes of a sector only.
Is there any difference between this  'low" capacity cards and the bigger ones?

Alan wrote: 
All CF cards are 512 byte/sector all I/O is 512 bytes. If you are getting 256 bytes only then you've not put it into 8bit mode, or it may not be an actual CF compliant card and support 8 bit mode, but if so then you'd get an error from the set features command.

There is no initialization as such for an IDE device. They power up with the registers set up so you can issue a normal read of CHS 0,0,1 without reloading them, so you can use them to bootstrap with a tiny ROM.

If you are not forcing a hardware reset and EDD sequence (which really isn't worth it and needs the ALT regs decoded anyway) then there is no set up. The drive is in a normal state from power up. It'll not show as ready for a moment (up to a minute or so on really ancient drives!).

The usual sequence for a simple 8bit micro is
Write AA 55 to the sector low 2 registers, check it reads back the same
Write 55 AA to the sector low 2 registers,  ditto
(That checks a card is present)

Send a set features for 8bit, and check if it worked. If it errors you have a 16bit only device

For interest the whole minimum set of 16-bit IDE routines are here.
ide_read_sector and ide_write_sector are the two high level commands to get a LBA sector off or onto the disk.

They rely on these functions ide_setup_lba ide_wait_read and ide_wait_drq, to set up the LBA sector, and to wait for appropriate status triggers.
They are implemented here by ide_read_byte ide_read_block ide_write_byte and ide_write_block.

It is very simple to work in Mode 0 IDE.

P.

Nick Brok

unread,
Apr 13, 2022, 1:23:38 PM4/13/22
to retro-comp
For Alan:
It generated an error with my 4MB the 64MB card did not work, it seems it doesn't know 8 bit mode. Thanks. All other cards are working fine.

Op woensdag 13 april 2022 om 14:03:54 UTC+2 schreef Phillip Stevens:
Reply all
Reply to author
Forward
0 new messages