cancel
Showing results for 
Search instead for 
Did you mean: 

NUCLEO-H723ZG USB CDC communication not working when using FreeRTOS

abaril_catalys
Associate

Hello,

I'm trying to communicate with the USB FS CDC on my NUCLEO-H723ZG while using FreeRTOS and the device doesn't enumerate properly. I am using the current up-to-date software pack for STM32H7 -> 1.11.2

I use the CubeMX starting project with the NUCLEO-H723ZG and I only add the USB_OTG_HS as a Full Speed Device.

abaril_catalys_0-1713297296137.png

Then I add the middleware for the CDC using all default parameters.

abaril_catalys_1-1713297399942.png

If I use the project at this point, the USB communication with the virtual comm port works flawlessly. However, it stops working when I add the middleware FreeRTOS with its default parameters

abaril_catalys_2-1713297495294.png

In Windows 11 Device Manager, I am getting the error were the USB descriptor failed (Code 43)

abaril_catalys_3-1713297746949.png

Is there a configuration I am missing ? I would have expected the USB CDC driver to work right out of the box with FreeRTOS at this point...

I have added the .ioc used to generate the projet as well as the main with the code to send an Hello_world message to the virtual com port. The only hardware required is the NUCLEO-H723ZG with 2 USB cables.

1 ACCEPTED SOLUTION

Accepted Solutions

Hello,


However, this function is never called since the code only runs the default task after starting FreeRTOS so I doubt it is the problem.

-> I agree. 

Now testing your project and I've reproduced the issue. It seems there is a hardfault with your Task RTOS configuration.

The first thing to thing about in that situation (in baremetal is OK, with RTOS: Hardfault) is the Task stack size.

Increasing the stack size from 128 to 256 makes the hardfault disappears.

Hope it does answer your question.

 

 

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.

View solution in original post

3 REPLIES 3
SofLit
ST Employee

Hello,

Why are you calling CDC_Transmit_HS() from a loop in main 

  while (1)
  {
	  CDC_Transmit_HS(TxBuffer, strlen((const char *)TxBuffer));
	  	HAL_Delay(1000);
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
  }

and in StartDefaultTask() task ?:

void StartDefaultTask(void *argument)
{
  /* init code for USB_DEVICE */
  MX_USB_DEVICE_Init();
  /* USER CODE BEGIN 5 */
  /* Infinite loop */
  for(;;)
  {
	CDC_Transmit_HS(TxBuffer, strlen((const char *)TxBuffer));
    osDelay(1000);
  }
  /* USER CODE END 5 */
}

 

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.

Hello SofLit,

The CDC_Transmit_HS I called in the while(1) is a leftover function call when I first started the project without FreeRTOS to check functionality. My bad, I should have removed it when I added FreeRTOS in CubeMX. However, this function is never called since the code only runs the default task after starting FreeRTOS so I doubt it is the problem.

The call to CDC_Transmit_HS in the StartDefaultTask is used to display an "Hello World" every 1 second when I connect a serial terminal. Well if my code worked, that would have been the expected behavior...

Sorry for the confusion this leftover code caused, but I think the root cause of the problem is else where.

Thank you and have a nice day.

Hello,


However, this function is never called since the code only runs the default task after starting FreeRTOS so I doubt it is the problem.

-> I agree. 

Now testing your project and I've reproduced the issue. It seems there is a hardfault with your Task RTOS configuration.

The first thing to thing about in that situation (in baremetal is OK, with RTOS: Hardfault) is the Task stack size.

Increasing the stack size from 128 to 256 makes the hardfault disappears.

Hope it does answer your question.

 

 

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.