Skip to content
This repository was archived by the owner on Apr 18, 2024. It is now read-only.

Commit 749578b

Browse files
authored
Feature/tune uart params (#264)
* Add tunable parameters for Windows * Fix nrfutil in pipeline (Linux)
1 parent b630b06 commit 749578b

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

.azure-pipelines/azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ jobs:
213213
sudo apt-get update
214214
sudo apt-get install ninja-build gcc-8 g++-8 clang-9 clang-format-9 clang-tidy-9 python3-pycurl python3-pip python3-certifi python3-setuptools libusb-1.0-0-dev libudev-dev
215215
/usr/bin/python3 -m pip install -U pip
216-
/usr/bin/python3 -m pip install nrfutil
216+
/usr/bin/python3 -m pip install --ignore-installed nrfutil
217217
chmod a+x $(System.ArtifactsDirectory)/nrftc
218218
$(System.ArtifactsDirectory)/nrftc install arm-toolchain -a $(Agent.BuildDirectory)/toolchain -i armgcc:${{ parameters.ARMGCC_VERSION }} -e $(Agent.BuildDirectory)/tcenv.sh
219219
cat $(Agent.BuildDirectory)/tcenv.sh

src/common/transport/uart_transport.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ constexpr auto DELAY_BEFORE_READ_WRITE = std::chrono::milliseconds(200);
6161
// if opening a UART port right after close.
6262
constexpr auto DELAY_BEFORE_OPEN = std::chrono::milliseconds(200);
6363

64+
#if defined(_WIN32)
65+
// Wait for 20ms for data before returning from a read
66+
constexpr auto readTotalTimeoutConstant = 20;
67+
#endif
68+
6469
struct UartTransport::impl : Transport
6570
{
6671
std::array<uint8_t, UartTransportBufferSize> readBuffer;
@@ -283,6 +288,26 @@ struct UartTransport::impl : Transport
283288
}
284289
#endif
285290

291+
#if defined(_WIN32)
292+
::COMMTIMEOUTS timeouts;
293+
294+
// See
295+
// https://docs.microsoft.com/en-us/windows/win32/api/winbase/ns-winbase-commtimeouts
296+
// for documentation of these parameters
297+
timeouts.ReadIntervalTimeout = MAXDWORD;
298+
timeouts.ReadTotalTimeoutMultiplier = MAXDWORD;
299+
timeouts.ReadTotalTimeoutConstant = readTotalTimeoutConstant;
300+
301+
timeouts.WriteTotalTimeoutMultiplier = 0;
302+
timeouts.WriteTotalTimeoutConstant = 0;
303+
304+
if (!::SetCommTimeouts(serialPort->native_handle(), &timeouts))
305+
{
306+
const auto error = std::error_code(errno, std::system_category());
307+
throw std::system_error(error, "Failed to set communication timeout parameters");
308+
}
309+
#endif
310+
286311
// Wait a bit before making the device available since there are problems
287312
// if data is sent right after open.
288313
//

0 commit comments

Comments
 (0)