eclipse-threadx / usbx

Eclipse ThreadX - USBX is a high-performance USB host, device, and on-the-go (OTG) embedded stack, that is fully integrated with Eclipse ThreadX RTOS
https://github.com/eclipse-threadx/rtos-docs/blob/main/rtos-docs/usbx/index.md
MIT License
148 stars 88 forks source link

UsbX device MTP #73

Closed MarcoTrap closed 1 year ago

MarcoTrap commented 1 year ago

I'm trying to add MTP class to my device: I found only that it works with PIMA enabling define UX_PIMA_WITH_MTP_SUPPORT. I write some code to test it and linking the device to Win10 it enumerates the MTP, but anything else. The callbacks are not called.

This is a part of the code:

static UINT usbx_device_class_pima_parameter_object_number_get(struct UX_SLAVE_CLASS_PIMA_STRUCT *pima, ULONG object_format_code, ULONG object_association, ULONG *object_number)
{
    UX_PARAMETER_NOT_USED(pima);
    UX_PARAMETER_NOT_USED(object_format_code);
    UX_PARAMETER_NOT_USED(object_association);
    UX_PARAMETER_NOT_USED(object_number);

    PRINTF("pima_parameter_object_number_get\r\n");
}

static UINT usbx_device_class_pima_parameter_object_handles_get(struct UX_SLAVE_CLASS_PIMA_STRUCT *pima,
        ULONG object_handles_format_code,
        ULONG object_handles_association,
        ULONG *object_handles_array,
        ULONG object_handles_max_number)
{
    UX_PARAMETER_NOT_USED(pima);
    UX_PARAMETER_NOT_USED(object_handles_format_code);
    UX_PARAMETER_NOT_USED(object_handles_association);
    UX_PARAMETER_NOT_USED(object_handles_array);
    UX_PARAMETER_NOT_USED(object_handles_max_number);

    PRINTF("pima_parameter_object_handles_get\r\n");
}

static UINT usbx_device_class_pima_parameter_object_info_get(struct UX_SLAVE_CLASS_PIMA_STRUCT *pima, ULONG object_handle,
        UX_SLAVE_CLASS_PIMA_OBJECT **object)
{
    UX_PARAMETER_NOT_USED(pima);
    UX_PARAMETER_NOT_USED(object_handle);
    UX_PARAMETER_NOT_USED(object);

    PRINTF("pima_parameter_object_info_get\r\n");
}

static UINT usbx_device_class_pima_parameter_object_data_get(struct UX_SLAVE_CLASS_PIMA_STRUCT *pima, ULONG object_handle,
        UCHAR *object_buffer, ULONG object_offset, ULONG object_length_requested, ULONG *object_actual_length)
{
    UX_PARAMETER_NOT_USED(pima);
    UX_PARAMETER_NOT_USED(object_handle);
    UX_PARAMETER_NOT_USED(object_buffer);
    UX_PARAMETER_NOT_USED(object_offset);
    UX_PARAMETER_NOT_USED(object_length_requested);
    UX_PARAMETER_NOT_USED(object_actual_length);

    PRINTF("pima_parameter_object_data_get\r\n");

    return 0;
}

static UINT usbx_device_class_pima_parameter_object_info_send(struct UX_SLAVE_CLASS_PIMA_STRUCT *pima,
        UX_SLAVE_CLASS_PIMA_OBJECT *object, ULONG storage_id, ULONG parent_object_handle, ULONG *object_handle)
{
    UX_PARAMETER_NOT_USED(pima);
    UX_PARAMETER_NOT_USED(object);
    UX_PARAMETER_NOT_USED(storage_id);
    UX_PARAMETER_NOT_USED(parent_object_handle);
    UX_PARAMETER_NOT_USED(object_handle);

    PRINTF("pima_parameter_object_info_send\r\n");

    return 0;
}

static UINT usbx_device_class_pima_parameter_object_data_send(struct UX_SLAVE_CLASS_PIMA_STRUCT *pima, ULONG object_handle,
        ULONG phase ,UCHAR *object_buffer, ULONG object_offset, ULONG object_length)
{
    UX_PARAMETER_NOT_USED(pima);
    UX_PARAMETER_NOT_USED(object_handle);
    UX_PARAMETER_NOT_USED(phase);
    UX_PARAMETER_NOT_USED(object_buffer);
    UX_PARAMETER_NOT_USED(object_offset);
    UX_PARAMETER_NOT_USED(object_length);

    PRINTF("pima_parameter_object_data_send\r\n");

    return 0;
}

