Quantcast
Channel:
Viewing all articles
Browse latest Browse all 59170

Forum Post: RE: Adding USB Host Class Storage Device to working example

$
0
0
The example hasn't been published, but I have a running USB mass host and its configuration looks as following: create a new thread, add USBX and USBX Port, enable the USBHS USB INT RESUME interrupt for USBX Port go to components and add (on top of the two that have been added already): fx, ux_host_class_hub and ux_host_class_storage in your thread, add following include directives: #include "fx_api.h" #include "ux_api.h" #include "ux_hcd_rx.h" #include "ux_host_class_storage.h" #include "ux_host_class_hub.h" create a variable and allocate it 65536 bytes, this will be your USB host memory (I called it char g_msc_memory[MSC_DRIVER_MEMORY]) create following variables to store the configuration for your connected device/open files: static UX_HOST_CLASS_STORAGE *g_storage = UX_NULL; static UX_HOST_CLASS_STORAGE_MEDIA *g_storage_media = UX_NULL; static FX_MEDIA *g_media = FX_NULL; static FX_FILE g_my_file; * create following function to respond to USB events: UINT host_change_function(ULONG event, UX_HOST_CLASS * class, VOID * instance) { UINT            status; UX_HOST_CLASS   *storage_class;    /* Check if there is a device insertion.  */    if (UX_DEVICE_INSERTION == event)    {        /* Get the storage class.  */        status = ux_host_stack_class_get(_ux_system_host_class_storage_name, &storage_class);        if (UX_SUCCESS != status)        {            return(status);        }        /* Check if we got a storage class device.  */        if (storage_class == class)        {            /* We only get the first media attached to the class container. */            if (UX_NULL == g_media)            {                g_storage = instance;                g_storage_media = class - ux_host_class_media;                g_media = &g_storage_media - ux_host_class_storage_media;            }        }    }    /* Check if some device is removed.  */    else if(UX_DEVICE_REMOVAL == event)    {        /*  Check if the storage device is removed.  */        if (instance == g_storage)        {            /* Set pointers to null, so that the demo thread will not try to access the media any more.  */            g_media = UX_NULL;            g_storage_media = UX_NULL;            g_storage = UX_NULL;        }    }    else    {        /* Default case, nothing to do */    }    return(UX_SUCCESS); } your USB host thread should have the following code: UINT status; /* Initialize FileX. */ fx_system_initialize(); status = ux_system_initialize(&g_msc_memory, MSC_DRIVER_MEMORY, UX_NULL, 0); if (UX_SUCCESS != status) while(1); /* The code below is required for installing the host portion of USBX */ status = ux_host_stack_initialize(host_change_function); if (UX_SUCCESS != status) while(1); /* Register all the host class drivers for this USBX implementation. */ status = ux_host_stack_class_register("ux_host_class_hub", ux_host_class_hub_entry); if (UX_SUCCESS != status) while(1); status = ux_host_stack_class_register("ux_host_class_storage", ux_host_class_storage_entry); if (UX_SUCCESS != status) while(1); /* Register all the USB host controllers available in this system */ err = ux_host_stack_hcd_register("RX-USB0", _ux_hcd_rx_initialize , UX_RX_CONTROLLER, UX_RX_CONTROLLER_RX62N); if (UX_SUCCESS != err) while(1); while (UX_NULL == g_media) tx_thread_sleep(1); And now your device is ready to access the file system using FileX commands. I hope this helps

Viewing all articles
Browse latest Browse all 59170

Trending Articles