Using KSDK 1.1, KDS 2.0
I'm developing a data-logger using the FRDM-K64F
Basically I want a "double" application:
- normal behavior: data logging
- alternate behaviour, when program starts with USB cable connected (to the K64F USB connetor): MSD (so I can read the files saved on the SD card when in data-logging mode)
The data logging works, and I tried the MSD example (and it works).
Now I'm trying to merge the two.
What I wish to do is choose between the two mode at startup: if the USB cable is not conneted -> datalogging, if the USB cable is connected (so the board is connected to a PC) -> MSD.
Some ideas how to do that?
Thanks Regards Giacomo
PS: what throughput I should expect tranfering data from the SD card to a PC (using USB-MSD)?
Hi giacomopetrini,
you may check power on usb (if is connected to computer or if you need power supply).
Look at the schematic FRDM-K64F http://cache.freescale.com/files/microcontrollers/hardware_tools/schematics/FRDM-K64F_SCH.pdf
Pin 10 on connector J3, page 4. Connect to any pin but through a voltage divider. And the voltage divider connect to any pin and check log 1 or log 0.
You need the voltage divider because the pins are not 5V tolerant and must be here 3.3V maximum.
And with your SD card - you can rewrite the SD - like USB Stack and with the second USB you can send the data away.
I hope it helps.
Iva
Hello,
thanks for the tip, butI can't use it because on top of the FRDM-K64F there is a "shield" that I designed and it would be difficult to access the P5V_USB pin.
On the other hand the board will be powered by a battery when "on the field": the shiled has a DCDC converter and I read the battery voltage, so I can just read the bat. voltage and if 0 just assume that I'm powering it through the USB cable and switch to MSD mode...
But I hoped that there was some sort of mechanism integrated in the USB module to automatically detect when the device is connected/disconnected to a host.
Regards Giacomo
Hi giacomopetrini,
voltage you may to read.
Please, which of these examples do you use? dev_msd_disk_frdmk64f_mqx, dev_msd_disk_frdmk64f_bm ?
Many thanks,
Iva
bare metal.
Hi,
if you go to disc.c, you can add the printf if your device is e.g. Attached.
go to void USB_App_Device_Callback(uint8_t event_type, void* val,void* arg)
and add following line
if(event_type == USB_DEV_EVENT_BUS_RESET)
{
g_disk.start_app=FALSE;
}
else if(event_type == USB_DEV_EVENT_ENUM_COMPLETE)
{
g_disk.start_app=TRUE;
USB_PRINTF("\n\rAttached\r\n");
}
and for rejected device (which you must eject by right click on the Removable Disc in Computer)
and add the following line:
switch(event_type)
{
...
case USB_MSC_START_STOP_EJECT_MEDIA :
/* Code to be added by user for starting, stopping or
ejecting the disk drive. e.g. starting/stopping the motor in
case of CD/DVD*/
USB_PRINTF("\n\rRejected\r\n");
break;
}
now you have an information, when the device was attached and rejected so if you create global variable e.g. unit8_t usb_attached = 0;
and above mentioned fuctions you can change this global variable. In your your logger task you can compare this variable and enable/disable logging.
I hope it helps,
Iva
OK.
But what I want to do is sense if I need to go to USB mode or normal mode before starting the USB stuff.
I hoped that the USB module in the K60 had some hw flag that is set if a usb cable is connected and reset if the cable is disconneted.
Thanks anyway
Regards Giacomo
PS: it helps anyway, but not for the purpose of my question :smileywink: