打印
[PSoC™]

怎么在psoc creator hex文件中添加时间戳

[复制链接]
366|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
本帖最后由 IFX_Lingling 于 2024-2-22 08:59 编辑

Question:
为了实现更好的软件版本控制,PSoC Creator 生成的十六进制文件名能否自动添加时间戳?

Answer:
是的。PSoC Creator 在链接器配置图形用户界面中提供了一个编译后选项,使客户能够执行自定义的单个链接器脚本命令或包含多个命令的 bat 文件。
例如:在编译后文本框中添加以下链接器脚本命令,可使 PSoC Creator 除生成十六进制文件外,还生成一个 bin 文件。

"C:\Program Files (x86)\Cypress\PSoC Creator\4.4\PSoC Creator\import\gnu\arm\5.4.1\bin\arm-none-eabi-objcopy" -S -O binary ".\CortexM0p\ARM_GCC_541\Debug\Design01.elf" ".\CortexM0p\ARM_GCC_541\Debug\Design01.bin"

但在十六进制文件中添加时间戳需要多个命令,因此应使用 bat 文件来实现这一功能。

Step1: Create a text file named HexTimeStamp and save it as a bat file.

Step2: Add command "..\HexTimeStamp.bat" ${OutputDir} ${ProjectShortName} in post build text.

Step3: Add below script  in bat file.
:: Post-build command "..\HexTimeStamp.bat" ${OutputDir} ${ProjectShortName}, bat file must be placed in the same path (deep level) as project .cydsn folder
:: ${OutputDir} = %1,the path of hex file locate at
:: ${ProjectShortName} = %2, the name of project and hex file
:: Print date and time value, like Wed 08/25/2021_13:38:44.32
echo %date%_%time%
:: relocate path to where hex file locate at, like \CortexM4\ARM_GCC_541\Debug\
cd %1
::echo off
:: format month+day data, 08/25 --> 0825
set date_num1=%date:~4,5%
set date_num1=%date_num1:-=%
set date_num1=%date_num1:/=%
:: format year data, /2021 --> 2021
set date_num2=%date:~9,5%
set date_num2=%date_num2:-=%
set date_num2=%date_num2:/=%
:: format hours:minute:second data, 13:38:44 --> 133844
:: if first value is 0, add zero in the left side. 3:38:44 -->033844
set time_num=%time:~0,8%
set time_num=%time_num::=%
if "%time_num:~0,1%"==" " set "time_num=0%time_num:~1%"
echo on
echo "Insent time stamp in hex file's name >>"
:: combine into final time stamp value and add into hex file name
:: .\Hex_TimeStamp.hex .\Hex_TimeStamp_20210825_133844.hex
copy .\%2.hex .\%2_%date_num2%%date_num1%_%time_num%.hex
Step4: Build project multi times, you can find timestamp is added into hex file name.

PSoC Creator Build log for bat file:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: ..\HexTimeStamp.bat Hex_TimeStamp
:: ..\Hex_TimeStamp.cydsn>echo Wed 08/25/2021_13:38:44.32
:: ..\Hex_TimeStamp.cydsn>cd .\CortexM4\ARM_GCC_541\Debug\
:: ..\Hex_TimeStamp.cydsn\CortexM4\ARM_GCC_541\Debug>set date_num1=08/25
:: ..\Hex_TimeStamp.cydsn\CortexM4\ARM_GCC_541\Debug>set date_num1=08/25
:: ..\Hex_TimeStamp.cydsn\CortexM4\ARM_GCC_541\Debug>set date_num1=0825
:: ..\Hex_TimeStamp.cydsn\CortexM4\ARM_GCC_541\Debug>set date_num2=/2021
:: ..\Hex_TimeStamp.cydsn\CortexM4\ARM_GCC_541\Debug>set date_num2=/2021
:: ..\Hex_TimeStamp.cydsn\CortexM4\ARM_GCC_541\Debug>set date_num2=2021
:: ..\Hex_TimeStamp.cydsn\CortexM4\ARM_GCC_541\Debug>set time_num=13:38:44
:: ..\Hex_TimeStamp.cydsn\CortexM4\ARM_GCC_541\Debug>set time_num=133844
:: ..\Hex_TimeStamp.cydsn\CortexM4\ARM_GCC_541\Debug>if "1" == " " set "time_num=033844"
:: ..\Hex_TimeStamp.cydsn\CortexM4\ARM_GCC_541\Debug>echo on
:: ..\Hex_TimeStamp.cydsn\CortexM4\ARM_GCC_541\Debug>echo "Insent time stamp in hex file's name >>"
:: ..\Hex_TimeStamp.cydsn\CortexM4\ARM_GCC_541\Debug>copy .\Hex_TimeStamp.hex .\Hex_TimeStamp_20210825_133844.hex
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

内容转自:https://community.infineon.com/t5/Knowledge-Base-Articles/How-to-add-TimeStamp-into-HEX-file-name-in-PSoC-Creator/ta-p/286566



使用特权

评论回复
沙发
EmmaTT| | 2024-2-28 19:00 | 只看该作者
能不能生成汇编文件啊

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

认证:
简介:关于英飞凌——我们致力于打造一个更加便利、安全和环保的世界,在赢得自身成功发展的同时,积极践行企业社会责任。

105

主题

189

帖子

5

粉丝