9. Serialization

9. Serialization

9.1 Introduction


The programmer has the ability to automatically program the target device's serial number (SN) and save it in flash memory. New SNs can be created automatically by incrementing a starting base SN, or can be taken from a file created by the user. SNs that have been used are stored in separate data files to account for devices that have already been programmed. In addition to this SN, the model name, group, and revision number can also be programmed to the target device. The user can specify the display SN format and location in flash memory where this information will be stored.
The SN is programmed when "Auto Program" or "Write SN/Model" buttons are pressed and the SN feature is enabled. When the "Auto Program" function is activated the SN is programmed to the target's device memory after code data has been programmed. If "Auto Program" fails for any reason then the new SN is neither created nor programmed to the device. In the case of Gang programming, as many SNs will be used up as there are successfully programmed devices. If there are not enough SNs left to program all devices in the Gang programmer then an error will appear, and the procedure will abort resulting in no devices being serialized.
The software also allows the microcontroller to retain its SN if one has already been assigned to it. Every time a device is programmed and serialization is enabled the contents of the target's memory are scanned for an existing SN. If the SN is found at the specified location the message in Figure 9.1 will appear and allow the user to decide to keep the old SN, program a new SN from the list, or program a SN typed manually.

Figure 9.1: If an MCU already contains serialization information at a specified location then a conflict window will appear giving the user the option to retain the old serial number, or program in a new one.

The Serialization Dialog screen, shown in Figure 9.2, allows the user to configure how serialization is done. Serialization can be enabled, or disabled, by selecting the check mark in the ENABLE Serialization check-box. When serialization is disabled all edit lines and check boxes are disabled. When serialization is enabled, most fields have to be set to ensure that the result will be as the user expects. The necessary fields include:

  • Display Format - The display format describes the meaning of the characters that comprise the SN.

  • Memory Format - The memory format describes how the SN will be stored in the device's flash memory.

  • Memory Location - This address is the memory location reserved for the SN. It can only overlap code regions if the Remove code contents in the location where the serialization and model are defined check-box is also selected.

  • Starting Number and Increment - When using all display formats except "Custom" and "from File", these parameters are necessary. The starting number will indicate the value of the first SN created. Subsequent SNs will be determined by adding the increment to the current SN number. Both of these parameters can only be positive integers and create SNs that remain within the maximum range described later in this chapter.

  • Output File - The specified file will store all successfully programmed SNs. The output file is very important not only for logging purposes, but also for restoring state across programming sessions. The output file is used to retrieve the last SN programmed and set the next SN to be programmed when restoring the programming session. If the output file is deleted, or another blank file is selected, the Serialization process will essentially reset to the beginning, and the first SN will be programmed at the next iteration.


The serialization dialog screen also contains several useful optional features:

  • Model/Group/Revision - In addition to the aforementioned SN formats, the software also allows the user to program each device with separate HEX or ASCII data. This information is saved at a different memory location from the SN, and does not change after each programming cycle. This is used to program static information that should be the same for each target device, like the software revision number, model, etc.

  • BarCode Scanner - The BarCode Scanner can be used as an input mechanism for new SNs. When enabled, scanning a barcode will set the “Next SN" shown in Figure 9.1 to the value read by the BarCode Scanner. For convenience, the software can be configured to start the “Auto Program" procedure immediately after the BarCode Scanner reads a new number, by selecting the Start AUTOPROGRAM following BarCode scan check-box.

 

Figure 9.2: Serialization options can be selected here.

9.2 Serial Number Display Format


