Best Example for USB drive to SD card Writing

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

Best Example for USB drive to SD card Writing

2,533 Views
charles2
Contributor II

Hi,

I would like to make K66 development board as the device, and USB stick, connecting to Micro USB port, as the host. Then writing the files from the USB stick to the SD card. Is there an example for this purpose? If not, which one is the closest example I can modify.

Thanks!

0 Kudos
Reply
7 Replies

2,395 Views
charles2
Contributor II

I am trying to modify the codes in host_msd_fatfs.c file in order to add SDDISK works together with USBDISK. There is no error when I use f_mount function to add the SDDISK. 

However, when I tried to create & open a file on the SDDISK, it always return error code. I have tried  f_open(&file1, "2:file.bin", FA_WRITE | FA_READ | FA_CREATE_ALWAYS), f_open(&file1, test_file_name1, FA_WRITE | FA_READ | FA_CREATE_ALWAYS) where test_file_name1 is from sprintf(test_file_name1, "%c:", SDDISK + '0').

Then I look at the example in sdcard_fatfs, and tried to use make file function like f_mkfs(....), the result is similar to the f_open, always return an error code.

What am I missing?

0 Kudos
Reply

2,395 Views
Sabina_Bruce
NXP Employee
NXP Employee

Hello Charles,

Its possible that it may have to do with the string that is placed for the path and how it is taken.

Please take a look at the following post and try the different option to see if this is your case as well. 

If it does not work please let me know.

Best Regards,

Sabina

0 Kudos
Reply

2,395 Views
charles2
Contributor II

Hi Sabina,

Thanks for your reply. I have figured out the reason why FATfs is not working. It is because the SD card was not initialized. I found the boolean variable "g_sd_isHostReady" was Null. 

Main.PNG

Then I tried to add function "sdcardWaitCardInsert()" and associated files, however, it causes bus_fault and hard_fault after calling function "Port_SetPinInterruptConfig()". I have attached several screenshots for the variables when this function is called, as well as the screenshot when I run the original sdcard_fatfs example.

Faults.PNG

Is it caused by the conflict with USB_HOST interrupt or what?

Modified.PNG

Port_SetPinInterruptConfig2_Original.PNG

Before the function "PORT_SetPinInterruptConfig(BOARD_SDHC_CD_PORT_BASE, BOARD_SDHC_CD_GPIO_PIN, kPORT_InterruptEitherEdge);"     is called,  the value of user->cd changes to 0x128cc while the original working example's value is 0xa4e8. I tracked it back, the g_sd.usrParam.cd is the address of s_sdCardDetect, which is automatically generated.

Original SD config.PNG

Modified SD Config (wrong).PNG

Also, after entering "PORT_SetPinInterruptConfig()", the value of some variables are null while they are all 0 in the original example.

Any advice will be helpful, thanks in advance.

0 Kudos
Reply

2,395 Views
Sabina_Bruce
NXP Employee
NXP Employee

Hello Charles,

Hope you are doing well.

Could you please clarify the description of your application. From what I am understanding you would like the USB memory stick to work as a host. However this is not possible, a USB memory is a mass storage device. 

Please let me know if I misunderstood you. 

Hope it helps!

Sabina

-----------------------------------------------------------------------------------------------------------------------

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

----------------------------------------------------------------------------------------------------------------------- 

0 Kudos
Reply

2,395 Views
charles2
Contributor II

Sorry for the confusion, my mistake. I mean the K66 board as the host, and the memory stick works as slave. Then reading from USB memory and write to the SD card.

0 Kudos
Reply

2,395 Views
Sabina_Bruce
NXP Employee
NXP Employee

Hello Charles,

The examples that use host_msd are good options to get you started.

pastedImage_1.png

For more information on how each works please refer to the read me files located in the SDK folder using the followings paths:

SDK_2.7.0_FRDM-K66F.zip\boards\frdmk66f\usb_examples\usb_host_msd_command\freertos

SDK_2.7.0_FRDM-K66F.zip\boards\frdmk66f\usb_examples\usb_host_msd_fatfs\freertos

Please let me know if you have further questions.

Best Regards,

Sabina

2,395 Views
charles2
Contributor II

Thanks, Saniba.

0 Kudos
Reply