2017-03-05 04:23 PM
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 #stm32cubemx2017-03-07 05:22 AM
Hi
Riggs.Rob
,Thank you for your feedback.I will forward this to our MX team.
-Nesrine-
2017-03-09 07:02 AM
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.
2017-07-21 10:24 AM
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 */.
.
.
}