Sorry, you need to enable JavaScript to visit this website.

standalone SD card SDIO

Unsolved
15 posts / 0 new
yaro123's picture
yaro123
Junior(1)
standalone SD card SDIO

Hello,

I try to use the SD card of the Zedboard via the SDIO port. I use chans FatFs. First I implemented the diskio.c by my own, but then debugging it I found that there is an implementation in an example project, so now I use that one.
It can be found here:
Xilinx\SDK\2014.2\data\embeddedsw\lib\sw_services\xilffs_v2_1

Initialization works partly, but not fully:
.

XSdPs_SdCardInitialize
XSdPs_Change_ClkFreq(&SdInstance, SD_CLK_25_MHZ);
and XSdPs_Select_Card
.

work propperly, but XSdPs_Get_BusWidth does not anymore.
It seems like commands are accepted, but DMA transfers are not:
.
/*
* Send block write command
*/
Status = XSdPs_CmdTransfer(InstancePtr, CMD55,
InstancePtr->RelCardAddr, 0);
if (Status != XST_SUCCESS) {
....Status = XST_FAILURE;
....goto RETURN_PATH;
}

BlkCnt = XSDPS_SCR_BLKCNT;
BlkSize = XSDPS_SCR_BLKSIZE;

/*
* Set block size to the value passed
*/
BlkSize &= XSDPS_BLK_SIZE_MASK;
XSdPs_WriteReg16(InstancePtr->Config.BaseAddress,
XSDPS_BLK_SIZE_OFFSET, BlkSize);

XSdPs_SetupADMA2DescTbl(InstancePtr, BlkCnt, SCR);

XSdPs_WriteReg16(InstancePtr->Config.BaseAddress,
XSDPS_XFER_MODE_OFFSET,
XSDPS_TM_DAT_DIR_SEL_MASK | XSDPS_TM_DMA_EN_MASK);

Status = XSdPs_CmdTransfer(InstancePtr, ACMD51, 0, BlkCnt);
if (Status != XST_SUCCESS) {
....Status = XST_FAILURE;
....goto RETURN_PATH;
}
.
SdPs_CmdTransfer(InstancePtr, ACMD51, 0, BlkCnt) returns with 1.
.

Maybe I did something wrong in the hardware design. I added the SD 0 Peripheral and assigned CD to MIO 47, WP to MIO46.
Do I have to activate the DMA somehow?
.
There is one funny fact: when I let the example program run, a file is generated on the SD, but it cannot be neither read nor written by the zynq.
.
Best regards,
Yaro

yaro123's picture
yaro123
Junior(1)
solved

Hello,

I solved the problem.
The configuration of the Zynq processing system in Vivado was wrong. For the speed of the sd 0 port one should choose "fast" and disable the pullups, otherwise strange things happend.
.
By the way I found out how to include the library I found automatically:
Right click the bsp project and choose settings. There you can choose additional librarys. The FatFs SDIO lib is xilffs.
.
The documentation can be found here (have a look at the creation date):
http://www.xilinx.com/support/documentation/sw_manuals/xilinx2014_1/osli...
.
I hope that will help somebody.
.
Best regards,
Yaro

yaro123's picture
yaro123
Junior(1)
important note

Verry important note:
The data caches have to be disabled, otherwise it does not work propperly.

Can someone tell my why?

w.pram's picture
w.pram
Junior(0)
data caches

