Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why ux_slave_class_name of ux_slave_interface_next_interface is NULL? #7

Open
FengChendian opened this issue Dec 6, 2022 · 1 comment

Comments

@FengChendian
Copy link

FengChendian commented Dec 6, 2022

Describe the set-up

I try to migrate USBX CDC ACM to STM32F407ZGT6. Now USB Device can be recognized by Computer as STM32 USB Device.

image

But I can't read any data from PC host. And I found ux_utility_memory_compare is not right.

  /* Compares two memory blocks ux_slave_class_name and _ux_system_slave_class_cdc_acm_name */
  ux_status = ux_utility_memory_compare(data_interface->ux_slave_interface_class->ux_slave_class_name,
                                        _ux_system_slave_class_cdc_acm_name,
                                        ux_utility_string_length_get(_ux_system_slave_class_cdc_acm_name));

ux_status is always return 255. data_interface->ux_slave_interface_class is NULL.
image

The full read code is like:

void usbx_cdc_acm_read_thread_entry(ULONG arg)
{
  UX_SLAVE_DEVICE *device;
  UX_SLAVE_INTERFACE *data_interface;
  UX_SLAVE_CLASS_CDC_ACM *cdc_acm;
  ULONG actual_length;
  ULONG ux_status = UX_SUCCESS;
  ULONG senddataflag = 0;

  /* Get device */
  device = &_ux_system_slave->ux_system_slave_device;

  while (1)
    {

      /* Check if device is configured */
      if (device->ux_slave_device_state == UX_DEVICE_CONFIGURED)
        {
          /* Get Data interface */
          data_interface = device->ux_slave_device_first_interface->ux_slave_interface_next_interface;

          /* Compares two memory blocks ux_slave_class_name and _ux_system_slave_class_cdc_acm_name */
          ux_status = ux_utility_memory_compare(data_interface->ux_slave_interface_class->ux_slave_class_name,
                                                _ux_system_slave_class_cdc_acm_name,
                                                ux_utility_string_length_get(_ux_system_slave_class_cdc_acm_name));

          /* Check Compares success */
           if (ux_status == UX_SUCCESS)
            {
              cdc_acm =  data_interface->ux_slave_interface_class_instance;

              /* Set transmission_status to UX_FALSE for the first time */
              cdc_acm -> ux_slave_class_cdc_acm_transmission_status = UX_FALSE;

              /* Read the received data in blocking mode */
              ux_device_class_cdc_acm_read(cdc_acm, (UCHAR *)UserRxBufferFS, 3,
                                           &actual_length);
              if (actual_length != 0)
                {
                  /* Send the data via UART */
//                  if (HAL_UART_Transmit_DMA(&huart3, (uint8_t *)UserRxBufferFS,
//                                            actual_length) != HAL_OK)
//                    {
//                      /* Transfer error in reception process */
//                      Error_Handler();
//                    }

                  /* Wait until the requested flag TX_NEW_TRANSMITTED_DATA is received */
                  if (tx_event_flags_get(&EventFlag, TX_NEW_TRANSMITTED_DATA, TX_OR_CLEAR,
                                         &senddataflag, TX_WAIT_FOREVER) != TX_SUCCESS)
                    {
                      Error_Handler();
                    }
                }
            }
        }
      else
        {
          tx_thread_sleep(1);
        }
    }
}

STM32CUBEMX 6.6.1
Firmware FW_F4_V1.27.0

Question
Are there any reasons for "next interface.ux_slave_class_name is NULL"? I can't find any error in my code. Because USB device has been configured correctly. ux_app_parameters_change(VOID *cdc_acm) is also called when connected.

Screenshots

image

Here is my cubemx screenshots.
image

@whj4674672
Copy link

As it happens, I also encountered the same problem, which has been solved. You can try something.

You need to ensure the configuration in CUBEMX

UX_SLAVE_REQUEST_CONTROL_MAX_LENGTH    <= 256
UX_SLAVE_REQUEST_DATA_MAX_LENGTH            <= 512

This problem occurs because of insufficient memory
You can fix this by modifying #define USBX_MEMORY_SIZE (6 * 1024)

Finally, remember to modify the size of the THREADX memory heap synchronously

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants