• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

CompactFlash help

CTho9305

Elite Member
For a project, I have to talk to a CF card (we're using some 256MB card), and I'm using a TinyARM to control it. I read through the spec, but I still don't understand how to read from it and write to it.

My adapter can only do TrueIDE mode (there are only 3 address pins available... it doesn't tie pin 9 to GND, but I assume I'll have to). I get the impression from the spec that I have to load certain control control registers and then issue a "do it" command. What registers and values isn't clear. The list of possibilities is way too long 🙁. Do I have to use CHS mode, or can I treat it as a flat address range? Any help would be appreciated.
 
You might want to read the ATA specification for a description of the register set. The thing to remember is that on IDE, the controller is inside the drive, and what people call an "IDE controller" is actually just a bus bridge with a pair of address decoders.
The other thing to know is where these address decoders map the IDE controller into your processor's address space.
What access methods the drive supports is found by reading the "configuration sector", where the drive reports all that stuff. This is the first thing to do, after performing a proper IDE interface reset.

In other words, look at a (legacy, non-DMA) IDE driver to learn that stuff. CF in IDE mode is exactly the same thing.
 
Are there any particular documents you'd suggest reading? I'm finding a lot of different sites, but no single big document (like the CompactFlash PDF spec).

The other thing to know is where these address decoders map the IDE controller into your processor's address space.
It's not going to be in my processor's address space... the processor is an ARM running custom code, and the CF card is just connected (using one of these) on some random PIOs that were available (I can arrange them in any way that's convenient). I guess that means I have to write even more code?
 
Er, what's wrong with the example code the supplier of the adapter board seem to have on their CD?

But well yes, if you don't have a proper ISA-ish bus to connect to and no address decoders for CS1 and CS2 address ranges, then you're going to have to write your own code that simulates such a bus arrangement on GPIOs. (Remember that back in the days, IDE was stemming off ISA using a bunch of line drivers and said address decoder. You can still do it exactly like that from a generic 16-bit-wide ISA-ish bus as found on many embedded SoCs.)

That'll be even more reading the ATA specification then. (This is the same ATA specification as for normal hard disks, btw. Not something CF related - that's also why the CF spec doesn't mention anything about this.)
 
They didn't send the CD 🙁. I didn't order the card - so I don't know what happened. Apparently the adapters were stuck in US customs for over a week too. Maybe someone in another group has more info (though it seems everybody is having trouble).
 
So if you HAVE to do it yourself, you'll need to start out implementing that physical interface layer. Make your pretend-IDE interface from a bunch of GPIO - 16 data, two chip-select, a couple more misc (read/write etc, IOready, etc.). It's probably a good idea to wire an old HDD to it so you don't zap expensive CF cards while trying to get this right 😉
 
Looks like it actually isn't so bad - I was misunderstanding some of the CF spec - it does provide all the info I need 🙂. I talked to a guy who had it working and got the info I needed. Easy to use 🙂

Unfortunately, my TinyARM is insisting that the upper two bits of data are always 1 when reading... if I pull it down with a 10k resistor, the TinyARM reads 0. If I pull it up with a 10k, the TinyARM reads 1. If I don't pull it, the logic analyzer shows it switching, but the ARM still reads 1s. I checked, and the pin on the ARM board is in fact getting zeros, so that's not the problem. If I were seeing 0s insetad of 1s, I'd say "ok, driving 3.3v into a 5v device might make 1s flaky", but it's 0s being read as 1s 🙁. I guess I will be fighting with this tomorrow 😉. At least the lower 4 bits look correct / reasonable 🙂
 
Back
Top