Programming software has eight formats for writing a serial number, referred to as Display Format, and three methods of storing the SN in memory, referred to as In Memory Format in the serialization dialog screen. When a serial number is created, the current date (if required) is taken from the PC timer, therefore ensure that your computer has the correct date and time.
Display Formats:

  1. YYYY-1234(5) - (SN Format F0) Serial number has 8 or 9 characters depending on other settings. First four characters specify the year, and the remaining 4 or 5 characters specify the serial number up to a maximum of:

    1. 9999 - when BCD memory format is selected, or if Ascii format with Decimal radix is selected (i.e. 20039999).

    2. 0xFFFF (65535) - when HEX memory format is selected, or if Ascii format with Hex radix is selected (i.e. 200365535, 2003aab0).

  2. YYMM-1234(5) - (SN Format F1) Serial number has 8 or 9 characters depending on other settings. First two characters specify the last two digits of the year, next two characters specify the month, and the remaining 4 or 5 characters specify the serial number up to a maximum of:

    1. 9999 - when BCD memory format is selected, or if Ascii format with Decimal radix is selected (i.e. 03059999).

    2. 0xFFFF (65535) - when HEX memory format is selected, or if Ascii format with Hex radix is selected (i.e. 030565535, or 0305aab0).

  3. YYMMDD-1234 - (SN Format F5) Serial number has 10 characters. First six characters contain date (year, month, day of month) and remaining 4 characters specify the serial number up to 9999, e.g. 1205309999.

  4. YYDDD-1234(5) - (SN Format F4) Serial number has 9 or 10 characters depending on other settings. First five characters specify the year, day of the year from 1 to 366, and remaining 4 or 5 characters specify the serial number up to a maximum of:

    1. 9999 - when BCD memory format is selected, or if Ascii format with Decimal radix is selected (i.e. 123559999).

    2. 0xFFFF (65535) - when HEX memory format is selected, or if Ascii format with Hex radix is selected (i.e. 1235565535, 12355ffff).

  5. 12345678 - (SN Format F2) Serial number has 8 digits. The maximum value is:

    1. 99999999 - when BCD memory format is selected, or if Ascii format with Decimal radix is selected.

    2. 0xFFFFFFFF - when HEX memory format is selected, or if Ascii format with Hex radix is selected.

  6. 1234(5) - (SN Format F3) Serial number has 4 or 5 characters depending on other settings. . The 4 or 5 characters specify the serial number up to a maximum of 9999 or 65535.

    1. 9999 - when BCD memory format is selected, or if Ascii format with Decimal radix is selected (i.e. 9999).

    2. 0xFFFF (65535) - when HEX memory format is selected, or if Ascii format with Hex radix is selected (i.e. 65535, or aab0).

  7. Custom - (SN Format F6) 4 to 256 ASCII characters or hexadecimal numbers entered manually or from the Bar-Code Reader.

  8. from File - (SN Format F7) 4 to 256 ASCII characters or hexadecimal numbers taken from a user created file.


For SN display formats 1 to 6 above (logfile format F0 through F5), the non-date components can be entered using either decimal or hexadecimal notation. Normally only characters from 0 to 9 will be accepted unless a "0x" prefix is added informing the software that a hexadecimal number is begin entered, allowing the user to use A to F as well. All characters are subsequently converted to a chosen memory format, which can be HEX, BCD or ASCII, before they are saved to flash memory.
When a "Custom" (F6) or “from File" (F7) SN display format is selected then all characters can be accepted depending on the memory format chosen. Specifically, when the ASCII format is selected the SN can be comprised of any characters and is saved using 8-bits per character into flash memory. Conversely, when the HEX format is selected the SN can only be comprised of HEX characters (0...9,A...F) and is saved using 4-bits per character.

9.3 Serial Number Memory Format


