FatFs + SDHC data logger with KSDK in Kinetis Design Studio

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

FatFs + SDHC data logger with KSDK in Kinetis Design Studio

FatFs + SDHC data logger with KSDK in Kinetis Design Studio

Hello KSDK friends:

 

This time I want to share with the community a project using FatFs and the SDHC + I2C drivers provided with the Kinetis SDK platform. This is a baremetal project with no RTOS.

 

If you are a follower of colleague Erich Styger's MCU_on_Eclipse blog, then you might be familiar with the demo application, which consists of a data logger to store the accelerometer values of a FRDM-K64F on-board FXOS8700CQ (accelerometer/magnetometer) to a Micro SD Card.

 

The difference is that this demo project is implemented with KSDK v1.2 platform, using the next components:

 

- FatFs: Generic File System used in embedded systems.

- SDHC peripheral driver: To handle the SD Card commands.

- SD Card driver: Part of the KSDK composite drivers.

- I2C peripheral driver: Used to communicate with the on-board FXOS8700CQ.

- other peripheral drivers and systems: Clock System, GPIO driver, etc.

 

2 attachments are included with this post:

 

1) Demo project for KDS (created with KDS v3.0.0).

2) Document with a detailed description of how the project was created.

 

If when importing the project KDS asks you to add compiler search paths, just select "No". Paths are already configured.

 

IMPORTANT: The project can be placed in any location, but the next conditions must be met before building the project:

 

- Build the K64F KSDK platform library KDS project. The "Debug" build configuration is used. If not familiar with this, please refer to "Getting Started with Kinetis SDK (KSDK) v.1.2.pdf" in KSDK doc folder: C:\Freescale\KSDK_1.2.0\doc.

 

- Check that the build variable {KSDK_PATH} is pointing to your KSDK v1.2 installation (Project -> Properties -> C/C++ Build -> Build Variables):

 

41775_41775.pngKSDK_PATH.png

 

 

RUNNING THE DEMO

 

1- Load the application to the FRDM-K64F.

2- Connect the PC to the FRDM-K64F OpenSDA micro USB port.

3- Open a terminal software and connect to the OpenSDA Virtual COM port. Configure the terminal for a baud of 115200.

4- Reset the board. You will see this message:

 

41776_41776.pngpastedImage_6.png

 

5- Insert micro SD Card. Now terminal should look like this:

 

41798_41798.pngpastedImage_12.png

 

6-  Accelerometer values will start to be printed to terminal and logged to SD Card each second.

 

A safe remove mechanism is implemented. Press SW3 in FRDM-K64F until you see the message shown below:

 

41799_41799.pngpastedImage_14.png

 

Keep SW3 pressed until SD Card is removed.

 

7- Now with a PC you can open the file LOG_DATA.txt:

 

41801_41801.pngpastedImage_16.png

 

The file can also be opened by a software such as Excel to graph the results:

 

41802_41802.pngpastedImage_17.png

 

I hope you like this demo!

 

Regards.

Jorge Gonzalez

Labels (1)
Attachments
Comments

Great project, well done. I have also created a similar blog post with detailed steps on how to setup using the sd card on the FRDM K64F with KSDK 1.2.0 and Processor Expert. Between this blog and mine I'm sure a lot of pain is saved for people figuring this out. See my blog at: FRDM K64F Data Logger using FatFs with KSDK 1.2.0 | Centaurian

Very good tutorial Wesley, thank you for sharing! :smileyhappy:

Regards!

Jorge Gonzalez

Good morning

It is an interesting project. I am looking for a solution, for writing on a normal flash spi device. In my understanding the support is finalized for the sd card, and I cannot attach a normal device. Maybe. I see the function

SDSPI_DRV_SendCommand(sdspi_spi_t *spi,

                                            sdspi_request_t *req,

                                            uint32_t timeout)

is formatting the command to send expecting a specific device.