Hi,
I think it has something to do with the copying scheme of caches. If you load data from SD card to external DDR, the cache will temporarily store it and keep it(It only flush the data to DDR if it's full). If the cache is not full, it never flush the data to DDR. But I'm not sure if this correct though.
I think you can re-enable the data cache imidiatly after you've done copying from SD card.

xilin's picture
xilin
Junior(0)
I have a simple Vivado Design

I have a simple Vivado Design with a Zynq processing system and added the SD 0 Peripheral and assigned CD to MIO 47, WP to MIO46 like yaro123.

Also the speed is fast and the Pullups are disabled.

But if I run the example xilffs_polled_example.c then

...
Res = f_open(&fil, SD_File, FA_CREATE_ALWAYS | FA_WRITE | FA_READ);
if (Res) {
return XST_FAILURE;
}
...

returns XST_FAILURE due to:

chk_mounted -> disk_initialize -> XSdPs_Pullup -> XSdPs_CmdTransfer and then the polling fails.

Did I miss any details or jumper settings?

Thx for any response

xilin's picture
xilin
Junior(0)
Edh4's hardware configuration solved it

My mistake, Edh4's hardware configuration (http://zedboard.org/comment/4876#comment-4876) helped:

In the ZYNQ7 processing system the MIO pins 40-45 are connected to the SD card interface.
Since these pins are programmed using the GPIO interface, it is mandatory that the SD0 peripheral in the Zynq Block Design (accessing the same pins) is not selected. On the other hand, the GPIO peripheral needs to be selected.

Mohammad's picture
Mohammad
Junior(0)
the problem is still there!

Hi Edh4,

I have the same problem, I ran the the whole flow with both configurations: selecting SD0 and not selecting. In both I am getting the same error.

any suggestion is appreciated.

Mohammad

yaro123's picture
yaro123
Junior(1)
Caches

By now I found out what the problem with the caches was caused by. In the new Vivado version (2014.4 I think) there is an updated version of the library where these issues are fixed.
The data transfer over sdio is done via dma. As w.pram mentioned, when you write to the cache, it's not necessarily written to ram immediately. If you want so, you have to flush the cache. Same goes for reading from sdio. If you have read from a buffer, that data is loaded into the cache. When now new data arrives via dma, the cache does'nt know that and still assumes, that his stored data is the most recent one. So you have to tell it explicitely, that the new data has to be loaded. This is done by invalidating the cache.
Now here we get into trouble, if the buffer is not allignet wit the cache lines, because if e.g. the buffer starts or ends in the middle of a cache line, by invalidateing the cache all changes to the whole line are lost. That might lead to verry hard discoverable bugs.
Well now all that is taken care of by the updated library, so don't be lazy and update your vivado =)

yaro123's picture
yaro123
Junior(1)
Newer version

I have adopted the code to a newer version of fatFs that has fewer bugs and more functions. You can download it here:
https://dl.dropboxusercontent.com/u/15987625/sdTest.7z

please report bugs if you find some.

Qing.He's picture
Qing.He
Junior(0)
Some SD cards fail to write

Hi,
Thanks for your help, I have tested your code on Microzed and Zedboard, here is what I found.
1.10 SD cards from 4 different vendors(Sandisk, Lexar,ATP,Delkin), 7 of 10 passed the test, 3 failed with empty file.
2. I have verified the card itself is good.
3. 2 failed cards (ATP Brand),I can boot from them (read file is ok), the 3rd failed one(Lexar brand) , I even couldn't boot from it.

Please share your experience if you have same issue.

Thanks

Qing.He's picture
Qing.He
Junior(0)
Some SD cards fail to write

Hi,
Thanks for your help, I have tested your code on Microzed and Zedboard, here is what I found.
1.10 SD cards from 4 different vendors(Sandisk, Lexar,ATP,Delkin), 7 of 10 passed the test, 3 failed with empty file.
2. I have verified the card itself is good.
3. 2 failed cards (ATP Brand),I can boot from them (read file is ok), the 3rd failed one(Lexar brand) , I even couldn't boot from it.

Please share your experience if you have same issue.

Thanks

yaro123's picture
yaro123
Junior(1)
Hello,

Hello,

make first sure, that the cards are formatted with fat32.
SD-Cards are in general pretty moody, so a lot of things might cause the problem.
Regarding the caches, please first make sure that your file buffers are 32-aligned.

Maybe try to uncomment (in diskio.c)
Status = XSdPs_Pullup(&SdInstance);
if (Status != XST_SUCCESS) {
s |= STA_NOINIT;
return s;
}

if (SCR[1] & WIDTH_4_BIT_SUPPORT) {
Status = XSdPs_Change_BusWidth(&SdInstance);
if (Status != XST_SUCCESS) {
s |= STA_NOINIT;
return s;
}
}

and

if (SCR[1] & WIDTH_4_BIT_SUPPORT) {
Status = XSdPs_Change_BusWidth(&SdInstance);
if (Status != XST_SUCCESS) {
s |= STA_NOINIT;
return s;
}
}

maybe even
Status = XSdPs_Change_ClkFreq(&SdInstance, SD_CLK_25_MHZ);
if (Status != XST_SUCCESS) {
s |= STA_NOINIT;
return s;
}

Doing the experiments, do not boot from the sd-card, but from JTAG to avoit problems.
Before every test, power-cycle the board (leave it off for >4 seconds).

To figure out, whether this is a Xilinx driver problem or a lirary problem, one could use a bitbanging low level driver available at http://elm-chan.org/fsw/ff/00index_e.html with a customization to Zynqs GPIO.

dannna's picture
dannna
Junior(0)
Reading data from DDR and writing it to SD

Hi,

I'm using Zedboard and I want to use the SD card not as boot.

The example xilffs_polled_example.c works good,

How can I use the f_write function in order to write data from DDR?

Thanks,
Danna

marcello33's picture
marcello33
Junior(0)
Read/Write SD Card using SPI and PL

Hi guys.
I'm using for the first time a FPGA and I need to communicate with a "Pmod SD Card" using a Zedboard Zynq, with Vivado system (Vivado + HLS + SDK).
My scope is to read/write data just using the Programmable Logic and the SPI protocolo, without the ARM interaction.
Do you have some similar projects to send me?
Thank you in advance.

enjoi's picture
enjoi
Junior(0)
Write to sdcard using ff.h and standalone

Hey Guys,
I try to use the ff.h library to write a string of data to the sdcard. For this I used the example given by sdk. The example works fine like it is. But when I try to write a string which size is smaller than 256 byte. Only the file is created, but no data is in it.
Do you have any idea how I can fix it?