SD Card driver question

Technical discussions related to any XMOS development kit or reference design. Eg XK-1A, sliceKIT, etc.
User avatar
landon
Experienced Member
Posts: 71
Joined: Mon Sep 06, 2010 4:05 pm

SD Card driver question

Post by landon »

I recently discovered the SD Card driver as part of the XS1-G dev kit...I don't have that dev kit but it looks like the same code ended up in Berni's WAV player project.

My question concerns the select line - I am currently trying to get this to work on a different XMOS board, so I simply remapped the SPI pins defined by the driver. But when I studied what I thought was the select line, it sort of dead-ends.

The four pins for SD driving are defined as:

Code: Select all

on stdcore[2] : port p_sd_cmd = XS1_PORT_1H;
on stdcore[2] : port p_sd_clk = XS1_PORT_1E;
on stdcore[2] : port p_sd_dat = XS1_PORT_1F;
on stdcore[2] : port p_sd_rsv = XS1_PORT_1G;
Certain cmd (MOSI), clk (CLK), dat (MISO), and rsv I have to assume is the device's select line (CS/SS).

But when I grep for the p_sd_rsv line, here's what I get:

Code: Select all

find . -name "*" -exec grep -iH "p_sd_rsv" {} \;
./Driver_SD/FAT16_server.h:void FAT16_server(chanend client1, port p_sd_cmd, port p_sd_clk, port p_sd_dat, port p_sd_rsv);
./Driver_SD/FAT16_server.xc:void FAT16_server(chanend client1, port p_sd_cmd, port p_sd_clk, port p_sd_dat, port p_sd_rsv)
./Driver_SD/FAT16_server.xc:            if (SD_link_initialise(p_sd_cmd, p_sd_clk, p_sd_dat, p_sd_rsv) == XMOS_SUCCESS)
./Driver_SD/SD_link.h:XMOS_RTN_t SD_link_initialise( port p_sd_cmd, port p_sd_clk, port p_sd_dat, port p_sd_rsv);
./Driver_SD/SD_link.xc:XMOS_RTN_t SD_link_initialise(port p_sd_cmd, port p_sd_clk, port p_sd_dat, port p_sd_rsv)
./Driver_SD/SD_link.xc:  SD_phy_initialise(p_sd_cmd, p_sd_clk, p_sd_dat, p_sd_rsv);
./Driver_SD/SD_phy.h:uint SD_phy_initialise(port p_sd_cmd, port p_sd_clk, port p_sd_dat, port p_sd_rsv);
./Driver_SD/SD_phy.xc:uint SD_phy_initialise(port p_sd_cmd, port p_sd_clk, port p_sd_dat, port p_sd_rsv)
./Driver_SD/SD_phy.xc:  p_sd_rsv <: 1;
./main.xc:on stdcore[2] : port p_sd_rsv = XS1_PORT_1G;
./main.xc:		on stdcore[2] : FAT16_server(ch_fs, p_sd_cmd, p_sd_clk, p_sd_dat, p_sd_rsv);  //Filesystem
There's only one actual usage of it, in the SD_phy_initialise() method where it raises the line high as it should do for a select line during the wake-up sequence.

The problem is, I don't ever see it asserted low anywhere in the code. Why? I have to assume this driver works because Berni used it in a project and it's part of an official XMOS dev kit.

What am I missing? I guess I could go through and do the assertions, but it feels more like I'm not understanding something first.

Landon


sanandak
New User
Posts: 2
Joined: Thu Nov 25, 2010 3:45 am

Post by sanandak »

That driver uses "1 bit SD mode," not SPI mode. In SD mode there are only three lines used: clk, cmd, and dat. cmd and dat are bi-directional. The clk pin is the same in both sd and spi mode; DAT is on the DO line; CMD is on the DI line. The 4th line (RSV) is unused, except during initialization, when the card is being set to either SD or SPI mode. (in SPI mode, that would be the CS line).

SA
User avatar
lilltroll
XCore Expert
Posts: 956
Joined: Fri Dec 11, 2009 3:53 am
Location: Sweden, Eskilstuna

Post by lilltroll »

SPI mode is only supported up to 1 Mbit on full-sized SD card. On micro-size it's not guaranteed to work.
The 1 bit mode can support speeds up to 25 Mbit/s , and the 4 bit mode up to 100 Mbit/s, but it's dependent on the speed rating on the card !?

The SD mode is thus much faster. Can you "ask" the card what speed it supports ?
Probably not the most confused programmer anymore on the XCORE forum.
User avatar
Berni
Respected Member
Posts: 363
Joined: Thu Dec 10, 2009 10:17 pm

Post by Berni »

Actually all modes work at the same speed(25Mhz for a normal card) and the cards speed actually comes from the access times. If you have a high speed card then it allows it to be clocked at 50MHz. The only speed advantage is from the 4bit SD bus as it transfers 4 times more data at the same clock rate.

Usually clocking it at somewhat under 25Mhz is plenty fast as that can give up to 3MB/s so don't bother with it too much as the 50Mhz mode has to be requested (Altho i found high speed cards seam to work at over 25MHz without requesting that, but you still have to check if it supports it, in case it gets a non high speed card).