HW Guidelines to configure USB OTG with STM32H563VIT6
Hi,
is there any HW guidelines to configure a USB OTG port with STM32H563VIT6 with VBUS detection?
Hi,
is there any HW guidelines to configure a USB OTG port with STM32H563VIT6 with VBUS detection?
Hello
about Dual role switching using USBX
>but most of the parameters are not present, such as USB_OTG_HS under connectivity
Yes you are correct about this point , STM32H723 is ST middleware native and uses USB_OTG_FS as instance while STM32H563 is USBX native and uses USB_DRD_FS as instance so they do not have the same method.
To implement USB DRD in a product that uses USBX and USB_DRD_FS like STM32H563 or STM32U545
-You need first to implement all necessary files for both USB classes. The easiest way is to create two separate projects: one with the required USB device class and another with the required USB host class. Test each project separately to ensure correct configuration and proper operation. Then, merge the files from one project into the other to create a project that contains the necessary files for both modes. From a personal point of view, it is recommended to use the USB host project as the base and add the device files from the device project since Device mode have generally less files than host mode.
here is list of files that need to be transferred (source and header).
Critical: follow the same original structure when pasting files.
-app_usbx_device
-ux_device_cdc_acm (ex: if device class is cdc_acm)
-middleware/usbx/common/core/src&inc folder files
-usbx device classes folder
-usbxstm32 device controllers folder
-stm32h5xx_hal_pcd and pcd_ex
*don’t forget to add the added include folders to include paths in the GCC assembler and GCC compiler or bunch of errors will be generated
Now for code developing part:
You can use the already mentioned H7A3_USBX_DualRole as a base to determine which files must be modified and how to implement the switch mechanism between both modes. de-initialization of the host class, disable the drive VBUS, and switch the USB instance used in the IRQ handler. here is an example:
void USB_IRQHandler(void)
{
/* USER CODE BEGIN USB_IRQn 0 */
/* USER CODE END USB_IRQn 0 */
if (g_usb_role == 1)
{
HAL_HCD_IRQHandler(&hhcd_USB_DRD_FS); // host mode
}
else
{
HAL_PCD_IRQHandler(&hpcd_USB_DRD_FS); // device mode
}
/* USER CODE BEGIN USB_IRQn 1 */
/* USER CODE END USB_IRQn 1 */
}
Additionally, initialization of the device class. Ensure a proper implementation of the device class memory pool size in app_azure_rtos.c.
this example also uses the USBX middleware, the only difference is the instance naming( USB_OTG_FS instead of USB_DRD_FS) and some other stuff like device class configuration
here is an example that should work on the STM32H563
HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, 0x00, PCD_SNG_BUF, 0x14);
HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, 0x80, PCD_SNG_BUF, 0x54);
HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, USBD_CDCACM_EPOUT_ADDR, PCD_SNG_BUF, 0x94);
HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, USBD_CDCACM_EPIN_ADDR, PCD_SNG_BUF, 0x98);
HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, USBD_CDCACM_EPINCMD_ADDR, PCD_SNG_BUF, 0x9C);
*Don't forget to increase dedicated memory pool size for threadX and both classes of USBX or errors related to memory allocation will occur.
Also, don't forget to enable
#define HAL_PCD_MODULE_ENABLED
in stm32h5xx_hal_conf.h if your base project is configured as host mode.
Hope that helps
BR
Gyessine
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.