1.. _autopts-win10:
2
3AutoPTS on Windows 10 with nRF52 board
4#######################################
5
6This tutorial shows how to setup AutoPTS client and server to run both on
7Windows 10. We use WSL1 with Ubuntu only to build a Zephyr project to
8an elf file, because Zephyr SDK is not available on Windows yet.
9Tutorial covers only nrf52840dk.
10
11.. contents::
12    :local:
13    :depth: 2
14
15Update Windows and drivers
16===========================
17
18Update Windows in:
19
20Start -> Settings -> Update & Security -> Windows Update
21
22Update drivers, following the instructions from your hardware vendor.
23
24Install Python 3
25=================
26
27Download and install `Python 3 <https://www.python.org/downloads/>`_.
28Setup was tested with versions >=3.8. Let the installer add the Python
29installation directory to the PATH and disable the path length limitation.
30
31.. image:: install_python1.png
32   :height: 300
33   :width: 450
34   :align: center
35
36.. image:: install_python2.png
37   :height: 300
38   :width: 450
39   :align: center
40
41Install Git
42============
43
44Download and install `Git <https://git-scm.com/downloads>`_.
45During installation enable option: Enable experimental support for pseudo
46consoles. We will use Git Bash as Windows terminal.
47
48.. image:: install_git.png
49   :height: 350
50   :width: 400
51   :align: center
52
53Install PTS 8
54==============
55
56Install latest PTS from https://www.bluetooth.org. Remember to install
57drivers from installation directory
58"C:/Program Files (x86)/Bluetooth SIG/Bluetooth PTS/PTS Driver/win64/CSRBlueCoreUSB.inf"
59
60.. image:: install_pts_drivers.png
61   :height: 250
62   :width: 850
63   :align: center
64
65.. note::
66
67    Starting with PTS 8.0.1 the Bluetooth Protocol Viewer is no longer included.
68    So to capture Bluetooth events, you have to download it separately.
69
70Setup Zephyr project for Windows
71=================================
72
73Perform Windows setup from `Getting Started Guide <https://docs.zephyrproject.org/latest/getting_started/index.html>`_.
74
75Install nrftools
76=================
77
78On Windows download latest nrftools (version >= 10.12.1) from site
79https://www.nordicsemi.com/Software-and-tools/Development-Tools/nRF-Command-Line-Tools/Download
80and run default install.
81
82.. image:: download_nrftools_windows.png
83   :height: 350
84   :width: 500
85   :align: center
86
87Connect devices
88================
89
90.. image:: devices_1.png
91   :height: 400
92   :width: 600
93   :align: center
94
95.. image:: devices_2.png
96   :height: 700
97   :width: 500
98   :align: center
99
100Flash board
101============
102
103In Device Manager find COM port of your nrf board. In my case it is COM3.
104
105.. image:: device_manager.png
106   :height: 400
107   :width: 450
108   :align: center
109
110In Git Bash, go to zephyrproject
111
112.. code-block::
113
114    cd ~/zephyrproject
115
116Build the auto-pts tester app
117
118.. code-block::
119
120    west build -p auto -b nrf52840dk/nrf52840 zephyr/tests/bluetooth/tester/
121
122You can display flashing options with:
123
124.. code-block::
125
126    west flash --help
127
128and flash board with built earlier elf file:
129
130.. code-block::
131
132    west flash --skip-rebuild --board-dir /dev/ttyS2 --elf-file ~/zephyrproject/build/zephyr/zephyr.elf
133
134Note that west does not accept COMs, so use /dev/ttyS2 as the COM3 equivalent,
135/dev/ttyS2 as the COM3 equivalent, etc.(/dev/ttyS + decremented COM number).
136
137Setup auto-pts project
138=======================
139
140In Git Bash, clone project repo:
141
142.. code-block::
143
144    git clone https://github.com/auto-pts/auto-pts.git
145
146Go into the project folder:
147
148.. code-block::
149
150    cd auto-pts
151
152Install required python modules:
153
154.. code-block::
155
156   pip3 install --user wheel
157   pip3 install --user -r autoptsserver_requirements.txt
158   pip3 install --user -r autoptsclient_requirements.txt
159
160Install socat.exe
161==================
162
163Download and extract socat.exe from https://sourceforge.net/projects/unix-utils/files/socat/1.7.3.2/
164into folder ~/socat-1.7.3.2-1-x86_64/.
165
166.. image:: download_socat.png
167   :height: 400
168   :width: 450
169   :align: center
170
171Add path to directory of socat.exe to PATH:
172
173.. image:: add_socat_to_path.png
174   :height: 400
175   :width: 450
176   :align: center
177
178Running AutoPTS
179================
180
181Server and client by default will run on localhost address. Run server:
182
183.. code-block::
184
185    python ./autoptsserver.py -S 65000
186
187.. image:: autoptsserver_run.png
188   :height: 200
189   :width: 800
190   :align: center
191
192.. note::
193
194    If the error "ImportError: No module named pywintypes" appeared after the fresh setup,
195    uninstall and install the pywin32 module:
196
197    .. code-block::
198
199        pip install --upgrade --force-reinstall pywin32
200
201Run client:
202
203.. code-block::
204
205    python ./autoptsclient-zephyr.py zephyr-master ~/zephyrproject/build/zephyr/zephyr.elf -t COM3 -b nrf52 -S 65000 -C 65001
206
207.. image:: autoptsclient_run.png
208   :height: 200
209   :width: 800
210   :align: center
211
212At the first run, when Windows asks, enable connection through firewall:
213
214.. image:: allow_firewall.png
215   :height: 450
216   :width: 600
217   :align: center
218
219Troubleshooting
220================
221
222- "When running actual hardware test mode, I have only BTP TIMEOUTs."
223
224This is a problem with connection between auto-pts client and board. There are many possible causes. Try:
225
226- Clean your auto-pts and zephyr repos with
227
228.. warning::
229
230    This command will force the irreversible removal of all uncommitted files in the repo.
231
232.. code-block::
233
234    git clean -fdx
235
236then build and flash tester elf again.
237
238- If you have set up Windows on virtual machine, check if guest extensions are installed properly or change USB compatibility mode in VM settings to USB 2.0.
239
240- Check, if firewall in not blocking python.exe or socat.exe.
241
242- Check if board sends ready event after restart (hex 00 00 80 ff 00 00). Open serial connection to board with e.g. PuTTy with proper COM and baud rate. After board reset you should see some strings in console.
243
244- Check if socat.exe creates tunnel to board. Run in console
245
246.. code-block::
247
248    socat.exe -x -v tcp-listen:65123 /dev/ttyS2,raw,b115200
249
250where /dev/ttyS2 is the COM3 equivalent. Open PuTTY, set connection type to Raw, IP to 127.0.0.1, port to 65123. After board reset you should see some strings in console.
251