Hi Folks,
I've got a reasonably full-functioned demo K22F SPI SD Card Application running - attached is the project.
It was created under:
KDS 3.1
KSDK 1.3
PE 3.0.2
It uses the K22F's OpenSDA port as an interface, running 115,200bps at 8-N-1 (I use Tera Term with it).
The console commands are:
help <== List commands
dir [Path][fileName.ext] <== Long filenames and wildcards are supported
copy con: [Path]fileName.ext <== Copy console input into the specified filename. End input with ^Z (Ctrl-Z).
<== For a new line, press "Enter" and then ^J (Ctrl-J) for CR/LF
copy [Path]sourceFileName.ext [Path]destFileName.ext
cd Path <== Set a new active Path. ".." is supported.
md Path <== Make a new Directory
rd Path <== Remove an EMPTY Directory
type [Path]fileName.ext <== Dump file contents onto console
rw1 <== Run single block read/write tests at sector 30000
rw2 <== Run two block read/write (using the WRITE_MULTIPLE_BLOCK command)
It supports Version 1.x and 2 SD cards and SDHC/SDXC cards. I didn't implement the code for MMC simply because it isn't available in the Micro SD format (and I don't know how many people still have some in use with full sized SD Cards). I've tested it on a variety of uSD Cards from 256 MB to 32 GB, so I'm fairly comfortable with saying that it works.
As I said, it works with the FRDM-K22F with the following modifications:
- Remove R52
- Remove R55
- Add Molex 1050270001 (Digi-Key WM6825CT-ND) connector (this requires quality soldering equipment)
ChaN's FatFs (http://elm-chan.org/fsw/ff/00index_e.html) is used for interfacing with the SD Card. All non-KSDK and non-PE code was development by me and it's free for use. If it's not as elegant as you would like, well it's development code. If you find any errors, I would appreciate it if you would point them out to me.
I should point out that I think there is an issue with the "Generic" example available on ChaN's side for the Multi Block Write with regards to sending the stop transmission token - I'm going to follow up with him on that. I believe that it is fixed in my code.
A goal of this code was to only use vanilla KSDK/PE APIs and, while the SD Card's DETECT pin is connected as an interrupt and debounced, I don't mount/unmount the SD Card FAT file system via the interrupts as I found it made the system unstable. The mounting takes place when the user presses the Enter button and, it the card is installed, it is mounted before the command is executed. The LED colours that you should watch on the K22F board is Blue indicating that the mount was successful and Red indicating the mount was unsuccessful.
One issue that was encountered that I do want to mention is that bulk/continuous/DMA SPI reads/writes are not implemented. I discovered that they do not work on about 40% of the SD Cards that I am working with. I have no idea why and I can't find any references as to the reason why - interestingly, I can't find any SPI SD Card example code which implements the bulk SPI reads/writes which leads me to believe that other people have had the same issue.
Unfortunately, due to the need for procuring and soldering on J8, this is not an application you can just try out on a whim. Despite this, I hope people will find this code useful.
myke