How to write / read data to a USB memory stick by using KSDK and Processor Expert

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

How to write / read data to a USB memory stick by using KSDK and Processor Expert

1,360 Views
MAPC
Senior Contributor I

Hello,

 

I'm starting a new project and I need to implement a data logger in a USB memory stick with K22, but I'm not very experienced in this area, I found the documentation of the KSDK drivers API, but I don't know which function to use to correctly do it.

 

I found an interesting document posted in this Community, explaining step by step how to quickly create a RAM disk demo with KSDK and Processor Expert, that can be used as reference and adapt to my application needs, but this demo only formats the memory stick.

 

I still don't know how to create, open, close and manipulate files into the USB memory stick, and write and read data to / from USB memory stick, by using the available KSDK API functions.

 

Can anybody guide me on that or provide me with some examples?

 

 

Thanks and best regards,

 

 

Marco Coelho

Labels (1)
0 Kudos
4 Replies

847 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

Hello Marco Aurelio:

You need the USB MSD Host class and also a file system for the file operations (f_open, f_write, etc).

Take the example from KSDK v1.2 at the next path:

C:\Freescale\KSDK_1.2.0\examples\frdmk22f\demo_apps\usb\host\msd\msd_fatfs

To compile that example you first need to build the SDK platform library and USB Host library. Refer to the file Integration of the USB Stack annd Kinetis SDK on how to build the required libraries.

Let us know if you have issues or doubts.

Regards!

Jorge Gonzalez

0 Kudos

847 Views
ivadorazinova
NXP Employee
NXP Employee

Hello Marco,

examples for USB are located at <ksdk_path>\examples\frdmk22f\demo_apps\usb

There are examples for both - device and host, and the documentation for USB Stack is under folder doc\usb

Please, look at the examples sdbench and sdcard located at <ksdk_path>\middleware\filesystem\mfs\examples

there are example without PEx.

In other case FatFS and SDHC data logger example is here

FatFs + SDHC data logger with KSDK in Kinetis Design Studio

I hope this helps you.

Iva

0 Kudos

847 Views
MAPC
Senior Contributor I

Hi, Iva

In this demo, a list of commands are executed, including Write and Read commands in the USB memory stick, but it seems that it doesn't create a .txt file before. As far as I understand the correct way to do it is creating a file and then write / read to / from the file inside the USB memory stick. So, I don't understand how this demo works and I didn't find any document explaining these commands in detail.

I'm not sure if this stack supports functions like fopen, fmount, putchar, getchar to do it.

Could you put it in more detail to me, please?

0 Kudos

847 Views
ivadorazinova
NXP Employee
NXP Employee

Hi Marco,

if you take a look at the example code sdbench and mfs_benchmark.c there are operations with file.

There are no operations as fopen, fclose etc., they were replaced by new ones :

For example

operation for open file

file_ptr = open(file_name, write_mode);

operation for write

wr = write(file_ptr, data_ptr, block_size);

operation for read

rd = read(file_ptr, data_ptr, block_size);

operation for close

close(file_ptr);

I hope this helps.

Regards!

Iva

0 Kudos