2022-09-22 11:52 PM
Hello,
We are Using the STM32L496AGI3 Controller.We are using the USB CDC Device only mode as Virtual Com Port for transferring the data serial.After our work is finished we are disabling the USB CDC using MX_USB_DEVICE_DeInit(); Function.
But after this if we are again Enabling the USB CDC using MX_USB_DEVICE_Init(); Function
We are not able to write and receive the data through USB as Virtual Com Port.Please give any suggestions.
2022-09-23 12:26 PM
> Please give any suggestions
Debug?
2022-09-26 12:14 AM
Hello Pavel A.
I am Using this USBD_LL_DeInit(); Function For DeInitializing. So you can correct me if this function is doing some problem.
Because when i am generating the code from the IDE only one Function is created Bydefault MX_USB_DEVICE_Init() but for the Deinit is not created so because of that reason i am using USBD_LL_DeInit() because my device are going into sleep for a while so i need to disable and after waking up again i need to init the MX_USB_DEVICE_Init();
2022-09-26 01:37 PM
Yes, USBD_LL_DeInit() should bring the USB device controller to a state when the host does not detect the device. Re-enabling then should cause re-enumeration. If this does not work, you'll need to debug .
The question is, why your device decides to sleep and wake up. Do you react to the suspend and resume requests from the USB host? to disconnection of the USB device? In other words, do you want to disable the USB controller at all?
2022-09-26 09:47 PM
We are Doing the Low Power Mode and try to consume less power during the Sleep Mode.Because of that Reason we We are doing deinit of the USB.So ,after deinitilization we are getting the less current consumption.
But issue is coming when device wake-up after sleep ,we are Initilizing the USB after wake-up But its not working.
Below is the Two function which is i am using for init and deinit of USB
We are using USB as Virtual Com Port in configuration in MxCubeIDE.
//Init function
void MX_USB_DEVICE_Init(void)
{
/* USER CODE BEGIN USB_DEVICE_Init_PreTreatment */
/* USER CODE END USB_DEVICE_Init_PreTreatment */
/* Init Device Library, add supported class and start the library. */
if (USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS) != USBD_OK)
{
Error_Handler();
}
if (USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC) != USBD_OK)
{
Error_Handler();
}
if (USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS) != USBD_OK)
{
Error_Handler();
}
if (USBD_Start(&hUsbDeviceFS) != USBD_OK)
{
Error_Handler();
}
/* USER CODE BEGIN USB_DEVICE_Init_PostTreatment */
/* USER CODE END USB_DEVICE_Init_PostTreatment */
}
//Deinit function
void MX_USB_DEVICE_DeInit(void)
{
USBD_DeInit(&hUsbDeviceFS);
}