mothercup/tools/flash_package.bat

46 lines
1.9 KiB
Batchfile

@echo off
rem ============================================================
rem flash_package.bat [image] - erase the chip and program the
rem merged package via NS-LINK (NSpyocd).
rem [image] optional, default: tools\out\caiic_full.hex
rem Connect NS-LINK to SWD (PA4/PA5) and the reset pin first,
rem and CLOSE Keil (it holds the probe).
rem ============================================================
setlocal
set ROOT=%~dp0..
set PYOCD="%ROOT%\nations-tec\N32WB03x_SDK_V2.0.0\utilities\dfu\NSpyocd\NSpyocd.exe"
rem The builtin "n32wb031" target only maps 256KB of flash (fails at
rem 0x01040000 on the dual-bank package); the DFP pack target
rem "n32wb031keq6_2" maps the full 512KB of the KEQ6-2 we actually use.
set PACK="%ROOT%\nations-tec\N32WB03x_DFP.1.4.0.pack"
set TARGET=n32wb031keq6_2
set IMAGE=%~1
if "%IMAGE%"=="" set IMAGE=out\caiic_full.hex
if not "%IMAGE:~0,1%"=="\" if not "%IMAGE:~1,1%"==":" set IMAGE=%~dp0%IMAGE%
if not exist "%IMAGE%" (
echo %IMAGE% not found - run tools\make_package.bat first
exit /b 1
)
rem -M under-reset: connect while holding the chip in reset
rem -f 1000000: 1 MHz SWD clock (slow but tolerant of wiring)
echo Erasing chip...
%PYOCD% erase --chip --pack %PACK% -M under-reset -f 1000000 -t %TARGET% || goto :fail
echo Programming %IMAGE% ...
rem -O smart_flash=false: with the pack target the pre-program diff pass
rem faults reading 0x01000000; programming+verify itself is fine.
%PYOCD% load --pack %PACK% -M under-reset -f 1000000 -t %TARGET% -O smart_flash=false "%IMAGE%" || goto :fail
echo Program Finish!
goto :eof
:fail
echo.
echo *** FLASH FAILED ***
echo Troubleshooting:
echo 1. Close Keil / any tool holding the probe, replug NS-LINK USB
echo 2. List probes: %PYOCD% list
echo 3. Check wiring: SWDIO=PA5 SWCLK=PA4 GND and the RESET pin
echo 4. If several probes are attached, add -u ^<probe_uid^> to the commands above
exit /b 1