RT1052 SDK2.7 USB CDC VCOM DeInit & Reinit

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

RT1052 SDK2.7 USB CDC VCOM DeInit & Reinit

Jump to solution
2,098 Views
variable_andrew
Senior Contributor I

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 RX Task Start...

  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);

  //  USB_DeviceIsrDisable(); -- doesn't exist - manually do below:
  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 /* FSL_FEATURE_SOC_SYSMPU_COUNT */
  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...

Labels (1)
1 Solution
2,010 Views
variable_andrew
Senior Contributor I

Hi jeremyzhou‌,

Looks like I got it working - issue related to the vTaskDelete for the USB Task.


Here's the project for testing USB teardown & re-init: GitHub - andrewrt/rt1050_cdc_vcom_freertos: RT1050 USB CDC VCOM FreeRTOS (w/ USB Task) demo - added ... 

To test: press the SW button on the EVK, it will try and tear down or re-init USB.

Is this (use of my de-init & re-init) the proper way to tear-down and re-init the USB vcom connection w/ USB Tasks?

View solution in original post

0 Kudos
4 Replies
2,010 Views
jeremyzhou
NXP Employee
NXP Employee

Hi ,

Thank you for your interest in NXP Semiconductor products and
for the opportunity to serve you.
I think I need more details about your demo project, so I was wondering if you can upload the complete the project and introduce the code flow in brief, as I can help me to figure the issue out.
Looking forward to your reply.

Have a great day,
TIC

 

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
2,011 Views
variable_andrew
Senior Contributor I

Hi jeremyzhou‌,

Looks like I got it working - issue related to the vTaskDelete for the USB Task.


Here's the project for testing USB teardown & re-init: GitHub - andrewrt/rt1050_cdc_vcom_freertos: RT1050 USB CDC VCOM FreeRTOS (w/ USB Task) demo - added ... 

To test: press the SW button on the EVK, it will try and tear down or re-init USB.

Is this (use of my de-init & re-init) the proper way to tear-down and re-init the USB vcom connection w/ USB Tasks?

0 Kudos
2,010 Views
jeremyzhou
NXP Employee
NXP Employee

Hi,

Thanks for your reply.
1) Is this (use of my de-init & re-init) the proper way to tear-down and re-init the USB VCOM connection w/ USB Tasks?
-- Yes, It's a proper way.

Have a great day,
TIC

 

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

1,940 Views
variable_andrew
Senior Contributor I

hi @jeremyzhou ,

I've updated the repository, and tested a bit more - if I repeatedly init and de-init the USB via the user button in the example I provided, eventually it seems the code will run out of heap space (so the de-init isn't freeing all the memory it is supposed to).

Could you please advise on what I'm missing in the USB de-init code to properly tear down USB?


Please refer to the updated repo for a demo - To test: press the SW button on the EVK, it will try and tear down or re-init USB.

Repo: https://github.com/andrewrt/rt1050_cdc_vcom_freertos

 

0 Kudos