What's the proper way to tear down (and bring back up again) the USB CDC Vcom when using FreeRTOS Tasks?
My usbRxTask setup is the same as the SDK demo, but the demo doesn't show how to tear down/re-init.
I am trying to tear down USB (usb2) when using power_mode_swtich (turning off usb2 pll, etc, then turning it back on before running usb init again).
When I tear down AFTER successfully connecting USB, I can't re-connect.
If I haven't connected yet, I can use my "de-init" code + power down clocks; then power up clocks + re-init multiple times and connect just fine, but as soon as I've connected, I can't tear down and REconnect again.
Current code, on 1st time initialization, call device app init and also start the FreeRTOS USB_DeviceTask:
USB_DeviceApplicationInit();
#if USB_DEVICE_CONFIG_USE_TASK
if (s_cdcVcom.deviceHandle) {
if (xTaskCreate(USB_DeviceTask, "usb device task", 1250, s_cdcVcom.deviceHandle, 5, &s_cdcVcom.deviceTaskHandle) != pdPASS) {
usb_echo("usb device task create failed!\r\n");
return;
}
}
Current tear down:
void usb_device_deinit(void){
USB_DeviceStop(s_cdcVcom.deviceHandle);
uint8_t irqNumber;
uint8_t usbDeviceEhciIrq[] = USBHS_IRQS;
irqNumber = usbDeviceEhciIrq[CONTROLLER_ID - kUSB_ControllerEhci0];
DisableIRQ((IRQn_Type)irqNumber);
USB_DeviceClassDeinit(CONTROLLER_ID);
USB_DeviceClockDeInit();
}
On power up, clocks are enabled via the standard flow in specific.c with
/* Init USB2 PLL - PLL7 */
CLOCK_InitUsb2Pll(&usb2PllConfig_PowerMode);
Then USB re-init is just the USB_DeviceApplicationInit() again:
void USB_DeviceApplicationInit(void) {
USB_DeviceClockInit();
#if (defined(FSL_FEATURE_SOC_SYSMPU_COUNT) && (FSL_FEATURE_SOC_SYSMPU_COUNT > 0U))
SYSMPU_Enable(SYSMPU, 0);
#endif
s_cdcVcom.speed = USB_SPEED_FULL;
s_cdcVcom.attach = 0;
s_cdcVcom.cdcAcmHandle = (class_handle_t)NULL;
s_cdcVcom.deviceHandle = NULL;
if (kStatus_USB_Success != USB_DeviceClassInit(CONTROLLER_ID, &s_cdcAcmConfigList, &s_cdcVcom.deviceHandle))
{
usb_echo("USB device init failed\r\n");
}
else
{
usb_echo("USB device CDC virtual com demo\r\n");
s_cdcVcom.cdcAcmHandle = s_cdcAcmConfigList.config->classHandle;
}
USB_DeviceIsrEnable();
USB_DeviceRun(s_cdcVcom.deviceHandle);
}
I've also tried deleting the FreeRTOS task in deinit, but that crashes.
Is there an example to show how to do this (teardown + reinit) properly?
I saw this thread on the NXP Community, but this is for Host, not "Device", and doesn't user FreeRTOS either...