SY8835_For_Demo_Ourself/UsrDoc/HEXBIN.bat

61 lines
2.0 KiB
Batchfile
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

:: @File Name: HEXBIN.bat
:: @Version : 1.0
:: @Author : Alex-XU
:: @Creat Date : 2023-03-30
:: @Brief :
:: 在keil中,生成hex、bin文件到 Out 文件夹中.
:: 复制本文件到keil工程文件所在目录下/Project目录下
:: 在keil 魔法棒USER里填写
:: .\Out.bat $K !P @P
:: $K hextobin转换工具位置 !P 工程名 @P 工程目录
:: .\HEXBIN.bat .\Objects\hex2bin_TP.exe mcu \Objects\
::关闭显示
@echo off
::获取时间
set year=%date:~0,4%
set month=%date:~5,2%
set day=%date:~8,2%
set hour=%time:~0,2%
set min=%time:~3,2%
set sec=%time:~6,2%
::创建输出文件夹 Out
if exist .\..\Out (
echo exist
) else (
mkdir .\..\Out
)
::设置hex2bin_TP.exe位置 ,\Objects\hex2bin_TP.exe
set exe_location=%1
::获取工程名 mcu.hex
set project_name=%2
::设置.hex文件所在目录路径\Objects\
set obj_path=%3
::设置输出后的文件名
set output_name=TP3102_%project_name%_%year%_%month%_%day%_%hour%_%min%_%sec%
::将bin文件生成到HEXBIN文件夹 >nul屏蔽成功命令 .\Objects\hex2bin_TP.exe .\Objects\mcu.hex .\Objects\bin.bin 16 0
%exe_location% .%obj_path%%project_name%.hex .%obj_path%%output_name%.bin 16 0 >nul
::将hex文件重命名
ren .%obj_path%%project_name%.hex %output_name%.hex >nul
ECHO Add CRC16 At the end of the .bin file
ECHO -------------------------------------
SET SREC_PATH=D:\Keil_v5\SREC
for /f %%i in ('dir /s /b .%obj_path%%output_name%.bin') do (
set indexdx=%%~zi
)
ECHO --- size= %indexdx% Byte----
ECHO %SREC_PATH%\srec_cat.exe .%obj_path%%output_name%.bin.bin -Binary -crop 0 %indexdx% -CRC16_Big_Endian %indexdx% -XMODEM -o .%obj_path%%output_name%_crc.bin -Binary
%SREC_PATH%\srec_cat.exe .%obj_path%%output_name%.bin -Binary -crop 0 %indexdx% -CRC16_Big_Endian %indexdx% -XMODEM -o .%obj_path%%output_name%_crc.bin -Binary
::将hex文件复制到HEXBIN文件夹
move .%obj_path%%output_name%.hex .\..\Out >nul
move .%obj_path%%output_name%.bin .\..\Out >nul
move .%obj_path%%output_name%_crc.bin .\..\Out >nul