If I want to use my spi device? Is there a guideline for what to do???

Thank You

Pietro

Hello Pietro di Castri:

The FatFs File System requires some low level physical support which needs to be implemented by the user. In this case the KSDK platform provided the low level support for SD Cards using SPI interface or the SDHC controller module available in some Kinetis MCUs.

The functions required by FatFs are:

disk_status()

disk_initialize()

disk_read()

disk_write()

disk_ioctl()

get_fattime()

A description of these functions is in the official FatFs page.

Unfortunately I am not aware of any guidelines to use a SPI Flash module with FatFs but you surely could find something in the web.

Regards!

Jorge Gonzalez

Hei Jorge

Thank You for the follow up. I am trying to arrange the plan for this. In my understanding the files needed are:

ff.c AND diskio.c, this one is just a wrapper to the functions implemented elsewhere. Plus the header files.

The files in the directory .\fsl_sdspi_disk propose a solution for using the SPI with a determined device. I don t think I need. I need to provide a similar file with the interface to my SPI flash device. Fix me if You think it is ok.

I see the fsl_sdspi_disk.c has also a timer, is it necessary??

Another think about reentrancy, I see in ff.h

int ff_cre_syncobj (uint8_t vol, _SYNC_t* sobj);/* Create a sync object */
int ff_req_grant (_SYNC_t sobj);/* Lock sync object */
void ff_rel_grant (_SYNC_t sobj);/* Unlock sync object */
int ff_del_syncobj (_SYNC_t sobj);/* Delete a sync object */

Is there an example how to implement these functions with the KSDK???

Thank You

Best Regards

Pietro

Hei

I am trying to start up with the implementation.

Every help is welcome.

I Have the N25Q00AA.

I can deleted in units of 4096

So I find natural to assign the GET_SECTOR_SIZE to this size.

Also the GET_BLOCK_SIZE is assigned to this size.

The GET_SECTOR_COUNT is assigned to 32768, number of sectors.

It should work, my mumble is: is there a sense in giving to the GET_SECTOR_SIZE a

smaller size than the erasable size (GET_BLOCK_SIZE) ???

For example if I give to the GET_SECTOR_SIZE 256 while the erasable size still 4096, does it create

any conflict???

Another mumble is the writing. Should the write service take care of erasing and rewriting, of only writing supposing the driver

has already asked the erasing of the sectors going to be written???

Thank You

Pietro

Hello Pietro:

Responding to your earlier questions:

- Yes, diskio.c is a wrapper for the low level driver calls.

- fsl_sdspi_disk provides interface functions between diskio.c and the actual SD Card driver. Indeed you need to create an interface file for the SPI flash.

- I do not see a timer, but if you mean the timeouts then those are part of the KSDK SPI driver. The timeouts are used in the blocking functions to make them semi-blocking, so the application does not hang when a transfer is not completed. In such case the driver returns a timeout error. I think it is a good practice to use timeouts, but this is up to you.

About the implementation, to be honest I have not digged deep to see how FatFs handles the memory management.

Regards!

Jorge Gonzalez

Hello, I decided to import this program using KDS 3.0 and KDSK 1.2. I had a clock error which I addressed by omitting a line of code but now I'm getting the following:

Error (1 item)

make ***No rule to make target '/lib/ksdk_platform_lib/kds/K64F12/debug/libksdk_platform.a', needed by 'K64_FatFs_KSDK.elf. Stop.

Warnings (4 items)

Invalid project path: Include path not found (\platform\driver\inc)

Invalid project path: Include path not found (\platform\hal\inc)

Invalid project path: Include path not found (\platform\osa\inc)

Invalid project path: Include path not found (\platform\system\inc)

Any ideas on how to resolve these errors and warnings?  Thank you!

Hello Efrain:

As mentioned in this document post you need to first build the KSDK platform library and also make sure that the KSDK_PATH build variable is correct. Refer to "Getting Started with Kinetis SDK (KSDK) v.1.2.pdf" in KSDK doc folder: C:\Freescale\KSDK_1.2.0\doc.

