cancel
Showing results for 
Search instead for 
Did you mean: 

HW Guidelines to configure USB OTG with STM32H563VIT6

POLessard
Associate II

Hi,

is there any HW guidelines to configure a USB OTG port with STM32H563VIT6 with VBUS detection?

1 ACCEPTED SOLUTION

Accepted Solutions
Gyessine
ST Employee

Hello @POLessard 
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

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

8 REPLIES 8

Thanks for the follow up;

Based on the attached image (found in AN4879), the STM32H563 appears to be only USB device or host, no support for OTG. Is that correct?

If so, is there a way to switch between host and device mode with some HW / SW?

> STM32H563 appears to be only USB device or host, no support for OTG. Is that correct?

Correct. No ID pin negotiation.

> If so, is there a way to switch between host and device mode with some HW / SW?

You can switch between device and host in software by de-initializing the device interface and initializing the host interface (or the opposite).

If you feel a post has answered your question, please click "Accept as Solution".
FBL
ST Employee

Hi @POLessard

I suggest you to refer to the reference design in Nucleo and discovery board NUCLEO-H563ZI

Maybe this article How to configure STM32 as USB dual role can be helpful.

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.




Best regards,
FBL

Thanks for the feedback, is there a way to use/monitor the connector Type-C CC1/CC2 pins to determine the mode, such as sensing Type-C connector CC1/CC2 pins with ADC pins?

Thanks for the feedback, I followed the steps from the article above, the article refers to the NUCLEO-H723ZG and I was able to reproduce the steps, it seems to be straight forward but our device is the STM32H563VIT6. I tried to reproduce the steps using the NUCLEO-H563ZG but most of the parameters are not present, such as USB_OTG_HS under connectivity, etc... Do you have any example of USB dual mode support from the STM32H5 series?

Hi @POLessard 

Dual role is not supported using CubeMX, you need to copy stack resources manually (either USBX or classic core middleware). This example might be helpful H7A3_USBX_DualRole using USBX.  @Gyessine may help you on this. 

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.




Best regards,
FBL
Gyessine
ST Employee

Hello @POLessard 
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

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.