cancel
Showing results for 
Search instead for 
Did you mean: 

Set USB Max Power for CDC Device Using STM32CubeMX?

Rob.Riggs
Senior
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
3 REPLIES 3
Nesrine M_O
Lead II
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
Senior III
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
Associate II
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) + 😎 = (500 / 2);

  /* USER CODE END USB_MspInit 0 */

.

.

.

}