Regards!

Jorge Gonzalez

Hi Jorge,

I am having issues going from your previous example you created for the kds 3.0 KSDK 1.3

to kds 3.1 ksdk 2.0. can you please take a look at my  SDK 3.1 + KSDK 2.0 + SD card driver

Thank you,

Neil

Hello Jorge,

Thanks for the response.  I had worked through those sections previously but I decided to perform the building of the library again.  After building the library again I am still getting the same error:

Error (1 item)

make ***No rule to make target '/lib/ksdk_platform_lib/kds/K64F12/debug/libksdk_platform.a', needed by 'K64_FatFs_KSDK.elf. Stop.

I was able to correct all of the warning by editing the includes within the project properties.  I had to add 'Project' to beginning of the Includes paths: for example, "${PROJECT_KSDK_PATH}/platform/drivers/inc".  I did this for each warning that I got and it cleared them up.  But I am still getting the above error.  I have re-imported the program, tried downloading the program again, and even worked through every step within the PDF attached.  Any further ideas why I am getting this error.  It seems like this specific file is not in that location even though all the settings within the project check out.  Let me know if you have any further ideas.  Thank you. 

Efrain

Hi Efrain,

The error is referring to this:

Erase.jpg

Please make sure you have Other linker flags: -specs=nano.specs -specs=nosys.specs

but that is not your error.

The error stems from KSDK 1.3.0 (lack of) installation of the ksdk_platform_lib.

Follow the instructions here:

Appendix B – Build the KSDK platform library

If you already did this, then make sure to compile the project after following the instructions.  It will place

the ksdk_platform_lib file inside of KSDK 1.3.0 and satisfy that error....

Hopefully that will be the last one, if not Ooooh boy get ready!

I will look from time to time and help as much as I can.

Cheers hope this helps!

Neil Porven

Hello,

I have gone through the rebuilding of the library many times and I just rebuilt then compiled the program and still the same error.  It seems like all it needs is that one file in that specific location.  I wonder if I can import or add that file to that location manually.  If you have any other ideas let me know.  Thank you. 

DescriptionResourcePathLocationType
make: *** No rule to make target `/lib/ksdk_platform_lib/kds/K64F12/debug/libksdk_platform.a', needed by `K64_FatFs_KSDK.elf'.  Stop.K64_FatFs_KSDKC/C++ Problem

Hello Efrain:

The path in that error is incomplete. If the library is not compiled it should report something like this:

pastedImage_0.png

So I guess you have not confirmed the KSDK_PATH variable as advised. Ultimately it does not matter if you use KSDK_PATH or PROJECT_KSDK_PATH (these are called build variables) but you need to be sure that either one being used is pointing to the correct path. Mark the check box for "Show system variables":

pastedImage_3.png

When setting paths also pay attention to the KSDK version. I built the project with KSDK v1.2, but I think you downloaded KSDK v1.3.

Then in the linker settings check that the path to the library is correct:

pastedImage_4.png

Let me know if the error is not resolved.

Regards,

Jorge Gonzalez

Hello,

I really appreciate your help with this.  I would really like to get this working.  I have gone through all of the steps here.  Everything pretty much matches up.  I am even tried to reinstall the programs:  KDS 3.0 with the update to 3.1.0 along with KDSK 1.2.0.  I am still getting the same error message.  One thing I noticed is that the error message has forward slashes in the directory path while in the property Build Variables path it has back slashes.  I am not sure if that would make a difference.  I will try and change that and see if anything changes.  If you have any further ideas please let me know. Again...thank you!

Efrain

Hi Efrain,

Did the slashes help your issue?  Sometimes, something as small as slashes or missed " " can  make things fail.

Neil Porven

No ratings
Version history
Last update:
‎06-24-2015 03:15 PM
Updated by: