It is common practice to give appliances a unique serial or identification number.
This serial number is located in the external memory of the device, for example in EEPROM,
but it can also be programmed with the MCU software, inside the MCU program memory
array.
In some cases, the serial number should remain secret and unreadable to external devices.
In other cases, it should be readable from the MCU by a remote PC through any interface
specified by the manufacturer (for example, SCI).
This application note provides technical details on the software and tools associated with
implementing a serial numbering technique. Some hints have been taken from the on-line
help of the STVP7 visual programming software tool.
C language examples are provided which are ready to be added to the source code if
compiled with a Metrowerks C compiler (such as old Hiware, Panta or Codewarrior). The
examples provide may also be ported to other C compilers.
The examples can be applied to any ST7 microcontrollers which is equipped with non
volatile memory.
August 2007 Rev 11/12
www.st.com
Serial number encoding techniquesAN2614
1 Serial number encoding techniques
A serial number can be composed of any numberof letters and/or digits. A common serial
number encoding technique is to encode the serial number as a string of ASCII characters,
as shown in Ta bl e 1 .
The numbers can also be combined in pairs, to form more concise 2-digit characters as
shown in Ta bl e 2 .
Table 2.Serial numbering in pairs
Serial number0 1 2 3 4 5 6 7
Corresponding numbers (hexa)01h 23h 45h 67h
Other encoding techniques are possible.
Such ‘encryption’ can be used so that only authorized people can decode the serial number.
2/12
AN2614Embedding the serial number
2 Embedding the serial number
The serial number may need to be:
1.Embedded in the MCU, or stored in external memory (such as EEPROM)
2. Read from the MCU by an external device (for example, through an SCI interface)
3. Protected against read-out
4. Programmed at production level or updated just before shipment
Embedding the serial number inside the MCU software meetsall the above requirements.
This is especially true for the ST7 microcontrollers, whose Flash memory array can be
programmed anytime with minimum hardware requirements (by means of ICP or IAP).
Before embedding the serial number, its format (size, encoding etc.) should be known .
For exampe, a serial number encoded over a four-character identification string may look as
follows:
char Serial_Number[4];
2.1 Embedding the serial number inside the MCU software
2.1.1 Fixed serial number
This is the easiest way to implement the serial number, since it can either be programmed
with the MCU software or programmed later.
If a common serial number is assigned to all appliances of a production lot, the string can be
part of the normal MCU software without any specific requirements, as shown below:
#pragma INTO_ROM // in case -Cc option is not used
const char Serial_Number[4] = “0123”; // forget the trailing ‘\0’
3/12
Embedding the serial numberAN2614
2.1.2 Reserving space for unique serial numbers
If a different number needs to be given to each MCU, then a specific area must be reserved
inside the software memory array which can be programmed on a chip-by-chip basis.
This is done inside the PRM file. A section indicating the size of the identification string
should be created, and a placement name assigned to it.
In the following example, 4 bytes are reserved at the beginning of the Flash memory array:
SECTIONS
//...
SER_NUM = READ_ONLY 0x1000 TO 0x1003;/* Serial number area */
USER_ROM = READ_ONLY 0x1004 TO 0xFFDF;/* FLASH area */
PLACEMENT
//...
SERIAL INTO SER_NUM;
In the software, the identification string may then be allocated inside this dedicated memory
space as follows:
#pragma CONST_SEG SERIAL // map the next string into SERIAL section
const char Serial_Number[4];
#pragma CONST_SEG DEFAULT // restore normal string mapping
Once compiled and linked, the MAP file will show a segment called ‘SERIAL’ which is
four-bytes wide and contains the serial number as shown below:
-----------------------------------------------------Segmentname Size Type From To Name
SERIAL 4 R 1000 1003 SER_NUM
2.1.3 Protection against read-out
To avoid subsequent reads of the serial number, the entire ST7 Flash memory array can be
protected against read-out by enabling the read-out protection bit located in the first option
byte. Protection is thus ensured as it can only be removed by erasing the entire Flash
memory array (see Section 3: Automatic serial number generation in the MCU on page 6).
Note:Such read-out protection is device-dependent and is not a feature of all MCUs.
4/12
Loading...
+ 8 hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.