static UINT usbx_device_class_pima_parameter_object_delete(struct UX_SLAVE_CLASS_PIMA_STRUCT *pima, ULONG object_handle)
{
    UX_PARAMETER_NOT_USED(pima);
    UX_PARAMETER_NOT_USED(object_handle);

    PRINTF("pima_parameter_object_delete\r\n");

    return 0;
}

static UINT usbx_device_class_pima_parameter_object_prop_desc_get(struct UX_SLAVE_CLASS_PIMA_STRUCT *pima, ULONG object_handle,
        ULONG object_property, UCHAR **object_prop_dataset, ULONG *object_prop_dataset_length)
{
    UX_PARAMETER_NOT_USED(pima);
    UX_PARAMETER_NOT_USED(object_handle);
    UX_PARAMETER_NOT_USED(object_property);
    UX_PARAMETER_NOT_USED(object_prop_dataset);
    UX_PARAMETER_NOT_USED(object_prop_dataset_length);

    PRINTF("pima_parameter_object_prop_desc_get\r\n");

    return 0;
}

static UINT usbx_device_class_pima_parameter_object_prop_value_get(struct UX_SLAVE_CLASS_PIMA_STRUCT *pima, ULONG object_handle,
        ULONG object_property, UCHAR **object_prop_value, ULONG *object_prop_value_length)
{
    UX_PARAMETER_NOT_USED(pima);
    UX_PARAMETER_NOT_USED(object_handle);
    UX_PARAMETER_NOT_USED(object_property);
    UX_PARAMETER_NOT_USED(object_prop_value);
    UX_PARAMETER_NOT_USED(object_prop_value_length);

    PRINTF("pima_parameter_object_prop_value_get\r\n");

    return 0;
}

static UINT usbx_device_class_pima_parameter_object_prop_value_set(struct UX_SLAVE_CLASS_PIMA_STRUCT *pima, ULONG object_handle,
        ULONG object_property, UCHAR *object_prop_value, ULONG object_prop_value_length)
{
    UX_PARAMETER_NOT_USED(pima);
    UX_PARAMETER_NOT_USED(object_handle);
    UX_PARAMETER_NOT_USED(object_property);
    UX_PARAMETER_NOT_USED(object_prop_value);
    UX_PARAMETER_NOT_USED(object_prop_value_length);

    PRINTF("pima_parameter_object_prop_value_set\r\n");

    return 0;
}

static UINT usbx_device_class_pima_parameter_object_references_get(struct UX_SLAVE_CLASS_PIMA_STRUCT *pima, ULONG object_handle,
        UCHAR **object_handle_array, ULONG *object_handle_array_length)
{
    UX_PARAMETER_NOT_USED(pima);
    UX_PARAMETER_NOT_USED(object_handle);
    UX_PARAMETER_NOT_USED(object_handle_array);
    UX_PARAMETER_NOT_USED(object_handle_array_length);

    PRINTF("pima_parameter_object_references_get\r\n");

    return 0;
}

static UINT usbx_device_class_pima_parameter_object_references_set(struct UX_SLAVE_CLASS_PIMA_STRUCT *pima, ULONG object_handle,
        UCHAR *object_handle_array, ULONG object_handle_array_length)
{
    UX_PARAMETER_NOT_USED(pima);
    UX_PARAMETER_NOT_USED(object_handle);
    UX_PARAMETER_NOT_USED(object_handle_array);
    UX_PARAMETER_NOT_USED(object_handle_array_length);

    PRINTF("pima_parameter_object_references_set\r\n");

    return 0;
}

.
.
.

 /*
     * The code below is required for installing the device portion of USBX.
     */
    status = ux_device_stack_initialize(device_framework_high_speed, DEVICE_FRAMEWORK_LENGTH_HIGH_SPEED,
                                        device_framework_full_speed, DEVICE_FRAMEWORK_LENGTH_FULL_SPEED,
                                        string_framework, STRING_FRAMEWORK_LENGTH,
                                        language_id_framework, LANGUAGE_ID_FRAMEWORK_LENGTH, UX_NULL);
    if (status != UX_SUCCESS)
        goto err;

    mtp_ramdisk1_parameter.ux_device_class_pima_parameter_manufacturer              = "MANUFACTURER";
    mtp_ramdisk1_parameter.ux_device_class_pima_parameter_model                     = "MODEL";
    mtp_ramdisk1_parameter.ux_device_class_pima_parameter_device_version            = "DEVICE_VERSION";
    mtp_ramdisk1_parameter.ux_device_class_pima_parameter_serial_number             = "SERIAL_NUMBER";
    mtp_ramdisk1_parameter.ux_device_class_pima_parameter_storage_id                = 1;
    mtp_ramdisk1_parameter.ux_device_class_pima_parameter_storage_type              = UX_DEVICE_CLASS_PIMA_STC_UNDEFINED;
    mtp_ramdisk1_parameter.ux_device_class_pima_parameter_storage_file_system_type  = UX_DEVICE_CLASS_PIMA_FSTC_UNDEFINED;
    mtp_ramdisk1_parameter.ux_device_class_pima_parameter_storage_access_capability = UX_DEVICE_CLASS_PIMA_AC_READ_WRITE;
    mtp_ramdisk1_parameter.ux_device_class_pima_parameter_storage_max_capacity_low  = RAM_DISK_SIZE;
    mtp_ramdisk1_parameter.ux_device_class_pima_parameter_storage_max_capacity_high = 0;
    mtp_ramdisk1_parameter.ux_device_class_pima_parameter_storage_free_space_low    = RAM_DISK_SIZE;
    mtp_ramdisk1_parameter.ux_device_class_pima_parameter_storage_free_space_high   = 0;
    mtp_ramdisk1_parameter.ux_device_class_pima_parameter_storage_free_space_image  = 0xFFFFFFFF;
    mtp_ramdisk1_parameter.ux_device_class_pima_parameter_storage_description       = "DESCRIPTION";
    mtp_ramdisk1_parameter.ux_device_class_pima_parameter_storage_volume_label      = "0123456789";

    mtp_ramdisk1_parameter.ux_device_class_pima_parameter_object_number_get         = usbx_device_class_pima_parameter_object_number_get;
    mtp_ramdisk1_parameter.ux_device_class_pima_parameter_object_handles_get        = usbx_device_class_pima_parameter_object_handles_get;
    mtp_ramdisk1_parameter.ux_device_class_pima_parameter_object_info_get           = usbx_device_class_pima_parameter_object_info_get;
    mtp_ramdisk1_parameter.ux_device_class_pima_parameter_object_data_get           = usbx_device_class_pima_parameter_object_data_get;
    mtp_ramdisk1_parameter.ux_device_class_pima_parameter_object_info_send          = usbx_device_class_pima_parameter_object_info_send;
    mtp_ramdisk1_parameter.ux_device_class_pima_parameter_object_data_send          = usbx_device_class_pima_parameter_object_data_send;
    mtp_ramdisk1_parameter.ux_device_class_pima_parameter_object_delete             = usbx_device_class_pima_parameter_object_delete;

    //UX_PIMA_WITH_MTP_SUPPORT
    mtp_ramdisk1_parameter.ux_device_class_pima_parameter_object_prop_desc_get      = usbx_device_class_pima_parameter_object_prop_desc_get;
    mtp_ramdisk1_parameter.ux_device_class_pima_parameter_object_prop_value_get     = usbx_device_class_pima_parameter_object_prop_value_get;
    mtp_ramdisk1_parameter.ux_device_class_pima_parameter_object_prop_value_set     = usbx_device_class_pima_parameter_object_prop_value_set;
    mtp_ramdisk1_parameter.ux_device_class_pima_parameter_object_references_get     = usbx_device_class_pima_parameter_object_references_get;
    mtp_ramdisk1_parameter.ux_device_class_pima_parameter_object_references_set     = usbx_device_class_pima_parameter_object_references_set;

    /* Initialize the device storage class. The class is connected with interface 0 on configuration 1. */
    status = ux_device_stack_class_register("PIMA",
                                            _ux_device_class_pima_entry,
                                            DEVICE_CONFIGURATION_NUMBER,
                                            DEVICE_INTERFACE_NUMBER,
                                            (VOID *)&mtp_ramdisk1_parameter);

Can you help me? Are there any examples about MTP?

Thanks, Marco

AYEDMSTM commented 1 year ago

Hi @MarcoTrap

This is a sample example showing support of MTP that can be accessed from ST github .

https://github.com/STMicroelectronics/x-cube-azrtos-h7/tree/main/Projects/STM32H735G-DK/Applications/USBX/Ux_Device_PIMA_MTP

Regards ST Team.

MarcoTrap commented 1 year ago

Hi @AYEDMSTM thank you so much, it was very helpful.

Marco