2026-03-25 7:27 AM - edited 2026-03-25 7:31 AM
Hello,
As a lot of people here, i'm trying to implement USB in standalone mode (bare metal, no OS used).
still can't make it work. I'm looking for help. I checked a lot of forum posts, a lot of github pages.
I based myself on :
https://github.com/STMicroelectronics/x-cube-azrtos-h7/blob/dev/usbx/Projects/NUCLEO-H723ZG/Applications/USBX/Ux_Device_CDC_ACM_Standalone/USBX/App/app_usbx_device.c
and tried to implement the AzureRTOS USBX standalone version
Here is my Cube MX configuration :
Clock USB :
I only used X-CUBE-AZRTOS-WB and desactivated USBX :
Using buffer <10*1024 would rise a memory error flag in ux_device_stack_initialize() :
The rest is default configuration.
Then USB_OTG_HS : Device_Only and :
Then i generated the code,
I added :
if(MX_USBX_Device_Init() != HAL_OK)
{
for(;;);
}And inside of it :
/* USER CODE BEGIN MX_USBX_Device_Init1 */
USBX_APP_Device_Init();
/* USER CODE END MX_USBX_Device_Init1 */And inside of it :
/* USER CODE BEGIN USB_Device_Init_PreTreatment_1 */
/* Set Rx FIFO */
HAL_PCDEx_SetRxFiFo(&hpcd_USB_OTG_HS, 0x200);
/* Set Tx FIFO 0 */
HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_HS, 0, 0x10);
/* Set Tx FIFO 1 */
HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_HS, 1, 0x10);
/* Set Tx FIFO 2 */
HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_HS, 2, 0x20);
/* USER CODE END USB_Device_Init_PreTreatment_1 */Inside of MX_USB_OTG_HS_PCD_Init() i added :
/* USER CODE BEGIN USB_OTG_HS_Init 1 */
memset(&hpcd_USB_OTG_HS, 0x0, sizeof(PCD_HandleTypeDef));
/* USER CODE END USB_OTG_HS_Init 1 */Inside of _ux_utility_time_get() i added :
/* USER CODE BEGIN _ux_utility_time_get */
time_tick = HAL_GetTick();
/* USER CODE END _ux_utility_time_get */ I also implemented the TX and RX function but my code is blocking before that.
Inside of MX_USB_OTG_HS_PCD_Init -> HAL_PCD_Init -> USB_CoreInit -> USB_CoreReset
do
{
count++;
if (count > HAL_USB_TIMEOUT)
{
return HAL_TIMEOUT;
}
} while ((USBx->GRSTCTL & USB_OTG_GRSTCTL_CSRSTDONE) == 0U);
Does anyone succeed to implement USBX with STM32WBA65 in bare metal ?
Thanks for your help,
Yvan
Solved! Go to Solution.
2026-03-26 6:50 AM
Hey,
I finally succeed to make it work.
The point is : by default in X-CUBE-AZRTOS-WB we have this :
and if i undestood corectly, ENDPOINT_IN_CMD_ADDR should be different of IN and OUT ADDR.
So i just modify like it :
USBD_CDCACM_ENDPOINT_IN_CMD_ADDR 2
And then it worked.
I also used in the end those values for the endpoint :
/* Set Rx FIFO */
HAL_PCDEx_SetRxFiFo(&hpcd_USB_OTG_HS, 0x200);
/* Set Tx FIFO 0 */
HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_HS, 0, 0x40); // EP0
/* Set Tx FIFO 1 */
HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_HS, 1, 0x80); // CDC IN
/* Set Tx FIFO 2 */
HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_HS, 2, 0x10); // CDC CMD
thanks for your help,
If someone need i can share my project of USB Standalone for STM32WBA65
Yvan
2026-03-25 7:48 AM
Hi @SnoZek,
I faced a similar issue and spent some time figuring it out. I'm using STM32CubeMX 6.17 and the same board.
Make sure that your code calls the following function:
__HAL_RCC_SYSCFG_CLK_ENABLE();If it does not appear in your project, add this call inside the /* USER CODE BEGIN MspInit 0 */ section of the void HAL_MspInit(void) function.
Here is helpful resource to resolve usb related issues.
https://community.st.com/t5/stm32-mcus/faq-troubleshooting-a-usb-core-soft-reset-stuck-on-an-stm32/ta-p/803224
2026-03-25 8:53 AM
Hi @jmk ,
Thanks for your answer,
I added the line and it didn't block anymore.
Now the code is running and in the while(1) :
USBX_Device_Process(NULL);calling :
ux_device_stack_tasks_run();Now, my PC (Windows) see the USB device which is already a big step but with an error : "Device descriptor request failed"
Thanks for your help,
2026-03-26 3:53 AM
Hi @SnoZek
Glad you fixed the first issue.
Now, it seems you need to check your configuration. You can check this example as reference.
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.
2026-03-26 6:50 AM
Hey,
I finally succeed to make it work.
The point is : by default in X-CUBE-AZRTOS-WB we have this :
and if i undestood corectly, ENDPOINT_IN_CMD_ADDR should be different of IN and OUT ADDR.
So i just modify like it :
USBD_CDCACM_ENDPOINT_IN_CMD_ADDR 2
And then it worked.
I also used in the end those values for the endpoint :
/* Set Rx FIFO */
HAL_PCDEx_SetRxFiFo(&hpcd_USB_OTG_HS, 0x200);
/* Set Tx FIFO 0 */
HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_HS, 0, 0x40); // EP0
/* Set Tx FIFO 1 */
HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_HS, 1, 0x80); // CDC IN
/* Set Tx FIFO 2 */
HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_HS, 2, 0x10); // CDC CMD
thanks for your help,
If someone need i can share my project of USB Standalone for STM32WBA65
Yvan