A scope will work great! We just need to see if the vector image comes out OK.
As far as the code. I see how we can do it already. Here is the main loop:
Code:
for (;;) {
/* Only try to read in bytes from the CDC interface if the transmit buffer is not full */
if (!(RingBuffer_IsFull(&USBtoUSART_Buffer)))
{
int16_t ReceivedByte = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);
/* Read bytes from the USB OUT endpoint into the USART transmit buffer */
if (!(ReceivedByte < 0))
RingBuffer_Insert(&USBtoUSART_Buffer, ReceivedByte);
}
/* Check if the UART receive buffer flush timer has expired or the buffer is nearly full */
RingBuff_Count_t BufferCount = RingBuffer_GetCount(&USARTtoUSB_Buffer);
if ((TIFR0 & (1 << TOV0)) || (BufferCount > BUFFER_NEARLY_FULL))
{
TIFR0 |= (1 << TOV0);
if (USARTtoUSB_Buffer.Count) {
LEDs_TurnOnLEDs(LEDMASK_TX);
PulseMSRemaining.TxLEDPulse = TX_RX_LED_PULSE_MS;
}
/* Read bytes from the USART receive buffer into the USB IN endpoint */
while (BufferCount--)
CDC_Device_SendByte(&VirtualSerial_CDC_Interface, RingBuffer_Remove(&USARTtoUSB_Buffer));
/* Turn off TX LED(s) once the TX pulse period has elapsed */
if (PulseMSRemaining.TxLEDPulse && !(--PulseMSRemaining.TxLEDPulse))
LEDs_TurnOffLEDs(LEDMASK_TX);
/* Turn off RX LED(s) once the RX pulse period has elapsed */
if (PulseMSRemaining.RxLEDPulse && !(--PulseMSRemaining.RxLEDPulse))
LEDs_TurnOffLEDs(LEDMASK_RX);
}
/* Load the next byte from the USART transmit buffer into the USART */
if (!(RingBuffer_IsEmpty(&USBtoUSART_Buffer))) {
Serial_TxByte(RingBuffer_Remove(&USBtoUSART_Buffer));
LEDs_TurnOnLEDs(LEDMASK_RX);
PulseMSRemaining.RxLEDPulse = TX_RX_LED_PULSE_MS;
}
CDC_Device_USBTask(&VirtualSerial_CDC_Interface);
USB_USBTask();
}
Notice that it looks at the ring buffer to see if it is NOT full before reading more data from the USB buffer. We can just use that. So it will basically go... If CTS IO Pin is LOW then do not put any data in the ring buffer. That should work as the whole premise is that the USB is really fast and the UART can be really slow as in 300 bps. So this basically regulates the speed of the whole thing so that the UART doesn't get overwhelmed and is fed data at the proper rate.
Do you have any good references for doing the DFU boot loading? I will look it up on my own however I thought you might be more familiar with it.