On my custom board based on K66F180 cpu I have successfully developed an application that handles memory sticks on USB Host.
I have developed my application with KDS 3.1.0 and KSDK 1.3.0 + PEx. My application is based on MQX RTOS Standard and I created my project following the tutorial How To: Create an MQX RTOS for KSDK project with Processor Expert in Kinetis Design Studio IDE .
Following the tutorial FRDM K64F Data Logger using FatFs with KSDK 1.2.0 | Centaurian and the host_msd_fatfs_mqx_twrk65f180m demo project provided with KSDK 1.3.0, I chose FatFs file system for the USB mass storage devices.
Now, on the same board I am developing another application that handles memory sticks on USB Host. This second application is more simple than the first one (it's a custom USB Host MSD bootloader), so I chose the OSA BareMetal mode provided with PEx. I use the same USB Host and FatFs source files of my first application.
In my application based on the OSA BareMetal mode I defined two task: the main Boot_task and the USB_task. Like in my first application, the USB_task waits for attach/detach events and mounts the FatFs file system on a successfully attached mass storage device.
I run into the following issues:
I know USB Host core creates some internal OS_tasks, OS_events, OS_MessageQueues and OS_Mutex: for this, there is an adapter interface to the current SDK OS abstraction.
Issue 3. looks like some internal task or event related to the control-pipe transactions is not running properly in my OSA BareMetal system.
I have the macro OS_ADAPTER_ACTIVE_OS = OS_ADAPTER_SDK in the adapter_cfg.h header file. The macro USE_RTOS = 0 (no RTOS is used). In this condition msd_disk_ioctl(), msd_disk_read() and msd_disk_write() functions call the OSA_PollAllOtherTasks() function while waiting the command end. So the internal USB tasks should run and process the command transaction
OSA BareMetal mode is a possible choise also in the host_msd_fatfs_mqx_twrk65f180m demo project provided with KSDK 1.3.0.
What is the right configuration for the USB Host stack working in OSA BareMetal mode?
Thanks.
Hello Alessandro,
I am glad you could get your project working in both boards. About PTA28 and PTA29 in TWR-K65F180M, I will try to report this issue to documentation team, so I could expect that User Manual gets updated with this useful information.
I am still editing a document that lists the steps needed to create a basic USB Host MSC + fatfs + KSDK 1.3 + PEx project for future references, will let you know when this is completed.
If more help is needed just let me know it!
Regards,
Isaac
Hi Alessandro Vagniluca,
As I know, PEx for ksdk 1.3 doesn't support Host MSD class, so maybe there is any compatibility issue.
but there is a bare metal demo for msd_fatfs based on TWR-K65F180M , you may find it in the folder of "C:\Freescale\KSDK_1.3.0\examples\twrk65f180m\demo_apps\usb\host\msd\msd_fatfs\bm", how about using it as a starting point?
Hope that helps,
Have a great day,
Kan
NXP Technical Support
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Dear Kan,
Yes, I know PEx for KSDK 1.3.0 provides only the fsl_usb_framework component for USB Host functionality.
As I said, in my previous MQX_Standard project I got USB Host MSD working properly, just using the fsl_usb_framework component to define and initialize the USB Host driver and then manually adding to my project the source files from the "<KSDK_1.3.0>\usb\usb_core\host" library folder (I am working on my custom board, I haven't got a TWR-K65F180M).
I loaded the fsl_usb_framework PEx component and configured it in Host mode to generate the driver information table for USB_CLASS_MASS_STORAGE with USB_SUBCLASS_MASS_UFI and USB_SUBCLASS_MASS_SCSI sub-classes and USB_PROTOCOL_MASS_BULK protocol. I use the same usb_host_mass_device_event() MSD event call-back function and my USB task has the same architecture of APP_Task() function in the host_msd_fatfs_mqx_twrk65f180m demo project provided with KSDK 1.3.0.
On a USB_DEVICE_INTERFACE_OPENED mass device state event I call f_mount() to mount the FatFs file system on the attached USB memory stick and I signal the available mass storage device ready to all the other tasks.
Now, I copied my previous working project in a new one and I based this one in OSA BareMetal Mode with only the 3 task needed by custom USB Host MSD bootloader. In this my new project the USB task keeps the same architecture of APP_Task() function in the host_msd_fatfs_mqx_twrk65f180m demo project.
I see the macro TASK_MAX_NUM is set to 5 in <MY_PROJECT>\SDK\platform\osa\inc\fsl_os_abstraction_bm.h header file generated by PEx. How many internal tasks are created by the USB Host core?
In my project I have the macro _DEBUG=1 to enable the debug output on the Debug Console: in fact, I have got the occurrence of issue 2. "3TR Timeout!" through the Debug Console. But I receive no other error messages from the USB Host core.
Best regards,
Alessandro
Hello Alessandro,
I could notice that there is a failure in your project when it tries to mount fatfs in the MSD, it seems to be a NULL pointer that would handle the information for attached device, then, host tries to detach the device and re-enumerate again but it does not matter how many times the device is enumerated, the problem is always shown.
I've created a basic USB Host + PEx + Fatfs 0.09 + KSDK 1.3 and BareMetal implementation example that seems to be working properly. Next image shows how the system is mounted correctly and some IOCTL functions are sent to device correctly.
I hope this can help you!
Best Regards,
Isaac Avila
Dear Isaac Avila
I'm working under K64, do you have this example project (BM + USB Host) for this processor (K64)?
Hello Yaniv,
I think that you are looking for this document: USB Host Project with KSDK 1.3 and Processor Expert
Hope this helps!
Regards,
Isaac Avila
This is very helpful
In any case i'm tring to create a bootloader Base on USB as a host and I
Wonder if you have this kind of example?
What should I need to do in order to create such process with the BM OS
(goto /swap etc.) ?
בתאריך יום ב׳, 23 במאי 2016, 19:01, מאת isaacavila <
admin@community.freescale.com>:
NXP Community
<https://community.freescale.com/resources/statics/1000/35400-NXP-Community-Email-banner-600x75.jpg>
Problems Using USB Host MSD with KDS + PEx + FatFs in OSA BareMetal Mode
reply from isaacavila
<https://community.freescale.com/people/isaacavila?et=watches.email.thread>
in Kinetis Software Development Kit - View the full discussion
<https://community.freescale.com/message/653164?et=watches.email.thread#comment-653164>
Hello Yaniv,
Unfortunately, I do not have such example, the only reference for this bootloader could be this application note http://cache.nxp.com/files/microcontrollers/doc/app_note/AN4368.pdf but this is using MQX. You would need to migrate this for KSDK but maybe this AN can help you!
Hope this helps!
Regards,
Isaac
Dear Isaac,
Thank you for your help. Now I have my custom USB Host MSD bootloader firmware working properly in OSA BareMetal mode both on the TWR-K65F180M and on my custom board based on K66F180 cpu.
I see it is mandatory to flag both MPU and FMC settings in the PEx fsl_usb_framework component:
The usbFmw1_host_soc_init() function in the generated usbFmw1_host_bsp.c file automatically enables MPU clock gating and then disables MPU.
The USB task priority must be set to 4 (KHCI task priority is set to 3).
Also, the usbFmw1 component is set to be auto-initialized for convenience at startup. If after the startup my USB task deinitializes the USB Host driver and then re-initializes it (to see if the USB Host driver is well initialized and ready), then the USB Host driver does not work any more. So, I have to trust all the auto-initializations made at startup.
Working with USB on the TWR-K65F180M, care must be taken on driving the two leds D8 and D9 of the two touch pads for visual application signals: these leds are driven by PTA28 and PTA29 cpu port-pin, which are the same GPIO4 and GPIO6 who drive the USB power switch on the TWR-SER board. Blinking those leds causes VB_HOST supply to be disabled. It should be remarked in the TWR-K65F180M user manual.
Best Regards,
Alessandro