cancel
Showing results for 
Search instead for 
Did you mean: 

STM32U5 USB device under FreeRTOS

S_D
Associate

Hi,

We want to implement a USB-C functionality to our customized board (based on a STM32U5G9).  The software uses FreeRTOS environnement.  Is there an existing USB (Device) example, tutorial or library that could be compatible with our project?

regards

3 REPLIES 3
Nicolas P.
ST Employee

Hello @S_D 

Would this be what you would be looking for  : U5 discovery board example :  USBPD_SNK_UX_Device_HID_CDC_ACM ?

This is a complete USB power delivery example with USB device.

You can also start with this wiki. for setting up a USBPD sink, the base to have a USB device after.

And to start the USB part from the USBPD contract have a look here.

We use notifications to start the USB stack.

You can have a look at these videos too, starting with CubeMX. G0 with TCPP01 shield , and G0 with x-cube-tcpp pack , to have an overview of the steps to be done.

Regards,

Nicolas

theophile
Associate II

Hello, 

We have chose the STM32U599 / STM32U5A9 (STM32U5G9 also candidate) for our new product development, because of theirs RAM/Flash capacity. 

I just have starting the firmware development, and I discover that the USB stack that I used until now on STM32F2 and F4 MCU is not supported anymore by STM32CubeIDE (cubeMX..) and that the new USB stack provided can only work under a ThreadX environment.  This is REALLY a bad news, as the previous stack was easy to use with or without FreeRTOS. Forcing the customer to use the Azure RTOS is very disappointing.

I've seen that there are some alternative stack like tinyUSB, or a repository where we can find the old stack (https://community.st.com/t5/stm32-mcus/how-to-use-stmicroelectronics-classic-usb-device-middleware-with/ta-p/599274) but it requires more work, and we are less confident in the perinity of this solution.

I hope ST will provide again an USB stack in the future, which is not OS-dependant.

It's a shame that ST does not care about the software longevity, like it does with the hardware longevity. I started developping on STM32 10 years ago, with the standard peripheral library, then the HAL replaced it with some benefices and drawbacks, now the USB stack is replaced again... 

I would like suggest to ST to perform poll to its users when it makes such changes that has a great impact on user developments!

Thank you for reading!

After having difficulties to use the TinyUSB stack, I followed the previously mentionned tutorial ( https://community.st.com/t5/stm32-mcus/how-to-use-stmicroelectronics-classic-usb-device-middleware-with/ta-p/599274 ).

It has been quite easy to obtain a working example (in my case, it was an USB MSC device (a kind of RAM-disk).

 

However, I have had to customize the USB_LL_Init() function :

HAL_PCDEx_SetRxFiFo(&hpcd_USB_OTG_HS, 0x80);

HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_HS, 0, 0x40);

HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_HS, 1, 0x80);

 

In usbd_conf.h :

/* BillBoard Class Config */

#define USBD_CLASS_USER_STRING_DESC 1U

#define USBD_CLASS_BOS_ENABLED 0U

#define USB_BB_MAX_NUM_ALT_MODE 0x2U

 

in main.c :

static void MX_USB_OTG_HS_PCD_Init(void)

{

 

/* USER CODE BEGIN USB_OTG_HS_Init 0 */

hpcd_USB_OTG_HS.pData = &hUsbDeviceHS;

/* USER CODE END USB_OTG_HS_Init 0 */

 

/* USER CODE BEGIN USB_OTG_HS_Init 1 */

/* USER CODE END USB_OTG_HS_Init 1 */

hpcd_USB_OTG_HS.Instance = USB_OTG_HS;

hpcd_USB_OTG_HS.Init.dev_endpoints = 9;

hpcd_USB_OTG_HS.Init.speed = PCD_SPEED_HIGH_IN_FULL;

hpcd_USB_OTG_HS.Init.phy_itface = USB_OTG_HS_EMBEDDED_PHY;

hpcd_USB_OTG_HS.Init.Sof_enable = DISABLE;

hpcd_USB_OTG_HS.Init.low_power_enable = DISABLE;

hpcd_USB_OTG_HS.Init.lpm_enable = DISABLE;

hpcd_USB_OTG_HS.Init.use_dedicated_ep1 = DISABLE;

hpcd_USB_OTG_HS.Init.vbus_sensing_enable = DISABLE;

hpcd_USB_OTG_HS.Init.dma_enable = DISABLE;

if (HAL_PCD_Init(&hpcd_USB_OTG_HS) != HAL_OK)

{

Error_Handler();

}

/* USER CODE BEGIN USB_OTG_HS_Init 2 */

if(USBD_Init(&hUsbDeviceHS, &MSC_Desc, 0) != USBD_OK)

Error_Handler();

 

if (USBD_RegisterClass(&hUsbDeviceHS, &USBD_MSC) != USBD_OK)

Error_Handler();

 

 

if (USBD_MSC_RegisterStorage(&hUsbDeviceHS, &USBD_MSC_fops) != USBD_OK)

{

Error_Handler();

}

if (USBD_Start(&hUsbDeviceHS) != USBD_OK)

{

Error_Handler();

}

/* USER CODE END USB_OTG_HS_Init 2 */

}

 

I'm using the STM32U5G9 USB HS in FS mode (this MCU does not have an USB FS IP). Maybe it could be easy to make it also work in HS mode.