MKV10/11 SD Card Library

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

MKV10/11 SD Card Library

Jump to solution
2,894 Views
abdullah_cinar
Contributor III

Hi,

I'm trying to find a bare-metal SD card library driven by DSPI for MKV11 series microcontrollers. Is there any example for something like port to FATFS?

I would like to know if there is already a pre-used library before I start writing my own.

Thanks,

Abdullah.

Edit: I attached the KV11 project that works. See the last post, I couldn't attach file there so I did it here.

0 Kudos
1 Solution
2,473 Views
abdullah_cinar
Contributor III

I finally got it working!

The issue was related to DSPI SCK driving. The problem has been solved when I added below delays (current values are given for default SDSPI baudrates, you may need to change them for different initial SPI speeds.).

pastedImage_1.png

I had to write my own routine to test the sd card by the CMD0 and check the R1 response. I realized that the SCK was skipping one low sequence between consecutive bytes. So I changed the delay configurations of the DSPI driver library in spi_init function.

By the way, there is no SDSDPI middleware library for MKV11, I migrated the MKV10 files to MKV11.

For anyone who has the same problem; I attached my MKV11 project which includes this migrated library to the first post, it works for me. The main routine has 2 option, first is to test the CMD0 command manually after calling the spi_init function. The second option is to use the FAT, you can enable the first option and scope the signals if you have a problem. Sorry the source code is a mess since it just worked and I didn't need to beautify it for now, but I guess it will be easy to understand the basics.

I used SDK 2.6.0 for MKV11 in MCUXpresso IDE and 4GB Fat32 SanDisk SD Card. By the way, I had 47K pull-ups on the MOSI, MISO and SCK lines but it didn't work until I replace them with 10K ohms.

View solution in original post

0 Kudos
16 Replies
2,474 Views
abdullah_cinar
Contributor III

I finally got it working!

The issue was related to DSPI SCK driving. The problem has been solved when I added below delays (current values are given for default SDSPI baudrates, you may need to change them for different initial SPI speeds.).

pastedImage_1.png

I had to write my own routine to test the sd card by the CMD0 and check the R1 response. I realized that the SCK was skipping one low sequence between consecutive bytes. So I changed the delay configurations of the DSPI driver library in spi_init function.

By the way, there is no SDSDPI middleware library for MKV11, I migrated the MKV10 files to MKV11.

For anyone who has the same problem; I attached my MKV11 project which includes this migrated library to the first post, it works for me. The main routine has 2 option, first is to test the CMD0 command manually after calling the spi_init function. The second option is to use the FAT, you can enable the first option and scope the signals if you have a problem. Sorry the source code is a mess since it just worked and I didn't need to beautify it for now, but I guess it will be easy to understand the basics.

I used SDK 2.6.0 for MKV11 in MCUXpresso IDE and 4GB Fat32 SanDisk SD Card. By the way, I had 47K pull-ups on the MOSI, MISO and SCK lines but it didn't work until I replace them with 10K ohms.

0 Kudos
2,473 Views
mjbcswitzerland
Specialist V

Hi

http://www.utasker.com/kinetis/TWR-KV10Z32.html
http://www.utasker.com/docs/uTasker/uTasker_utFAT.PDF


Open source solution for KV and FAT: Open Source version at https://github.com/uTasker/uTasker-Kinetis

Including KV and SD card simulator:

pastedImage_1.png

Regards

Mark

0 Kudos
2,473 Views
abdullah_cinar
Contributor III

I thought uTasker is an OS? I need a bare-metal solution if there is, otherwise I will review it and try to write my own.

0 Kudos
2,473 Views
mjbcswitzerland
Specialist V

Hi

uTasker is a solution and not an OS. It can be run in uTasker scheduling mode (default), in bare-metal mode by removing uTaskerStart() from main() or in FreeRTOS mode.

Bare metal mode saves about 2..3k of code space but loses various features that then need to be added using custom code so it is very rare to use bare-metal mode [typically only on very small devices where complete code sizes of a few hundred bytes is to be achieved] due to the fact the uTasker scheduler is in fact more or less equivalent to a bare-metal project, with an intelligent main() forever loop.

If you just want the utFAT code it is also available at
http://www.utasker.com/forum/index.php?topic=1667.0

Regards

Mark

0 Kudos
2,473 Views
abdullah_cinar
Contributor III

Hi Mark,

Thank you for the clarification. I will also start reviewing the uTasker. I need to add the SD card functionality to an ongoing project which was developed by bare-metal C, so I asked it if it supports bare-metal.

Thanks,

Abdullah.

0 Kudos
2,473 Views
mjbcswitzerland
Specialist V

Hi

It is generally quite easy to integrate existing bare metal code into the project - see chapter 8 of
http://www.utasker.com/docs/uTasker/uTaskerV1.4_user_guide.PDF

It then allows improvements in efficiency and use of dynamic low power (etc.) to be achieved by removing typical bare metal blocking operation with event driven techniques.
If peripheral drivers from the uTasker library can be used it then gives full simulation of the chip and the project which allows accelerated development and debugging capabilities that can help further slash project development times and costs.

https://community.nxp.com/thread/512558

Regards

Mark

0 Kudos
2,473 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Abdullah Çınar,

Please check the following information, maybe useful to you:

1. Porting FatFs file system to KL26 SPI SD card code 