This section describes the different formats in which serial numbers can be stored in flash memory. These numbers can be stored using various types of byte-ordering schemes including:

  1. Most-Significant-Byte (MSB) first - The most significant byte, in a number composed of multiple bytes, is the byte that represents the greatest value 8-bit sub-component of that number. For example, the number 0x12345678 is composed of 4 bytes: 0x12, 0x34, 0x56, and 0x78, where 0x12 is the most significant byte. When this 4 byte number is stored in memory using MSB first ordering, then the lowest byte address (the first address) will store the most significant byte (0x12). Addr: 0x0, Content: 0x12 Addr: 0x1, Content: 0x34 Addr: 0x2, Content: 0x56 Addr: 0x3, Content: 0x78

  2. Most-Significant-Word (MSW) first - The most significant word, in a number composed of multiple words, is the word that represents the greatest value 16-bit sub-component of that number. For example, the number 0x12345678 is composed of 2 words: 0x1234, and 0x5678, where 0x1234 is the most significant word. When this 2 word number is stored in memory using MSW first ordering, then the lowest word address (the first address) will store the most significant word (0x1234). Addr: 0x0, Content: 0x1234 Addr: 0x2, Content: 0x5678

  3. Least-Significant-Byte (LSB) first - The least significant byte, in a number composed of multiple bytes, is the byte that represents the smallest value 8-bit sub-component of that number. For example, the number 0x12345678 is composed of 4 bytes: 0x12, 0x34, 0x56, and 0x78, where 0x78 is the least significant byte. When this 4 byte number is stored in memory using LSB first ordering, then the lowest byte address (the first address) will store the least significant byte (0x78). Addr: 0x0, Content: 0x78 Addr: 0x1, Content: 0x56 Addr: 0x2, Content: 0x34 Addr: 0x3, Content: 0x12

  4. Least-Significant-Word (LSW) first - The least significant word, in a number composed of multiple words, is the word that represents the smallest value 16-bit sub-component of that number. For example, the number 0x12345678 is composed of 2 words: 0x1234, and x5678, where 0x5678 is the least significant word. When this 2 word number is stored in memory using LSW first ordering, then the lowest word address (the first address) will store the least significant word (0x5678).

Addr: 0x0, Content: 0x5678
Addr: 0x2, Content: 0x1234

Figure 9.3: This window will appear when there is a conflict between memory allocated to code and the SN. To avoid this pop-up, select the option to "Remove code contents in the location where the serialization and model are defined" in Figure 9.2.
The location in the target device's flash memory where the SN will be stored is specified in the \Memory Location - SN Start Address in Memory" field of the serialization dialog screen (see Figure 9.3). Specified address must be even and should be specified in empty memory space, not used by program code or data block. However, if you'd like to integrate the SN with existing code, by programming the SN to a code location, then check the box Remove code contents in the location where the serialization and model are defined .
The SN memory formats will be described in the following subsections.

9.3.1 HEX Memory Format


When this format is selected the serial number is encoded using hexadecimal (HEX) notation. In general, each sub-component of the SN written in base 10 is converted to an equivalent base 16 number. The number of bytes used varies depending on the display format (F0, F1, F2, F4, and F5 - 4 bytes; F3 - 2 bytes; F6, and F7 - between 2 to 128 bytes).
Display Format: YYYY-12345 - size in FLASH - 4 bytes
Can be stored using MSW, and LSW/LSB byte-ordering.
SN: 200300123 will be encoded as:
YYYY: 2003 = 0x07D3 (HEX)
12345: 00123 = 0x007B (HEX)
and combined into one 32-bit HEX number: 0x07D3007B
<-- Addr-->
00-01-02-03
D3 07 7B 00 -> HEX(MSW first)
7B 00 D3 07 -> HEX(LSW/LSB first)
Display Format: YYMM-12345 - size in FLASH - 4 bytes
Can be stored using MSW, and LSW/LSB byte-ordering.
SN: 030300123 will be encoded as:
YYMM: 0303 = 0x012F (HEX)
12345: 00123 = 0x007B (HEX)
and combined into one 32-bit HEX number: 0x012F007B
<-- Addr-->
00-01-02-03
2F 01 7B 00 -> HEX(MSW first)
7B 00 2F 01 -> HEX(LSW/LSB first)
Display Format: YYMMDD-1234 - size in FLASH - 4 bytes
Can be stored using MSW, and LSW/LSB byte-ordering.
The date component is compressed to fit into only two bytes as
follows: