The Xboot bootloader requires the ESC character (0x1B) before receiving the 'S' character from the 'avr109 virtual programmer' within avrdude to initiate programming. If one wants to initiate programming via UART from main application code, then the main application code needs to 'catch' the 0x1B character - which is the first character sent out by avrdude. Once this character is captured by the main application, the main application executes code which causes a software reset. The device then restarts in the boot-loader (this is a fuse setting).
The issue I am having is that once the xboot boot-loader starts, it is waiting for the ESC character first in order to enter programming mode, but this character has already been received (and read) in the main application code. So the bootloader's first received character is the 'S' character (sent from avrdude) which is not sufficient to initiate programming mode, and therefore avrdude hangs, waiting for a response from the bootloader.
A few questions :
a) Does a software reset clear the received byte in the USART?
b) Does reading a received byte in the USART, clear it automatically?
c) Any suggestion on howto solve this issue?