Generate multiple HEX files with compile time as hard coded as serial number.

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

Hello,

 

I am using Atmel Studio 7 on Windows 10. I'm using __DATE__ and __TIME__ in program memory hard coded to generate serial number.

It takes around 4-5 seconds to rebuild project for each individual HEX file generation. though __TIME__ is updates every second so no repetition issue now.

Is there any way to auto generate HEX files on specific time interval? if yes can it be auto renamed by?

 

PS: i'm not allowed to use random number as serial, and its must be hard coded in firmware.

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

Take a look at srec_cat  http://srecord.sourceforge.net/man/man1/srec_cat.html

 

With the right script it can read in a .hex file, replace certain known offsets with whatever value you want like the host computer's date and time, and write out a new .hex file.  I use it to calculate the program CRC and embed it inside .hex file as a post build script.

Last Edited: Mon. Jul 1, 2019 - 02:23 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Personally I'd use Pre/Post steps probably done in Python. Snapshot the time at the start so it doesn't matter if it "ticks on"later in the build and feed that into the build. Also feed it into a post build step where the generated files are renamed according to the info recorded at the start.

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

Thank You ScottMN and clawson for suggestion.

 

As clawson suggested i modified my project with "serial_number.h" file to store just hardware version detail and serial number, and created a batch script to re-write that file with new serial number based on timestamp. And after rebuilding the project it copies that HEX file and rename it accordingly and saves in destination folder.

 

I attached the batch file as text for sample.

Sorry for late responce.

Attachment(s): 

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

I guess it depends on what languages you are familiar with but I would highly recommend learning a bit of Python for jobs like this in future (doing stuff in Python always seems to feel about 10 times easier than anything else like batch scrips or whatever!)

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

You are right, it depends on the language you are familiar with. And sure, I will keep your recommendation in mind and currently I'm still on learning curve of python. For this task I choose batch script just because it won't require any additional software and runs natively on windows. Also this was the first time I wrote a batch script. :)

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

Pratik Suthar wrote:
I'm using __DATE__ and __TIME__ in program memory hard coded to generate serial number

That seems a strange strategy. What are you going to do for software updates ; put the date & time of the computer back ?

 

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

You have a valid question, it might be problematic to use __DATE__ and __TIME__ when you are planning to provide updates. Though in my case I’m using AVR as a controller for operating relay, firing TRIAC on specific firing angle and it controls all of this over serial communication. for this kind of application, I was only needed to give firmware an info of like how many relays and/or TRIACs are on the board (in this case also serial number to communication API for hardware differentiator). This is a base part of the hardware, on secondary part it is serial to Bluetooth/ZigBee/WiFi/Ethernet gateway card and those cards are modular with base hardware. So, I need some info in base hardware to further identify if same hardware is connected through different protocol. and I’m giving updates to only those secondary (communication gateway) cars which leads to single updates for all type of hardware and reduces the complication afterwards.

 

First, I planned to use chip-id for this purpose but I ended up with date time method to gain more control over number and it also represents sort-of manufacturing time. (I'm not sure if AVR (Mega) have chip-id)

The attachment I attached in previous comment also provides option to enter serial manually for new HEX file generation. If project is on single microcontroller based and also further planning to give updates then you are right this is not the best way. Thanks.

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

Pratik Suthar wrote:
it might be problematic to use __DATE__ and __TIME__ when you are planning to provide updates.

 

If the chip is updated via a bootloader, then you could reserve the flash page just below the bootloader for the serial number, and

modify the bootloader not to touch that page.  The serial number would be programmed by ISP and would survive any updates.