Skip to content

Instantly share code, notes, and snippets.

@tdowgielewicz
Created August 8, 2014 08:06
Show Gist options
  • Save tdowgielewicz/cd0a04634f4c0ef36822 to your computer and use it in GitHub Desktop.
Save tdowgielewicz/cd0a04634f4c0ef36822 to your computer and use it in GitHub Desktop.
USB support LPC1768
/**
*****************************************************************************
* @title USB_CDC.c
* @author Lean966
* @date 14 Jul 2011
* @brief USB Device as CDC for LPC17xx, the character are recived and tra
* smitted on the simulated VCOM .
* Note: the same example, could b
* e used for the LPC17xx USB CDC stack.
*******************************************************************************
*/
////// The above comment is automatically generated by CoIDE ///////////////////
#include "LPC17xx.h"
#include "lpc17xx_clkpwr.h"
#include "lpc_types.h"
/*----------------------------------------------------------------------------
Include USB Stack
*---------------------------------------------------------------------------*/
#include "usb.h"
#include "usbcfg.h"
#include "usbhw.h"
#include "usbcore.h"
#include "cdc.h"
#include "cdcuser.h"
#include "serial.h"
void wait_ms(int ms)
{
int i;
INT_32 k;
for (i=0;i< ms;i++){
for(k=0;k<8600;) k++; //experimental
}
}
void LPC_USB_CDC()
{
static char serBuf [USB_CDC_BUFSIZE];
int numBytesToRead, numBytesRead, numAvailByte;
USB_Init();
USB_Connect(TRUE); // USB Connect
while (!USB_Configuration) ; // wait until USB is configured
while(1)
{
CDC_OutBufAvailChar (&numAvailByte); //get buffer from serial/usb
if (numAvailByte > 0)
{
numBytesToRead = numAvailByte > 32 ? 32 : numAvailByte; //check if not bigger than 32B
numBytesRead = CDC_RdOutBuf (&serBuf[0], &numBytesToRead);
USB_WriteEP (CDC_DEP_IN, (unsigned char *)&serBuf[0], numBytesRead); //write what was read
USB_WriteEP (CDC_DEP_IN, "dziendobry", 10); //just testing
}
else
{
wait_ms(50);
USB_WriteEP (CDC_DEP_IN, "Waiting.", 8);
}
}
}
int main(void)
{
SystemInit();
LPC_USB_CDC();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment