void CDC_BulkIn(void) { int numBytesSend; // split into packets numBytesSend = (cdc_bulkIN_count < USB_CDC_BUFSIZE) ? cdc_bulkIN_count : USB_CDC_BUFSIZE; if ( numBytesSend || ((numBytesSend == 0) && cdc_bulkIN_ZLP) ) { USB_WriteEP (CDC_DEP_IN, cdc_bulkIN_ptr, numBytesSend); // send over USB cdc_bulkIN_count -= numBytesSend; cdc_bulkIN_ptr += numBytesSend; cdc_bulkIN_ZLP = (numBytesSend == USB_CDC_BUFSIZE); if ((!cdc_bulkIN_count) && (!cdc_bulkIN_ZLP)) //<---added for mono-packet transfers to release flag cdc_bulkIN_occupied = FALSE; //<---added for mono-packet transfers to release flag } else { cdc_bulkIN_occupied = FALSE; } } |
CDC_DepInEmpty = 0; // USB_WriteEP (CDC_DEP_IN, (unsigned char *)&serBuf[0], 2); // comment this line LPC_USB->DevIntSet = 1 << (EPAdr( CDC_DEP_IN ) + 1); // invoke endpoint interrupt |
void USB_EndPoint1 (uint32_t event) { if ( (event == USB_EVT_IN) && (CDC_DepInEmpty == 0) ) { CDC_DepInEmpty = 1; USB_WriteEP (CDC_DEP_IN, (unsigned char *)&serBuf[0], 2); } } |
if (USB_P_EP[m]) { USB_P_EP[m](USB_EVT_OUT); } |
void USB_EndPoint2 (uint32_t event) { CDC_BulkOut (); /* data received from Host */ } |
void CDC_BulkOut(void) { static uint32_t led_state = 0; led_state++; if(led_state & 0x80) GPIOSetValue( LED_PORT, LED_BIT, LED_ON ); else GPIOSetValue( LED_PORT, LED_BIT, LED_OFF ); // get data from USB into intermediate buffer numBytesRead = USB_ReadEP(CDC_DEP_OUT, &BulkBufOut[0]); // ... add code to check for overwrite // store data in a buffer to transmit it over serial interface //CDC_WrOutBuf ((char *)&BulkBufOut[0], &numBytesRead); } |
int main (void) { /* Basic chip initialization is taken care of in SystemInit() called * from the startup code. SystemInit() and chip settings are defined * in the CMSIS system_<part family>.c file. */ /* Enable Timer32_1, IOCON, and USB blocks */ LPC_SYSCON->SYSAHBCLKCTRL |= (EN_TIMER32_1 | EN_IOCON | EN_USBREG); /* Initialize 32-bit timer 0. TIME_INTERVAL is defined as 10mS */ /* You may also want to use the Cortex SysTick timer to do this */ /* interrupt each 16 mS **/ init_timer32(0, (SystemFrequency/LPC_SYSCON->SYSAHBCLKDIV)/62); /* Enable timer 0. Our interrupt handler will begin incrementing * the TimeTick global each time timer 0 matches and resets. */ enable_timer32(0); /* Initialize GPIO (sets up clock) */ GPIOInit(); /* Set LED port pin to output */ GPIOSetDir( LED_PORT, LED_BIT, 1 ); /* LED off */ GPIOSetValue( LED_PORT, LED_BIT, LED_OFF ); USBIOClkConfig(); VCOM_Init(); // VCOM Initialization USB_Init(); // USB Initialization USB_Connect(TRUE); // USB Connect NVIC_SetPriority(USB_IRQn, 0);//maximum interrupt prior for USB IRQ NVIC_SetPriority(TIMER_32_0_IRQn, 31);//minimum interrupt prior for TIMER32_0 IRQ while (!USB_Configuration) ; // wait until USB is configured while (1) { // Loop forever VCOM_Serial2Usb(); // read serial port and initiate USB event //VCOM_CheckSerialState(); //VCOM_Usb2Serial(); } // end while } // end main () |
ErrorCode_t VCOM_bulk_out_hdlr(USBD_HANDLE_T hUsb, void* data, uint32_t event) { ... pVcom->rxlen = pUsbApi->hw->ReadEP(hUsb, USB_CDC_EP_BULK_OUT, pVcom->rxBuf); pVcom->rxBuf[pVcom->rxlen++] = pVcom->rxlen; // <------ (1) delete this line pUsbApi->hw->WriteEP (pVcom->hUsb, USB_CDC_EP_BULK_IN, pVcom->rxBuf, pVcom->rxlen); |
pVcom->rxlen = pUsbApi->hw->ReadEP(hUsb, USB_CDC_EP_BULK_OUT, pVcom->rxBuf); pVcom->rxBuf[pVcom->rxlen++] = pVcom->rxlen; pUsbApi->hw->WriteEP (pVcom->hUsb, USB_CDC_EP_BULK_IN, pVcom->rxBuf, pVcom->rxlen); |
cdcuser.c #define CDC_BUF_SIZE (64) // Output buffer in bytes (power 2) |
#define CDC_BUF_SIZE (1024) // Output buffer in bytes (power 2) |
cdcuser.c uint32_t cdc_bulkIN_count = 0; uint8_t *cdc_bulkIN_ptr = NULL; uint8_t cdc_bulkIN_occupied = FALSE; uint8_t cdc_bulkIN_ZLP = FALSE; void CDC_BulkIn(void) { int numBytesSend; // split into packets numBytesSend = (cdc_bulkIN_count < USB_CDC_BUFSIZE) ? cdc_bulkIN_count : USB_CDC_BUFSIZE; if ( numBytesSend || ((numBytesSend == 0) && cdc_bulkIN_ZLP) ) { USB_WriteEP (CDC_DEP_IN, cdc_bulkIN_ptr, numBytesSend); // send over USB cdc_bulkIN_count -= numBytesSend; cdc_bulkIN_ptr += numBytesSend; cdc_bulkIN_ZLP = (numBytesSend == USB_CDC_BUFSIZE); } else { cdc_bulkIN_occupied = FALSE; } } |
uint32_t CDC_block_send( uint8_t *buffer, uint32_t send_size ) { if ( !cdc_bulkIN_occupied ) { // The bulk IN endpoint is not busy cdc_bulkIN_occupied = TRUE; // fill the context cdc_bulkIN_ptr = buffer; cdc_bulkIN_count = send_size; cdc_bulkIN_ZLP = FALSE; LPC_USB->DevIntSet = EPAdr( CDC_DEP_IN ); // trigger interrupt manually return TRUE; } return FALSE; } |
usbuser.c #if USB_CONFIGURE_EVENT void USB_Configure_Event (void) { if (USB_Configuration) { /* Check if USB is configured */ /* add your code here */ cdc_bulkIN_count = 0; cdc_bulkIN_ptr = NULL; cdc_bulkIN_occupied = FALSE; cdc_bulkIN_ZLP = FALSE; } } #endif |