I was testing the lpc21isp program on Linux using a USB-to-serial
converter as the interface to my development board and I think I
found a bug in the ClearSerialPortBuffers() function. The "tty"
termios structure is not initialized before it is written to the
serial port to flush the input and output buffers. For some reason,
this causes glitches on the DTR and RTS outputs of the USB-to-serial
adapter and then prevents synchronization with the microcontroller.
Is there any reason that the current termios configuration
("origtty") read from the port couldn't be written back with the
TCSAFLUSH action?
I am using version 1.49 of lpc21isp.
Thanks,
Gregg.
/*****************************
ClearSerialPortBuffers********************/
/** Empty the serial port buffers. Cleans things to a known state.
*/
static void ClearSerialPortBuffers(ISP_ENVIRONMENT *IspEnvironment)
{
#if defined COMPILE_FOR_LINUX
/* variables to store the current tty state, create a new one */
struct termios origtty, tty;
/* store the current tty settings */
tcgetattr(IspEnvironment->fdCom, &origtty);
// Flush input and output buffers
tcsetattr(IspEnvironment->fdCom, TCSAFLUSH, &tty);
/* reset the tty to its original settings */
tcsetattr(IspEnvironment->fdCom, TCSADRAIN, &origtty);
#endif // defined COMPILE_FOR_LINUX
#if defined COMPILE_FOR_WINDOWS || defined COMPILE_FOR_CYGWIN
PurgeComm(IspEnvironment->hCom, PURGE_TXABORT | PURGE_RXABORT |
PURGE_TXCLEAR | PURGE_RXCLEAR);
#endif // defined COMPILE_FOR_WINDOWS || defined COMPILE_FOR_CYGWIN
}
#endif // !defined COMPILE_FOR_LPC21