Versioning the embedded software

General discussions about working with the Astrobe IDE and programming ARM Cortex-M0, M3, M4 and M7 microcontrollers.
Post Reply
bscholte
Posts: 19
Joined: Sat Jan 24, 2015 6:15 pm
Location: Austria
Contact:

Versioning the embedded software

Post by bscholte » Tue Mar 30, 2021 7:39 pm

If you have many embedded systems in the field, keeping track of the installed software is a real problem. It would be much easier to store the software version inside the embedded code and output this when needed. In our case, our embedded systems send status reports to their hosts and they add the software revision code to each report. We use a resource addition to the Main or some other module which holds the version info. To get this done, the approach is as follows:
  • Make a small program to create a unique revision Nr. This can be a counter, but we simply use a simple "Binarized" Timestamp. This does not only give a small and unique number, it also allows to backtrack the version date and time. This small command line program was written in Delphi and the important bits look like:

    Code: Select all

    program SetRev;
    {$APPTYPE CONSOLE}
    {$R *.res}
    uses
      System.SysUtils, System.Classes;
    var
      FileName:String;
      ResFile:tFileStream;
      Data:array[0..1] of integer;
      Bin:ARRAY[0..7] of byte;
    begin
      try
        if ParamCount=1 then
          begin
            FileName:=ChangeFileExt(ParamStr(1), '.res');
            ResFile:=tFileStream.Create(FileName, fmCreate or fmOpenWrite or fmShareExclusive);
            Data[0]:=DateToInt(Now); //This procedure translates the current date into an integer. We use the same format as the LPC1769 uses.
            Data[1]:=TimeToInt(Now); //This procedure translates the current time into an integer. Again, the same format as the LPC1769 uses.
            //any other unique number generator (e.g. like Delphi built-in UUID's) would be fine too. Just keep an eye on the length of the ID
            System.Move(Data, Bin, 8);
            ResFile.WriteData(Bin, Length(Bin));
            ResFile.Free;
            Writeln('New Revision Data Written to '+FileName);
          end
         else Halt(1);
      except
        on E: Exception do
          Writeln(E.ClassName, ': ', E.Message);
      end;
    end.
  • Install this program in the Astrobe Folder.
  • Now select a module to add the RES to and add the following lines to the "Tools.ini" File (assuming that "MYAPP.mod" is your file to hold the version):

    Code: Select all

    [Command5]
    MenuItem=Set APP &Revision
    Path=C:\Program Files (x86)\AstrobeM3 Professional Edition\SetRev.exe
    Parameters="MYAPP.mod"
    WorkingFolder=%FileDir%
    ConsoleApp=TRUE
    Prompt=FALSE
  • To read the firmware revision code as bytes, add into MYAPP.mod

    Code: Select all

    PROCEDURE GetFirmware*(VAR FW:ARRAY OF BYTE);
    VAR Res:ResData.Resource;
        I:INTEGER;
    BEGIN
      ResData.Open(Res, "MYAPP");
      IF ResData.Size(Res) = 8 THEN FOR I:=0 TO 7 DO ResData.GetByte(Res, I, FW[I]) END
                               ELSE FOR I:=0 TO 7 DO FW[I]:=0 END
                               END;
    END GetFirmware;
  • This proc can be easily modified to get back the original two integers of even the timestamp
Once the app is ready to get distributed, click "Set APP Revision" from the tools Menu in the IDE. Then build the APP. Your APP will now output the stored revision code whenever needed. Since it is inside the Firmware as resource, it only gets changed when the firmware is updated.

Hope this is useful....................
(PS. Drop a line if you would need the SetRev.exe)

Post Reply