-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathns-updater.bat
More file actions
512 lines (456 loc) · 12.8 KB
/
ns-updater.bat
File metadata and controls
512 lines (456 loc) · 12.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
@echo off
REM color 0a
setlocal enabledelayedexpansion
:: Welcome message
::====================================================
set main_board_configured=0
set power_board_configured=0
set esp_configured=0
set version=1.20
call :get_version main_board mb_version
call :get_version power_board pb_version
call :get_version NS esp_version
call :update_info
:: Main menu
::====================================================
:display_main_menu
set "menu_opt="
echo *** Main Menu ***
echo 1 - Configure programmers
echo 2 - Update software
echo 3 - Erase software
echo Q - Quit
choice /c 123Q /n /m ""
set menu_opt=%errorlevel%
call :update_info
if %menu_opt%==1 goto :display_configure_programmers
if %menu_opt%==2 goto :display_update_software
if %menu_opt%==3 goto :display_erase_software
if %menu_opt%==4 goto :end_program
exit /b 0
:: Configure params menu
::====================================================
:display_configure_programmers
set "menu_opt="
echo *** Configure ***
echo 1 - Main board programmer
echo 2 - Power board programmer
echo 3 - ESP programmer
echo Q - Return to Main menu
choice /c 123Q /n /m ""
set menu_opt=%errorlevel%
call :update_info
if %menu_opt%==1 goto :configure_main_board
if %menu_opt%==2 goto :configure_power_board
if %menu_opt%==3 goto :configure_esp
if %menu_opt%==4 goto :display_main_menu
exit /b 0
:: Update software menu
::====================================================
:display_update_software
set "menu_opt="
set updating_all=0
echo *** Update Software ***
echo 1 - Main board
echo 2 - Power board
echo 3 - ESP
echo 4 - Update ALL
echo Q - Return to Main menu
choice /c 1234Q /n /m ""
set menu_opt=%errorlevel%
call :update_info
if %menu_opt%==1 goto :update_main_board
if %menu_opt%==2 goto :update_power_board
if %menu_opt%==3 goto :update_esp
if %menu_opt%==4 goto :update_all
if %menu_opt%==5 goto :display_main_menu
exit /b 0
:: Erase software menu
::====================================================
:display_erase_software
set "menu_opt="
set erasing_all=0
echo *** Erase Software ***
echo 1 - Main board
echo 2 - Power board
echo 3 - ESP
echo 4 - Erase ALL
echo Q - Return to Main menu
choice /c 1234Q /n /m ""
set menu_opt=%errorlevel%
call :update_info
if %menu_opt%==1 goto :erase_main_board
if %menu_opt%==2 goto :erase_power_board
if %menu_opt%==3 goto :erase_esp
if %menu_opt%==4 goto :erase_all
if %menu_opt%==5 goto :display_main_menu
exit /b 0
:: Configure Main board
::====================================================
:configure_main_board
set "func_return="
echo [Select Main board programmer drive]
echo.
call :select_drive mb_drive
set func_return=%errorlevel%
if %func_return%==10 goto :configure_main_board
if %func_return%==11 (
call :update_info
echo [Main board not configured]
echo.
goto :display_configure_programmers
)
call :update_info
echo [Main board configured]
set main_board_configured=1
echo.
goto :display_configure_programmers
exit /b 0
:: Configure Power board
::====================================================
:configure_power_board
set "func_return="
echo [Select Power board programmer drive]
echo.
call :select_drive pb_drive
set func_return=%errorlevel%
if %func_return%==10 goto :configure_power_board
if %func_return%==11 (
call :update_info
echo [Power board not configured]
echo.
goto :display_configure_programmers
)
call :update_info
echo [Power board configured]
set power_board_configured=1
echo.
goto :display_configure_programmers
exit /b 0
:: Configure ESP
::====================================================
:configure_esp
set "func_return="
echo [Select ESP programmer port]
echo.
call :select_port esp_port
set func_return=%errorlevel%
if %func_return%==10 goto :configure_esp
if %func_return%==11 (
call :update_info
echo [ESP not configured]
echo.
goto :display_configure_programmers
)
call :update_info
echo [ESP configured]
set esp_configured=1
echo.
goto :display_configure_programmers
exit /b 0
:: Update Main board
::====================================================
:update_main_board
if %main_board_configured%==0 (
if %updating_all%==0 call :update_info
echo [Main board is not configured]
echo.
if %updating_all%==1 goto :update_power_board
goto :display_update_software
)
call :install_software main_board %mb_drive% %mb_version%
if %updating_all%==1 goto :update_power_board
goto :display_update_software
exit /b 0
:: Update Power board
::====================================================
:update_power_board
if %power_board_configured%==0 (
if %updating_all%==0 call :update_info
echo [Power board is not configured]
echo.
if %updating_all%==1 goto :update_esp
goto :display_update_software
)
call :install_software power_board %pb_drive% %pb_version%
if %updating_all%==1 goto :update_esp
goto :display_update_software
exit /b 0
:: Update ESP
::====================================================
:update_esp
if %esp_configured%==0 (
if %updating_all%==0 call :update_info
echo [ESP port is not configured]
echo.
if %updating_all%==1 goto :display_update_software
goto :display_update_software
)
call :install_esp %esp_port%
if %updating_all%==1 goto :display_update_software
goto :display_update_software
exit /b 0
:: Update ALL
::====================================================
:update_all
set "menu_opt="
set updating_all=1
echo Connect the Main board, Power board and ESP programmers to the Nectarsun
echo to update all configured boards in one go
echo.
if defined mb_drive (
if defined pb_drive (
if "%mb_drive%"=="%pb_drive%" call :same_drive_defined
)
)
choice /c YN /m "Ready to update "
set menu_opt=%errorlevel%
call :update_info
if %menu_opt%==1 goto :update_main_board
goto :display_update_software
exit /b 0
:: Erase Main board
::====================================================
:erase_main_board
if %main_board_configured%==0 (
if %erasing_all%==0 call :update_info
echo [Main board is not configured]
echo.
if %erasing_all%==1 goto :erase_power_board
goto :display_erase_software
)
call :erase_st_flash %mb_drive%
if %erasing_all%==1 goto :erase_power_board
goto :display_erase_software
exit /b 0
:: Erase Power board
::====================================================
:erase_power_board
if %power_board_configured%==0 (
if %erasing_all%==0 call :update_info
echo [Power board is not configured]
echo.
if %erasing_all%==1 goto :erase_esp
goto :display_erase_software
)
call :erase_st_flash %pb_drive%
if %erasing_all%==1 goto :erase_esp
goto :display_erase_software
exit /b 0
:: Erase ESP
::====================================================
:erase_esp
if %esp_configured%==0 (
if %erasing_all%==0 call :update_info
echo [ESP port is not configured]
echo.
goto :display_erase_software
)
call :erase_esp_flash %esp_port%
goto :display_erase_software
exit /b 0
:: Erase ALL
::====================================================
:erase_all
set "menu_opt="
set erasing_all=1
echo Connect the Main board, Power board and ESP programmers to the Nectarsun
echo to erase all boards in one go
echo.
if defined mb_drive (
if defined pb_drive (
if "%mb_drive%"=="%pb_drive%" call :same_drive_defined
)
)
choice /c YN /m "Ready to erase "
set menu_opt=%errorlevel%
call :update_info
if %menu_opt%==1 goto :erase_main_board
goto :display_erase_software
exit /b 0
:: Check if same drive defined for MB and PB
::====================================================
:same_drive_defined
call :update_info
echo.
echo [ERROR]
echo Same drive selected for Main and Power board programmers!
echo Can't run the 'Update All' option!
echo.
echo *** Select one of the options ***
echo 1 - Change drive for Main board
echo 2 - Change drive for Power board
choice /c 12 /n /m ""
if errorlevel 2 (
call :update_info
echo.
echo [Changing drive for Power board]
call :select_drive pb_drive
)
if errorlevel 1 (
call :update_info
echo.
echo [Changing drive for Main board]
call :select_drive mb_drive
)
exit /b 0
:: Install ST software
::====================================================
:install_software
echo.
REM xcopy "bin\%~1*.bin" %~2:\
tools\st-link.exe -c ID=%~2 -ME -V -P "bin\%~1_%~3.bin" 0x08000000
echo.
if errorlevel 0 (
echo [Software updated on 'Probe %~2']
echo.
exit /b 0
)
echo.
echo [ERROR]
echo [Something went wrong]
echo.
exit /b %errorlevel%
:: Erase ST software
::====================================================
:erase_st_flash
tools\st-link.exe -c ID=%~1 -ME
echo.
if errorlevel 0 (
echo [Flash erased on 'Probe %~1']
echo.
exit /b 0
)
echo.
echo [ERROR]
echo [Something went wrong]
echo.
exit /b 0
:: Install ESP software
::====================================================
:install_esp
tools\esptool.exe -p COM%~1 -c esp8266 -b 460800 --before default_reset -a hard_reset write_flash 0x00000 bin\NS-%esp_version%.bin
if errorlevel 0 (
echo.
echo [ESP successfully updated]
echo.
) else (
echo.
echo [ERROR]
echo [Something went wrong]
echo.
)
exit /b 0
:: Erase ESP software
::====================================================
:erase_esp_flash
tools\esptool.exe -p COM%~1 -c esp8266 -b 460800 --before default_reset -a hard_reset erase_flash
if errorlevel 0 (
echo.
echo [ESP successfully updated]
echo.
) else (
echo.
echo [ERROR]
echo [Something went wrong]
echo.
)
exit /b 0
:: Get firmware version
::====================================================
:get_version
for %%F in (bin\%~1*.*) do set filename=%%~nF
if %~1 == NS (
set "%~2=%filename:~-3%"
) else (
set "%~2=%filename:~-8%"
)
exit /b 0
:: Select ESP port
::====================================================
:select_port
echo *** Available COM ports ***
reg query HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM | find "REG_SZ" > %temp%\comlist-temp.txt
for /f "tokens=2,4* delims=\= " %%a in (%temp%\comlist-temp.txt) do echo %%b (%%a)
echo.
set /p "port=Select COM port (1,2,3, etc.) and press 'Enter': "
if "%port%"=="q" (
set "port="
exit /b 11
)
mode COM%port% | find "RTS" > nul
if errorlevel 1 (
set "port="
echo.
echo [ERROR]
echo [COM port not found]
exit /b 10
)
echo.
echo [COM%port% selected]
set %~1=%port%
exit /b 0
:: Select ST programmer drive
::====================================================
:select_drive
echo *** Available drives ***
tools\st-link.exe -List | find "SN" > probes.list
set /a count=0
for /f "tokens=2* delims=: " %%f in (probes.list) do (
echo !count!: ST-Link %%f
set /a count+=1
)
set /a count-=1
echo.
del probes.list
REM wmic logicaldisk get name, volumename
REM echo Q: Return to Main menu
set /p "drive=Select drive (0,1,2, etc.) and press 'Enter': "
if "%drive%"=="q" (
set /a "drive="
exit /b 11
)
if %drive% gtr !count! (
echo.
echo [ERROR]
echo [Probe does not exist]
exit /b 10
)
echo.
echo [Probe %drive% selected]
set /a "%~1=%drive%"
exit /b 0
:: Print info on top of the screen
::====================================================
:update_info
cls
echo *** Nectarsun Software Updater v%version% ***
echo.
echo Board ^| Firmware Version ^| Probe/COM port
echo -------^|------------------^|----------------
if defined mb_drive (
echo Main ^| %mb_version% ^| Probe %mb_drive%
) else (
echo Main ^| %mb_version% ^| N^/A
)
if defined pb_drive (
echo Power ^| %pb_version% ^| Probe %pb_drive%
) else (
echo Power ^| %pb_version% ^| N^/A
)
if defined esp_port (
echo ESP ^| %esp_version% ^| COM%esp_port%
) else (
echo ESP ^| %esp_version% ^| N^/A
)
echo.
exit /b 0
:: End program
::====================================================
:end_program
echo *** Bye bye ^<3 ***
echo.
echo.
exit /b %errorlevel%
::====================================================
endlocal