FAT on USB Mass Storage

Hi,

 

I would like to use the USB port to connect a memory stick and use it read/write files.

I have a old example here which uses "g_fx_media0 FileX on USB Mass Storage".

I am currently using SSP 1.2.1 and I am not finding this framework to add to my project.

 

Which framework should I use to achieve what I need?

Parents
  • Hi Mad River,

    You can find this stack in X-Ware > FileX > FileX on USB Mass Storage. In USBX on ux configuration make sure to set USBX Pool Memory Size to 65536 bytes and probably you may want to enable Auto Media Initialization in the top-level block of this stack.

    Regards,
    adboc
  • Hi adboc,

    I inserted the stack as you indicated.
    Tried to compile it and got these errors:

    ../src/synergy_gen/common_data.c: In function 'ux_host_init0':
    ../src/synergy_gen/common_data.c:299:59: error: 'SYNERGY_NOT_DEFINED_initialize' undeclared (first use in this function)
    SYNERGY_NOT_DEFINED_initialize, SYNERGY_NOT_DEFINED,
    ^
    ../src/synergy_gen/common_data.c:299:91: error: 'SYNERGY_NOT_DEFINED' undeclared (first use in this function)
    SYNERGY_NOT_DEFINED_initialize, SYNERGY_NOT_DEFINED,
    ^
    ../src/synergy_gen/common_data.c:300:59: error: 'UX_SYNERGY_CONTROLLER' undeclared (first use in this function)

     

     

    The function is that one:
    void ux_host_init0(void)
    {
    /** Register a USB host controller. */
    UINT status_g_ux_host_0 = ux_host_stack_hcd_register ((UCHAR*) "SYNERGY_NOT_DEFINED",
    SYNERGY_NOT_DEFINED_initialize, SYNERGY_NOT_DEFINED,
    UX_SYNERGY_CONTROLLER);
    if (UX_SUCCESS != status_g_ux_host_0)
    {
    g_ux_host_0_err_callback (NULL, &status_g_ux_host_0);
    }
    }

    What should I create to replace SYNERGY_NOT_DEFINED_initialize, SYNERGY_NOT_DEFINED and UX_SYNERGY_CONTROLLER?

     

     

     

    EDIT:

    I saw this is new content from 1.2.1.

    The only examples I could find are using 1.2.0.

    Is there any examples of how to use the FX on USB in the new 1.2.1? (Or at least how to compile the auto-generated code)

     

Reply
  • Hi adboc,

    I inserted the stack as you indicated.
    Tried to compile it and got these errors:

    ../src/synergy_gen/common_data.c: In function 'ux_host_init0':
    ../src/synergy_gen/common_data.c:299:59: error: 'SYNERGY_NOT_DEFINED_initialize' undeclared (first use in this function)
    SYNERGY_NOT_DEFINED_initialize, SYNERGY_NOT_DEFINED,
    ^
    ../src/synergy_gen/common_data.c:299:91: error: 'SYNERGY_NOT_DEFINED' undeclared (first use in this function)
    SYNERGY_NOT_DEFINED_initialize, SYNERGY_NOT_DEFINED,
    ^
    ../src/synergy_gen/common_data.c:300:59: error: 'UX_SYNERGY_CONTROLLER' undeclared (first use in this function)

     

     

    The function is that one:
    void ux_host_init0(void)
    {
    /** Register a USB host controller. */
    UINT status_g_ux_host_0 = ux_host_stack_hcd_register ((UCHAR*) "SYNERGY_NOT_DEFINED",
    SYNERGY_NOT_DEFINED_initialize, SYNERGY_NOT_DEFINED,
    UX_SYNERGY_CONTROLLER);
    if (UX_SUCCESS != status_g_ux_host_0)
    {
    g_ux_host_0_err_callback (NULL, &status_g_ux_host_0);
    }
    }

    What should I create to replace SYNERGY_NOT_DEFINED_initialize, SYNERGY_NOT_DEFINED and UX_SYNERGY_CONTROLLER?

     

     

     

    EDIT:

    I saw this is new content from 1.2.1.

    The only examples I could find are using 1.2.0.

    Is there any examples of how to use the FX on USB in the new 1.2.1? (Or at least how to compile the auto-generated code)

     

Children
  • I tried to replace:

    /** Register a USB host controller. */
    UINT status_g_ux_host_0 = ux_host_stack_hcd_register ((UCHAR*) "SYNERGY_NOT_DEFINED",
    SYNERGY_NOT_DEFINED_initialize, SYNERGY_NOT_DEFINED,
    UX_SYNERGY_CONTROLLER);

     

    for:

    /** Register a USB host controller. */
    UINT status_g_ux_host_0 = ux_host_stack_hcd_register ((UCHAR*) "Anything",
    ux_hcd_synergy_initialize, UX_SYNERGY_CONTROLLER,
    UX_SYNERGY_CONTROLLER_S3A7);

     

    But the e2studio undo my changes when I compile the code! The code goes back to its original content (which doesn't compile!).

    So, the Synergy generate a file that doesn't compile and I can't edit that file.

    Now, what can I do?

  • Hi Mad River,

    The SYNERGY_NOT_DEFINED is a place holder because you have not selected a required module and configured it.

    Please verify your configuration is correct.  You can not edit files in the synergy or the synergy_gen folders because they are auto-generated when you build.  You must change your configuration in the Synergy Configurator to fix these files.

    Here is an example of properly configured USB mass storage host configuration:

    -Gary

  • Hi Gary,

    I was missing the HCD module. I was expecting that the Synergy would not generate the code if something is missing, but it doesn't show any sort of error in the Threads tab.

    Anyway, it compile now! Tomorrow I will test it.

    Thank you very much!
  • HI Mad River,

                   As Gary indicated, your SSP configuration is incomplete so some parameters are missing from the Synergy_cfg, etc. I attached USBX_Mass_Storage_Host_PKS5D9.zip as an example to show how to configure and setup in the SSP1.2.1. The pool memory size is dependent on your selected device and USB classes. The SSP User Manual lists recommended pool sizes for these combinations. Please let me know if you have any questions. Thanks

    Joe

  • Hi everyone,

    Thanks to your help I was able to compile the generated code.

    Now, I am trying to run it.
    As soon I resume the application, my program goes to:

    void g_fx_media0_err_callback_failed_to_get_fx_media_internal(void * p_instance, void * p_data)
    {
    /** Suppress compiler warning for not using parameters. */
    SSP_PARAMETER_NOT_USED (p_instance);
    SSP_PARAMETER_NOT_USED (p_data);

    /** A FileX media control block for a USB mass storage device was not found. */
    BSP_CFG_HANDLE_UNRECOVERABLE_ERROR (0);
    }

    Am I missing some initialization?

     

     

    EDIT:

    Deeper debug indicates that the problem occurs here:

    void fx_media_init_function0(void)
    {
         /** Suspend the thread until a USB Mass Storage Device inserted. */
         UINT err_g_fx_media0_semaphore_get = tx_semaphore_get (&ux_host_storage_semaphore_insertion, 1000);
         if (TX_SUCCESS != err_g_fx_media0_semaphore_get)
        {
              g_fx_media0_err_callback_failed_to_get_fx_media (&ux_host_storage_semaphore_insertion,
              &err_g_fx_media0_semaphore_get);
        }

     

    I am confused about this comment "/** Suspend the thread until a USB Mass Storage Device inserted. */"

     

    In my application the USB memory stick is not inserted at startup time.

    The user can eventually insert the USB memory stick while the application is already running.

    The USB memory stick may even never be inserted.

  • Mad River,

    You can set the timeout in the g_fx_media0 FileX on USB Mass Storage properties window. The default is 1000. If you want to hold off the thread until a memory stick is inserted, change the "Timeout ticks for Media Initialization" to 0xFFFFFFFF which is TX_WAIT_FOREVER.

    -Gary
  • Hi Gary,

    What if I don't want to block expecting to the memory stick be inserted?
    I would like to keep the application running and trigger a callback when the memory stick be inserted.

    I suppose that I can do it setting the auto-initialization of the fx file to "disabled".
    And do the following inside the triggered callback:

    /** Initialize the FileX Media Control Block g_fx_media0 for a USB Mass Storage device. */
    /** Get the pointer to a USBX Host Mass Storage Instance. */
    g_ux_host_class_storage0 = g_ux_new_host_storage_instance;

    /** Initialize the FileX Media Control Block g_fx_media0 for a USB Mass Storage device. */
    UINT err_g_fx_media0_get = ux_system_host_storage_fx_media_get (g_ux_new_host_storage_instance,
    &g_ux_host_class_storage0_media, &g_fx_media0_ptr);
    if (UX_SUCCESS != err_g_fx_media0_get)
    {
    g_fx_media0_err_callback_failed_to_get_fx_media (&g_fx_media0_ptr, &err_g_fx_media0_get);
    }

    Is my assumption correct?
  • Mad River,

    Yes, you can disable the auto init for g_fx_media0 and call it via the call back in USBX ux_host_change_callback to mount the stick. You will have to determine which device was just enumerated or de-enumerated in the callback.

    -Gary
  • Mad River,

     

    Here is an example of using the host change call back & event flags to init the media when its inserted.

    -Gary

    SK_S7_USB_MSC_Host_Example.zip

  • Hello Mad River,

    You can disable auto initialization and perform it yourself after the USB stick has been inserted. Please refer to the following example project for SK-S7 and SSP 1.2.0: s7_sk_ux_mass_host_1_2_0.zip. On SSP 1.2.0, you cannot call initialization from the insertion callback (init will block waiting for a semaphore that's placed only after the callback) so you'll need to use another semaphore to signal a thread to perform initialization.

    Regards