Hello!
I have modified the usb_dev_bulk example a bit, I can read the data which is coming from the host (PC) but I can't send my "status codes" back. Only the very firs letter which is '1' goes back to the host.
static uint32_t EchoNewDataToHost(tUSBDBulkDevice *psDevice, uint8_t *pui8Data, uint32_t ui32NumBytes) { uint32_t ui32Loop, ui32Space, ui32Count; uint32_t ui32ReadIndex; uint32_t ui32WriteIndex; uint32_t valueL; uint32_t valueR; uint32_t valueC; tUSBRingBufObject sTxRing; // // Get the current buffer information to allow us to write directly to // the transmit buffer (we already have enough information from the // parameters to access the receive buffer directly). // USBBufferInfoGet(&g_sTxBuffer, &sTxRing); // // How much space is there in the transmit buffer? // ui32Space = USBBufferSpaceAvailable(&g_sTxBuffer); // // How many characters can we process this time round? // ui32Loop = (ui32Space < ui32NumBytes) ? ui32Space : ui32NumBytes; ui32Count = ui32Loop; // // Update our receive counter. // g_ui32RxCount += ui32NumBytes; // // Dump a debug message. // DEBUG_PRINT("Received %d bytes\n", ui32NumBytes); // // Set up to process the characters by directly accessing the USB buffers. // ui32ReadIndex = (uint32_t)(pui8Data - g_pui8USBRxBuffer); ui32WriteIndex = sTxRing.ui32WriteIndex; while(ui32Loop) { UARTprintf("\n" ); // // LEFT SIDE USB MSG // if((g_pui8USBRxBuffer[ui32ReadIndex] == 'L')) { ui32ReadIndex++; ui32ReadIndex = (ui32ReadIndex == BULK_BUFFER_SIZE) ? 0 : ui32ReadIndex; GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, GPIO_PIN_3); UARTprintf("LEFT" ); char buffer[3]; uint32_t i; for(i = 0; i<3; i++){ buffer[i] = g_pui8USBRxBuffer[ui32ReadIndex]; ui32ReadIndex++; ui32ReadIndex = (ui32ReadIndex == BULK_BUFFER_SIZE) ? 0 : ui32ReadIndex; } valueL = atoi((char *)buffer); UARTprintf("\n %i", valueL); sprintf(g_pui8USBTxBuffer, "100"); } // // RGITH SIDE USB MSG // else if((g_pui8USBRxBuffer[ui32ReadIndex] == 'R')) { ui32ReadIndex++; ui32ReadIndex = (ui32ReadIndex == BULK_BUFFER_SIZE) ? 0 : ui32ReadIndex; UARTprintf(" RIGHT " ); char buffer[3]; uint32_t i; for(i = 0; i<3; i++){ buffer[i] = g_pui8USBRxBuffer[ui32ReadIndex]; ui32ReadIndex++; ui32ReadIndex = (ui32ReadIndex == BULK_BUFFER_SIZE) ? 0 : ui32ReadIndex; } valueR = atoi((char *)buffer); UARTprintf("\n %i", valueR); sprintf(g_pui8USBTxBuffer, "100"); } ui32Loop--; } // // We've processed the data in place so now send the processed data // back to the host. // USBBufferDataWritten(&g_sTxBuffer, sizeof(g_pui8USBTxBuffer[BULK_BUFFER_SIZE])); DEBUG_PRINT("Wrote %d bytes\n", ui32Count); // // We processed as much data as we can directly from the receive buffer so // we need to return the number of bytes to allow the lower layer to // update its read pointer appropriately. // return(ui32Count); }
I you could tell me what's wrong that would be really nice, I have never used USB communication before, I have always used UART. So in the next step I would like to get help with creating a function like "UARTPrintln" which can be called with a simple parameter which would be the message itself.