Tool/software: Code Composer Studio
Hello!
I am trying to create a small little application using the TM4C123GH6PM, currently with the launch pad, but I will turn the design into a single PCB one, once the program is finished.
So what I am trying to achive is, send some lines to the board from the PC via USB, it should recognicse the command, do it job and echo back OK or an Error code.
Commands look like this:
- Rxxx
- Lxxx
- Zxxx
- Txxx
- etc..
Where the X-s are representating number, it's always 3 digits.
What I have managed to do so far is to modify the usb_dev_bulk, I have changed the part "EchoNewDataToHost"
static uint32_t EchoNewDataToHost(tUSBDBulkDevice *psDevice, uint8_t *pui8Data, uint32_t ui32NumBytes) { uint32_t ui32Loop, ui32Space, ui32Count; uint32_t ui32ReadIndex; uint32_t ui32WriteIndex; 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) { // // Copy from the receive buffer to the transmit buffer converting // character case on the way. // // // Is this a lower case character? // if((g_pui8USBRxBuffer[ui32ReadIndex] == 'L')) { GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, GPIO_PIN_3); UARTprintf("LEFT" ); } else if((g_pui8USBRxBuffer[ui32ReadIndex] == 'R')) { GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2); UARTprintf(" RIGHT " ); } else { GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, 0); GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0); // // Is this an upper case character? // if((g_pui8USBRxBuffer[ui32ReadIndex] >= 'A') && (g_pui8USBRxBuffer[ui32ReadIndex] <= 'Z')) { // // Convert to lower case and write to the transmit buffer. // g_pui8USBTxBuffer[ui32WriteIndex] = (g_pui8USBRxBuffer[ui32ReadIndex] - 'Z') + 'z'; } else { // // Copy the received character to the transmit buffer. // g_pui8USBTxBuffer[ui32WriteIndex] = g_pui8USBRxBuffer[ui32ReadIndex]; } } // // Move to the next character taking care to adjust the pointer for // the buffer wrap if necessary. // ui32WriteIndex++; ui32WriteIndex = (ui32WriteIndex == BULK_BUFFER_SIZE) ? 0 : ui32WriteIndex; ui32ReadIndex++; ui32ReadIndex = (ui32ReadIndex == BULK_BUFFER_SIZE) ? 0 : ui32ReadIndex; ui32Loop--; } // // We've processed the data in place so now send the processed data // back to the host. // USBBufferDataWritten(&g_sTxBuffer, ui32Count); 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); }
So now I know the program separates the first 2 commands, but I would like to ask for your help on :
- how to get the next 3 digits after the command
- how to get these 3 digits as numbers (int s)
- how to echo back strings easily (something UARTprintf or something)
Thank you for helping me!