cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 H573-DK USBX CDC ACM CLASS Stand-Alone

iCenger
Associate

Hello ST Community,

I was trying to use USBX with ThreadX and it worked. So far so good. But in our project, we will use FreeRTOS and after some research and getting in touch with some people, I learned that I can not use USBX with FreeRTOS. So they suggested to me to use USBX StandAlone. I'm now trying using USBX CDC ACM class in standalone mode. I inited USBX, my virtual comport appears in the device manager. I tried to send data from discovery kit to my PC with this function "_ux_device_class_cdc_acm_write_run" and I could send it. After one try, i tried to send again but this time it didnt send and this function "_ux_device_class_cdc_acm_write_run" returned "UX_STATE_WAIT". 

 

I debugged the code, examine the transmit process. After transmit an interrupt occured and these flags are set;

 

 

 

transfer_request -> ux_slave_transfer_request_completion_code = UX_SUCCESS;

/* The transfer is completed. */
transfer_request -> ux_slave_transfer_request_status = UX_TRANSFER_STATUS_COMPLETED;
transfer_request -> ux_slave_transfer_request_actual_length =
transfer_request -> ux_slave_transfer_request_requested_length;

 

 

 



Then I started to examine "_ux_device_class_cdc_acm_write_run" this and I find out my code returns "UX_STATE_NEXT" from here;

 

 

 

    if (ed_status & UX_DCD_STM32_ED_STATUS_TRANSFER)
    {
        if (ed_status & UX_DCD_STM32_ED_STATUS_DONE)
        {

            /* Keep used, stall and task pending bits.  */
            ed -> ux_dcd_stm32_ed_status &= (UX_DCD_STM32_ED_STATUS_USED |
                                        UX_DCD_STM32_ED_STATUS_STALLED |
                                        UX_DCD_STM32_ED_STATUS_TASK_PENDING);
            UX_RESTORE
            return(UX_STATE_NEXT);
        }
        UX_RESTORE
        return(UX_STATE_WAIT);
    }

 

 

 

normally, when it sends it should pass this code block and run this part;

 

 

 

    /* Start transfer.  */
    ed -> ux_dcd_stm32_ed_status |= UX_DCD_STM32_ED_STATUS_TRANSFER;

    /* Check for transfer direction.  Is this a IN endpoint ? */
    if (transfer_request -> ux_slave_transfer_request_phase == UX_TRANSFER_PHASE_DATA_OUT)
    {

        /* Transmit data.  */
        HAL_PCD_EP_Transmit(dcd_stm32 -> pcd_handle,
                            endpoint->ux_slave_endpoint_descriptor.bEndpointAddress,
                            transfer_request->ux_slave_transfer_request_data_pointer,
                            transfer_request->ux_slave_transfer_request_requested_length);
    }
    else
    {

        /* We have a request for a SETUP or OUT Endpoint.  */
        /* Receive data.  */
        HAL_PCD_EP_Receive(dcd_stm32 -> pcd_handle,
                            endpoint->ux_slave_endpoint_descriptor.bEndpointAddress,
                            transfer_request->ux_slave_transfer_request_data_pointer,
                            transfer_request->ux_slave_transfer_request_requested_length);
    }

 

 

 

 

 I can't find any example or documentation about this. Should I clean this transfer request or do something else? Or am I doing this completely wrong? Can you help me with this?

I attached my init and send files.

Thanks.

Best Regards.

1 ACCEPTED SOLUTION

Accepted Solutions
pkapt
Associate II

Looks like I just didn't add a   HAL_PCDEx_SetTxFiFo() call for the endpoint that was sending data to the host. Adding that in fixed everything.

View solution in original post

5 REPLIES 5
FBL
ST Employee

Hi @iCenger 

Did you check the provided example in Cube

STM32CubeH5/Projects/NUCLEO-H563ZI/Applications/USBX/Ux_Device_HID_CDC_ACM at main · STMicroelectronics/STM32CubeH5 · GitHub

To use it in CDC ACM standalone, you can simply de-initialize the HID mouse class de-allocate stack for HID thread and thread creation.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

pkapt
Associate II

Were you able to figure out your issue? I'm running into an identical one.

FBL
ST Employee

Hi @pkapt 

Could you share more details about the issue?

_ux_device_class_cdc_acm_write_run function returning UX_STATE_WAIT?

Would you share your project?

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

pkapt
Associate II

Hi @FBL

My use case is a CDC ACM device in standalone mode. I am running baremetal with no RTOS. 

In ux_device_cdc_acm.c, I register write and read callbacks using ux_device_class_cdc_acm_ioctl with UX_SLAVE_CLASS_CDC_ACM_IOCTL_TRANSMISSION_START. The device enumerates on the host PC and I am able to connect to it. When I send data from host PC, the read callback that I registered previously gets called and the firmware receives the expected data from the host PC. 

My problem is when writing from my device to the host PC. I'm attempting to use ux_device_class_cdc_acm_write_with_callback() to write data to the host PC. The function returns UX_SUCCESS, but my host PC never receives the data. In my main loop, I call ux_device_stack_tasks_run(), which eventually calls _ux_dcd_stm32_transfer_run(), seen below.

Line 6 never evaluates to true and this function always returns UX_STATE_WAIT.

// ux_dcd_stm32_transfer_run.c

    /* ED transfer in progress.  */
    if (ed_status & UX_DCD_STM32_ED_STATUS_TRANSFER)
    {
        if (ed_status & UX_DCD_STM32_ED_STATUS_DONE)
        {

            /* Keep used, stall and task pending bits.  */
            ed -> ux_dcd_stm32_ed_status &= (UX_DCD_STM32_ED_STATUS_USED |
                                        UX_DCD_STM32_ED_STATUS_STALLED |
                                        UX_DCD_STM32_ED_STATUS_TASK_PENDING);
            UX_RESTORE
            return(UX_STATE_NEXT);
        }
        UX_RESTORE
        return(UX_STATE_WAIT);
    }

 

 

 

Below are my STM32CubeMX configurations for the USB peripheral and the USBX middleware.

Any input is greatly appreciated. Please let me know if you need anything else from me.

pkapt_0-1725386606921.png

pkapt_1-1725386635424.png

pkapt_2-1725386666454.png

 

 

 

 

pkapt
Associate II

Looks like I just didn't add a   HAL_PCDEx_SetTxFiFo() call for the endpoint that was sending data to the host. Adding that in fixed everything.