<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>LPC Microcontrollersのトピックlpc1768 as a USB listener</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/lpc1768-as-a-USB-listener/m-p/1043195#M40513</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm working with an LPC1768(FBD100) and need to connect to a PC through a serial USB. As a starting point, I used the sample package USB virtual com port.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Installed packages:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="USB-dependencies.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/115767i93E7A497959FBD49/image-size/large?v=v2&amp;amp;px=999" role="button" title="USB-dependencies.png" alt="USB-dependencies.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="USB-dependencies-1.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/115768i31CB28009B6047FB/image-size/large?v=v2&amp;amp;px=999" role="button" title="USB-dependencies-1.png" alt="USB-dependencies-1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="USB-dependencies-2.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/115769iCB3C6E70CE0D6D48/image-size/large?v=v2&amp;amp;px=999" role="button" title="USB-dependencies-2.png" alt="USB-dependencies-2.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;[code]&lt;/P&gt;&lt;P&gt;#include "includes.h"&lt;/P&gt;&lt;P&gt;int main (void) {&lt;BR /&gt; MenuEntryVType* MenuEntry;&lt;BR /&gt; GUI_Init();&lt;BR /&gt; WM_SetCreateFlags(WM_CF_MEMDEV);&lt;BR /&gt;&lt;BR /&gt; FRAMEWIN_SetDefaultSkinClassic();&lt;BR /&gt; PROGBAR_SetDefaultSkinClassic();&lt;BR /&gt; SCROLLBAR_SetDefaultSkinClassic();&lt;BR /&gt; FRAMEWIN_SetDefaultFont(StdFont);&lt;BR /&gt;&lt;BR /&gt; InitOutputs();&lt;BR /&gt; InitADCs();&lt;BR /&gt; InitDAC();&lt;BR /&gt; InitPWM(100);&lt;BR /&gt; InitI2C();&lt;BR /&gt; GetConfig();&lt;/P&gt;&lt;P&gt;osDelay(1500);&lt;/P&gt;&lt;P&gt;// Works as expected ; new COMx device shows in dev manager.&lt;BR /&gt; USBD_Initialize (0U); // USB Device 0 Initialization&lt;BR /&gt; USBD_Connect (0U); // USB Device 0 Connect&lt;/P&gt;&lt;P&gt;// menu handling code&lt;BR /&gt; // actual functionality start servos, etc.)&lt;BR /&gt; // does not get executed. Why?&lt;BR /&gt; return 0;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;[/code]&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Why does USBD_Connect() hang? no code gets executed past that point; the device does connect, however, to the PC:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="USB-connect-working-but-code-after-does-not-exec.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/115770iD4903CBA9490081A/image-size/large?v=v2&amp;amp;px=999" role="button" title="USB-connect-working-but-code-after-does-not-exec.png" alt="USB-connect-working-but-code-after-does-not-exec.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;rl_usb.h contains the definitions of USBD_Initialize() and USBD_Connect():&lt;/P&gt;&lt;P&gt;[code]&lt;/P&gt;&lt;P&gt;/// \brief Initialize USB Device stack and controller&lt;BR /&gt;/// \param[in] device index of USB Device.&lt;BR /&gt;/// \return status code that indicates the execution status of the function as defined with \ref usbStatus.&lt;BR /&gt;extern usbStatus USBD_Initialize (uint8_t device);&lt;/P&gt;&lt;P&gt;/// \brief Activate pull-up on D+ or D- line to signal USB Device connection on USB Bus&lt;BR /&gt;/// \param[in] device index of USB Device.&lt;BR /&gt;/// \return status code that indicates the execution status of the function as defined with \ref usbStatus.&lt;BR /&gt;extern usbStatus USBD_Connect (uint8_t device);&lt;/P&gt;&lt;P&gt;[/code]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;These are function declarations; I don't know where the implementations are (likely in USB_CM3_L.lib).&lt;/P&gt;&lt;P&gt;Read/write functions are defined in USBD_User_CDC_ACM_UART_0.c&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;[code]&lt;/P&gt;&lt;P&gt;/*------------------------------------------------------------------------------&lt;BR /&gt; * MDK Middleware - Component ::USB:Device&lt;BR /&gt; * Copyright (c) 2004-2019 ARM Germany GmbH. All rights reserved.&lt;BR /&gt; *------------------------------------------------------------------------------&lt;BR /&gt; * Name: USBD_User_CDC_ACM_UART_0.c&lt;BR /&gt; * Purpose: USB Device Communication Device Class (CDC)&lt;BR /&gt; * Abstract Control Model (ACM) USB &amp;lt;-&amp;gt; UART Bridge User module&lt;BR /&gt; * Rev.: V1.0.3&lt;BR /&gt; *----------------------------------------------------------------------------*/&lt;BR /&gt;/**&lt;BR /&gt; * \addtogroup usbd_cdcFunctions&lt;BR /&gt; *&lt;BR /&gt; * USBD_User_CDC_ACM_UART_0.c implements the application specific&lt;BR /&gt; * functionality of the CDC ACM class and is used to demonstrate a USB &amp;lt;-&amp;gt; UART&lt;BR /&gt; * bridge. All data received on USB is transmitted on UART and all data&lt;BR /&gt; * received on UART is transmitted on USB.&lt;BR /&gt; *&lt;BR /&gt; * Details of operation:&lt;BR /&gt; * UART -&amp;gt; USB:&lt;BR /&gt; * Initial reception on UART is started after the USB Host sets line coding&lt;BR /&gt; * with SetLineCoding command. Having received a full UART buffer, any&lt;BR /&gt; * new reception is restarted on the same buffer. Any data received on&lt;BR /&gt; * the UART is sent over USB using the CDC0_ACM_UART_to_USB_Thread thread.&lt;BR /&gt; * USB -&amp;gt; UART:&lt;BR /&gt; * While the UART transmit is not busy, data transmission on the UART is&lt;BR /&gt; * started in the USBD_CDC0_ACM_DataReceived callback as soon as data is&lt;BR /&gt; * received on the USB. Further data received on USB is transmitted on&lt;BR /&gt; * UART in the UART callback routine until there is no more data available.&lt;BR /&gt; * In this case, the next UART transmit is restarted from the&lt;BR /&gt; * USBD_CDC0_ACM_DataReceived callback as soon as new data is received&lt;BR /&gt; * on the USB.&lt;BR /&gt; *&lt;BR /&gt; * The following constants in this module affect the module functionality:&lt;BR /&gt; *&lt;BR /&gt; * - UART_PORT: specifies UART Port&lt;BR /&gt; * default value: 0 (=UART0)&lt;BR /&gt; * - UART_BUFFER_SIZE: specifies UART data Buffer Size&lt;BR /&gt; * default value: 512&lt;BR /&gt; *&lt;BR /&gt; * Notes:&lt;BR /&gt; * If the USB is slower than the UART, data can get lost. This may happen&lt;BR /&gt; * when USB is pausing during data reception because of the USB Host being&lt;BR /&gt; * too loaded with other tasks and not polling the Bulk IN Endpoint often&lt;BR /&gt; * enough (up to 2 seconds of gap in polling Bulk IN Endpoint may occur).&lt;BR /&gt; * This problem can be solved by using a large enough UART buffer to&lt;BR /&gt; * compensate up to a few seconds of received UART data or by using UART&lt;BR /&gt; * flow control.&lt;BR /&gt; * If the device that receives the UART data (usually a PC) is too loaded&lt;BR /&gt; * with other tasks it can also loose UART data. This problem can only be&lt;BR /&gt; * solved by using UART flow control.&lt;BR /&gt; *&lt;BR /&gt; * This file has to be adapted in case of UART flow control usage.&lt;BR /&gt; */&lt;/P&gt;&lt;P&gt;//! [code_USBD_User_CDC_ACM]&lt;/P&gt;&lt;P&gt;#include &amp;lt;stdbool.h&amp;gt;&lt;/P&gt;&lt;P&gt;#include "rl_usb.h"&lt;/P&gt;&lt;P&gt;#&lt;BR /&gt;if defined(RTE_CMSIS_RTOS2)#include "cmsis_os2.h"&lt;/P&gt;&lt;P&gt;#&lt;BR /&gt;if defined(RTE_CMSIS_RTOS2_RTX5)#include "rtx_os.h"&lt;/P&gt;&lt;P&gt;# endif# endif#&lt;BR /&gt;if defined(RTE_CMSIS_RTOS)#include "cmsis_os.h"&lt;/P&gt;&lt;P&gt;# endif&lt;/P&gt;&lt;P&gt;#include "Driver_USART.h"&lt;/P&gt;&lt;P&gt;// UART Configuration ----------------------------------------------------------&lt;/P&gt;&lt;P&gt;# define UART_PORT 1 // UART Port number&lt;BR /&gt;# define UART_BUFFER_SIZE 512 // UART Buffer Size&lt;/P&gt;&lt;P&gt;//------------------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;# define _UART_Driver_(n) Driver_USART## n# define UART_Driver_(n) _UART_Driver_(n)&lt;BR /&gt;extern ARM_DRIVER_USART UART_Driver_(UART_PORT);#&lt;BR /&gt;define ptrUART( &amp;amp; UART_Driver_(UART_PORT))&lt;/P&gt;&lt;P&gt;// External functions&lt;BR /&gt;# ifdef USB_CMSIS_RTOS&lt;BR /&gt;extern void CDC0_ACM_UART_to_USB_Thread(void&lt;BR /&gt; const * arg) __attribute((noreturn));#&lt;BR /&gt;endif&lt;/P&gt;&lt;P&gt;// Local Variables&lt;BR /&gt;static uint8_t uart_rx_buf[UART_BUFFER_SIZE];&lt;BR /&gt;static uint8_t uart_tx_buf[UART_BUFFER_SIZE];&lt;/P&gt;&lt;P&gt;static volatile int32_t uart_rx_cnt = 0;&lt;BR /&gt;static volatile int32_t usb_tx_cnt = 0;&lt;/P&gt;&lt;P&gt;static void * cdc_acm_bridge_tid = 0 U;&lt;BR /&gt;static CDC_LINE_CODING cdc_acm_line_coding = {&lt;BR /&gt; 0 U,&lt;BR /&gt; 0 U,&lt;BR /&gt; 0 U,&lt;BR /&gt; 0 U&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;// Called when UART has transmitted or received requested number of bytes.&lt;BR /&gt;// \param[in] event UART event&lt;BR /&gt;// - ARM_USART_EVENT_SEND_COMPLETE: all requested data was sent&lt;BR /&gt;// - ARM_USART_EVENT_RECEIVE_COMPLETE: all requested data was received&lt;BR /&gt;static void UART_Callback(uint32_t event) {&lt;BR /&gt; int32_t cnt;&lt;/P&gt;&lt;P&gt;if (event &amp;amp; ARM_USART_EVENT_SEND_COMPLETE) {&lt;BR /&gt; // USB -&amp;gt; UART&lt;BR /&gt; cnt = USBD_CDC_ACM_ReadData(0 U, uart_tx_buf, UART_BUFFER_SIZE);&lt;BR /&gt; if (cnt &amp;gt; 0) {&lt;BR /&gt; ptrUART - &amp;gt; Send(uart_tx_buf, (uint32_t)(cnt));&lt;BR /&gt; }&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;if (event &amp;amp; ARM_USART_EVENT_RECEIVE_COMPLETE) {&lt;BR /&gt; // UART data received, restart new reception&lt;BR /&gt; uart_rx_cnt += UART_BUFFER_SIZE;&lt;BR /&gt; ptrUART - &amp;gt; Receive(uart_rx_buf, UART_BUFFER_SIZE);&lt;BR /&gt; }&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Thread: Sends data received on UART to USB&lt;BR /&gt;// \param[in] arg not used.&lt;BR /&gt;# ifdef USB_CMSIS_RTOS2&lt;BR /&gt;__NO_RETURN static void CDC0_ACM_UART_to_USB_Thread(void * arg) {&lt;BR /&gt; #&lt;BR /&gt; else&lt;BR /&gt; __NO_RETURN void CDC0_ACM_UART_to_USB_Thread(void&lt;BR /&gt; const * arg) {&lt;BR /&gt; #&lt;BR /&gt; endif&lt;BR /&gt; int32_t cnt, cnt_to_wrap;&lt;/P&gt;&lt;P&gt;(void)(arg);&lt;/P&gt;&lt;P&gt;while (1) {&lt;BR /&gt; // UART - &amp;gt; USB&lt;BR /&gt; if (ptrUART - &amp;gt; GetStatus().rx_busy != 0 U) {&lt;BR /&gt; cnt = uart_rx_cnt;&lt;BR /&gt; cnt += ptrUART - &amp;gt; GetRxCount();&lt;BR /&gt; cnt -= usb_tx_cnt;&lt;BR /&gt; if (cnt &amp;gt;= UART_BUFFER_SIZE) {&lt;BR /&gt; // Dump data received on UART if USB is not consuming fast enough&lt;BR /&gt; usb_tx_cnt += cnt;&lt;BR /&gt; cnt = 0 U;&lt;BR /&gt; }&lt;BR /&gt; if (cnt &amp;gt; 0) {&lt;BR /&gt; cnt_to_wrap = (int32_t)(UART_BUFFER_SIZE - ((uint32_t) usb_tx_cnt &amp;amp; (UART_BUFFER_SIZE - 1)));&lt;BR /&gt; if (cnt &amp;gt; cnt_to_wrap) {&lt;BR /&gt; cnt = cnt_to_wrap;&lt;BR /&gt; }&lt;BR /&gt; cnt = USBD_CDC_ACM_WriteData(0 U, (uart_rx_buf + ((uint32_t) usb_tx_cnt &amp;amp; (UART_BUFFER_SIZE - 1))), cnt);&lt;BR /&gt; if (cnt &amp;gt; 0) {&lt;BR /&gt; usb_tx_cnt += cnt;&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt; osDelay(10 U);&lt;BR /&gt; }&lt;BR /&gt; }#&lt;BR /&gt; ifdef USB_CMSIS_RTOS2# ifdef USB_CMSIS_RTOS2_RTX5&lt;BR /&gt; static osRtxThread_t cdc0_acm_uart_to_usb_thread_cb_mem __SECTION(.bss.os.thread.cb);&lt;BR /&gt; static uint64_t cdc0_acm_uart_to_usb_thread_stack_mem[512 U / 8 U] __SECTION(.bss.os.thread.stack);#&lt;BR /&gt; endif&lt;BR /&gt; static&lt;BR /&gt; const osThreadAttr_t cdc0_acm_uart_to_usb_thread_attr = {&lt;BR /&gt; "CDC0_ACM_UART_to_USB_Thread",&lt;BR /&gt; 0 U,&lt;BR /&gt; #ifdef USB_CMSIS_RTOS2_RTX5 &amp;amp;&lt;BR /&gt; cdc0_acm_uart_to_usb_thread_cb_mem,&lt;BR /&gt; sizeof(osRtxThread_t),&lt;BR /&gt; &amp;amp;&lt;BR /&gt; cdc0_acm_uart_to_usb_thread_stack_mem[0],&lt;BR /&gt; #&lt;BR /&gt; else&lt;BR /&gt; NULL,&lt;BR /&gt; 0 U,&lt;BR /&gt; NULL,&lt;BR /&gt; #endif&lt;BR /&gt; 512 U,&lt;BR /&gt; osPriorityNormal,&lt;BR /&gt; 0 U,&lt;BR /&gt; 0 U&lt;BR /&gt; };#&lt;BR /&gt; else&lt;BR /&gt; extern&lt;BR /&gt; const osThreadDef_t os_thread_def_CDC0_ACM_UART_to_USB_Thread;&lt;BR /&gt; osThreadDef(CDC0_ACM_UART_to_USB_Thread, osPriorityNormal, 1 U, 0 U);#&lt;BR /&gt; endif&lt;BR /&gt; [/code]&lt;/P&gt;&lt;P&gt;// CDC ACM Callbacks -----------------------------------------------------------&lt;/P&gt;&lt;P&gt;// Called when new data was received from the USB Host.&lt;BR /&gt; // \param[in] len number of bytes available to read.&lt;BR /&gt; void USBD_CDC0_ACM_DataReceived(uint32_t len) {&lt;BR /&gt; int32_t cnt;&lt;/P&gt;&lt;P&gt;(void)(len);&lt;/P&gt;&lt;P&gt;if (ptrUART - &amp;gt; GetStatus().tx_busy == 0 U) {&lt;BR /&gt; // Start USB -&amp;gt; UART&lt;BR /&gt; cnt = USBD_CDC_ACM_ReadData(0 U, uart_tx_buf, UART_BUFFER_SIZE);&lt;BR /&gt; if (cnt &amp;gt; 0) {&lt;BR /&gt; ptrUART - &amp;gt; Send(uart_tx_buf, (uint32_t)(cnt));&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;// Called during USBD_Initialize to initialize the USB CDC class instance (ACM).&lt;BR /&gt; void USBD_CDC0_ACM_Initialize(void) {&lt;BR /&gt; ptrUART - &amp;gt; Initialize(UART_Callback);&lt;BR /&gt; ptrUART - &amp;gt; PowerControl(ARM_POWER_FULL);&lt;/P&gt;&lt;P&gt;#&lt;BR /&gt; ifdef USB_CMSIS_RTOS2&lt;BR /&gt; cdc_acm_bridge_tid = osThreadNew(CDC0_ACM_UART_to_USB_Thread, NULL, &amp;amp; cdc0_acm_uart_to_usb_thread_attr);#&lt;BR /&gt; else&lt;BR /&gt; cdc_acm_bridge_tid = osThreadCreate(osThread(CDC0_ACM_UART_to_USB_Thread), NULL);#&lt;BR /&gt; endif&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;// Called during USBD_Uninitialize to de-initialize the USB CDC class instance (ACM).&lt;BR /&gt; void USBD_CDC0_ACM_Uninitialize(void) {&lt;/P&gt;&lt;P&gt;if (osThreadTerminate(cdc_acm_bridge_tid) == osOK) {&lt;BR /&gt; cdc_acm_bridge_tid = NULL;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;ptrUART - &amp;gt; Control(ARM_USART_ABORT_RECEIVE, 0 U);&lt;BR /&gt; ptrUART - &amp;gt; PowerControl(ARM_POWER_OFF);&lt;BR /&gt; ptrUART - &amp;gt; Uninitialize();&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;// Called upon USB Bus Reset Event.&lt;BR /&gt; void USBD_CDC0_ACM_Reset(void) {&lt;BR /&gt; ptrUART - &amp;gt; Control(ARM_USART_ABORT_SEND, 0 U);&lt;BR /&gt; ptrUART - &amp;gt; Control(ARM_USART_ABORT_RECEIVE, 0 U);&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;// Called upon USB Host request to change communication settings.&lt;BR /&gt; // \param[in] line_coding pointer to CDC_LINE_CODING structure.&lt;BR /&gt; // \return true set line coding request processed.&lt;BR /&gt; // \return false set line coding request not supported or not processed.&lt;BR /&gt; bool USBD_CDC0_ACM_SetLineCoding(const CDC_LINE_CODING * line_coding) {&lt;BR /&gt; uint32_t data_bits = 0 U, parity = 0 U, stop_bits = 0 U;&lt;BR /&gt; int32_t status;&lt;/P&gt;&lt;P&gt;ptrUART - &amp;gt; Control(ARM_USART_ABORT_SEND, 0 U);&lt;BR /&gt; ptrUART - &amp;gt; Control(ARM_USART_ABORT_RECEIVE, 0 U);&lt;BR /&gt; ptrUART - &amp;gt; Control(ARM_USART_CONTROL_TX, 0 U);&lt;BR /&gt; ptrUART - &amp;gt; Control(ARM_USART_CONTROL_RX, 0 U);&lt;/P&gt;&lt;P&gt;switch (line_coding - &amp;gt; bCharFormat) {&lt;BR /&gt; case 0: // 1 Stop bit&lt;BR /&gt; stop_bits = ARM_USART_STOP_BITS_1;&lt;BR /&gt; break;&lt;BR /&gt; case 1: // 1.5 Stop bits&lt;BR /&gt; stop_bits = ARM_USART_STOP_BITS_1_5;&lt;BR /&gt; break;&lt;BR /&gt; case 2: // 2 Stop bits&lt;BR /&gt; stop_bits = ARM_USART_STOP_BITS_2;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;switch (line_coding - &amp;gt; bParityType) {&lt;BR /&gt; case 0: // None&lt;BR /&gt; parity = ARM_USART_PARITY_NONE;&lt;BR /&gt; break;&lt;BR /&gt; case 1: // Odd&lt;BR /&gt; parity = ARM_USART_PARITY_ODD;&lt;BR /&gt; break;&lt;BR /&gt; case 2: // Even&lt;BR /&gt; parity = ARM_USART_PARITY_EVEN;&lt;BR /&gt; break;&lt;BR /&gt; default:&lt;BR /&gt; return false;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;switch (line_coding - &amp;gt; bDataBits) {&lt;BR /&gt; case 5:&lt;BR /&gt; data_bits = ARM_USART_DATA_BITS_5;&lt;BR /&gt; break;&lt;BR /&gt; case 6:&lt;BR /&gt; data_bits = ARM_USART_DATA_BITS_6;&lt;BR /&gt; break;&lt;BR /&gt; case 7:&lt;BR /&gt; data_bits = ARM_USART_DATA_BITS_7;&lt;BR /&gt; break;&lt;BR /&gt; case 8:&lt;BR /&gt; data_bits = ARM_USART_DATA_BITS_8;&lt;BR /&gt; break;&lt;BR /&gt; default:&lt;BR /&gt; return false;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;status = ptrUART - &amp;gt; Control(ARM_USART_MODE_ASYNCHRONOUS |&lt;BR /&gt; data_bits |&lt;BR /&gt; parity |&lt;BR /&gt; stop_bits |&lt;BR /&gt; ARM_USART_FLOW_CONTROL_NONE,&lt;BR /&gt; line_coding - &amp;gt; dwDTERate);&lt;/P&gt;&lt;P&gt;if (status != ARM_DRIVER_OK) {&lt;BR /&gt; return false;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;// Store requested settings to local variable&lt;BR /&gt; cdc_acm_line_coding = * line_coding;&lt;/P&gt;&lt;P&gt;uart_rx_cnt = 0;&lt;BR /&gt; usb_tx_cnt = 0;&lt;/P&gt;&lt;P&gt;ptrUART - &amp;gt; Control(ARM_USART_CONTROL_TX, 1 U);&lt;BR /&gt; ptrUART - &amp;gt; Control(ARM_USART_CONTROL_RX, 1 U);&lt;/P&gt;&lt;P&gt;ptrUART - &amp;gt; Receive(uart_rx_buf, UART_BUFFER_SIZE);&lt;/P&gt;&lt;P&gt;return true;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;// Called upon USB Host request to retrieve communication settings.&lt;BR /&gt; // \param[out] line_coding pointer to CDC_LINE_CODING structure.&lt;BR /&gt; // \return true get line coding request processed.&lt;BR /&gt; // \return false get line coding request not supported or not processed.&lt;BR /&gt; bool USBD_CDC0_ACM_GetLineCoding(CDC_LINE_CODING * line_coding) {&lt;/P&gt;&lt;P&gt;// Load settings from ones stored on USBD_CDC0_ACM_SetLineCoding callback&lt;BR /&gt; * line_coding = cdc_acm_line_coding;&lt;/P&gt;&lt;P&gt;return true;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;// Called upon USB Host request to set control line states.&lt;BR /&gt; // \param [in] state control line settings bitmap.&lt;BR /&gt; // - bit 0: DTR state&lt;BR /&gt; // - bit 1: RTS state&lt;BR /&gt; // \return true set control line state request processed.&lt;BR /&gt; // \return false set control line state request not supported or not processed.&lt;BR /&gt; bool USBD_CDC0_ACM_SetControlLineState(uint16_t state) {&lt;BR /&gt; // Add code for set control line state&lt;/P&gt;&lt;P&gt;(void)(state);&lt;/P&gt;&lt;P&gt;return true;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;//! [code_USBD_User_CDC_ACM]&lt;/P&gt;&lt;P&gt;[/code]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is it possible to run the lpc1768 as a USB listener and also perform a set of tasks in parallel? If yes, how should I go about it?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 14 Jul 2020 10:18:05 GMT</pubDate>
    <dc:creator>kevinr11082005</dc:creator>
    <dc:date>2020-07-14T10:18:05Z</dc:date>
    <item>
      <title>lpc1768 as a USB listener</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/lpc1768-as-a-USB-listener/m-p/1043195#M40513</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm working with an LPC1768(FBD100) and need to connect to a PC through a serial USB. As a starting point, I used the sample package USB virtual com port.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Installed packages:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="USB-dependencies.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/115767i93E7A497959FBD49/image-size/large?v=v2&amp;amp;px=999" role="button" title="USB-dependencies.png" alt="USB-dependencies.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="USB-dependencies-1.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/115768i31CB28009B6047FB/image-size/large?v=v2&amp;amp;px=999" role="button" title="USB-dependencies-1.png" alt="USB-dependencies-1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="USB-dependencies-2.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/115769iCB3C6E70CE0D6D48/image-size/large?v=v2&amp;amp;px=999" role="button" title="USB-dependencies-2.png" alt="USB-dependencies-2.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;[code]&lt;/P&gt;&lt;P&gt;#include "includes.h"&lt;/P&gt;&lt;P&gt;int main (void) {&lt;BR /&gt; MenuEntryVType* MenuEntry;&lt;BR /&gt; GUI_Init();&lt;BR /&gt; WM_SetCreateFlags(WM_CF_MEMDEV);&lt;BR /&gt;&lt;BR /&gt; FRAMEWIN_SetDefaultSkinClassic();&lt;BR /&gt; PROGBAR_SetDefaultSkinClassic();&lt;BR /&gt; SCROLLBAR_SetDefaultSkinClassic();&lt;BR /&gt; FRAMEWIN_SetDefaultFont(StdFont);&lt;BR /&gt;&lt;BR /&gt; InitOutputs();&lt;BR /&gt; InitADCs();&lt;BR /&gt; InitDAC();&lt;BR /&gt; InitPWM(100);&lt;BR /&gt; InitI2C();&lt;BR /&gt; GetConfig();&lt;/P&gt;&lt;P&gt;osDelay(1500);&lt;/P&gt;&lt;P&gt;// Works as expected ; new COMx device shows in dev manager.&lt;BR /&gt; USBD_Initialize (0U); // USB Device 0 Initialization&lt;BR /&gt; USBD_Connect (0U); // USB Device 0 Connect&lt;/P&gt;&lt;P&gt;// menu handling code&lt;BR /&gt; // actual functionality start servos, etc.)&lt;BR /&gt; // does not get executed. Why?&lt;BR /&gt; return 0;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;[/code]&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Why does USBD_Connect() hang? no code gets executed past that point; the device does connect, however, to the PC:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="USB-connect-working-but-code-after-does-not-exec.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/115770iD4903CBA9490081A/image-size/large?v=v2&amp;amp;px=999" role="button" title="USB-connect-working-but-code-after-does-not-exec.png" alt="USB-connect-working-but-code-after-does-not-exec.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;rl_usb.h contains the definitions of USBD_Initialize() and USBD_Connect():&lt;/P&gt;&lt;P&gt;[code]&lt;/P&gt;&lt;P&gt;/// \brief Initialize USB Device stack and controller&lt;BR /&gt;/// \param[in] device index of USB Device.&lt;BR /&gt;/// \return status code that indicates the execution status of the function as defined with \ref usbStatus.&lt;BR /&gt;extern usbStatus USBD_Initialize (uint8_t device);&lt;/P&gt;&lt;P&gt;/// \brief Activate pull-up on D+ or D- line to signal USB Device connection on USB Bus&lt;BR /&gt;/// \param[in] device index of USB Device.&lt;BR /&gt;/// \return status code that indicates the execution status of the function as defined with \ref usbStatus.&lt;BR /&gt;extern usbStatus USBD_Connect (uint8_t device);&lt;/P&gt;&lt;P&gt;[/code]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;These are function declarations; I don't know where the implementations are (likely in USB_CM3_L.lib).&lt;/P&gt;&lt;P&gt;Read/write functions are defined in USBD_User_CDC_ACM_UART_0.c&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;[code]&lt;/P&gt;&lt;P&gt;/*------------------------------------------------------------------------------&lt;BR /&gt; * MDK Middleware - Component ::USB:Device&lt;BR /&gt; * Copyright (c) 2004-2019 ARM Germany GmbH. All rights reserved.&lt;BR /&gt; *------------------------------------------------------------------------------&lt;BR /&gt; * Name: USBD_User_CDC_ACM_UART_0.c&lt;BR /&gt; * Purpose: USB Device Communication Device Class (CDC)&lt;BR /&gt; * Abstract Control Model (ACM) USB &amp;lt;-&amp;gt; UART Bridge User module&lt;BR /&gt; * Rev.: V1.0.3&lt;BR /&gt; *----------------------------------------------------------------------------*/&lt;BR /&gt;/**&lt;BR /&gt; * \addtogroup usbd_cdcFunctions&lt;BR /&gt; *&lt;BR /&gt; * USBD_User_CDC_ACM_UART_0.c implements the application specific&lt;BR /&gt; * functionality of the CDC ACM class and is used to demonstrate a USB &amp;lt;-&amp;gt; UART&lt;BR /&gt; * bridge. All data received on USB is transmitted on UART and all data&lt;BR /&gt; * received on UART is transmitted on USB.&lt;BR /&gt; *&lt;BR /&gt; * Details of operation:&lt;BR /&gt; * UART -&amp;gt; USB:&lt;BR /&gt; * Initial reception on UART is started after the USB Host sets line coding&lt;BR /&gt; * with SetLineCoding command. Having received a full UART buffer, any&lt;BR /&gt; * new reception is restarted on the same buffer. Any data received on&lt;BR /&gt; * the UART is sent over USB using the CDC0_ACM_UART_to_USB_Thread thread.&lt;BR /&gt; * USB -&amp;gt; UART:&lt;BR /&gt; * While the UART transmit is not busy, data transmission on the UART is&lt;BR /&gt; * started in the USBD_CDC0_ACM_DataReceived callback as soon as data is&lt;BR /&gt; * received on the USB. Further data received on USB is transmitted on&lt;BR /&gt; * UART in the UART callback routine until there is no more data available.&lt;BR /&gt; * In this case, the next UART transmit is restarted from the&lt;BR /&gt; * USBD_CDC0_ACM_DataReceived callback as soon as new data is received&lt;BR /&gt; * on the USB.&lt;BR /&gt; *&lt;BR /&gt; * The following constants in this module affect the module functionality:&lt;BR /&gt; *&lt;BR /&gt; * - UART_PORT: specifies UART Port&lt;BR /&gt; * default value: 0 (=UART0)&lt;BR /&gt; * - UART_BUFFER_SIZE: specifies UART data Buffer Size&lt;BR /&gt; * default value: 512&lt;BR /&gt; *&lt;BR /&gt; * Notes:&lt;BR /&gt; * If the USB is slower than the UART, data can get lost. This may happen&lt;BR /&gt; * when USB is pausing during data reception because of the USB Host being&lt;BR /&gt; * too loaded with other tasks and not polling the Bulk IN Endpoint often&lt;BR /&gt; * enough (up to 2 seconds of gap in polling Bulk IN Endpoint may occur).&lt;BR /&gt; * This problem can be solved by using a large enough UART buffer to&lt;BR /&gt; * compensate up to a few seconds of received UART data or by using UART&lt;BR /&gt; * flow control.&lt;BR /&gt; * If the device that receives the UART data (usually a PC) is too loaded&lt;BR /&gt; * with other tasks it can also loose UART data. This problem can only be&lt;BR /&gt; * solved by using UART flow control.&lt;BR /&gt; *&lt;BR /&gt; * This file has to be adapted in case of UART flow control usage.&lt;BR /&gt; */&lt;/P&gt;&lt;P&gt;//! [code_USBD_User_CDC_ACM]&lt;/P&gt;&lt;P&gt;#include &amp;lt;stdbool.h&amp;gt;&lt;/P&gt;&lt;P&gt;#include "rl_usb.h"&lt;/P&gt;&lt;P&gt;#&lt;BR /&gt;if defined(RTE_CMSIS_RTOS2)#include "cmsis_os2.h"&lt;/P&gt;&lt;P&gt;#&lt;BR /&gt;if defined(RTE_CMSIS_RTOS2_RTX5)#include "rtx_os.h"&lt;/P&gt;&lt;P&gt;# endif# endif#&lt;BR /&gt;if defined(RTE_CMSIS_RTOS)#include "cmsis_os.h"&lt;/P&gt;&lt;P&gt;# endif&lt;/P&gt;&lt;P&gt;#include "Driver_USART.h"&lt;/P&gt;&lt;P&gt;// UART Configuration ----------------------------------------------------------&lt;/P&gt;&lt;P&gt;# define UART_PORT 1 // UART Port number&lt;BR /&gt;# define UART_BUFFER_SIZE 512 // UART Buffer Size&lt;/P&gt;&lt;P&gt;//------------------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;# define _UART_Driver_(n) Driver_USART## n# define UART_Driver_(n) _UART_Driver_(n)&lt;BR /&gt;extern ARM_DRIVER_USART UART_Driver_(UART_PORT);#&lt;BR /&gt;define ptrUART( &amp;amp; UART_Driver_(UART_PORT))&lt;/P&gt;&lt;P&gt;// External functions&lt;BR /&gt;# ifdef USB_CMSIS_RTOS&lt;BR /&gt;extern void CDC0_ACM_UART_to_USB_Thread(void&lt;BR /&gt; const * arg) __attribute((noreturn));#&lt;BR /&gt;endif&lt;/P&gt;&lt;P&gt;// Local Variables&lt;BR /&gt;static uint8_t uart_rx_buf[UART_BUFFER_SIZE];&lt;BR /&gt;static uint8_t uart_tx_buf[UART_BUFFER_SIZE];&lt;/P&gt;&lt;P&gt;static volatile int32_t uart_rx_cnt = 0;&lt;BR /&gt;static volatile int32_t usb_tx_cnt = 0;&lt;/P&gt;&lt;P&gt;static void * cdc_acm_bridge_tid = 0 U;&lt;BR /&gt;static CDC_LINE_CODING cdc_acm_line_coding = {&lt;BR /&gt; 0 U,&lt;BR /&gt; 0 U,&lt;BR /&gt; 0 U,&lt;BR /&gt; 0 U&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;// Called when UART has transmitted or received requested number of bytes.&lt;BR /&gt;// \param[in] event UART event&lt;BR /&gt;// - ARM_USART_EVENT_SEND_COMPLETE: all requested data was sent&lt;BR /&gt;// - ARM_USART_EVENT_RECEIVE_COMPLETE: all requested data was received&lt;BR /&gt;static void UART_Callback(uint32_t event) {&lt;BR /&gt; int32_t cnt;&lt;/P&gt;&lt;P&gt;if (event &amp;amp; ARM_USART_EVENT_SEND_COMPLETE) {&lt;BR /&gt; // USB -&amp;gt; UART&lt;BR /&gt; cnt = USBD_CDC_ACM_ReadData(0 U, uart_tx_buf, UART_BUFFER_SIZE);&lt;BR /&gt; if (cnt &amp;gt; 0) {&lt;BR /&gt; ptrUART - &amp;gt; Send(uart_tx_buf, (uint32_t)(cnt));&lt;BR /&gt; }&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;if (event &amp;amp; ARM_USART_EVENT_RECEIVE_COMPLETE) {&lt;BR /&gt; // UART data received, restart new reception&lt;BR /&gt; uart_rx_cnt += UART_BUFFER_SIZE;&lt;BR /&gt; ptrUART - &amp;gt; Receive(uart_rx_buf, UART_BUFFER_SIZE);&lt;BR /&gt; }&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Thread: Sends data received on UART to USB&lt;BR /&gt;// \param[in] arg not used.&lt;BR /&gt;# ifdef USB_CMSIS_RTOS2&lt;BR /&gt;__NO_RETURN static void CDC0_ACM_UART_to_USB_Thread(void * arg) {&lt;BR /&gt; #&lt;BR /&gt; else&lt;BR /&gt; __NO_RETURN void CDC0_ACM_UART_to_USB_Thread(void&lt;BR /&gt; const * arg) {&lt;BR /&gt; #&lt;BR /&gt; endif&lt;BR /&gt; int32_t cnt, cnt_to_wrap;&lt;/P&gt;&lt;P&gt;(void)(arg);&lt;/P&gt;&lt;P&gt;while (1) {&lt;BR /&gt; // UART - &amp;gt; USB&lt;BR /&gt; if (ptrUART - &amp;gt; GetStatus().rx_busy != 0 U) {&lt;BR /&gt; cnt = uart_rx_cnt;&lt;BR /&gt; cnt += ptrUART - &amp;gt; GetRxCount();&lt;BR /&gt; cnt -= usb_tx_cnt;&lt;BR /&gt; if (cnt &amp;gt;= UART_BUFFER_SIZE) {&lt;BR /&gt; // Dump data received on UART if USB is not consuming fast enough&lt;BR /&gt; usb_tx_cnt += cnt;&lt;BR /&gt; cnt = 0 U;&lt;BR /&gt; }&lt;BR /&gt; if (cnt &amp;gt; 0) {&lt;BR /&gt; cnt_to_wrap = (int32_t)(UART_BUFFER_SIZE - ((uint32_t) usb_tx_cnt &amp;amp; (UART_BUFFER_SIZE - 1)));&lt;BR /&gt; if (cnt &amp;gt; cnt_to_wrap) {&lt;BR /&gt; cnt = cnt_to_wrap;&lt;BR /&gt; }&lt;BR /&gt; cnt = USBD_CDC_ACM_WriteData(0 U, (uart_rx_buf + ((uint32_t) usb_tx_cnt &amp;amp; (UART_BUFFER_SIZE - 1))), cnt);&lt;BR /&gt; if (cnt &amp;gt; 0) {&lt;BR /&gt; usb_tx_cnt += cnt;&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt; osDelay(10 U);&lt;BR /&gt; }&lt;BR /&gt; }#&lt;BR /&gt; ifdef USB_CMSIS_RTOS2# ifdef USB_CMSIS_RTOS2_RTX5&lt;BR /&gt; static osRtxThread_t cdc0_acm_uart_to_usb_thread_cb_mem __SECTION(.bss.os.thread.cb);&lt;BR /&gt; static uint64_t cdc0_acm_uart_to_usb_thread_stack_mem[512 U / 8 U] __SECTION(.bss.os.thread.stack);#&lt;BR /&gt; endif&lt;BR /&gt; static&lt;BR /&gt; const osThreadAttr_t cdc0_acm_uart_to_usb_thread_attr = {&lt;BR /&gt; "CDC0_ACM_UART_to_USB_Thread",&lt;BR /&gt; 0 U,&lt;BR /&gt; #ifdef USB_CMSIS_RTOS2_RTX5 &amp;amp;&lt;BR /&gt; cdc0_acm_uart_to_usb_thread_cb_mem,&lt;BR /&gt; sizeof(osRtxThread_t),&lt;BR /&gt; &amp;amp;&lt;BR /&gt; cdc0_acm_uart_to_usb_thread_stack_mem[0],&lt;BR /&gt; #&lt;BR /&gt; else&lt;BR /&gt; NULL,&lt;BR /&gt; 0 U,&lt;BR /&gt; NULL,&lt;BR /&gt; #endif&lt;BR /&gt; 512 U,&lt;BR /&gt; osPriorityNormal,&lt;BR /&gt; 0 U,&lt;BR /&gt; 0 U&lt;BR /&gt; };#&lt;BR /&gt; else&lt;BR /&gt; extern&lt;BR /&gt; const osThreadDef_t os_thread_def_CDC0_ACM_UART_to_USB_Thread;&lt;BR /&gt; osThreadDef(CDC0_ACM_UART_to_USB_Thread, osPriorityNormal, 1 U, 0 U);#&lt;BR /&gt; endif&lt;BR /&gt; [/code]&lt;/P&gt;&lt;P&gt;// CDC ACM Callbacks -----------------------------------------------------------&lt;/P&gt;&lt;P&gt;// Called when new data was received from the USB Host.&lt;BR /&gt; // \param[in] len number of bytes available to read.&lt;BR /&gt; void USBD_CDC0_ACM_DataReceived(uint32_t len) {&lt;BR /&gt; int32_t cnt;&lt;/P&gt;&lt;P&gt;(void)(len);&lt;/P&gt;&lt;P&gt;if (ptrUART - &amp;gt; GetStatus().tx_busy == 0 U) {&lt;BR /&gt; // Start USB -&amp;gt; UART&lt;BR /&gt; cnt = USBD_CDC_ACM_ReadData(0 U, uart_tx_buf, UART_BUFFER_SIZE);&lt;BR /&gt; if (cnt &amp;gt; 0) {&lt;BR /&gt; ptrUART - &amp;gt; Send(uart_tx_buf, (uint32_t)(cnt));&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;// Called during USBD_Initialize to initialize the USB CDC class instance (ACM).&lt;BR /&gt; void USBD_CDC0_ACM_Initialize(void) {&lt;BR /&gt; ptrUART - &amp;gt; Initialize(UART_Callback);&lt;BR /&gt; ptrUART - &amp;gt; PowerControl(ARM_POWER_FULL);&lt;/P&gt;&lt;P&gt;#&lt;BR /&gt; ifdef USB_CMSIS_RTOS2&lt;BR /&gt; cdc_acm_bridge_tid = osThreadNew(CDC0_ACM_UART_to_USB_Thread, NULL, &amp;amp; cdc0_acm_uart_to_usb_thread_attr);#&lt;BR /&gt; else&lt;BR /&gt; cdc_acm_bridge_tid = osThreadCreate(osThread(CDC0_ACM_UART_to_USB_Thread), NULL);#&lt;BR /&gt; endif&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;// Called during USBD_Uninitialize to de-initialize the USB CDC class instance (ACM).&lt;BR /&gt; void USBD_CDC0_ACM_Uninitialize(void) {&lt;/P&gt;&lt;P&gt;if (osThreadTerminate(cdc_acm_bridge_tid) == osOK) {&lt;BR /&gt; cdc_acm_bridge_tid = NULL;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;ptrUART - &amp;gt; Control(ARM_USART_ABORT_RECEIVE, 0 U);&lt;BR /&gt; ptrUART - &amp;gt; PowerControl(ARM_POWER_OFF);&lt;BR /&gt; ptrUART - &amp;gt; Uninitialize();&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;// Called upon USB Bus Reset Event.&lt;BR /&gt; void USBD_CDC0_ACM_Reset(void) {&lt;BR /&gt; ptrUART - &amp;gt; Control(ARM_USART_ABORT_SEND, 0 U);&lt;BR /&gt; ptrUART - &amp;gt; Control(ARM_USART_ABORT_RECEIVE, 0 U);&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;// Called upon USB Host request to change communication settings.&lt;BR /&gt; // \param[in] line_coding pointer to CDC_LINE_CODING structure.&lt;BR /&gt; // \return true set line coding request processed.&lt;BR /&gt; // \return false set line coding request not supported or not processed.&lt;BR /&gt; bool USBD_CDC0_ACM_SetLineCoding(const CDC_LINE_CODING * line_coding) {&lt;BR /&gt; uint32_t data_bits = 0 U, parity = 0 U, stop_bits = 0 U;&lt;BR /&gt; int32_t status;&lt;/P&gt;&lt;P&gt;ptrUART - &amp;gt; Control(ARM_USART_ABORT_SEND, 0 U);&lt;BR /&gt; ptrUART - &amp;gt; Control(ARM_USART_ABORT_RECEIVE, 0 U);&lt;BR /&gt; ptrUART - &amp;gt; Control(ARM_USART_CONTROL_TX, 0 U);&lt;BR /&gt; ptrUART - &amp;gt; Control(ARM_USART_CONTROL_RX, 0 U);&lt;/P&gt;&lt;P&gt;switch (line_coding - &amp;gt; bCharFormat) {&lt;BR /&gt; case 0: // 1 Stop bit&lt;BR /&gt; stop_bits = ARM_USART_STOP_BITS_1;&lt;BR /&gt; break;&lt;BR /&gt; case 1: // 1.5 Stop bits&lt;BR /&gt; stop_bits = ARM_USART_STOP_BITS_1_5;&lt;BR /&gt; break;&lt;BR /&gt; case 2: // 2 Stop bits&lt;BR /&gt; stop_bits = ARM_USART_STOP_BITS_2;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;switch (line_coding - &amp;gt; bParityType) {&lt;BR /&gt; case 0: // None&lt;BR /&gt; parity = ARM_USART_PARITY_NONE;&lt;BR /&gt; break;&lt;BR /&gt; case 1: // Odd&lt;BR /&gt; parity = ARM_USART_PARITY_ODD;&lt;BR /&gt; break;&lt;BR /&gt; case 2: // Even&lt;BR /&gt; parity = ARM_USART_PARITY_EVEN;&lt;BR /&gt; break;&lt;BR /&gt; default:&lt;BR /&gt; return false;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;switch (line_coding - &amp;gt; bDataBits) {&lt;BR /&gt; case 5:&lt;BR /&gt; data_bits = ARM_USART_DATA_BITS_5;&lt;BR /&gt; break;&lt;BR /&gt; case 6:&lt;BR /&gt; data_bits = ARM_USART_DATA_BITS_6;&lt;BR /&gt; break;&lt;BR /&gt; case 7:&lt;BR /&gt; data_bits = ARM_USART_DATA_BITS_7;&lt;BR /&gt; break;&lt;BR /&gt; case 8:&lt;BR /&gt; data_bits = ARM_USART_DATA_BITS_8;&lt;BR /&gt; break;&lt;BR /&gt; default:&lt;BR /&gt; return false;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;status = ptrUART - &amp;gt; Control(ARM_USART_MODE_ASYNCHRONOUS |&lt;BR /&gt; data_bits |&lt;BR /&gt; parity |&lt;BR /&gt; stop_bits |&lt;BR /&gt; ARM_USART_FLOW_CONTROL_NONE,&lt;BR /&gt; line_coding - &amp;gt; dwDTERate);&lt;/P&gt;&lt;P&gt;if (status != ARM_DRIVER_OK) {&lt;BR /&gt; return false;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;// Store requested settings to local variable&lt;BR /&gt; cdc_acm_line_coding = * line_coding;&lt;/P&gt;&lt;P&gt;uart_rx_cnt = 0;&lt;BR /&gt; usb_tx_cnt = 0;&lt;/P&gt;&lt;P&gt;ptrUART - &amp;gt; Control(ARM_USART_CONTROL_TX, 1 U);&lt;BR /&gt; ptrUART - &amp;gt; Control(ARM_USART_CONTROL_RX, 1 U);&lt;/P&gt;&lt;P&gt;ptrUART - &amp;gt; Receive(uart_rx_buf, UART_BUFFER_SIZE);&lt;/P&gt;&lt;P&gt;return true;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;// Called upon USB Host request to retrieve communication settings.&lt;BR /&gt; // \param[out] line_coding pointer to CDC_LINE_CODING structure.&lt;BR /&gt; // \return true get line coding request processed.&lt;BR /&gt; // \return false get line coding request not supported or not processed.&lt;BR /&gt; bool USBD_CDC0_ACM_GetLineCoding(CDC_LINE_CODING * line_coding) {&lt;/P&gt;&lt;P&gt;// Load settings from ones stored on USBD_CDC0_ACM_SetLineCoding callback&lt;BR /&gt; * line_coding = cdc_acm_line_coding;&lt;/P&gt;&lt;P&gt;return true;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;// Called upon USB Host request to set control line states.&lt;BR /&gt; // \param [in] state control line settings bitmap.&lt;BR /&gt; // - bit 0: DTR state&lt;BR /&gt; // - bit 1: RTS state&lt;BR /&gt; // \return true set control line state request processed.&lt;BR /&gt; // \return false set control line state request not supported or not processed.&lt;BR /&gt; bool USBD_CDC0_ACM_SetControlLineState(uint16_t state) {&lt;BR /&gt; // Add code for set control line state&lt;/P&gt;&lt;P&gt;(void)(state);&lt;/P&gt;&lt;P&gt;return true;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;//! [code_USBD_User_CDC_ACM]&lt;/P&gt;&lt;P&gt;[/code]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is it possible to run the lpc1768 as a USB listener and also perform a set of tasks in parallel? If yes, how should I go about it?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Jul 2020 10:18:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/lpc1768-as-a-USB-listener/m-p/1043195#M40513</guid>
      <dc:creator>kevinr11082005</dc:creator>
      <dc:date>2020-07-14T10:18:05Z</dc:date>
    </item>
    <item>
      <title>Re: lpc1768 as a USB listener</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/lpc1768-as-a-USB-listener/m-p/1043196#M40514</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Kevin,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What do you mean about a USB listener? Do you plan to use one of the USB instances as host and the other as a device and process the packages in the middle of a USB communication?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think this will be a little difficult to do this&amp;nbsp;with this MCU. The speed to receive the messages and interchanging it between them with the frequency used by the USB will be a little difficult with the core frequency and will not leave much time for other tasks.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best Regards,&lt;/P&gt;&lt;P&gt;Alexis Andalon&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Jul 2020 22:40:35 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/lpc1768-as-a-USB-listener/m-p/1043196#M40514</guid>
      <dc:creator>Alexis_A</dc:creator>
      <dc:date>2020-07-17T22:40:35Z</dc:date>
    </item>
    <item>
      <title>Re: lpc1768 as a USB listener</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/lpc1768-as-a-USB-listener/m-p/1043197#M40515</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;What do you mean about a USB listener? Do you plan to use one of the USB instances as host and the other as a device and process the &amp;gt;packages in the middle of a USB communication?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;No, it's a direct link between a master and a slave that talk through a VirtualCOM port over USB.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;Thx!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;Kevin&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 Jul 2020 13:57:32 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/lpc1768-as-a-USB-listener/m-p/1043197#M40515</guid>
      <dc:creator>kevinr11082005</dc:creator>
      <dc:date>2020-07-24T13:57:32Z</dc:date>
    </item>
    <item>
      <title>Re: lpc1768 as a USB listener</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/lpc1768-as-a-USB-listener/m-p/1043198#M40516</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Kevin,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This MCU has a ROM library that implements some of the functions so you only need to fill the structures and the ROM code will do all the work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since you don't have two cores in this MCU you can't run the task in parallel but you could use some kind of synchronization or an RTOS (there's a FreeRTOS example in the LPCOpen).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best Regards,&lt;/P&gt;&lt;P&gt;Alexis Andalon&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 27 Jul 2020 22:28:07 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/lpc1768-as-a-USB-listener/m-p/1043198#M40516</guid>
      <dc:creator>Alexis_A</dc:creator>
      <dc:date>2020-07-27T22:28:07Z</dc:date>
    </item>
    <item>
      <title>Re: lpc1768 as a USB listener</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/lpc1768-as-a-USB-listener/m-p/1043199#M40517</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've managed to get it to run but have another problem with keil's component manager and made a post but it's currently pending.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;Kev&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 Jul 2020 08:51:23 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/lpc1768-as-a-USB-listener/m-p/1043199#M40517</guid>
      <dc:creator>kevinr11082005</dc:creator>
      <dc:date>2020-07-29T08:51:23Z</dc:date>
    </item>
  </channel>
</rss>

