cancel
Showing results for 
Search instead for 
Did you mean: 

USBX CDC for the stm32u5 in standalone (no RTOS) problem

ckoec
Associate II

Hello,

I implemented a virtual com port using the usbx stack for the stm32U575 in standalone mode and it basicaly works.

My problem is that I just can't put more than 8 bytes in the TX buffer at the time. If I do the program gets stuck (in the main loop)

I tried both: ux_device_class_cdc_acm_write_with_callback and ux_device_class_cdc_acm_write_run

but they only work when the buffer length is less than 8 bytes.

I have the following code in app_usbx_device.c:

  /* USER CODE BEGIN MX_USBX_Device_Init1 */

  /* Initialize the USB Peripheral */
	MX_USB_OTG_FS_PCD_Init();
  
	HAL_PCDEx_SetRxFiFo(&hpcd_USB_OTG_FS, 0x80);
	HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 0, USBD_MAX_EP0_SIZE / 4);
	HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 1, USBD_CDCACM_EPIN_FS_MPS / 4);
	HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 2, USBD_CDCACM_EPINCMD_FS_MPS / 4);
  
  
	/* Link the USB drivers with the USBX DCD and check if it return error */ 
	if(ux_dcd_stm32_initialize((ULONG)USB_OTG_FS, (ULONG)&hpcd_USB_OTG_FS) != UX_SUCCESS){
			  Error_Handler();
	}

	/* Start the PCD Peripheral */
	HAL_PCD_Start(&hpcd_USB_OTG_FS);
  
  /* USER CODE END MX_USBX_Device_Init1 */

And in ux_device_cdc_acm.c (with callback):

VOID USBD_CDC_ACM_Activate(VOID *cdc_acm_instance)
{
  /* USER CODE BEGIN USBD_CDC_ACM_Activate */
	cdc_acm = (UX_SLAVE_CLASS_CDC_ACM*) cdc_acm_instance;

	UX_SLAVE_CLASS_CDC_ACM_CALLBACK_PARAMETER cdc_acm_slave_callback;
	   
	cdc_acm_slave_callback.ux_device_class_cdc_acm_parameter_read_callback = USBX_cdc_acm_device_read_callback;
    cdc_acm_slave_callback.ux_device_class_cdc_acm_parameter_write_callback = USBX_cdc_acm_device_write_callback;
    ux_device_class_cdc_acm_ioctl(cdc_acm, UX_SLAVE_CLASS_CDC_ACM_IOCTL_TRANSMISSION_START, (VOID*)&cdc_acm_slave_callback);
	
  /* USER CODE END USBD_CDC_ACM_Activate */

  return;
}

 

I was wondering if the routine, which empties the buffer doesn't get called in standalone mode or if I missed something in the init of the stack.

Thank you in advance for your input !

1 ACCEPTED SOLUTION

Accepted Solutions
ckoec
Associate II

Thank you for your answer !

I compared the example with my code and I noticed that the TX buffers sizes were not correct.

This works:

HAL_PCDEx_SetRxFiFo(&hpcd_USB_OTG_FS, 0x80);
HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 0, 0x10);
HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 1, 0x20);
HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 2, 0x10);

 

View solution in original post

2 REPLIES 2
FBL
ST Employee

Hi @ckoec 

Have you tried this example ST-TOMAS-Examples-USB/U5_USBX_VCP_Standalone

Add debugging prints to trace and identify where it gets stuck. This can help you pinpoint the exact location of the issue. Here for example, you can see a circular buffer handling.

 

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
	  EventFlag |= RX_NEW_RECEIVED_DATA;

	    /* Increment the UserTxBufPtrIn pointer */
	  UserTxBufPtrIn++;

	  /* Rollback the UserTxBufPtrIn if it equal to APP_TX_DATA_SIZE */
	  if (UserTxBufPtrIn == APP_TX_DATA_SIZE)
	  {
	    UserTxBufPtrIn = 0;
	  }

	  /* Start another reception: provide the buffer pointer with offset and the buffer size */
	  if (HAL_UART_Receive_IT(uart_handler, (uint8_t *)UserTxBufferFS + UserTxBufPtrIn, 1) != HAL_OK)
	  {
	    /* Transfer error in reception process */
	    Error_Handler();
	  }
}

 

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.


ckoec
Associate II

Thank you for your answer !

I compared the example with my code and I noticed that the TX buffers sizes were not correct.

This works:

HAL_PCDEx_SetRxFiFo(&hpcd_USB_OTG_FS, 0x80);
HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 0, 0x10);
HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 1, 0x20);
HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 2, 0x10);