2 * The Clear BSD License
3 * Copyright (c) 2015, Freescale Semiconductor, Inc.
4 * Copyright 2016-2017 NXP
7 * Redistribution and use in source and binary forms, with or without modification,
8 * are permitted (subject to the limitations in the disclaimer below) provided
9 * that the following conditions are met:
11 * o Redistributions of source code must retain the above copyright notice, this list
12 * of conditions and the following disclaimer.
14 * o Redistributions in binary form must reproduce the above copyright notice, this
15 * list of conditions and the following disclaimer in the documentation and/or
16 * other materials provided with the distribution.
18 * o Neither the name of the copyright holder nor the names of its
19 * contributors may be used to endorse or promote products derived from this
20 * software without specific prior written permission.
22 * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
27 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
30 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include "fsl_device_registers.h"
35 #include "clock_config.h"
41 #include "usb_device_config.h"
43 #include "usb_device.h"
45 #include "usb_device_cdc_acm.h"
46 #include "usb_device_ch9.h"
48 #include "usb_device_descriptor.h"
49 #include "virtual_com.h"
50 #if (defined(FSL_FEATURE_SOC_SYSMPU_COUNT) && (FSL_FEATURE_SOC_SYSMPU_COUNT > 0U))
51 #include "fsl_sysmpu.h"
52 #endif /* FSL_FEATURE_SOC_SYSMPU_COUNT */
53 #if defined(USB_DEVICE_CONFIG_EHCI) && (USB_DEVICE_CONFIG_EHCI > 0)
57 /* Provided by users. */
58 extern void USB_DeviceClockInit(void);
59 extern void USB_DeviceIsrEnable(void);
60 /*******************************************************************************
62 ******************************************************************************/
64 /*******************************************************************************
66 ******************************************************************************/
67 /* Data structure of virtual com device */
68 usb_cdc_vcom_struct_t s_cdcVcom;
70 /* Line codinig of cdc device */
71 static uint8_t s_lineCoding[LINE_CODING_SIZE] = {
72 /* E.g. 0x00,0xC2,0x01,0x00 : 0x0001C200 is 115200 bits per second */
73 (LINE_CODING_DTERATE >> 0U) & 0x000000FFU,
74 (LINE_CODING_DTERATE >> 8U) & 0x000000FFU,
75 (LINE_CODING_DTERATE >> 16U) & 0x000000FFU,
76 (LINE_CODING_DTERATE >> 24U) & 0x000000FFU,
77 LINE_CODING_CHARFORMAT,
78 LINE_CODING_PARITYTYPE,
79 LINE_CODING_DATABITS};
81 /* Abstract state of cdc device */
82 static uint8_t s_abstractState[COMM_FEATURE_DATA_SIZE] = {(STATUS_ABSTRACT_STATE >> 0U) & 0x00FFU,
83 (STATUS_ABSTRACT_STATE >> 8U) & 0x00FFU};
85 /* Country code of cdc device */
86 static uint8_t s_countryCode[COMM_FEATURE_DATA_SIZE] = {(COUNTRY_SETTING >> 0U) & 0x00FFU,
87 (COUNTRY_SETTING >> 8U) & 0x00FFU};
89 /* CDC ACM information */
90 static usb_cdc_acm_info_t s_usbCdcAcmInfo = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 0, 0, 0, 0};
92 /* Data buffer for receiving and sending*/
93 static uint8_t s_currRecvBuf[DATA_BUFF_SIZE];
94 volatile static uint32_t s_recvSize = 0;
95 volatile static uint32_t s_sendSize = 0;
96 volatile static uint8_t s_sendComplete = 0;
97 volatile static uint8_t s_currRecvIndex = 0;
98 static uint32_t s_usbBulkMaxPacketSize = FS_CDC_VCOM_BULK_OUT_PACKET_SIZE;
99 /*******************************************************************************
101 ******************************************************************************/
103 /*******************************************************************************
105 ******************************************************************************/
107 * @brief Interrupt in pipe callback function.
109 * This function serves as the callback function for interrupt in pipe.
111 * @param handle The USB device handle.
112 * @param message The endpoint callback message
113 * @param callbackParam The parameter of the callback.
115 * @return A USB error code or kStatus_USB_Success.
117 usb_status_t USB_DeviceCdcAcmInterruptIn(usb_device_handle handle,
118 usb_device_endpoint_callback_message_struct_t *message,
121 usb_status_t error = kStatus_USB_Error;
127 * @brief Bulk in pipe callback function.
129 * This function serves as the callback function for bulk in pipe.
131 * @param handle The USB device handle.
132 * @param message The endpoint callback message
133 * @param callbackParam The parameter of the callback.
135 * @return A USB error code or kStatus_USB_Success.
137 usb_status_t USB_DeviceCdcAcmBulkIn(usb_device_handle handle,
138 usb_device_endpoint_callback_message_struct_t *message,
141 usb_status_t error = kStatus_USB_Error;
143 if ((message->length != 0) && (!(message->length % s_usbBulkMaxPacketSize)))
145 /* If the last packet is the size of endpoint, then send also zero-ended packet,
146 ** meaning that we want to inform the host that we do not have any additional
147 ** data, so it can flush the output.
149 USB_DeviceSendRequest(handle, USB_CDC_VCOM_BULK_IN_ENDPOINT, NULL, 0);
151 else if ((1 == s_cdcVcom.attach) && (1 == s_cdcVcom.startTransactions))
153 if ((message->buffer != NULL) || ((message->buffer == NULL) && (message->length == 0)))
155 /* User: add your own code for send complete event */
157 #if defined(FSL_FEATURE_USB_KHCI_KEEP_ALIVE_ENABLED) && (FSL_FEATURE_USB_KHCI_KEEP_ALIVE_ENABLED > 0U) && \
158 defined(USB_DEVICE_CONFIG_KEEP_ALIVE_MODE) && (USB_DEVICE_CONFIG_KEEP_ALIVE_MODE > 0U) && \
159 defined(FSL_FEATURE_USB_KHCI_USB_RAM) && (FSL_FEATURE_USB_KHCI_USB_RAM > 0U)
160 USB0->INTEN &= ~USB_INTEN_SOFTOKEN_MASK;
164 else if ((0 == s_sendComplete) && (1 == s_cdcVcom.attach) && (0 == s_cdcVcom.startTransactions))
175 * @brief Bulk out pipe callback function.
177 * This function serves as the callback function for bulk out pipe.
179 * @param handle The USB device handle.
180 * @param message The endpoint callback message
181 * @param callbackParam The parameter of the callback.
183 * @return A USB error code or kStatus_USB_Success.
185 usb_status_t USB_DeviceCdcAcmBulkOut(usb_device_handle handle,
186 usb_device_endpoint_callback_message_struct_t *message,
189 usb_status_t error = kStatus_USB_Error;
190 if (USB_UNINITIALIZED_VAL_32 == message->length)
192 s_recvSize = 0xFFFFFFFFU;
194 else if ((1 == s_cdcVcom.attach) && (1 == s_cdcVcom.startTransactions))
196 s_recvSize = message->length;
197 #if defined(FSL_FEATURE_USB_KHCI_KEEP_ALIVE_ENABLED) && (FSL_FEATURE_USB_KHCI_KEEP_ALIVE_ENABLED > 0U) && \
198 defined(USB_DEVICE_CONFIG_KEEP_ALIVE_MODE) && (USB_DEVICE_CONFIG_KEEP_ALIVE_MODE > 0U) && \
199 defined(FSL_FEATURE_USB_KHCI_USB_RAM) && (FSL_FEATURE_USB_KHCI_USB_RAM > 0U)
200 USB0->INTEN |= USB_INTEN_SOFTOKEN_MASK;
204 #if defined(FSL_FEATURE_USB_KHCI_KEEP_ALIVE_ENABLED) && (FSL_FEATURE_USB_KHCI_KEEP_ALIVE_ENABLED > 0U) && \
205 defined(USB_DEVICE_CONFIG_KEEP_ALIVE_MODE) && (USB_DEVICE_CONFIG_KEEP_ALIVE_MODE > 0U) && \
206 defined(FSL_FEATURE_USB_KHCI_USB_RAM) && (FSL_FEATURE_USB_KHCI_USB_RAM > 0U)
207 USB0->INTEN &= ~USB_INTEN_SOFTOKEN_MASK;
218 * @brief Get the setup packet buffer.
220 * This function provides the buffer for setup packet.
222 * @param handle The USB device handle.
223 * @param setupBuffer The pointer to the address of setup packet buffer.
225 * @return A USB error code or kStatus_USB_Success.
227 usb_status_t USB_DeviceGetSetupBuffer(usb_device_handle handle, usb_setup_struct_t **setupBuffer)
229 static uint32_t cdcVcomSetup[2];
230 if (NULL == setupBuffer)
232 return kStatus_USB_InvalidParameter;
234 *setupBuffer = (usb_setup_struct_t *)&cdcVcomSetup;
235 return kStatus_USB_Success;
239 * @brief Get the setup packet data buffer.
241 * This function gets the data buffer for setup packet.
243 * @param handle The USB device handle.
244 * @param setup The pointer to the setup packet.
245 * @param length The pointer to the length of the data buffer.
246 * @param buffer The pointer to the address of setup packet data buffer.
248 * @return A USB error code or kStatus_USB_Success.
250 usb_status_t USB_DeviceGetClassReceiveBuffer(usb_device_handle handle,
251 usb_setup_struct_t *setup,
255 static uint8_t setupOut[8];
256 if ((NULL == buffer) || ((*length) > sizeof(setupOut)))
258 return kStatus_USB_InvalidRequest;
261 return kStatus_USB_Success;
265 * @brief Configure remote wakeup feature.
267 * This function configures the remote wakeup feature.
269 * @param handle The USB device handle.
270 * @param enable 1: enable, 0: disable.
272 * @return A USB error code or kStatus_USB_Success.
274 usb_status_t USB_DeviceConfigureRemoteWakeup(usb_device_handle handle, uint8_t enable)
276 return kStatus_USB_InvalidRequest;
280 * @brief CDC class specific callback function.
282 * This function handles the CDC class specific requests.
284 * @param handle The USB device handle.
285 * @param setup The pointer to the setup packet.
286 * @param length The pointer to the length of the data buffer.
287 * @param buffer The pointer to the address of setup packet data buffer.
289 * @return A USB error code or kStatus_USB_Success.
291 usb_status_t USB_DeviceProcessClassRequest(usb_device_handle handle,
292 usb_setup_struct_t *setup,
296 usb_status_t error = kStatus_USB_InvalidRequest;
298 usb_cdc_acm_info_t *acmInfo = &s_usbCdcAcmInfo;
300 uint16_t *uartBitmap;
301 if (setup->wIndex != USB_CDC_VCOM_COMM_INTERFACE_INDEX)
306 switch (setup->bRequest)
308 case USB_DEVICE_CDC_REQUEST_SEND_ENCAPSULATED_COMMAND:
310 case USB_DEVICE_CDC_REQUEST_GET_ENCAPSULATED_RESPONSE:
312 case USB_DEVICE_CDC_REQUEST_SET_COMM_FEATURE:
313 if (USB_DEVICE_CDC_FEATURE_ABSTRACT_STATE == setup->wValue)
315 *buffer = s_abstractState;
317 else if (USB_DEVICE_CDC_FEATURE_COUNTRY_SETTING == setup->wValue)
319 *buffer = s_countryCode;
324 error = kStatus_USB_Success;
326 case USB_DEVICE_CDC_REQUEST_GET_COMM_FEATURE:
327 if (USB_DEVICE_CDC_FEATURE_ABSTRACT_STATE == setup->wValue)
329 *buffer = s_abstractState;
330 *length = COMM_FEATURE_DATA_SIZE;
332 else if (USB_DEVICE_CDC_FEATURE_COUNTRY_SETTING == setup->wValue)
334 *buffer = s_countryCode;
335 *length = COMM_FEATURE_DATA_SIZE;
340 error = kStatus_USB_Success;
342 case USB_DEVICE_CDC_REQUEST_CLEAR_COMM_FEATURE:
344 case USB_DEVICE_CDC_REQUEST_GET_LINE_CODING:
345 *buffer = s_lineCoding;
346 *length = LINE_CODING_SIZE;
347 error = kStatus_USB_Success;
349 case USB_DEVICE_CDC_REQUEST_SET_LINE_CODING:
350 *buffer = s_lineCoding;
351 error = kStatus_USB_Success;
353 case USB_DEVICE_CDC_REQUEST_SET_CONTROL_LINE_STATE:
355 acmInfo->dteStatus = setup->wValue;
356 /* activate/deactivate Tx carrier */
357 if (acmInfo->dteStatus & USB_DEVICE_CDC_CONTROL_SIG_BITMAP_CARRIER_ACTIVATION)
359 acmInfo->uartState |= USB_DEVICE_CDC_UART_STATE_TX_CARRIER;
363 acmInfo->uartState &= (uint16_t)~USB_DEVICE_CDC_UART_STATE_TX_CARRIER;
366 /* activate carrier and DTE */
367 if (acmInfo->dteStatus & USB_DEVICE_CDC_CONTROL_SIG_BITMAP_DTE_PRESENCE)
369 acmInfo->uartState |= USB_DEVICE_CDC_UART_STATE_RX_CARRIER;
373 acmInfo->uartState &= (uint16_t)~USB_DEVICE_CDC_UART_STATE_RX_CARRIER;
376 /* Indicates to DCE if DTE is present or not */
377 acmInfo->dtePresent = (acmInfo->dteStatus & USB_DEVICE_CDC_CONTROL_SIG_BITMAP_DTE_PRESENCE) ? true : false;
379 /* Initialize the serial state buffer */
380 acmInfo->serialStateBuf[0] = NOTIF_REQUEST_TYPE; /* bmRequestType */
381 acmInfo->serialStateBuf[1] = USB_DEVICE_CDC_REQUEST_SERIAL_STATE_NOTIF; /* bNotification */
382 acmInfo->serialStateBuf[2] = 0x00; /* wValue */
383 acmInfo->serialStateBuf[3] = 0x00;
384 acmInfo->serialStateBuf[4] = 0x00; /* wIndex */
385 acmInfo->serialStateBuf[5] = 0x00;
386 acmInfo->serialStateBuf[6] = UART_BITMAP_SIZE; /* wLength */
387 acmInfo->serialStateBuf[7] = 0x00;
388 /* Notifiy to host the line state */
389 acmInfo->serialStateBuf[4] = setup->wIndex;
390 /* Lower byte of UART BITMAP */
391 uartBitmap = (uint16_t *)&acmInfo->serialStateBuf[NOTIF_PACKET_SIZE + UART_BITMAP_SIZE - 2];
392 *uartBitmap = acmInfo->uartState;
393 len = (uint32_t)(NOTIF_PACKET_SIZE + UART_BITMAP_SIZE);
394 error = USB_DeviceSendRequest(handle, USB_CDC_VCOM_INTERRUPT_IN_ENDPOINT, acmInfo->serialStateBuf, len);
397 if (acmInfo->dteStatus & USB_DEVICE_CDC_CONTROL_SIG_BITMAP_CARRIER_ACTIVATION)
399 /* To do: CARRIER_ACTIVATED */
403 /* To do: CARRIER_DEACTIVATED */
405 if (acmInfo->dteStatus & USB_DEVICE_CDC_CONTROL_SIG_BITMAP_DTE_PRESENCE)
408 if (1 == s_cdcVcom.attach)
410 s_cdcVcom.startTransactions = 1;
411 #if defined(FSL_FEATURE_USB_KHCI_KEEP_ALIVE_ENABLED) && (FSL_FEATURE_USB_KHCI_KEEP_ALIVE_ENABLED > 0U) && \
412 defined(USB_DEVICE_CONFIG_KEEP_ALIVE_MODE) && (USB_DEVICE_CONFIG_KEEP_ALIVE_MODE > 0U) && \
413 defined(FSL_FEATURE_USB_KHCI_USB_RAM) && (FSL_FEATURE_USB_KHCI_USB_RAM > 0U)
414 USB0->INTEN &= ~USB_INTEN_SOFTOKEN_MASK;
420 /* DTE_DEACTIVATED */
421 if (1 == s_cdcVcom.attach)
423 s_cdcVcom.startTransactions = 0;
428 case USB_DEVICE_CDC_REQUEST_SEND_BREAK:
438 * @brief USB device callback function.
440 * This function handles the usb device specific requests.
442 * @param handle The USB device handle.
443 * @param event The USB device event type.
444 * @param param The parameter of the device specific request.
446 * @return A USB error code or kStatus_USB_Success.
448 usb_status_t USB_DeviceCallback(usb_device_handle handle, uint32_t event, void *param)
450 usb_status_t error = kStatus_USB_Error;
451 uint8_t *temp8 = (uint8_t *)param;
455 case kUSB_DeviceEventBusReset:
457 USB_DeviceControlPipeInit(s_cdcVcom.deviceHandle);
458 s_cdcVcom.attach = 0;
459 #if (defined(USB_DEVICE_CONFIG_EHCI) && (USB_DEVICE_CONFIG_EHCI > 0)) || \
460 (defined(USB_DEVICE_CONFIG_LPCIP3511HS) && (USB_DEVICE_CONFIG_LPCIP3511HS > 0U))
461 if (kStatus_USB_Success ==
462 USB_DeviceGetStatus(s_cdcVcom.deviceHandle, kUSB_DeviceStatusSpeed, &s_cdcVcom.speed))
464 USB_DeviceSetSpeed(handle, s_cdcVcom.speed);
469 case kUSB_DeviceEventSetConfiguration:
472 s_cdcVcom.attach = 1;
473 s_cdcVcom.currentConfiguration = *temp8;
474 if (USB_CDC_VCOM_CONFIGURE_INDEX == (*temp8))
476 usb_device_endpoint_init_struct_t epInitStruct;
477 usb_device_endpoint_callback_struct_t endpointCallback;
479 /* Initiailize endpoint for interrupt pipe */
480 endpointCallback.callbackFn = USB_DeviceCdcAcmInterruptIn;
481 endpointCallback.callbackParam = handle;
483 epInitStruct.zlt = 0;
484 epInitStruct.transferType = USB_ENDPOINT_INTERRUPT;
485 epInitStruct.endpointAddress = USB_CDC_VCOM_INTERRUPT_IN_ENDPOINT |
486 (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT);
487 if (USB_SPEED_HIGH == s_cdcVcom.speed)
489 epInitStruct.maxPacketSize = HS_CDC_VCOM_INTERRUPT_IN_PACKET_SIZE;
493 epInitStruct.maxPacketSize = FS_CDC_VCOM_INTERRUPT_IN_PACKET_SIZE;
496 USB_DeviceInitEndpoint(s_cdcVcom.deviceHandle, &epInitStruct, &endpointCallback);
498 /* Initiailize endpoints for bulk pipe */
499 endpointCallback.callbackFn = USB_DeviceCdcAcmBulkIn;
500 endpointCallback.callbackParam = handle;
502 epInitStruct.zlt = 0;
503 epInitStruct.transferType = USB_ENDPOINT_BULK;
504 epInitStruct.endpointAddress =
505 USB_CDC_VCOM_BULK_IN_ENDPOINT | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT);
506 if (USB_SPEED_HIGH == s_cdcVcom.speed)
508 epInitStruct.maxPacketSize = HS_CDC_VCOM_BULK_IN_PACKET_SIZE;
512 epInitStruct.maxPacketSize = FS_CDC_VCOM_BULK_IN_PACKET_SIZE;
515 USB_DeviceInitEndpoint(s_cdcVcom.deviceHandle, &epInitStruct, &endpointCallback);
517 endpointCallback.callbackFn = USB_DeviceCdcAcmBulkOut;
518 endpointCallback.callbackParam = handle;
520 epInitStruct.zlt = 0;
521 epInitStruct.transferType = USB_ENDPOINT_BULK;
522 epInitStruct.endpointAddress =
523 USB_CDC_VCOM_BULK_OUT_ENDPOINT | (USB_OUT << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT);
524 if (USB_SPEED_HIGH == s_cdcVcom.speed)
526 epInitStruct.maxPacketSize = HS_CDC_VCOM_BULK_OUT_PACKET_SIZE;
530 epInitStruct.maxPacketSize = FS_CDC_VCOM_BULK_OUT_PACKET_SIZE;
533 USB_DeviceInitEndpoint(s_cdcVcom.deviceHandle, &epInitStruct, &endpointCallback);
535 if (USB_SPEED_HIGH == s_cdcVcom.speed)
537 s_usbBulkMaxPacketSize = HS_CDC_VCOM_BULK_OUT_PACKET_SIZE;
541 s_usbBulkMaxPacketSize = FS_CDC_VCOM_BULK_OUT_PACKET_SIZE;
554 * @brief USB configure endpoint function.
556 * This function configure endpoint status.
558 * @param handle The USB device handle.
559 * @param ep Endpoint address.
560 * @param status A flag to indicate whether to stall the endpoint. 1: stall, 0: unstall.
562 * @return A USB error code or kStatus_USB_Success.
564 usb_status_t USB_DeviceConfigureEndpointStatus(usb_device_handle handle, uint8_t ep, uint8_t status)
568 return USB_DeviceStallEndpoint(handle, ep);
572 return USB_DeviceUnstallEndpoint(handle, ep);
576 /* See virtual_com.h for documentation of this function. */
577 void USB_VcomWriteBlocking(usb_device_handle baseAddr, const uint8_t *buf, size_t count)
579 while ((s_cdcVcom.attach != 1) || (s_cdcVcom.startTransactions != 1))
583 USB_DeviceSendRequest((usb_device_handle)baseAddr, USB_CDC_VCOM_BULK_IN_ENDPOINT, (uint8_t *)buf, count);
584 while (!s_sendComplete)
591 /* See virtual_com.h for documentation of this function. */
592 status_t USB_VcomReadBlocking(usb_device_handle baseAddr, uint8_t *buf, size_t count)
594 status_t error = kStatus_Success;
595 size_t bufIndex = 0U, bytesToReceive = 0U;
598 /* Waiting for the USB ready. */
599 while ((s_cdcVcom.attach != 1) || (s_cdcVcom.startTransactions != 1))
606 /* If no receive request. */
609 if (kStatus_USB_Success !=
610 USB_DeviceRecvRequest(baseAddr, USB_CDC_VCOM_BULK_OUT_ENDPOINT, s_currRecvBuf, s_usbBulkMaxPacketSize))
616 /* Waiting for data received by virtual com. */
617 while (s_recvSize <= 0)
622 /* When receive request is error. */
623 if (0xFFFFFFFFU == s_recvSize)
625 /* Waiting for the USB ready and transfer started. */
626 while ((s_cdcVcom.attach != 1) || (s_cdcVcom.startTransactions != 1))
634 bytesToReceive = MIN(count, s_recvSize);
635 memcpy((void *)&buf[bufIndex], s_currRecvBuf + s_currRecvIndex, bytesToReceive);
636 count -= bytesToReceive;
637 s_recvSize -= bytesToReceive;
638 bufIndex += bytesToReceive;
639 s_currRecvIndex += bytesToReceive;
641 } while (0U != count);
645 /* See virtual_com.h for documentation of this function. */
646 usb_device_handle USB_VcomInit(void)
648 usb_device_handle deviceHandle = NULL;
650 USB_DeviceClockInit();
652 #if (defined(FSL_FEATURE_SOC_SYSMPU_COUNT) && (FSL_FEATURE_SOC_SYSMPU_COUNT > 0U))
653 SYSMPU_Enable(SYSMPU, 0);
654 #endif /* FSL_FEATURE_SOC_SYSMPU_COUNT */
656 s_cdcVcom.speed = USB_SPEED_FULL;
657 s_cdcVcom.attach = 0;
658 s_cdcVcom.deviceHandle = NULL;
660 if (kStatus_USB_Success != USB_DeviceInit(CONTROLLER_ID, USB_DeviceCallback, &s_cdcVcom.deviceHandle))
666 deviceHandle = s_cdcVcom.deviceHandle;
667 USB_DeviceIsrEnable();
668 USB_DeviceRun(s_cdcVcom.deviceHandle);
673 /* See virtual_com.h for documentation of this function. */
674 void USB_VcomDeinit(usb_device_handle deviceHandle)
676 USB_DeviceStop(deviceHandle);
677 USB_DeviceDeinit(deviceHandle);
678 s_cdcVcom.deviceHandle = NULL;
679 #if defined(USB_DEVICE_CONFIG_EHCI) && (USB_DEVICE_CONFIG_EHCI > 0)
680 USB_EhciPhyDeinit(CONTROLLER_ID);
682 #if defined(USB_DEVICE_CONFIG_KHCI) && (USB_DEVICE_CONFIG_KHCI > 0)
683 CLOCK_DisableUsbfs0Clock();
685 #if defined(USB_DEVICE_CONFIG_LPCIP3511FS) && (USB_DEVICE_CONFIG_LPCIP3511FS > 0U)
686 /* enable USB IP clock, user code. */
687 CLOCK_DisableClock(kCLOCK_Usbd0);
688 #endif /* USB_DEVICE_CONFIG_LPCIP3511FS */
690 #if defined(USB_DEVICE_CONFIG_LPCIP3511HS) && (USB_DEVICE_CONFIG_LPCIP3511HS > 0U)
691 /* enable USB IP clock,user code. */
692 #endif /* USB_DEVICE_CONFIG_LPCIP3511HS */