Skip to content

Commit 64307d2

Browse files
committed
Add Windows wrapper for GD32 flashing
Add a `flash.cmd` helper for Windows that locates Python 3, creates a dedicated virtual environment if needed, installs `pyserial` on demand, and then runs `flash.py`. This makes the GD32 flashing workflow easier to run on Windows without manual environment setup.
1 parent 90af25d commit 64307d2

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

common/scripts/gd32/flash.cmd

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
@echo off
2+
setlocal EnableExtensions
3+
4+
rem Directory containing this .cmd file
5+
set "DIR=%~dp0"
6+
7+
rem Prefer the Windows Python launcher, then fall back to python.exe
8+
set "PYTHON_CMD="
9+
where py >nul 2>&1
10+
if not errorlevel 1 (
11+
set "PYTHON_CMD=py -3"
12+
) else (
13+
where python >nul 2>&1
14+
if not errorlevel 1 set "PYTHON_CMD=python"
15+
)
16+
17+
if not defined PYTHON_CMD (
18+
echo ERROR: No Python 3 installation found. 1>&2
19+
exit /b 1
20+
)
21+
22+
set "VENV=%USERPROFILE%\venvs\gd32-common"
23+
set "PY=%VENV%\Scripts\python.exe"
24+
25+
if not exist "%PY%" (
26+
echo Creating virtual environment: %VENV%
27+
%PYTHON_CMD% -m venv "%VENV%"
28+
if errorlevel 1 (
29+
echo ERROR: Failed to create virtual environment. 1>&2
30+
exit /b 1
31+
)
32+
)
33+
34+
rem Install pyserial only when it is missing.
35+
"%PY%" -c "import serial" >nul 2>&1
36+
if errorlevel 1 (
37+
echo Installing pyserial...
38+
"%PY%" -m pip install -U pip
39+
if errorlevel 1 exit /b 1
40+
41+
"%PY%" -m pip install -U pyserial
42+
if errorlevel 1 exit /b 1
43+
)
44+
45+
rem Final dependency check.
46+
"%PY%" -c "import serial; print('PySerial OK')"
47+
if errorlevel 1 (
48+
echo ERROR: PySerial is not working. 1>&2
49+
exit /b 1
50+
)
51+
52+
"%PY%" "%DIR%flash.py" %*
53+
set "RC=%ERRORLEVEL%"
54+
55+
endlocal & exit /b %RC%

0 commit comments

Comments
 (0)