adding time/date to the program in product line (as a device ID)

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi everyone, 

 

I've designed an ATMega32 based device and we are going to launch the new device and establish the product line. I want to design a method to make a specific ID for the device that indicates it's time and date of production.

the simplest method is to insert time and date of device production into the flash memory of the microcontroller, but how? I know that I can use the macros "__date__" and "__time__" for defining the compile time/date but it only indicates the compile time rather than the program time (which indicates the time of manufacturing).

It is possible to build a specific programmer with the internal RTC but we don't have much time for it... . I'd rather do it simply by debugging on Atmel studo (by pressing F5), but unfortunately by pressing F5, it only send the pre-compiled program into the microcontroller and no compile process happens (so time and date is outdated).

 

any advice?

 

Amin

This topic has a solution.
Last Edited: Tue. Feb 12, 2019 - 12:23 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You could add a pre-build event to the project in AS7 that does something like "touch" on the source file where __DATE__ and __TIME__ are used. The make system will then see the source as "edited" so will force a rebuild when you start debugging.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The fastest way to production would be to force a re-compile before every programming cycle to update __time__

 

Another way, if you use external programming software is to add a string in flash with random data in your source code.

With a few lines of Python or any other script language you can than simply do a search and replace for that "random string" in the binary image or intel hex file.

The string should have a reasonable lengt to ensure it would not occur anywhere else in the code (30 bytes of randomness will do).

 

I do find it kind of strange if you're using atmel studio in a production environment.

There are programmers available ( < EUR 200) for  production environments, which are stand-alone (no PC needed) and can also insert dates and serial numbers.

 

If you tell us what programmer hardware you yave then someone here might know a command line utility that works wit it and is fit for scripting.

 

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm using atmel ISP MKII programmer. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

you mean something like running a bat file that rewrites the main.c file?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

someone here might know a command line utility

It is possible to add stuff to the hex, bin or even elf files without needing a recompile, using only the command line tools installed with AS7. This way you could have a script that adds the info you need and invokes atprogram or avrdude or whatever to do the actual programming.

 

Last year I did a proof of concept of a script that read some data from a barcode scanner and added it to an elf file, which was then programmed to the AVR. I don't have the details now, but --update-section was the key flag. I think I used this blog post by an Atmel Studio developer for inspiration.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

makhorsandi wrote:
you mean something like running a bat file that rewrites the main.c file?
Yes, that's the idea. There is a common utility called "touch" and I'm sure there must be a Windows build of it. You use "touch main.c" and it effectively does a no-change edit on the file simply so that it's "last modified" time is incremented. Later "make" will now see that file as "changed" (simply because it compares the last modified time of the .c to the .o) so that will trigger it to rebuild. 

 

I just googled and found, for example: https://sourceforge.net/projects...

 

Then in a pre-build event you'd simply add that "touch main.c" (or whatever the file is called) and now the build will always rebuild because at least one file (main.c) will appear to be edited.

 

EDIT: another way to get "touch" (and loads of other useful utilities): http://gnuwin32.sourceforge.net/...

 

(I think AS7 itself may bundle some of these)

 

EDIT2: I was right, AS7 does provide touch:

 

C:\program files (x86)\Atmel\Studio\7.0\shellUtils\touch.exe

 

In fact a number of useful things there:

 Directory of C:\Program Files (x86)\Atmel\Studio\7.0\shellutils

24/09/2018  11:57    <DIR>          .
24/09/2018  11:57    <DIR>          ..
22/06/2018  13:22            29,568 basename.exe
22/06/2018  13:22            68,480 cat.exe
22/06/2018  13:22            89,984 chgrp.exe
22/06/2018  13:22            87,936 chmod.exe
22/06/2018  13:22            92,032 chown.exe
22/06/2018  13:22            30,592 chroot.exe
22/06/2018  13:22            31,616 cksum.exe
22/06/2018  13:22            32,128 comm.exe
22/06/2018  13:22           136,064 cp.exe
22/06/2018  13:22            82,304 csplit.exe
22/06/2018  13:22            44,928 cut.exe
22/06/2018  13:22           134,528 date.exe
22/06/2018  13:22            93,568 dd.exe
22/06/2018  13:22            87,936 df.exe
22/06/2018  13:22           186,752 dir.exe
22/06/2018  13:22            36,736 dircolors.exe
22/06/2018  13:22            30,080 dirname.exe
22/06/2018  13:22           114,560 du.exe
22/06/2018  13:22            31,104 echo.exe
22/06/2018  13:22            30,080 env.exe
22/06/2018  13:22            33,664 expand.exe
22/06/2018  13:22            68,480 expr.exe
22/06/2018  13:22            37,248 factor.exe
22/06/2018  13:22            23,936 false.exe
22/06/2018  13:22            36,736 fmt.exe
22/06/2018  13:22            32,640 fold.exe
22/06/2018  13:22           134,528 gdate.exe
22/06/2018  13:22            31,104 gecho.exe
22/06/2018  13:22           141,184 ginstall.exe
22/06/2018  13:22           108,416 gln.exe
22/06/2018  13:22            75,136 gmkdir.exe
22/06/2018  13:22            31,104 grmdir.exe
22/06/2018  13:20             2,015 groups
22/06/2018  13:22           102,272 gsort.exe
22/06/2018  13:22            79,232 head.exe
22/06/2018  13:22            31,616 hostid.exe
22/06/2018  13:22            29,568 hostname.exe
22/06/2018  13:22            34,176 id.exe
22/06/2018  13:22           141,184 install.exe
22/06/2018  13:22            46,464 join.exe
22/06/2018  13:22            34,688 kill.exe
22/06/2018  13:22           904,064 libiconv2.dll
22/06/2018  13:22           109,440 libintl3.dll
22/06/2018  13:22            37,760 link.exe
22/06/2018  13:22           108,416 ln.exe
22/06/2018  13:22            30,080 logname.exe
22/06/2018  13:22           186,752 ls.exe
22/06/2018  13:22           331,136 make.exe
22/06/2018  13:22            48,000 md5sum.exe
22/06/2018  13:22            75,136 mkdir.exe
22/06/2018  13:22            67,456 mkfifo.exe
22/06/2018  13:22            73,600 mknod.exe
22/06/2018  13:22           144,768 mv.exe
22/06/2018  13:22            32,128 nice.exe
22/06/2018  13:22            72,064 nl.exe
22/06/2018  13:22            34,176 nohup.exe
22/06/2018  13:22            92,032 od.exe
22/06/2018  13:22            32,128 paste.exe
22/06/2018  13:22            64,896 pathchk.exe
22/06/2018  13:22            75,136 pinky.exe
22/06/2018  13:22           127,360 pr.exe
22/06/2018  13:22            29,056 printenv.exe
22/06/2018  13:22            51,072 printf.exe
22/06/2018  13:22           117,120 ptx.exe
22/06/2018  13:22            67,456 pwd.exe
22/06/2018  13:22            66,432 readlink.exe
22/06/2018  13:22           115,072 rm.exe
22/06/2018  13:22            31,104 rmdir.exe
22/06/2018  13:22            32,640 seq.exe
22/06/2018  13:22            31,616 setuidgid.exe
22/06/2018  13:22            48,000 sha1sum.exe
22/06/2018  13:22            93,056 shred.exe
22/06/2018  13:22            33,664 sleep.exe
22/06/2018  13:22           102,272 sort.exe
22/06/2018  13:22            78,208 split.exe
22/06/2018  13:22         1,447,824 srec_cat.exe
22/06/2018  13:22            81,792 stat.exe
22/06/2018  13:22            55,680 stty.exe
22/06/2018  13:22            84,352 su.exe
22/06/2018  13:22            42,368 sum.exe
22/06/2018  13:22            29,056 sync.exe
22/06/2018  13:22            98,176 tac.exe
22/06/2018  13:22            94,080 tail.exe
22/06/2018  13:22            30,592 tee.exe
22/06/2018  13:22            68,992 test.exe
22/06/2018  13:22            84,864 touch.exe
22/06/2018  13:22            49,024 tr.exe
22/06/2018  13:23            23,936 true.exe
22/06/2018  13:23            32,640 tsort.exe
22/06/2018  13:23            29,568 tty.exe
22/06/2018  13:23            39,808 uname.exe
22/06/2018  13:23            34,688 unexpand.exe
22/06/2018  13:23            38,784 uniq.exe
22/06/2018  13:23            30,592 unlink.exe
22/06/2018  13:23            38,272 uptime.exe
22/06/2018  13:23            41,344 users.exe
22/06/2018  13:23           186,752 vdir.exe
22/06/2018  13:23           106,368 wc.exe
22/06/2018  13:23            79,232 who.exe
22/06/2018  13:23            30,592 whoami.exe
22/06/2018  13:23            29,056 yes.exe
22/06/2018  13:23            75,136 [.exe
             102 File(s)      9,253,231 bytes

 

Last Edited: Wed. Feb 6, 2019 - 11:24 AM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yesss. it's the solution. I've added this command in prebuild event command line:

 

start "" "$(DevEnvDir)\shellutils\touch.exe" "$(MSBuildProjectDirectory)\main.c"

it works properly. The file "touch.exe" is running with the parameter "main.c".