Hi,
I have been struggling to get a fully working example of USBD CDC happening using the RTX.
I modified the source at C:\Keil\ARM\Boards\Keil\MCB1700\RL\USB\Device\RTX\Memory\
to create a CDC example.
This seems to work well in that it connects and I have a serial port created on the host. The descriptors are all okay.
Using USBlyzer I can see the descriptors transferring okay, and using Tera term I can set the COM Port up okay.
When I send a character from Tera Term, USBlyzer captures the transferred character, and I can see the interrupt for the Endpoint 2 (corresponding to the CDC Bulk Endpoint defined in the usb_config.c wizard) BUT I do not get any characters appearing using usbd_cdc_ser_availchar (&numAvailByte);
Now I have run the CDC example from NXP for the LPC17xx in the latest CMSIS lpc17xx.cmsis.driver.library.zip and this works well. So I know my hardware is okay and my PC Host has the driver installed okay.
My main problem is the complete lack of documentation from Keil on how to use the CDC with RTX. There are no complete examples.
There is no description on when/how to use the usbd_cdc_ser_initport() i.e., is this the virtual serial port over the USB OR is it another serial port for using with the usbd_cdc_ser_usb2serial() and usbd_cdc_ser_serial2usb(). If the latter, then how does one specify which serial port?
Do I need to call usbd_cdc_ser_openport() before seeing data over the virtual serial port?
There is no explanation on the returned value from void usbd_cdc_ser_linestate(U16* lineState);
So I am finding this hard going. Has anyone else managed to get USB CDC working with the RTX?
My example code for USB Loopback is...
/*---------------------------------------------------------------------------- * RL-ARM - USB *---------------------------------------------------------------------------- * Name: USBD_Demo.c * Purpose: USB Device Demonstration * Rev.: V4.20 *---------------------------------------------------------------------------- * This code is part of the RealView Run-Time Library. * Copyright (c) 2004-2011 KEIL - An ARM Company. All rights reserved. *---------------------------------------------------------------------------*/ #include <RTL.h> #include <rl_usb.h> #include <LPC17xx.h> /*--------------------------------------------------------------------------- Reads character from USB buffer and resends them back out the USB buffer *---------------------------------------------------------------------------*/ void usbd_vcom_usb2usb(void) { static S8 serBuf [32]; static S32 numBytesToRead, numBytesRead; static S32 numAvailByte; /* Check if any USB CDC serial data available */ usbd_cdc_ser_availchar (&numAvailByte); /* If USB CDC data available, then read in and loop back (limit to 32 chars at a time) */ if (numAvailByte > 0) { numBytesToRead = numAvailByte > 32 ? 32 : numAvailByte; numBytesRead = usbd_cdc_ser_read (&serBuf[0], &numBytesToRead); if (numBytesRead > 0) { usbd_cdc_ser_write(&serBuf[0], &numBytesRead); } } } /*---------------------------------------------------------------------------- Initialises the USBD Serial Port and then Opens it. *---------------------------------------------------------------------------*/ __task void init (void) { os_tsk_prio_self(100); usbd_init(); /* USB Device Initialization */ usbd_connect(__TRUE); /* USB Device Connect */ os_tsk_prio_self(1); usbd_cdc_ser_initport(9600, 8, 0, 1); usbd_cdc_ser_openport(); while (1) { /* Loop forever */ usbd_vcom_usb2usb(); usbd_vcom_chkserstate(); } usbd_cdc_ser_closeport(); } int main (void) { SystemInit (); /* Initialize Clocks */ os_sys_init(init); /* Init RTX and start 'init' */ }
Also, my definitions for usbconfig.c are ... #define USBD_CDC_ENABLE 1 #define USBD_CDC_EP_INTIN 1 #define USBD_CDC_WMAXPACKETSIZE 16 #define USBD_CDC_BINTERVAL 2 #define USBD_CDC_HS_ENABLE 0 #define USBD_CDC_HS_WMAXPACKETSIZE 16 #define USBD_CDC_HS_BINTERVAL 2 #define USBD_CDC_EP_BULKIN 2 #define USBD_CDC_EP_BULKOUT 2 #define USBD_CDC_WMAXPACKETSIZE1 64 #define USBD_CDC_HS_ENABLE1 0 #define USBD_CDC_HS_WMAXPACKETSIZE1 64 #define USBD_CDC_HS_BINTERVAL1 0 #define USBD_CDC_CIF_STRDESC L"USB_CDC" #define USBD_CDC_DIF_STRDESC L"USB_CDC1" #define USBD_CDC_BUFSIZE 64 #define USBD_CDC_OUTBUFSIZE 128