Skip to main content
Rob.Riggs
Senior
March 6, 2017
Question

Set USB Max Power for CDC Device Using STM32CubeMX?

  • March 6, 2017
  • 3 replies
  • 1146 views
Posted on March 06, 2017 at 01:23

I am using an STM32L4 device.  I am making a USB device that uses CDC and have battery charge detection enabled.  I need to request 500mA from the USB port if a standard downstream port is detected.  It appears that the max power is hard-coded for 100mA in 'Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src/usbd_cdc.c' and that this will be overwritten by STM32CubeMX every time the project is regenerated if I modify this file.

Is there an expected way that this value should be changed for CubeMX projects?  There does not appear to be any public interface into this device structure.

#stm32l4 #hal #usb #usb-power #cdc #stm32cubemx
This topic has been closed for replies.

3 replies

Nesrine M_O
Associate
March 7, 2017
Posted on March 07, 2017 at 14:22

Hi

Riggs.Rob

,

Thank you for your feedback.I will forward this to our MX team.

-Nesrine-

stm32cube-t
ST Employee
March 9, 2017
Posted on March 09, 2017 at 16:02

Hello Rob,

As you noticed the USB descriptors are currently hard coded in the usbd_cdc.c file. We need an update of the USB middleware library to have these descriptors configurable via STM32CubeMX.

ali teke
Visitor II
July 21, 2017
Posted on July 21, 2017 at 19:24

Hi @riggs.rob, you can access the structures and set it in run time. You may place your code inside usbd_conf.c file, maybe this helps to you.

void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle)

{

  if(pcdHandle->Instance==USB)

  {

  /* USER CODE BEGIN USB_MspInit 0 */

    uint16_t length;

    *(USBD_CDC.GetFSConfigDescriptor(&length) + 8) = (500 / 2);

  /* USER CODE END USB_MspInit 0 */

.

.

.

}