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"
40 #include "usb_device_config.h"
42 #include "usb_device.h"
44 #include "usb_device_cdc_acm.h"
45 #include "usb_device_ch9.h"
47 #include "usb_device_descriptor.h"
48 #include "virtual_com.h"
49 #if (defined(FSL_FEATURE_SOC_SYSMPU_COUNT) && (FSL_FEATURE_SOC_SYSMPU_COUNT > 0U))
50 #include "fsl_sysmpu.h"
51 #endif /* FSL_FEATURE_SOC_SYSMPU_COUNT */
52 #if defined(USB_DEVICE_CONFIG_EHCI) && (USB_DEVICE_CONFIG_EHCI > 0)
59 /* Provided by users. */
60 extern void USB_DeviceClockInit(void);
61 extern void USB_DeviceIsrEnable(void);
62 /*******************************************************************************
64 ******************************************************************************/
66 /*******************************************************************************
68 ******************************************************************************/
70 static uint8_t cdc_rx_buf_space[1024];
71 static uint8_t cdc_tx_buf_space[1024] alignas(4);
73 static struct ringbuf cdc_rx_buf =
74 RINGBUF_INIT (cdc_rx_buf_space, sizeof (cdc_rx_buf_space));
76 struct buffer cdc_tx_buf;
78 /* Data structure of virtual com device */
79 usb_cdc_vcom_struct_t s_cdcVcom;
81 /* Line codinig of cdc device */
82 static uint8_t s_lineCoding[LINE_CODING_SIZE] = {
83 /* E.g. 0x00,0xC2,0x01,0x00 : 0x0001C200 is 115200 bits per second */
84 (LINE_CODING_DTERATE >> 0U) & 0x000000FFU,
85 (LINE_CODING_DTERATE >> 8U) & 0x000000FFU,
86 (LINE_CODING_DTERATE >> 16U) & 0x000000FFU,
87 (LINE_CODING_DTERATE >> 24U) & 0x000000FFU,
88 LINE_CODING_CHARFORMAT,
89 LINE_CODING_PARITYTYPE,
90 LINE_CODING_DATABITS};
92 /* Abstract state of cdc device */
93 static uint8_t s_abstractState[COMM_FEATURE_DATA_SIZE] = {(STATUS_ABSTRACT_STATE >> 0U) & 0x00FFU,
94 (STATUS_ABSTRACT_STATE >> 8U) & 0x00FFU};
96 /* Country code of cdc device */
97 static uint8_t s_countryCode[COMM_FEATURE_DATA_SIZE] = {(COUNTRY_SETTING >> 0U) & 0x00FFU,
98 (COUNTRY_SETTING >> 8U) & 0x00FFU};
100 /* CDC ACM information */
101 static usb_cdc_acm_info_t s_usbCdcAcmInfo = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 0, 0, 0, 0};
103 /* Data buffer for receiving and sending*/
104 static uint8_t s_currRecvBuf[DATA_BUFF_SIZE];
105 static volatile uint32_t s_recvSize = 0;
106 static volatile uint8_t s_sendComplete = 0;
107 static uint32_t s_usbBulkMaxPacketSize = FS_CDC_VCOM_BULK_OUT_PACKET_SIZE;
108 /*******************************************************************************
110 ******************************************************************************/
112 /*******************************************************************************
114 ******************************************************************************/
116 * @brief Interrupt in pipe callback function.
118 * This function serves as the callback function for interrupt in pipe.
120 * @param handle The USB device handle.
121 * @param message The endpoint callback message
122 * @param callbackParam The parameter of the callback.
124 * @return A USB error code or kStatus_USB_Success.
126 usb_status_t USB_DeviceCdcAcmInterruptIn(usb_device_handle handle,
127 usb_device_endpoint_callback_message_struct_t *message,
130 usb_status_t error = kStatus_USB_Error;
136 * @brief Bulk in pipe callback function.
138 * This function serves as the callback function for bulk in pipe.
140 * @param handle The USB device handle.
141 * @param message The endpoint callback message
142 * @param callbackParam The parameter of the callback.
144 * @return A USB error code or kStatus_USB_Success.
146 usb_status_t USB_DeviceCdcAcmBulkIn(usb_device_handle handle,
147 usb_device_endpoint_callback_message_struct_t *message,
150 usb_status_t error = kStatus_USB_Error;
152 if ((message->length != 0) && (!(message->length % s_usbBulkMaxPacketSize)))
154 /* If the last packet is the size of endpoint, then send also zero-ended packet,
155 ** meaning that we want to inform the host that we do not have any additional
156 ** data, so it can flush the output.
158 USB_DeviceSendRequest(handle, USB_CDC_VCOM_BULK_IN_ENDPOINT, NULL, 0);
160 else if ((1 == s_cdcVcom.attach) && (1 == s_cdcVcom.startTransactions))
162 if ((message->buffer != NULL) || ((message->buffer == NULL) && (message->length == 0)))
164 /* User: add your own code for send complete event */
166 USB_DeviceRecvRequest (handle, USB_CDC_VCOM_BULK_OUT_ENDPOINT, s_currRecvBuf, s_usbBulkMaxPacketSize);
167 #if defined(FSL_FEATURE_USB_KHCI_KEEP_ALIVE_ENABLED) && (FSL_FEATURE_USB_KHCI_KEEP_ALIVE_ENABLED > 0U) && \
168 defined(USB_DEVICE_CONFIG_KEEP_ALIVE_MODE) && (USB_DEVICE_CONFIG_KEEP_ALIVE_MODE > 0U) && \
169 defined(FSL_FEATURE_USB_KHCI_USB_RAM) && (FSL_FEATURE_USB_KHCI_USB_RAM > 0U)
170 USB0->INTEN &= ~USB_INTEN_SOFTOKEN_MASK;
174 else if ((0 == s_sendComplete) && (1 == s_cdcVcom.attach) && (0 == s_cdcVcom.startTransactions))
185 * @brief Bulk out pipe callback function.
187 * This function serves as the callback function for bulk out pipe.
189 * @param handle The USB device handle.
190 * @param message The endpoint callback message
191 * @param callbackParam The parameter of the callback.
193 * @return A USB error code or kStatus_USB_Success.
195 usb_status_t USB_DeviceCdcAcmBulkOut(usb_device_handle handle,
196 usb_device_endpoint_callback_message_struct_t *message,
199 usb_status_t error = kStatus_USB_Error;
200 if (USB_UNINITIALIZED_VAL_32 == message->length)
202 s_recvSize = 0xFFFFFFFFU;
204 else if ((1 == s_cdcVcom.attach) && (1 == s_cdcVcom.startTransactions))
206 s_recvSize = message->length;
207 #if defined(FSL_FEATURE_USB_KHCI_KEEP_ALIVE_ENABLED) && (FSL_FEATURE_USB_KHCI_KEEP_ALIVE_ENABLED > 0U) && \
208 defined(USB_DEVICE_CONFIG_KEEP_ALIVE_MODE) && (USB_DEVICE_CONFIG_KEEP_ALIVE_MODE > 0U) && \
209 defined(FSL_FEATURE_USB_KHCI_USB_RAM) && (FSL_FEATURE_USB_KHCI_USB_RAM > 0U)
210 USB0->INTEN |= USB_INTEN_SOFTOKEN_MASK;
214 for (uint32_t offset = 0; s_recvSize-- > 0; offset++) {
215 if (ringbuf_is_full (&cdc_rx_buf))
218 ringbuf_write (&cdc_rx_buf, s_currRecvBuf[offset]);
226 #if defined(FSL_FEATURE_USB_KHCI_KEEP_ALIVE_ENABLED) && (FSL_FEATURE_USB_KHCI_KEEP_ALIVE_ENABLED > 0U) && \
227 defined(USB_DEVICE_CONFIG_KEEP_ALIVE_MODE) && (USB_DEVICE_CONFIG_KEEP_ALIVE_MODE > 0U) && \
228 defined(FSL_FEATURE_USB_KHCI_USB_RAM) && (FSL_FEATURE_USB_KHCI_USB_RAM > 0U)
229 USB0->INTEN &= ~USB_INTEN_SOFTOKEN_MASK;
232 USB_DeviceRecvRequest (handle, USB_CDC_VCOM_BULK_OUT_ENDPOINT, s_currRecvBuf, s_usbBulkMaxPacketSize);
242 * @brief Get the setup packet buffer.
244 * This function provides the buffer for setup packet.
246 * @param handle The USB device handle.
247 * @param setupBuffer The pointer to the address of setup packet buffer.
249 * @return A USB error code or kStatus_USB_Success.
251 usb_status_t USB_DeviceGetSetupBuffer(usb_device_handle handle, usb_setup_struct_t **setupBuffer)
253 static uint32_t cdcVcomSetup[2];
254 if (NULL == setupBuffer)
256 return kStatus_USB_InvalidParameter;
258 *setupBuffer = (usb_setup_struct_t *)&cdcVcomSetup;
259 return kStatus_USB_Success;
263 * @brief Get the setup packet data buffer.
265 * This function gets the data buffer for setup packet.
267 * @param handle The USB device handle.
268 * @param setup The pointer to the setup packet.
269 * @param length The pointer to the length of the data buffer.
270 * @param buffer The pointer to the address of setup packet data buffer.
272 * @return A USB error code or kStatus_USB_Success.
274 usb_status_t USB_DeviceGetClassReceiveBuffer(usb_device_handle handle,
275 usb_setup_struct_t *setup,
279 static uint8_t setupOut[8];
280 if ((NULL == buffer) || ((*length) > sizeof(setupOut)))
282 return kStatus_USB_InvalidRequest;
285 return kStatus_USB_Success;
289 * @brief Configure remote wakeup feature.
291 * This function configures the remote wakeup feature.
293 * @param handle The USB device handle.
294 * @param enable 1: enable, 0: disable.
296 * @return A USB error code or kStatus_USB_Success.
298 usb_status_t USB_DeviceConfigureRemoteWakeup(usb_device_handle handle, uint8_t enable)
300 return kStatus_USB_InvalidRequest;
304 * @brief CDC class specific callback function.
306 * This function handles the CDC class specific requests.
308 * @param handle The USB device handle.
309 * @param setup The pointer to the setup packet.
310 * @param length The pointer to the length of the data buffer.
311 * @param buffer The pointer to the address of setup packet data buffer.
313 * @return A USB error code or kStatus_USB_Success.
315 usb_status_t USB_DeviceProcessClassRequest(usb_device_handle handle,
316 usb_setup_struct_t *setup,
320 usb_status_t error = kStatus_USB_InvalidRequest;
322 usb_cdc_acm_info_t *acmInfo = &s_usbCdcAcmInfo;
324 uint16_t *uartBitmap;
325 if (setup->wIndex != USB_CDC_VCOM_COMM_INTERFACE_INDEX)
330 switch (setup->bRequest)
332 case USB_DEVICE_CDC_REQUEST_SEND_ENCAPSULATED_COMMAND:
334 case USB_DEVICE_CDC_REQUEST_GET_ENCAPSULATED_RESPONSE:
336 case USB_DEVICE_CDC_REQUEST_SET_COMM_FEATURE:
337 if (USB_DEVICE_CDC_FEATURE_ABSTRACT_STATE == setup->wValue)
339 *buffer = s_abstractState;
341 else if (USB_DEVICE_CDC_FEATURE_COUNTRY_SETTING == setup->wValue)
343 *buffer = s_countryCode;
348 error = kStatus_USB_Success;
350 case USB_DEVICE_CDC_REQUEST_GET_COMM_FEATURE:
351 if (USB_DEVICE_CDC_FEATURE_ABSTRACT_STATE == setup->wValue)
353 *buffer = s_abstractState;
354 *length = COMM_FEATURE_DATA_SIZE;
356 else if (USB_DEVICE_CDC_FEATURE_COUNTRY_SETTING == setup->wValue)
358 *buffer = s_countryCode;
359 *length = COMM_FEATURE_DATA_SIZE;
364 error = kStatus_USB_Success;
366 case USB_DEVICE_CDC_REQUEST_CLEAR_COMM_FEATURE:
368 case USB_DEVICE_CDC_REQUEST_GET_LINE_CODING:
369 *buffer = s_lineCoding;
370 *length = LINE_CODING_SIZE;
371 error = kStatus_USB_Success;
373 case USB_DEVICE_CDC_REQUEST_SET_LINE_CODING:
374 *buffer = s_lineCoding;
375 error = kStatus_USB_Success;
377 case USB_DEVICE_CDC_REQUEST_SET_CONTROL_LINE_STATE:
379 acmInfo->dteStatus = setup->wValue;
380 /* activate/deactivate Tx carrier */
381 if (acmInfo->dteStatus & USB_DEVICE_CDC_CONTROL_SIG_BITMAP_CARRIER_ACTIVATION)
383 acmInfo->uartState |= USB_DEVICE_CDC_UART_STATE_TX_CARRIER;
387 acmInfo->uartState &= (uint16_t)~USB_DEVICE_CDC_UART_STATE_TX_CARRIER;
390 /* activate carrier and DTE */
391 if (acmInfo->dteStatus & USB_DEVICE_CDC_CONTROL_SIG_BITMAP_DTE_PRESENCE)
393 acmInfo->uartState |= USB_DEVICE_CDC_UART_STATE_RX_CARRIER;
397 acmInfo->uartState &= (uint16_t)~USB_DEVICE_CDC_UART_STATE_RX_CARRIER;
400 /* Indicates to DCE if DTE is present or not */
401 acmInfo->dtePresent = (acmInfo->dteStatus & USB_DEVICE_CDC_CONTROL_SIG_BITMAP_DTE_PRESENCE) ? true : false;
403 /* Initialize the serial state buffer */
404 acmInfo->serialStateBuf[0] = NOTIF_REQUEST_TYPE; /* bmRequestType */
405 acmInfo->serialStateBuf[1] = USB_DEVICE_CDC_REQUEST_SERIAL_STATE_NOTIF; /* bNotification */
406 acmInfo->serialStateBuf[2] = 0x00; /* wValue */
407 acmInfo->serialStateBuf[3] = 0x00;
408 acmInfo->serialStateBuf[4] = 0x00; /* wIndex */
409 acmInfo->serialStateBuf[5] = 0x00;
410 acmInfo->serialStateBuf[6] = UART_BITMAP_SIZE; /* wLength */
411 acmInfo->serialStateBuf[7] = 0x00;
412 /* Notifiy to host the line state */
413 acmInfo->serialStateBuf[4] = setup->wIndex;
414 /* Lower byte of UART BITMAP */
415 uartBitmap = (uint16_t *)&acmInfo->serialStateBuf[NOTIF_PACKET_SIZE + UART_BITMAP_SIZE - 2];
416 *uartBitmap = acmInfo->uartState;
417 len = (uint32_t)(NOTIF_PACKET_SIZE + UART_BITMAP_SIZE);
418 error = USB_DeviceSendRequest(handle, USB_CDC_VCOM_INTERRUPT_IN_ENDPOINT, acmInfo->serialStateBuf, len);
421 if (acmInfo->dteStatus & USB_DEVICE_CDC_CONTROL_SIG_BITMAP_CARRIER_ACTIVATION)
423 /* To do: CARRIER_ACTIVATED */
427 /* To do: CARRIER_DEACTIVATED */
429 if (acmInfo->dteStatus & USB_DEVICE_CDC_CONTROL_SIG_BITMAP_DTE_PRESENCE)
432 if (1 == s_cdcVcom.attach)
434 s_cdcVcom.startTransactions = 1;
435 #if defined(FSL_FEATURE_USB_KHCI_KEEP_ALIVE_ENABLED) && (FSL_FEATURE_USB_KHCI_KEEP_ALIVE_ENABLED > 0U) && \
436 defined(USB_DEVICE_CONFIG_KEEP_ALIVE_MODE) && (USB_DEVICE_CONFIG_KEEP_ALIVE_MODE > 0U) && \
437 defined(FSL_FEATURE_USB_KHCI_USB_RAM) && (FSL_FEATURE_USB_KHCI_USB_RAM > 0U)
438 USB0->INTEN &= ~USB_INTEN_SOFTOKEN_MASK;
444 /* DTE_DEACTIVATED */
445 if (1 == s_cdcVcom.attach)
447 s_cdcVcom.startTransactions = 0;
452 case USB_DEVICE_CDC_REQUEST_SEND_BREAK:
462 * @brief USB device callback function.
464 * This function handles the usb device specific requests.
466 * @param handle The USB device handle.
467 * @param event The USB device event type.
468 * @param param The parameter of the device specific request.
470 * @return A USB error code or kStatus_USB_Success.
472 usb_status_t USB_DeviceCallback(usb_device_handle handle, uint32_t event, void *param)
474 usb_status_t error = kStatus_USB_Error;
475 uint8_t *temp8 = (uint8_t *)param;
479 case kUSB_DeviceEventBusReset:
481 USB_DeviceControlPipeInit(s_cdcVcom.deviceHandle);
482 s_cdcVcom.attach = 0;
483 #if (defined(USB_DEVICE_CONFIG_EHCI) && (USB_DEVICE_CONFIG_EHCI > 0)) || \
484 (defined(USB_DEVICE_CONFIG_LPCIP3511HS) && (USB_DEVICE_CONFIG_LPCIP3511HS > 0U))
485 if (kStatus_USB_Success ==
486 USB_DeviceGetStatus(s_cdcVcom.deviceHandle, kUSB_DeviceStatusSpeed, &s_cdcVcom.speed))
488 USB_DeviceSetSpeed(handle, s_cdcVcom.speed);
493 case kUSB_DeviceEventSetConfiguration:
496 s_cdcVcom.attach = 1;
497 s_cdcVcom.currentConfiguration = *temp8;
498 if (USB_CDC_VCOM_CONFIGURE_INDEX == (*temp8))
500 usb_device_endpoint_init_struct_t epInitStruct;
501 usb_device_endpoint_callback_struct_t endpointCallback;
503 /* Initiailize endpoint for interrupt pipe */
504 endpointCallback.callbackFn = USB_DeviceCdcAcmInterruptIn;
505 endpointCallback.callbackParam = handle;
507 epInitStruct.zlt = 0;
508 epInitStruct.transferType = USB_ENDPOINT_INTERRUPT;
509 epInitStruct.endpointAddress = USB_CDC_VCOM_INTERRUPT_IN_ENDPOINT |
510 (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT);
511 if (USB_SPEED_HIGH == s_cdcVcom.speed)
513 epInitStruct.maxPacketSize = HS_CDC_VCOM_INTERRUPT_IN_PACKET_SIZE;
517 epInitStruct.maxPacketSize = FS_CDC_VCOM_INTERRUPT_IN_PACKET_SIZE;
520 USB_DeviceInitEndpoint(s_cdcVcom.deviceHandle, &epInitStruct, &endpointCallback);
522 /* Initiailize endpoints for bulk pipe */
523 endpointCallback.callbackFn = USB_DeviceCdcAcmBulkIn;
524 endpointCallback.callbackParam = handle;
526 epInitStruct.zlt = 0;
527 epInitStruct.transferType = USB_ENDPOINT_BULK;
528 epInitStruct.endpointAddress =
529 USB_CDC_VCOM_BULK_IN_ENDPOINT | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT);
530 if (USB_SPEED_HIGH == s_cdcVcom.speed)
532 epInitStruct.maxPacketSize = HS_CDC_VCOM_BULK_IN_PACKET_SIZE;
536 epInitStruct.maxPacketSize = FS_CDC_VCOM_BULK_IN_PACKET_SIZE;
539 USB_DeviceInitEndpoint(s_cdcVcom.deviceHandle, &epInitStruct, &endpointCallback);
541 endpointCallback.callbackFn = USB_DeviceCdcAcmBulkOut;
542 endpointCallback.callbackParam = handle;
544 epInitStruct.zlt = 0;
545 epInitStruct.transferType = USB_ENDPOINT_BULK;
546 epInitStruct.endpointAddress =
547 USB_CDC_VCOM_BULK_OUT_ENDPOINT | (USB_OUT << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT);
548 if (USB_SPEED_HIGH == s_cdcVcom.speed)
550 epInitStruct.maxPacketSize = HS_CDC_VCOM_BULK_OUT_PACKET_SIZE;
554 epInitStruct.maxPacketSize = FS_CDC_VCOM_BULK_OUT_PACKET_SIZE;
557 USB_DeviceInitEndpoint(s_cdcVcom.deviceHandle, &epInitStruct, &endpointCallback);
559 if (USB_SPEED_HIGH == s_cdcVcom.speed)
561 s_usbBulkMaxPacketSize = HS_CDC_VCOM_BULK_OUT_PACKET_SIZE;
565 s_usbBulkMaxPacketSize = FS_CDC_VCOM_BULK_OUT_PACKET_SIZE;
568 USB_DeviceRecvRequest (handle, USB_CDC_VCOM_BULK_OUT_ENDPOINT, s_currRecvBuf, s_usbBulkMaxPacketSize);
580 * @brief USB configure endpoint function.
582 * This function configure endpoint status.
584 * @param handle The USB device handle.
585 * @param ep Endpoint address.
586 * @param status A flag to indicate whether to stall the endpoint. 1: stall, 0: unstall.
588 * @return A USB error code or kStatus_USB_Success.
590 usb_status_t USB_DeviceConfigureEndpointStatus(usb_device_handle handle, uint8_t ep, uint8_t status)
594 return USB_DeviceStallEndpoint(handle, ep);
598 return USB_DeviceUnstallEndpoint(handle, ep);
603 flush_tx_buffer (void *user_data, void *vbuf, size_t bufsiz, size_t count)
607 /* Don't write data unless link is open. */
608 if (s_cdcVcom.attach != 1 || s_cdcVcom.startTransactions != 1)
611 USB_DeviceSendRequest (user_data, USB_CDC_VCOM_BULK_IN_ENDPOINT,
614 /* Wait for USB_DeviceCdcAcmBulkIn() to set s_sendComplete. */
615 while (!s_sendComplete)
619 /* Reset for the next write. */
625 /* See virtual_com.h for documentation of this function. */
627 USB_VcomInit (uint16_t vid, uint16_t pid)
629 usb_device_handle deviceHandle = NULL;
631 USB_DeviceClockInit();
633 #if (defined(FSL_FEATURE_SOC_SYSMPU_COUNT) && (FSL_FEATURE_SOC_SYSMPU_COUNT > 0U))
634 SYSMPU_Enable(SYSMPU, 0);
635 #endif /* FSL_FEATURE_SOC_SYSMPU_COUNT */
637 s_cdcVcom.speed = USB_SPEED_FULL;
638 s_cdcVcom.attach = 0;
639 s_cdcVcom.deviceHandle = NULL;
641 USB_DeviceSetVendorId(vid);
642 USB_DeviceSetProductId(pid);
644 if (kStatus_USB_Success != USB_DeviceInit(CONTROLLER_ID, USB_DeviceCallback, &s_cdcVcom.deviceHandle))
650 deviceHandle = s_cdcVcom.deviceHandle;
652 buffer_init (&cdc_tx_buf, cdc_tx_buf_space, sizeof (cdc_tx_buf_space),
653 flush_tx_buffer, deviceHandle);
655 USB_DeviceIsrEnable();
656 USB_DeviceRun(s_cdcVcom.deviceHandle);
661 /* See virtual_com.h for documentation of this function. */
663 USB_VcomDeinit (void)
665 if (s_cdcVcom.deviceHandle == NULL)
668 USB_DeviceStop (s_cdcVcom.deviceHandle);
669 USB_DeviceDeinit (s_cdcVcom.deviceHandle);
670 s_cdcVcom.deviceHandle = NULL;
672 /* XXX: We are not stopping the USBOTG clock yet. */
676 USB0_IRQHandler (void)
678 USB_DeviceKhciIsrFunction (s_cdcVcom.deviceHandle);
681 bool usb_serial_read (char *c)
683 if (ringbuf_is_empty (&cdc_rx_buf)) {
684 if (!s_recvSize || s_recvSize == (uint32_t) -1)
685 USB_DeviceRecvRequest (s_cdcVcom.deviceHandle,
686 USB_CDC_VCOM_BULK_OUT_ENDPOINT,
688 s_usbBulkMaxPacketSize);
693 *c = ringbuf_read (&cdc_rx_buf);