Hi all, good day!
We have a custom board that based on EVK1062 demo board. Our source code is based on SDK version 2.13.2.
I measured the current consumption at 3.3V rail when USB is initialized, up and running versus
when USB is not initialized and not running at all.
I can see about 8mA increase when USB is up and running which is pretty much normal since USB peripheral/clock is initialized.
During normal operation, we basically don't need USB. We only need it if we wanted to do firmware update or perform diagnostic check. So, by default USB is not initialize and will only initialize it when
it is connected. And then, when USB is disconnected, we de-initialize it.
The de-initialization, I've done it in a way that reversing the initialization steps.
I was surprise because after de-init the USB, the current that I was reading was still the same as when the USB is up and running.
Why is that? Can you please have a look below code snapshot? And please tell me if I forgot something or did something wrong.
Thank you very much.
Code snapshot for USB init:
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.deviceHandle = NULL;
if (kStatus_USB_Success != USB_DeviceInit(CONTROLLER_ID, USB_DeviceCallback, &s_cdcVcom.deviceHandle))
{
return;
}
USB_DeviceIsrEnable();
/*Add one delay here to make the DP pull down long enough to allow host to detect the previous disconnection.*/
SDK_DelayAtLeastUs(5000, BOARD_BOOTCLOCKRUN_CORE_CLOCK);
USB_DeviceRun(s_cdcVcom.deviceHandle);
Code snapshot for USB de-init:
uint32_t i_sr;
uint8_t irqNumber;
uint8_t usbDeviceEhciIrq[] = USBHS_IRQS;
irqNumber = usbDeviceEhciIrq[CONTROLLER_ID - kUSB_ControllerEhci0];
vf_enter_critical(&i_sr);
/* Stop the USB Device */
if(kStatus_USB_Success != USB_DeviceStop(s_cdcVcom.deviceHandle))
{
__asm("nop");
}
/* Disable the interrupt */
DisableIRQ((IRQn_Type)irqNumber);
s_cdcVcom.attach = 0;
s_cdcVcom.startTransactions = 0;
/* De-init the USB */
if(kStatus_USB_Success != USB_DeviceDeinit(s_cdcVcom.deviceHandle))
{
__asm("nop");
}
if(kUSB_ControllerEhci0 == CONTROLLER_ID)
{
/* disable the USB pll clock */
CLOCK_DisableUsbhs0PhyPllClock();
}
USB_EhciPhyDeinit(CONTROLLER_ID);
vf_exit_critical(i_sr);