SDHC Bus width with FatFS

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SDHC Bus width with FatFS

1,574 Views
giacomopetrini
Contributor IV

Hello,

I managed to use the FatFS (the version included in KSDK 1.0.0) on a FRDM-K64F baremetal without PE (but with KSDK 1.0.0 and KDS 2.0.0).

All works (I'm still trying to understand how the driver write to the sdhc, when to use f_sync, etc...maybe another post for that), but the SDHC bus width is set to 1bit.

I tried to force the bus to 4bit (the sdhc card supports it), but then I have an error (FR_DISK_ERR) when trying to open a file.

Since it should improve the performances I really wish to use the 4bit bus.

Some ideas?

 

Thanks

Best Regards Giacomo

Labels (1)
8 Replies

848 Views
mjbcswitzerland
Specialist V

Hi

Initialisation of the SD card always starts in 1 bit mode and 4 bit mode is moved to after its address has been established and the card has been selected.

Are you sure that you need to force 4-bit mode and that you haven't done it too soon?

Regards

Mark

848 Views
giacomopetrini
Contributor IV

If I don't force then the sd card is working with 1bit bus (checked the lines with an oscilloscope).

I setted (forced) the 4bit at the end of the sdhc init process (after SDCARD_DRV_Init()).

After that I do a f_mount() (that is just preparing the data structures of the fat fs) and then the f_open() (that gives me the FR_DISK_ERR).

In the SDCARD_DRV_Init() there is this code:

    if (DOES_HOST_SUPPORT_4BITS(card->host) && DOES_CARD_SUPPORT_4BITS(card))

    {

        if (kStatus_SDHC_NoError != SDCARD_DRV_SetBusWidth(card, kSdBusWidth4Bit))

        {

            return kStatus_SDHC_SetCardWideBusFailed;

        }

        if (kStatus_SDHC_NoError !=

                SDHC_DRV_SetBusWidth(card->hostInstance, kSdhcBusWidth4Bit))

        {

            return kStatus_SDHC_SetBusWidthFailed;

        }

    }

but DOES_HOST_SUPPORT_4BITS(card->host) return always false.

So probably I need to set something before the init, but I can't figure out what.

Some ideas?

Thanks

Best Regards Giacomo

0 Kudos

848 Views
mjbcswitzerland
Specialist V

Giacomo

I took a quick look at the KSDK 1.0.0 code and it doesn't look as though it ever uses anything but 1 bit mode. However I would expect that by forcing DOES_HOST_SUPPORT_4BITS() to be true would be adequate.- it only has to write the bus width to the SD card and then set it in the controller using SDHC_DRV_SetBusWidth(card->hostInstance, kSdhcBusWidth4Bit)).

I have however attached a FRDM-K64F binary from the uTasker project so that you can compare - it uses 4 bit bus and so you can check the registers for differences, etc.
It uses utFAT2.0 which has more features that FatFs (it has expert functions for analysing existing and deleted file objects on disk, can undelete files, has LFN write support with Linux workaround to avoid Microsoft FAT LFN copyright infringements, and various other capabilities - document at http://www.utasker.com/docs/uTasker/uTasker_utFAT.PDF )

The binary allows the SD card interface to be used on the OpenSDA virtual COM connection (115200Baud) - there is a DOS like interface in the SD card menu.

The board has the IP address 192.168.0.3 (can be modified via the command line menu) and the same interface is available via TELNET (log off the UART one first though)

If you connect with USB (on the other USB port) the SD card will appear as a hard disk to the PC.

If you FTP to the board the SD card content can also be modified using an FTP client.

If you create a directory called "dir1" and put web server content there with start side "index.htm" the board will perform a complete SD card based web server.

A big advantage is also that the FRDM-K64F, the SD card and Ethernet can be simulated in (approx) real-time using VisualStudio so the SD card operation can comfortably be tested without needing HW. This makes code anysis very efficient as well as general project work much faster than traditional techniques. Below is a screen shot of the attached binary project running in the simulator

Regards

Mark

µTasker Kinetis support

pastedImage_0.png

0 Kudos

848 Views
giacomopetrini
Contributor IV

I took a quick look at the KSDK 1.0.0 code and it doesn't look as though it ever uses anything but 1 bit mode. However I would expect that by forcing DOES_HOST_SUPPORT_4BITS() to be true would be adequate.- it only has to write the bus width to the SD card and then set it in the controller using SDHC_DRV_SetBusWidth(card->hostInstance, kSdhcBusWidth4Bit))

Ok, so probably I didn't write the bus width to the sd card....How can I do that with the KSDK 1.0.0?

Thanks

Best Regards

Giacomo

0 Kudos

848 Views
mjbcswitzerland
Specialist V

Giacomo

If you force the host bus width I expect the code to then automatically write the bus width using SDHC_DRV_SetBusWidth(card->hostInstance, kSdhcBusWidth4Bit))

I would check that this is being called and verify what it actually does; if the 4 bit mode has never been used before it is possible that the command has also never been tested and so could be doing something wrong.

Regards

Mark

0 Kudos

848 Views
giacomopetrini
Contributor IV

Ah ok, I understood now.

It's kind of complicated, because I should init the sd card with 1bit bus width, check if the card support 4bit and if so set both card and host to 4 bit...

I'll try as soon as I have some spare time...

Regards

Giacomo

0 Kudos

848 Views
giacomopetrini
Contributor IV

Ok, I added

    g_sdhcHost.caps |= FSL_SDHC_HOST_CAPS_SUPPORT_4BITS;

to the sdcard_disk_initialize(uint8_t pdrv) function of the fatfs (in fsl_sd_disk.c) just before the SDCARD_DRV_Init() and the 4bit bus width seems to be enabled and working without errors.

Bye Giacomo

0 Kudos

848 Views
leonardobueno
Contributor I

Giacomo,

Do you have the source code of your FatFs/SDCard test? I am trying to do kinda the same thing you did (baremetal without PE using KSDK 1.0.0), but I am running into a hardfault error when I execute the SDCARD_DRV_Init function. To be more precise, when the code first call SDHC_HAL_SendCmd function.

Could you share part of your code to help me find out my error?

Leonardo Bueno

0 Kudos