diff --git a/Host/SerialBoot.exe b/Host/SerialBoot.exe index 013dd247..20a4c7fe 100644 Binary files a/Host/SerialBoot.exe and b/Host/SerialBoot.exe differ diff --git a/Host/Source/MicroBoot/interfaces/uart/XcpTransport.pas b/Host/Source/MicroBoot/interfaces/uart/XcpTransport.pas index bbd41614..7964ab5d 100644 --- a/Host/Source/MicroBoot/interfaces/uart/XcpTransport.pas +++ b/Host/Source/MicroBoot/interfaces/uart/XcpTransport.pas @@ -86,6 +86,10 @@ begin sciDriver.DataBits := dbEight; sciDriver.StopBits := sbOneStopBit; sciDriver.Parity.Bits := prNone; + sciDriver.FlowControl.XonXoffOut := false; + sciDriver.FlowControl.XonXoffIn := false; + sciDriver.FlowControl.ControlRTS := rtsDisable; + sciDriver.FlowControl.ControlDTR := dtrEnable; // reset packet length packetLen := 0; diff --git a/Host/Source/SerialBoot/port/linux/timeutil.c b/Host/Source/SerialBoot/port/linux/timeutil.c index 0125127d..79a6db15 100644 --- a/Host/Source/SerialBoot/port/linux/timeutil.c +++ b/Host/Source/SerialBoot/port/linux/timeutil.c @@ -33,7 +33,7 @@ #include /* C types */ #include /* UNIX standard functions */ #include /* file control definitions */ -#include /* time definitions */ +#include /* time definitions */ /************************************************************************************//** diff --git a/Host/Source/SerialBoot/port/linux/xcptransport.c b/Host/Source/SerialBoot/port/linux/xcptransport.c index 04f92cd8..40229aa9 100644 --- a/Host/Source/SerialBoot/port/linux/xcptransport.c +++ b/Host/Source/SerialBoot/port/linux/xcptransport.c @@ -37,6 +37,7 @@ #include /* file control definitions */ #include /* error number definitions */ #include /* POSIX terminal control */ +#include /* system I/O control */ #include "xcpmaster.h" /* XCP master protocol module */ #include "timeutil.h" /* time utility module */ @@ -79,6 +80,7 @@ static sb_int32 hUart = UART_INVALID_HANDLE; sb_uint8 XcpTransportInit(sb_char *device, sb_uint32 baudrate) { struct termios options; + int iFlags; /* open the port */ hUart = open(device, O_RDWR | O_NOCTTY | O_NDELAY); @@ -132,6 +134,9 @@ sb_uint8 XcpTransportInit(sb_char *device, sb_uint32 baudrate) XcpTransportClose(); return SB_FALSE; } + /* turn on DTR */ + iFlags = TIOCM_DTR; + ioctl(hUart, TIOCMBIS, &iFlags); /* success */ return SB_TRUE; } /*** end of XcpTransportInit ***/ @@ -183,16 +188,21 @@ sb_uint8 XcpTransportSendPacket(sb_uint8 *data, sb_uint8 len, sb_uint16 timeOutM /* read the first byte, which contains the length of the xcp packet that follows */ bytesToRead = 1; - uartReadDataPtr = &responsePacket.len; + responsePacket.len = 0; while(bytesToRead > 0) { - result = read(hUart, uartReadDataPtr, bytesToRead); + result = read(hUart, &responsePacket.len, bytesToRead); if (result != -1) { bytesRead = result; - /* update the bytes that were already read */ - uartReadDataPtr += bytesRead; - bytesToRead -= bytesRead; + /* one byte should be read and it should contain the packet length, which cannot be 0 */ + if ((bytesRead == bytesToRead) && (responsePacket.len > 0)) + { + /* valid packet length received so stop this loop to continue with the reception + * remaining packet bytes + */ + bytesToRead = 0; + } } /* check for timeout if not yet done */ if ( (bytesToRead > 0) && (TimeUtilGetSystemTimeMs() >= timeoutTime) ) diff --git a/Host/Source/SerialBoot/port/win32/xcptransport.c b/Host/Source/SerialBoot/port/win32/xcptransport.c index 17b0bce6..3ea1323d 100644 --- a/Host/Source/SerialBoot/port/win32/xcptransport.c +++ b/Host/Source/SerialBoot/port/win32/xcptransport.c @@ -47,9 +47,6 @@ #define XCP_MASTER_UART_MAX_DATA ((XCP_MASTER_TX_MAX_DATA>XCP_MASTER_RX_MAX_DATA) ? \ (XCP_MASTER_TX_MAX_DATA+1) : (XCP_MASTER_RX_MAX_DATA+1)) -/** \brief The smallest time in millisecond that the UART is configured for. */ -#define UART_RX_TIMEOUT_MIN_MS (5) - /**************************************************************************************** * Local data declarations @@ -97,6 +94,11 @@ sb_uint8 XcpTransportInit(sb_char *device, sb_uint32 baudrate) dcbSerialParams.ByteSize = 8; dcbSerialParams.StopBits = ONESTOPBIT; dcbSerialParams.Parity = NOPARITY; + dcbSerialParams.fOutX = FALSE; + dcbSerialParams.fInX = FALSE; + dcbSerialParams.fRtsControl = RTS_CONTROL_DISABLE; + dcbSerialParams.fDtrControl = DTR_CONTROL_ENABLE; + if (!SetCommState(hUart, &dcbSerialParams)) { XcpTransportClose(); @@ -104,11 +106,12 @@ sb_uint8 XcpTransportInit(sb_char *device, sb_uint32 baudrate) } /* set communication timeout parameters */ - timeouts.ReadIntervalTimeout = UART_RX_TIMEOUT_MIN_MS; - timeouts.ReadTotalTimeoutConstant = UART_RX_TIMEOUT_MIN_MS; - timeouts.ReadTotalTimeoutMultiplier = 1; - timeouts.WriteTotalTimeoutConstant = UART_RX_TIMEOUT_MIN_MS; - timeouts.WriteTotalTimeoutMultiplier = 1; + timeouts.ReadIntervalTimeout = 0; + timeouts.ReadTotalTimeoutConstant = 0; + timeouts.ReadTotalTimeoutMultiplier = 100; + timeouts.WriteTotalTimeoutConstant = 0; + timeouts.WriteTotalTimeoutMultiplier = 100; + if (!SetCommTimeouts(hUart, &timeouts)) { XcpTransportClose(); @@ -177,19 +180,24 @@ sb_uint8 XcpTransportSendPacket(sb_uint8 *data, sb_uint8 len, sb_uint16 timeOutM /* ------------------------ XCP packet reception ----------------------------------- */ /* determine timeout time */ - timeoutTime = TimeUtilGetSystemTimeMs() + timeOutMs + UART_RX_TIMEOUT_MIN_MS; + timeoutTime = TimeUtilGetSystemTimeMs() + timeOutMs + 100; /* read the first byte, which contains the length of the xcp packet that follows */ dwToRead = 1; - uartReadDataPtr = &responsePacket.len; + responsePacket.len = 0; while(dwToRead > 0) { dwRead = 0; - if (ReadFile(hUart, uartReadDataPtr, dwToRead, &dwRead, NULL)) + if (ReadFile(hUart, &responsePacket.len, dwToRead, &dwRead, NULL)) { - /* update the bytes that were already read */ - uartReadDataPtr += dwRead; - dwToRead -= dwRead; + /* one byte should be read and it should contain the packet length, which cannot be 0 */ + if ((dwRead == dwToRead) && (responsePacket.len > 0)) + { + /* valid packet length received so stop this loop to continue with the reception + * remaining packet bytes + */ + dwToRead = 0; + } } /* check for timeout if not yet done */ if ( (dwToRead > 0) && (TimeUtilGetSystemTimeMs() >= timeoutTime) ) diff --git a/Host/openblt_uart.dll b/Host/openblt_uart.dll index effd2228..f7930d5b 100644 Binary files a/Host/openblt_uart.dll and b/Host/openblt_uart.dll differ diff --git a/Target/Source/boot.h b/Target/Source/boot.h index f01417d1..ffc50270 100644 --- a/Target/Source/boot.h +++ b/Target/Source/boot.h @@ -36,7 +36,7 @@ /** \brief Minor version of the bootloader core. */ #define BOOT_VERSION_CORE_MINOR (3u) /** \brief Build version of the bootloader core. */ -#define BOOT_VERSION_CORE_BUILD (0u) +#define BOOT_VERSION_CORE_BUILD (1u) /****************************************************************************************