Port of Keils USBCDC example, compiles ok. Gets stuck at init

Dependencies:   mbed

Committer:
tecnosys
Date:
Mon Jul 05 10:16:57 2010 +0000
Revision:
0:0b777ff85deb

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tecnosys 0:0b777ff85deb 1 #include "mbed.h"
tecnosys 0:0b777ff85deb 2 /*----------------------------------------------------------------------------
tecnosys 0:0b777ff85deb 3 * Name: vcomdemo.c
tecnosys 0:0b777ff85deb 4 * Purpose: USB virtual COM port Demo
tecnosys 0:0b777ff85deb 5 * Version: V1.20
tecnosys 0:0b777ff85deb 6 *----------------------------------------------------------------------------
tecnosys 0:0b777ff85deb 7 * This software is supplied "AS IS" without any warranties, express,
tecnosys 0:0b777ff85deb 8 * implied or statutory, including but not limited to the implied
tecnosys 0:0b777ff85deb 9 * warranties of fitness for purpose, satisfactory quality and
tecnosys 0:0b777ff85deb 10 * noninfringement. Keil extends you a royalty-free right to reproduce
tecnosys 0:0b777ff85deb 11 * and distribute executable files created using this software for use
tecnosys 0:0b777ff85deb 12 * on NXP Semiconductors LPC microcontroller devices only. Nothing else
tecnosys 0:0b777ff85deb 13 * gives you the right to use this software.
tecnosys 0:0b777ff85deb 14 *
tecnosys 0:0b777ff85deb 15 * Copyright (c) 2009 Keil - An ARM Company. All rights reserved.
tecnosys 0:0b777ff85deb 16 *---------------------------------------------------------------------------*/
tecnosys 0:0b777ff85deb 17
tecnosys 0:0b777ff85deb 18 #include "LPC17xx.h"
tecnosys 0:0b777ff85deb 19 //#include "LPC23xx.h"
tecnosys 0:0b777ff85deb 20 #include "type.h"
tecnosys 0:0b777ff85deb 21
tecnosys 0:0b777ff85deb 22 #include "usb.h"
tecnosys 0:0b777ff85deb 23 #include "usbcfg.h"
tecnosys 0:0b777ff85deb 24 #include "usbhw.h"
tecnosys 0:0b777ff85deb 25 #include "usbcore.h"
tecnosys 0:0b777ff85deb 26 #include "cdc.h"
tecnosys 0:0b777ff85deb 27 #include "cdcuser.h"
tecnosys 0:0b777ff85deb 28 #include "serial.h"
tecnosys 0:0b777ff85deb 29 #include "vcomdemo.h"
tecnosys 0:0b777ff85deb 30
tecnosys 0:0b777ff85deb 31
tecnosys 0:0b777ff85deb 32 /*----------------------------------------------------------------------------
tecnosys 0:0b777ff85deb 33 Initialises the VCOM port.
tecnosys 0:0b777ff85deb 34 Call this function before using VCOM_putchar or VCOM_getchar
tecnosys 0:0b777ff85deb 35 *---------------------------------------------------------------------------*/
tecnosys 0:0b777ff85deb 36 void VCOM_Init(void) {
tecnosys 0:0b777ff85deb 37 #if PORT_NUM
tecnosys 0:0b777ff85deb 38 CDC_Init (1);
tecnosys 0:0b777ff85deb 39 #else
tecnosys 0:0b777ff85deb 40 CDC_Init (0);
tecnosys 0:0b777ff85deb 41 #endif
tecnosys 0:0b777ff85deb 42 }
tecnosys 0:0b777ff85deb 43
tecnosys 0:0b777ff85deb 44
tecnosys 0:0b777ff85deb 45 /*----------------------------------------------------------------------------
tecnosys 0:0b777ff85deb 46 Reads character from serial port buffer and writes to USB buffer
tecnosys 0:0b777ff85deb 47 *---------------------------------------------------------------------------*/
tecnosys 0:0b777ff85deb 48 void VCOM_Serial2Usb(void) {
tecnosys 0:0b777ff85deb 49 static char serBuf [USB_CDC_BUFSIZE];
tecnosys 0:0b777ff85deb 50 int numBytesRead, numAvailByte;
tecnosys 0:0b777ff85deb 51
tecnosys 0:0b777ff85deb 52 ser_AvailChar (&numAvailByte);
tecnosys 0:0b777ff85deb 53 if (numAvailByte > 0) {
tecnosys 0:0b777ff85deb 54 if (CDC_DepInEmpty) {
tecnosys 0:0b777ff85deb 55 numBytesRead = ser_Read (&serBuf[0], &numAvailByte);
tecnosys 0:0b777ff85deb 56
tecnosys 0:0b777ff85deb 57 CDC_DepInEmpty = 0;
tecnosys 0:0b777ff85deb 58 USB_WriteEP (CDC_DEP_IN, (unsigned char *)&serBuf[0], numBytesRead);
tecnosys 0:0b777ff85deb 59 }
tecnosys 0:0b777ff85deb 60 }
tecnosys 0:0b777ff85deb 61
tecnosys 0:0b777ff85deb 62 }
tecnosys 0:0b777ff85deb 63
tecnosys 0:0b777ff85deb 64 /*----------------------------------------------------------------------------
tecnosys 0:0b777ff85deb 65 Reads character from USB buffer and writes to serial port buffer
tecnosys 0:0b777ff85deb 66 *---------------------------------------------------------------------------*/
tecnosys 0:0b777ff85deb 67 void VCOM_Usb2Serial(void) {
tecnosys 0:0b777ff85deb 68 static char serBuf [32];
tecnosys 0:0b777ff85deb 69 int numBytesToRead, numBytesRead, numAvailByte;
tecnosys 0:0b777ff85deb 70
tecnosys 0:0b777ff85deb 71 CDC_OutBufAvailChar (&numAvailByte);
tecnosys 0:0b777ff85deb 72 if (numAvailByte > 0) {
tecnosys 0:0b777ff85deb 73 numBytesToRead = numAvailByte > 32 ? 32 : numAvailByte;
tecnosys 0:0b777ff85deb 74 numBytesRead = CDC_RdOutBuf (&serBuf[0], &numBytesToRead);
tecnosys 0:0b777ff85deb 75 #if PORT_NUM
tecnosys 0:0b777ff85deb 76 ser_Write (1, &serBuf[0], &numBytesRead);
tecnosys 0:0b777ff85deb 77 #else
tecnosys 0:0b777ff85deb 78 ser_Write (0, &serBuf[0], &numBytesRead);
tecnosys 0:0b777ff85deb 79 #endif
tecnosys 0:0b777ff85deb 80 }
tecnosys 0:0b777ff85deb 81
tecnosys 0:0b777ff85deb 82 }
tecnosys 0:0b777ff85deb 83
tecnosys 0:0b777ff85deb 84
tecnosys 0:0b777ff85deb 85 /*----------------------------------------------------------------------------
tecnosys 0:0b777ff85deb 86 checks the serial state and initiates notification
tecnosys 0:0b777ff85deb 87 *---------------------------------------------------------------------------*/
tecnosys 0:0b777ff85deb 88 void VCOM_CheckSerialState (void) {
tecnosys 0:0b777ff85deb 89 unsigned short temp;
tecnosys 0:0b777ff85deb 90 static unsigned short serialState;
tecnosys 0:0b777ff85deb 91
tecnosys 0:0b777ff85deb 92 temp = CDC_GetSerialState();
tecnosys 0:0b777ff85deb 93 if (serialState != temp) {
tecnosys 0:0b777ff85deb 94 serialState = temp;
tecnosys 0:0b777ff85deb 95 CDC_NotificationIn(); // send SERIAL_STATE notification
tecnosys 0:0b777ff85deb 96 }
tecnosys 0:0b777ff85deb 97 }
tecnosys 0:0b777ff85deb 98
tecnosys 0:0b777ff85deb 99 /*----------------------------------------------------------------------------
tecnosys 0:0b777ff85deb 100 Main Program
tecnosys 0:0b777ff85deb 101 *---------------------------------------------------------------------------*/
tecnosys 0:0b777ff85deb 102 int main (void) {
tecnosys 0:0b777ff85deb 103
tecnosys 0:0b777ff85deb 104 SystemInit();
tecnosys 0:0b777ff85deb 105
tecnosys 0:0b777ff85deb 106 VCOM_Init(); // VCOM Initialization
tecnosys 0:0b777ff85deb 107
tecnosys 0:0b777ff85deb 108 USB_Init(); // USB Initialization
tecnosys 0:0b777ff85deb 109 USB_Connect(TRUE); // USB Connect
tecnosys 0:0b777ff85deb 110
tecnosys 0:0b777ff85deb 111 while (!USB_Configuration) ; // wait until USB is configured
tecnosys 0:0b777ff85deb 112
tecnosys 0:0b777ff85deb 113 while (1) { // Loop forever
tecnosys 0:0b777ff85deb 114 VCOM_Serial2Usb(); // read serial port and initiate USB event
tecnosys 0:0b777ff85deb 115 VCOM_CheckSerialState();
tecnosys 0:0b777ff85deb 116 VCOM_Usb2Serial();
tecnosys 0:0b777ff85deb 117 } // end while
tecnosys 0:0b777ff85deb 118 } // end main ()