Hardware and software configuration:
- FRDM-K22F, SCH-28164 REV D
- OpenSDA: J-Link firmware
- KDS 3.0 with SDK 1.2.0 Eclipse update installed
KSDK 1.2 provides an Eclipse update for those who want to use the Kinetis SDK with Eclipse and Processor Expert. and with this update , users may find MSD Class component has been supported, and there is a simple USB mass storage demo available directly in this PEx USB component, so that customers may easily build this demo and develop their own application based on that.
Here I will start to illustrate how to implement this demo step by step.
As FRDM-K22F is used in this test, so I directly choose this board and make the following configuration:
After above steps, we have a PEx project with some pre-installed components as shown below:
clockMan1 components has 6 configurations , and one of it is for USB application, you may set it as the init configuration right now, or it would be set automatically when you add the USB MSD components.
Now I find the MSD component from KSDK 1.2 and add it to my project:
This component will add 4 more reference components into this project, and we only have to configure the component "fsl_debug_console" to get rid of the error mark.
For FRDM-K22 board, UART1 is used as the debug console, and PTE0 and PTE1 are used as the TXD and RXD, so I set up this components as below:
The simple MSD demo is a RAM disk demo, and it is disabled by default, so we have to enable it in the fsl_usb_device_msd_class component, and the demo code will be automatically added into the project afterwards:
and then set the correct PID and VID information in the component of fsl_usb_descriptors.
so far looks like all components are configured correctly , but if we directly download this application, we will have an enumeration issue like below:
This is due to USB descriptors are placed to Flash memory area by default . You know , USB descriptors contain constant values so storing them in flash would leave more RAM for user application. The highlighted option in the following figure determines this .
but USB module in Kinetis doesn't have the permission for flash out of reset, so we still have something to do before going ahead.
There are several solutions for it, the most easiest way is setting the above option to "no", but we may do it in a PEx-like way by using the "Init_FMC" component.
Please note USB is the M4 of K22's crossbar-lite. so we give it the "read only" permission.
Init_FMC() is placed in Peripherals_Init() which is called right before Components_Init() where USB_Class_MSC_Init () is in, so it guarantees USB have the flash access permission before it starts up.
Now the demo can work well with the PC host, just as shown below:
So far only HID and MSD Class components are supported, and if you go through a similar process as above, you may easily implement a HID demo by yourself. Here I attach both the MSD and HID mouse demo for your reference.
Hope that helps,