From b11b8e8bf3933947c85867aeeafdc2ffd7b88c2c Mon Sep 17 00:00:00 2001 From: Cristian Maglie <c.maglie@arduino.cc> Date: Sat, 16 Aug 2014 08:49:59 +0200 Subject: [PATCH] Fix on USB-CDC 1200bps-touch reset condition Some serial libraries opens the serial port BEFORE setting the baudrate. This patch allows finer control on the reset condition, since it's checked on open/close (DTR) AND on serial port parameter change. --- cores/arduino/USB/CDC.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/cores/arduino/USB/CDC.cpp b/cores/arduino/USB/CDC.cpp index f113bc16..40fadaa2 100644 --- a/cores/arduino/USB/CDC.cpp +++ b/cores/arduino/USB/CDC.cpp @@ -119,21 +119,25 @@ bool WEAK CDC_Setup(Setup& setup) if (CDC_SET_LINE_CODING == r) { USBD_RecvControl((void*)&_usbLineInfo,7); - return false; } if (CDC_SET_CONTROL_LINE_STATE == r) { _usbLineInfo.lineState = setup.wValueL; + } + + if (CDC_SET_LINE_CODING == r || CDC_SET_CONTROL_LINE_STATE == r) + { // auto-reset into the bootloader is triggered when the port, already - // open at 1200 bps, is closed. - if (1200 == _usbLineInfo.dwDTERate) + // open at 1200 bps, is closed. We check DTR state to determine if host + // port is open (bit 0 of lineState). + if (1200 == _usbLineInfo.dwDTERate && (_usbLineInfo.lineState & 0x01) == 0) + { + initiateReset(250); + } + else { - // We check DTR state to determine if host port is open (bit 0 of lineState). - if ((_usbLineInfo.lineState & 0x01) == 0) - initiateReset(250); - else - cancelReset(); + cancelReset(); } return false; } -- GitLab