How to use USB host just for powering the FRDM-K64F device?

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

How to use USB host just for powering the FRDM-K64F device?

Jump to solution
1,640 Views
mahendranmanoha
Contributor III

I am using FRDM-K64F board to record data to SD Card. And I added the USB MSD functionality in the device to access the SDCard through USB. My end device will have provisions to operate with Battery power and/or USB power.

Two questions are

1. When my device is recording the data to SD Card, If I connect to USB Host, I don't want the USB MSD functionality to be active (I can do this by not enabling the USB functionality in the code). However, I don't want USB Host to suspend the USB device, but I'd like to have the Host keeps supplying power without USB device functionality enabled. How can I do that?

2. When my data recording stopped (with USB connected to Host), I can enable K66F USB device MSD functionality. But I'd like to know, how to let the Host knows that USB device is connected without physically unplug and replugging in USB.

Thanks,

Mahendran.

Labels (1)
1 Solution
1,384 Views
jorge_a_vazquez
NXP Employee
NXP Employee

Hi Mahendran Manoharan

There isn't any physical FET or a way to disconnect only Data lines in the USB, so I think that you would need to deinitialize the USB protocol that you initiate and then reinitialized it again when you need to use USB again, so USB host can correctly identify this.

USB_DeviceStop
USB_DeviceClassDeinit

Best regards

Jorge Alcala

View solution in original post

5 Replies
1,384 Views
jorge_a_vazquez
NXP Employee
NXP Employee

Hi Mahendran Manoharan

If I understand correctly, you are using the frdm board with usb_device_msc_sdcard example, so if you connect your frdm you can write to the SDcard, am I correct?

If you want to keep VBUS connected to supply your MCU but not USB communication, then you would need to disconnect D+ D- from the Host USB, so the Host and the MCU can detect a detach event. 

Hope this helps

Best regards

Jorge Alcala

0 Kudos
1,384 Views
mahendranmanoha
Contributor III

Dear Jorge,

Thanks for your response.

Yes, I am using the example you mentioned. Yes, I need to access SD Card through my program without enabling the USB MSD device in the software. As you said, if I need to disconnect D+ and D- lines, how can I do it through software, Is there a FET switch in K64F through which I can disconnect?

Besides, Once I completed my task functions with SD Card. I'd like to enable the USB MSD functionality for the host to detect the device as MSD without disconnecting and reconnecting the device. (I think the answer is same, I need to connect the D+ and D- lines)

So, the question would be how can connect and disconnect the data lines through software?

Thanks for your kind help Jorge,

Best regards,

Mahendran

PS: I was thinking about using the composite device functionality with a primary interface as CDC and secondary interface as MSD. So, when my device is connected it will act as CDC, during that I can complete my tasks. Once the tasks are completed, I switch the interface to MSD, so I need not disconnect and reconnect the USB and I can access SD Card in my program whenever I want by switching the interface. 

I would like to get suggestions from you about this thought process.

0 Kudos
1,385 Views
jorge_a_vazquez
NXP Employee
NXP Employee

Hi Mahendran Manoharan

There isn't any physical FET or a way to disconnect only Data lines in the USB, so I think that you would need to deinitialize the USB protocol that you initiate and then reinitialized it again when you need to use USB again, so USB host can correctly identify this.

USB_DeviceStop
USB_DeviceClassDeinit

Best regards

Jorge Alcala

1,384 Views
mahendranmanoha
Contributor III

Hi Jorge Alcala,

Its been a long time since resolving the K64F USB connection /disconnection issue.

For stopping USB MSC:

USB_DeviceStop(g_msc.deviceHandle);
USB_DeviceClassDeinit(CONTROLLER_ID);

For Restarting USB MSC:

g_msc.speed = USB_SPEED_FULL;
g_msc.attach = 0;
g_msc.mscHandle = (class_handle_t)NULL;
g_msc.deviceHandle = NULL;
USB_DeviceClassInit(CONTROLLER_ID, &msc_config_list, &g_msc.deviceHandle);
USB_DeviceRun(g_msc.deviceHandle);

I presently implemented the above code and the code work perfectly fine when there is no transfers happening. I created a scenario by copying a huge file to K64F USB drive. When the file is being copied, I tried to disable the USB functionality. USB functionality disconnected successfully. But after that, program execution and stuck in an infinite loop of 

file:          usb_device_ehci.c

function:      USB_DeviceEhciCancel() 

line:                  while (ehciState->registerBase->EPFLUSH & primeBit).

I tried a little bit more also by disabling/enabling clock, SD card and interrupt in proper sequence. But still the same result. Is there a way, I can connect and disconnect the USB functionality like a normal USB Drive even if there is any transfers happening?

Surprisingly, I tried disconnecting and connecting the USB cable (used for MSC) again while the transfer is made. There were no issues at all. It worked the way that everyone would expect.

best regards,

Mahendran

0 Kudos
1,384 Views
mahendranmanoha
Contributor III

Thanks Jorge Alcala for being patient about my primitive question and answering it.

You answer completed cleared my doubt regarding enabling/disabling the USB device functionality, which is very important for finalising my architecture.

Best regards,

Mahendran

0 Kudos