2. SDK code for KV11, select the fatfs and sdmmc 

https://mcuxpresso.nxp.com/en/builder 

pastedImage_2.png

Then, you can find the related driver in this folder: SDK_2.6.0_FRDM-KV11Z\middleware

Wish it helps you!

Kerry

 

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
2,473 Views
abdullah_cinar
Contributor III

Hi Kerry,

I included all the necessary files from the Kinetis SDK FatFS folders to my project. I am trying to run the "fsl_sdspi_disk".

I filled up the necessary configuration defines (spi_base, spi_cs).

I added the pin mux calls to init boot pin settings. 

When I get an error when I try to open a new file. Do you know where to start testing the library to know the cause of the error?

Below is the routine in my main.c file. I get "FR_OK" when I call "f_mount" but I get "FR_NOT_READY" when I call "f_open".

pastedImage_7.png

0 Kudos
2,473 Views
kerryzhou
NXP TechSupport
NXP TechSupport

HI Abdullah Çınar

When you meet the problem, I think you need to check the SD card initialization code at first, can you connect to the SD card, and do the sd card read and write operation? When that function works, then you can add the fatfs again.

Kerry

 

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
2,473 Views
abdullah_cinar
Contributor III

Hi Kerry,

I tried debugging the f_mount function and also the functions inside it. But I think it is hard to say what's wrong without scoping the board. I'm trying to understand the communication stages and the spi specs to understand what is going on.

Thanks,

Abdullah.

0 Kudos
2,473 Views
mjbcswitzerland
Specialist V

Hi

See sections 2 and 3 of http://www.utasker.com/docs/uTasker/uTasker_utFAT.PDF for the relevant details for SPI mode and a reference to the SPI signals that should be used.

Regards

Mark

0 Kudos
2,473 Views
mjbcswitzerland
Specialist V

Hi

If you have a FRDM-KV11Z board you can load a reference binary (attached) which adds SD card support to the following pins:

PTC5 = SPI0_CLK
PTC6 = SPI0_SOUT
PTC7 = SPI0_SIN
PTC1 = chip select

On the OpenSDA VCOM UART there is a DOS-like interface (115kBaud) [menu 8 - utFAT Disk Interface] which allows formatting, listing card content, moving between directories, creating, renaming, etc and also viewing details of files and their objects.

  Disk interface
===================
up           go to main menu
info         utFAT/card info
dir          [path] show directory content
dird         [path] show deleted directory content
dirh         [path] show hidden content
infof        [path] show file info
infod        [path] show deleted info
cd           [path] change dir. (.. for up)
comp         compare [file1] with [file2]
file         [path] new empty file
write        [path] test write to file
mkdir        new empty dir
rename       [from] [to] rename
trunc        truncate to [length] [path]
copy         [file1] to [file2]
hide         [path] file/dir to hide
unhide       [path] file/dir to un-hide
prot         [path] file/dir to write-protect
unprot       [path] file/dir to un-protet
print        [path] print file content
del          [path] delete file or dir.
undel        undelete [name]
format       [-16/12] [label] format (unformatted) disk
fformat      [-16/12] [label] full format (unformatted) disk
re-format    [-16/12] [label] reformat disk!!!!!
re-fformat   [-16/12] [label] full reformat disk!!!!!
sect         [hex no.] display sector
help         Display menu specific help
quit         Leave command mode

With Visuals Studio it can also be tested (simulates the board, the KV11 and the SD card) if build from the uTasker project:

pastedImage_6.png

If you measure the signals you can also see a reference as to what is sent to the card so that you can work on solving the porting problems.

This is a standard solution in the uTasker project that works on any Kinetis part (with enough memory for a FAT - on any SPI or SDHC) without porting requirements (and on memory sticks when USB host is available). It allows professional projects to benefit from immediate complete and mature solutions rather than requiring porting from examples (projects can also be switched between processors without needing different libraries and re-porting efforts)

Regards

Mark

0 Kudos
2,473 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Abdullah Çınar,

  You need to debug the disk_initialize, disk_write and disk_read in the diskio.c at first, if these function can works OK, it means your SD card communication is OK, otherwise, you still need to check the sd card communication level, not the fatfst file side.

Kerry

 

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
2,473 Views
abdullah_cinar
Contributor III

Hi Kerry,

Thank you so much for your help. I didn't know we can do that.

By the way, if I change the device from MKV10Z32 to MKV11Z64, I can add FatFs and I can not select Kinetis Design Studio. Do you know why?

If it is not possible to proceed with MKV11, I will start with MKV10 and then try to use the drivers in the MKV11 since the APIs are similar.

Thanks,

Abdullah.

0 Kudos
2,470 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Abdullah Çınar,

  I have checked the KDS, both KV10 and KV11 is supported.

pastedImage_1.png

So you KV11 can use KDS IDE, but now, KDS won't update the new chip, we have transferred to the MCUXpresso IDE.

Wish it helps you!

Kerry

 

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
2,470 Views
abdullah_cinar
Contributor III

Hi Kerry,

I already use KDS for KV11, but I couldn't add the FatFS middleware to SDK package of KV11. But it's okay, I downloaded the FatFS middleware for KV10 and I translated them since I'm also familiar with KV10. 

Since this project is in production, I can not migrate the whole project to MCUXpresso, for now, I only need to add the SD card interface.

Thanks!

0 Kudos