IMPORTANT: Cypress Developer Community is transitioning on October 20th. To learn more and be prepared for this change, check out our latest announcement.
Showing results for 
Search instead for 
Did you mean: 

Resource Library

How to add TimeStamp into HEX file name in PSoC Creator


How to add TimeStamp into HEX file name in PSoC Creator

Question: To achieve better software version control, can the hex filename generated by PSoC Creator add timestamp automatically?

Answer: Yes. PSoC Creator provides a post-build option in linker config GUI to enable customers to execute customize single linker script command or a bat file that includes multi commands.

For example: add the below linker script command in the post-build text box can make PSoC Creator generate a bin file besides the hex file.

"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"

But add timestamp into hex file needs require multi commands, so a bat file should be used to realize this feature.

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 


Version history
Revision #:
4 of 4
Last update:
‎Aug 25, 2021 08:32 PM
Updated by: