@echo off setlocal set PROJ=%~dp0STM32F407-Demo.uvprojx set LOG=%~dp0download_log.txt set TARGET=STM32F407-Demo :: UV4 location: env var DTU_KEIL_UV4 = full path of UV4.exe (same contract :: as build.bat; required, no machine-default fallback). if defined DTU_KEIL_UV4 goto uv4_set echo DOWNLOAD_FAIL: environment variable DTU_KEIL_UV4 is not set echo Set it to the full path of UV4.exe, e.g.: echo [Environment]::SetEnvironmentVariable('DTU_KEIL_UV4', 'D:\Tools\Keil\UV4\UV4.exe', 'User') exit /b 2 :uv4_set if exist "%DTU_KEIL_UV4%" goto uv4_ok echo ENV_ERROR: DTU_KEIL_UV4 is set but does not exist: "%DTU_KEIL_UV4%" echo Fix the variable value. No fallback to another UV4 install is attempted. exit /b 2 :uv4_ok set UV4=%DTU_KEIL_UV4% :: Remove stale log first: UV4 -o writes the log only when a download actually :: runs. A leftover log would otherwise be misreported as this download's :: result (same guard as build.bat). if exist "%LOG%" del "%LOG%" "%UV4%" -f "%PROJ%" -t%TARGET% -j0 -o "%LOG%" if not exist "%LOG%" ( echo DOWNLOAD_FAIL: no download log produced - UV4 did not run or hung exit /b 1 ) findstr /C:"Application running" "%LOG%" >nul if %ERRORLEVEL% equ 0 ( echo DOWNLOAD_OK: flashed and running exit /b 0 ) echo DOWNLOAD_FAIL: no application-running marker in log type "%LOG%" exit /b 1