XCP Book V1.5 EN
XCP Book V1.5 EN
vector.com
XCP
The standard protocol
for the embedded
Development
© 2022 by Vector Informatik GmbH. All rights reserved. This book is intended
for personal use only, not for technical or commercial use. It may not be used
as a basis for contracts of any kind. All information in this book has been
compiled with the greatest possible care. However, Vector Informatik does not
warrant or guarantee the accuracy of the information contained herein. Vector
Informatik's liability is excluded except for intent and gross negligence unless
liability is mandatory by law.
Introduction ....................................................................................................................... 5
1. Basics of the XCP protocol ........................................................................................ 9
1.1. The XCP communication model ...................................................................... 12
1.2. XCP protocol layer ............................................................................................. 16
1.2.1. Identification Field ...................................................................................... 17
1.2.2. The Counter Field ........................................................................................ 18
1.2.3. Timestamp .................................................................................................... 18
1.2.4. Data Field...................................................................................................... 19
1.3. Exchange of CTOs .............................................................................................. 19
1.3.1. XCP command structure ........................................................................... 19
1.3.2. RES ................................................................................................................. 24
1.3.3. ERR ................................................................................................................. 24
1.3.4. EV .................................................................................................................... 25
1.3.5. SERV ............................................................................................................... 25
1.3.6. Adjust parameters in the slave ................................................................ 26
1.4. Exchange of DTOs - synchronous data exchange ...................................... 29
1.4.1. Measurement method: Polling versus DAQ .......................................... 29
1.4.2. The DAQ-measurement method ............................................................. 30
1.4.3. The STIM-transmission method............................................................... 38
1.4.4. XCP packet addressing for DAQ and STIM .......................................... 38
1.4.5. Bypassing = DAQ + STIM ........................................................................... 40
1.5. Time correlation and synchronization ........................................................... 41
1.5.1. Introduction .................................................................................................. 41
1.5.2. XCP's own method for improving time synchronization ................... 41
1.5.3. Support for external time synchronization techniques ...................... 41
1.5.3.1. Short introduction to PTP .................................................................. 42
1.5.4. Sharing PTP and XCP ................................................................................. 44
1.5.4.1. Scenario 1: Free-running clock in XCP slave .................................. 45
1.5.4.2. Scenario 2: XCP slave clock is synchronized with Grandmaster
Clock ...................................................................................................................... 46
1.5.4.3. Scenario 3: XCP slave clock is syntonized with Grandmaster
Clock ...................................................................................................................... 46
1.5.4.4. Scenario 4.a: XCP slave with two clocks: Free-running clock
combined with a synchronized clock .............................................................. 47
1.5.4.5. Scenario 5: Free-running XCP slave clock and a controller clock
................................................................................................................................ 48
1.6. XCP transport layers ......................................................................................... 48
1.6.1. CAN ................................................................................................................ 49
1.6.2. CAN FD .......................................................................................................... 51
1.6.3. FlexRay........................................................................................................... 52
1.6.4. Ethernet......................................................................................................... 56
1.6.4.1. Detecting XCP on Ethernet slaves ................................................... 57
1.6.5. SxI.................................................................................................................... 58
1.6.6. USB ................................................................................................................. 58
Page 2
1.6.7. LIN ................................................................................................................... 59
1.7. XCP Services ........................................................................................................ 59
1.7.1. Memory page switching ............................................................................. 59
1.7.2. Backup of memory pages - Data Page Freezing ................................. 61
1.7.3. Flash programming .................................................................................... 61
1.7.4. Automatic detection of the slave ............................................................ 64
1.7.5. Block transfer mode for upload, download and flashing .................. 64
1.7.6. Saving a DAQ configuration and direct data transfer on power-up
.................................................................................................................................... 65
1.7.7. Protection mechanisms with XCP ........................................................... 65
2. ECU description file A2L .......................................................................................... 67
2.1. Structure of an A2L file .................................................................................... 69
2.2. Manual creation of A2L file .............................................................................. 70
2.3. A2L content versus ECU implementation .................................................... 72
3. Calibration concepts ................................................................................................. 73
3.1. Parameters in Flash ........................................................................................... 73
3.2. Parameters in RAM ............................................................................................ 75
3.3. Flash overlay ........................................................................................................ 76
3.4. Dynamic Flash Overlay Allocation .................................................................. 78
3.5. RAM pointer-based calibration concept according to AUTOSAR........... 79
3.5.1. Single pointer concept ............................................................................... 79
3.5.2. Double pointer concept.............................................................................. 81
3.6. Flash pointer-based calibration concept ...................................................... 82
4. Areas of application for XCP .................................................................................. 83
4.1. MIL: Model in the Loop ...................................................................................... 84
4.2. SIL: Software in the Loop................................................................................. 85
4.3. HIL: Hardware-in-the-loop ............................................................................... 86
4.4. RCP: Rapid Control Prototyping ..................................................................... 86
4.5. Bypassing ............................................................................................................. 87
4.6. Shortening iteration cycles with virtual ECUs ............................................. 90
4.7. External XCP slaves ........................................................................................... 91
4.8. Software debugging via XCP .......................................................................... 92
5. Exemplary XCP implementation ............................................................................ 94
5.1. Description of the functions ............................................................................ 95
5.2. Parameterization of the driver ....................................................................... 97
6. Overview of the protocol development ................................................................ 99
6.1. XCP Version 1.1 (2008) ..................................................................................... 99
6.2. XCP Version 1.2 (2013) ..................................................................................... 99
6.3. XCP Version 1.3 (2015) ..................................................................................... 99
6.4. XCP Version 1.4 (2017) ...................................................................................100
6.5. XCP Version 1.5 (2017) ...................................................................................101
List of abbreviations ...................................................................................................102
Bibliography ..................................................................................................................104
Web addresses .............................................................................................................104
List of Figures ...............................................................................................................105
Appendix - XCP Solutions at Vector ........................................................................107
Page 3
Subject index .................................................................................................................108
Page 4
Introduction
XCP is the standard protocol that enables read and write access to internal
memories of embedded systems. It has been established as a universal
measurement protocol for many years and allows the parameterization of
algorithms in embedded systems at runtime.
Page 5
Figure 1 Classic process flow when developing applications for embedded systems
Figure 2 Process flow when developing applications for embedded systems with the XCP
standard
Page 6
The ASAM interface model
XCP is based on the ASAM interface model. The following figure shows the
interfaces of a measurement and calibration system as XCP master to the XCP
slave in an ECU (Electronic Control Unit), to the description file and the
connection to a higher-level automation system.
Interface 1: "ASAM MCD 1MC" between ECU and measuring and calibration
system
ECU stands for Electronic Control Unit and is a common abbreviation for an
embedded system or control unit. This interface describes the physical and the
protocol-specific part. The most common interfaces are XCP on CAN, XCP on
CAN FD, XCP on Ethernet and XCP on FlexRay.
Page 7
XCP as an interface throughout the entire development process
The use of XCP is not limited to embedded systems. The protocol can be used
in different environments: from a simulated development environment,
hardware- and software-in-the-loop environments to embedded systems with
AUTOSAR Adaptive or POSIX operating systems. The rest of the book's
content is strongly related to ECUs. The behavior of the other systems can be
derived very well from it.
This means that XCP is available over a very large part of the development
process. This means that the same mechanisms, tools, descriptions, etc. are
always used. There is less upheaval between work steps. Fewer tools must be
purchased and trained. Iteration loops, in which results from later work steps
are passed back to previous work steps, can be drastically simplified.
The screenshots used were made with the help of the CANape measurement
and calibration tool from Vector Informatik GmbH. CANape is also used to
explain other processes, including the creation of an A2L file and much more.
You can follow this at any time with a free demo version, which is available in
the download center of the Vector website at www.vector.com/canape_demo.
Page 8
1. Basics of the XCP protocol
Interface 1 of the ASAM interface model describes the sending and receiving
of commands and data between slave and master. To realize the independence
of a physical transport layer, XCP was divided into a protocol and a transport
layer.
Figure 5 Division of the XCP protocol into protocol and transport layers
Depending on the transport layer, one speaks of XCP on CAN, XCP on Ethernet,
etc. The XCP protocol is currently available in version 1.5, which was adopted
in 2017.
Write access allows the user to change parameters in the slave. In the case of
control algorithms, the controller is thus optimized. However, other
parameters in the memory can also be changed, e.g. to achieve a defined
status.
Page 9
quantity therefore represents a request from the master to the slave: "Give
me the value of memory location 0x1234". The calibration of a parameter - the
write access - to the slave means: "Set on the address 0x9876 the value to 5".
Storage Basics
Flash memory are usually integrated into microcontroller chips for control units
and are used for permanent storage of code and data even without a power
supply. The special feature of flash memory is that while individual bytes can
be accessed for reading at any time, writing new content is only ever possible
block by block, usually in quite large blocks.
If this erasing routine is repeated several times, the insulating layer ("tunnel
oxide film") can be damaged. This causes the electrons to flow away slowly
and thus the information changes from 1 to 0 over time. For this reason, the
number of flash cycles permitted in an ECU is severely limited. In the series
ECU, it is often only in the single-digit range. The restriction is imposed by the
Flash Boot Loader, which uses a counter to record how many flash operations
Page 10
have already been performed. If the specified number is exceeded, the Flash
Boot Loader rejects a new flash request.
// Pseudocode representation
a = 5;
b = 2;
y = a * x + b;
If the application is flashed into the controller, the controller handles this code
after booting as follows: The value of x corresponds to a sensor value. So, at
some point in time, the application must query the sensor value and the value
is then stored in a memory location that is associated with the x. Since this
value must be written again and again at runtime, the memory location can
only be in RAM.
The quantity y is calculated. The values a and b as factor and offset are stored
as information in the flash memory. They are stored there as constants. The
value of y must also be stored in the RAM, since write access is only possible
there. Exactly where in the RAM the variables x and y or where in the flash a
and b are located is determined during the compiler/linker run. Here the unique
assignment of the objects to addresses takes place. The relationship between
object name, data type and address is documented in the linker MAP file. The
linker MAP file is generated by the linker run and can exist in different formats.
However, all formats have in common that at least object name and address
are contained in it.
If the offset b and the factor a in the example depend on the vehicle, the values
of a and b must be individually adapted to the conditions. This means that the
algorithm remains as it is, but the parameter values change from vehicle to
vehicle.
In the normal operating mode of a control unit, the application runs out of the
flash memory. This does not allow write access to individual objects. This
means that parameter values located in the flash area cannot be changed at
Page 11
runtime. If it is to be possible to change parameter values during runtime, the
variables to be changed must be in RAM and not in flash. How do the
parameters and their initial values get into the RAM? How do you solve the
problem if more parameters are to be changed than can be accommodated in
RAM at the same time? These questions lead us to the topic of calibration
concepts.
The mechanisms of the XCP protocol provide read and write access to memory
contents. The accesses are address oriented. The read access allows the
measurement of variables from the RAM and the write access allows the
calibration of the parameters in the RAM. XCP allows the measurement to be
carried out synchronously with the events in the control unit. This ensures that
the measured values correlate with each other. Each time a measurement is
restarted, the signals to be measured can be freely selected. For write access,
the parameters that are to be adjusted must be in RAM. This requires a
calibration concept.
The questions are answered in the chapters 2. ECU description file A2L and 3.
Calibration concepts.
XCP data is exchanged between master and slave on a frame or packet basis.
A distinction is made between the exchange of commands (CTO) and the
sending of synchronous data (DTO).
Page 12
Figure 6 XCP communication model with CTO and DTO
Commands are exchanged via CTOs (Command Transfer Objects). This is how
the master establishes contact, for example. A CMD must always be answered
by the slave with RES or ERR. The other CTO frames are sent asynchronously.
The Data Transfer Objects (DTO) are used for the exchange of synchronous
measurement and stimulation data.
Page 13
Exchange of status information between XCP master and slave
In more complex ECUs, the XCP slave and the ECU application can be different
instances. For example, the XCP slave can be active without the ECU
application running. Or one of the ECU resources can assume an active or
inactive state. The XCP slave can inform the XCP master about this.
The XCP slave must support the GET_STATUS command. The slave responds
to the master with information about the current status, which resources are
protected via seed-and-key, and other details.
Optional: If the XCP slave supports asynchronous event messages, it sends the
EV_ECU_STATE_CHANGE event to the XCP master and can thereby inform it
that there has been a status change. The XCP master can then query the
details again using the GET_STATUS command.
The master sends a request and waits for the response of the slave before
sending another command.
Page 14
Master Block Transfer Mode
The master can send several commands in succession to the slave without
waiting for an individual response from the slave to each command.
The block transfer mode is optional and speeds up the process for large data
transfers (for example, upload or download processes). However, the
performance of this mode in the direction of the slave must be considered. This
includes the minimum time interval MIN_ST between two commands and the
maximum number of commands without response MAX_BS. Optionally these
communication settings can be read out from the slave by the master via
GET_COMM_MODE_INFO.
Also, for time optimization the slave can send several frames one after the
other to the master. For example, to transfer a new data status from the slave.
The XCP command concerned is UPLOAD.
The limitations mentioned for the Master Block Transfer Mode do not have to
be observed for the Block Transfer Mode in the direction of the master. The
concept is based on the fact that the performance of the master is always
sufficient.
Page 15
Interleaved Communication Mode
In standard communication, the master and slave wait for each other. The
interleaved communication mode is available to accelerate the data
transmission. Here the master may send several requests in succession. It must
consider the size of the receive buffer on the slave side. The slave can send
several responses in succession to the master. The slave does not have to
consider any limitation of the master.
The interleaved mode must not be used simultaneously with a block mode. This
mode is optional and - in contrast to the block transfer mode - has no practical
relevance.
The XCP frame consists of three parts: the XCP header, the XCP packet and
the XCP tail. XCP Header and XCP Tail depend on the transport protocol. For
example, an XCP on CAN packet is enclosed by a CAN frame.
Page 16
The maximum XCP packet size depends on the transport layer. It is set
separately for the CTO and for the DTO packets:
MAX_CTO specifies the maximum length of a CTO packet in bytes.
MAX_DTO specifies the maximum length of a DTO packet in bytes.
When exchanging packets, both master and slave must be able to recognize
which information was sent by the other. This process is done with the help of
the identification field. Therefore, each packet starts with the packet identifier
(PID).
Page 17
Figure 13 Overview of the XCP Packet Identifier (PID)
A DTO package can optionally contain a counter field. If present, the counter
field is located directly after the identification field and has the size BYTE.
If the counter field is used when transmitting DAQ packets, the XCP slave
inserts a counter in the first ODT packet of a DAQ list. Which counter is
inserted is a property of the event for which this DAQ list is configured.
1.2.3. Timestamp
Figure 15 Timestamp
Page 18
DTO packets can be provided with a timestamp. BYTE, WORD and DWORD
are available as data types for timestamps. A CTO packet is transmitted
without a timestamp.
In the case of measurement data transmission via DAQ, the XCP slave writes
the measurement time to the timestamp field. Since all measured variables in
a DAQ list are acquired at the same time, the timestamp is transmitted only
once per DAQ cycle.
During STIM data transfer from the master to the slave, the XCP master
writes a value to the timestamp field. The XCP standard does not define the
meaning of the value.
More information about handling timestamps is explained in the chapter
Exchange of DTOs - synchronous data exchange.
The actual data is transferred in the data field. In the case of CTO packets, the
data field consists of specific parameters for the different commands. DTO
packets contain the measured values from the slave and in the case of sending
STIM data the values from the master.
Commands from the master to the slave as well as the responses and
messages from the slave to the master are transmitted via CTOs.
The slave receives a command from the master and must react to it with a
positive or negative response. The communication structure is always the
same:
Page 19
Command (CMD):
Position Type Description
0 BYTE Packet Identifier CMD (0xC0...0xFF)
1.. MAX_CTO-1 BYTE Command Data
Positive answer:
Negative answer:
Not only at the positive but also at the negative response specific parameters
can be transmitted as additional information. The establishment of the
connection between master and slave shall serve as an example. At the
beginning of a communication between master and slave, the master sends a
connect request to the slave, which the slave must answer positively to
establish a continuous point-to-point connection.
Connect command:
Mode 00 means that the master requests an XCP communication with the
slave. If the master uses 0xFF 0x01 when establishing the connection, the
master requests an XCP communication with the slave. At the same time, it
informs the slave that it should change to a certain - user defined - mode.
Page 20
Positive response from the slave:
The positive response of the slave can be somewhat more extensive. The slave
already informs the master about communication-specific information when
the connection is established. RESOURCE, for example, is information with
which the slave reports whether it supports page switching or whether flashing
via XCP is possible. With MAX_DTO the slave informs the master about the
maximum packet length for the measurement data transfer supported by the
slave and so on. The details of the parameters can be found in the ASAM XCP
Part 2 Protocol Layer Specification.
1.3.1.1. CMD
The master sends a general request to the slave via CMD. The PID (Packet
Identifier) field contains the identification number of the command. The
additional specific parameters are transported in the data field. Then the
master waits for a reaction from the slave in the form of a response (RES) or
an error (ERR).
XCP is also very scalable in its implementation, so that not every command has
to be implemented. In the A2L file, in the so-called XCP IF_DATA the available
CMDs are listed. If there is a discrepancy between the definition in the A2L file
and the implementation in the slave, the master can recognize from the
reaction of the slave that the slave does not support the command after all. If
the master sends a command that has not been implemented in the slave, the
Page 21
slave must acknowledge with ERR_CMD_UNKNOWN and no further activities
are triggered in the slave. Thus, the master recognizes fast that an optional
command was not implemented in the slave. Partly further parameters are
contained in the commands.
Standard commands:
Command PID Optional
CONNECT 0xFF No
DISCONNECT 0xFE No
GET_STATUS 0xFD No
SYNCH 0xFC No
GET_COMM_MODE_INFO 0xFB Yes
GET_ID 0xFA Yes
SET_REQUEST 0xF9 Yes
GET_SEED 0xF8 Yes
UNLOCK 0xF7 Yes
SET_MTA 0xF6 Yes
UPLOAD 0xF5 Yes
SHORT_UPLOAD 0xF4 Yes
BUILD_CHECKSUM 0xF3 Yes
TRANSPORT_LAYER_CMD 0xF2 Yes
USER_CMD 0xF1 Yes
GET_VERSION 0xC0, 0x00 Yes
Calibration commands:
Command PID Optional
DOWNLOAD 0xF0 No
DOWNLOAD_NEXT 0xEF Yes
DOWNLOAD_MAX 0xEE Yes
SHORT_DOWNLOAD 0xED Yes
MODIFY_BITS 0xEC Yes
Page 22
Page switching:
Command PID Optional
SET_CAL_PAGE 0xEB No
GET_CAL_PAGE 0xEA No
GET_PAG_PROCESSOR_INFO 0xE9 Yes
GET_SEGMENT_INFO 0xE8 Yes
GET_PAGE_INFO 0xE7 Yes
SET_SEGMENT_MODE 0xE6 Yes
GET_SEGMENT_MODE 0xE5 Yes
COPY_CAL_PAGE 0xE4 Yes
Flash programming:
Command PID Optional
PROGRAM_START 0xD2 No
Page 23
PROGRAM_CLEAR 0xD1 No
PROGRAM 0xD0 No
PROGRAM_RESET 0xCF No
GET_PGM_PROCESSOR_INFO 0xCE Yes
GET_SECTOR_INFO 0xCD Yes
PROGRAM_PREPARE 0xCC Yes
PROGRAM_FORMAT 0xCB Yes
PROGRAM_NEXT 0xCA Yes
PROGRAM_MAX 0xC9 Yes
PROGRAM_VERIFY 0xC8 Yes
Time synchronization:
Command PID Optional
TIME_CORRELATION_PROPERTIES 0xC6 Yes
1.3.2. RES
For more detailed information about the parameters, refer to the ASAM XCP
Protocol Layer specification.
1.3.3. ERR
If the request of the master is unusable, the slave sends an error message ERR
with error code.
Page 24
The possible error codes are described in the ASAM XCP Protocol Layer
specification.
1.3.4. EV
For more detailed information about the parameters, refer to the ASAM XCP
Protocol Layer specification.
1.3.5. SERV
Via this mechanism the slave can request the execution of a service from the
master. For example, the slave recognizes that a restart is necessary and
requests a corresponding reset command from the master.
The service request code table can be found in the ASAM XCP Protocol Layer
specification.
Page 25
1.3.6. Adjust parameters in the slave
To change a parameter in an XCP slave, the XCP master must send both the
address where the parameter is located and the value itself to the slave.
XCP always defines addresses with five bytes: four for the actual address and
one byte for the address extension. Based on a CAN transmission, only seven
useful bytes are available for XCP contents. If, for example, you change a 4-
byte value and want to send both pieces of information in one CAN frame, the
number of bytes is not sufficient. Since a total of nine bytes are required for
the transmission of the address and the new value, the change cannot be
transmitted in one CAN frame (seven user bytes). The change request is
therefore made with two packets from the master to the slave. The slave must
acknowledge both packets, in total four packets are exchanged.
The following figure shows the communication between master and slave
necessary for setting a parameter value. In the line with the envelope symbol
the data content of the packet is shown.
In the first packet the master transmits the command SET_MTA with the
address (HEX: 001C002C, Extension: 0), to which a new value is to be written,
to the slave. With the second packet the slave confirms the command
positively with Ok:SET_MTA.
The third packet DOWNLOAD transmits the hex value (00 00 E0 40) and
additionally the valid number of bytes. In this example the valid number of
bytes is four, because it is a float value. The slave confirms positive again with
the fourth packet.
Page 26
This completes the actual calibration process. In the trace display you can see
a subsequent SHORT_UPLOAD in the trace display - a special feature of
CANape, Vector's measurement and calibration tool. To make sure that the
calibration has worked, the value is read out again after the process and the
display in CANape is updated with the read-out value. In this way, the user can
see directly whether his calibration command has been successfully processed.
This command is also confirmed positively with Ok:SHORT_UPLOAD.
With the change of the parameter in the RAM of the control unit, the
application processes the new value. However, rebooting the ECU leads to
deletion of the value and overwriting of the value in RAM with the original value
from the flash (see chapter Calibration concepts).
Another possibility is to write back the RAM sizes to the Flash memory of the
control unit. This procedure is relatively complex. A flash memory must first be
erased before it can be rewritten. This in turn can only be done block by block.
It is therefore not possible to write back individual bytes. More about this can
be found in the chapter on calibration concepts.
Scenario: After work is done, the application engineer wants to go home for a
well-deserved rest. He saves the changes made in the RAM of the ECU in the
form of a parameter set file on his computer. The next day, he wants to
continue working where he left off the day before. He starts the control unit.
When booting, the parameters in RAM are initialized. But for this, the ECU uses
Page 27
the values that are stored in the flash. This means that the changes from the
previous day are no longer present in the ECU. To be able to continue working
with the status from the previous day, the application engineer transfers the
contents of the parameter set file to the RAM of the ECU via XCP using the
DOWNLOAD command.
Figure 19 Transfer of a parameter set file into the RAM of the control unit
Flashing an ECU is a way to change the parameters in the flash. These are then
written into the RAM as new parameters when the ECU is booted. A parameter
set file can be transferred into a C or H file and the new flash file is generated
by a new compiler/linker run. Depending on the size of the code, the generation
of a flashable hex file can take some time. In addition, depending on the work
process, the application engineer may not have the source code of the ECU.
Thus, this way is not available to him.
Alternatively, the parameter set file can be copied into the existing flash file. In
the flash file there is a hex file containing both the addresses and the values.
Now a parameter file can be copied to a hex file. To do this, CANape takes the
address and the value from the parameter set file and updates the value of the
parameter at the corresponding position in the hex file. This creates a new hex
file that contains the changed parameter values. However, this hex file may
now have to pass through further process steps to obtain a flashable file from
it. One problem here is always the checksums that the ECU checks to see
whether it has received the data correctly. If the flashable file is available, it
can be flashed into the ECU and after the reboot the new parameter values
are available in the ECU. the new parameter values are available in the ECU.
Page 28
1.4. Exchange of DTOs - synchronous data exchange
As shown in Figure 6 XCP communication model with CTO and DTO is shown,
DTOs (Data Transfer Objects) are available for exchanging synchronous
measurement and stimulation data. Via DAQ data is sent from the slave to the
master synchronously to internal events. This communication is divided into
two phases:
In an initialization phase the master informs the slave which data the slave
should send at different events. After this phase, the master triggers the
measurement at the slave and the measurement phase begins. From this point
on, the slave sends the desired data to the master, which only "listens" until it
sends a "measurement stop" to the slave. The triggering of the measurement
data acquisition and the sending are done by events in the control unit.
Via STIM the master sends data to the slave. This communication also consists
of two phases:
In the initialization phase the master tells the slave which data it will send to
the slave. After this phase the master sends the data to the slave and the STIM
processor stores the data. As soon as a corresponding STIM event is triggered
in the slave, the data is transferred to the application's memory.
Via the command SHORT_UPLOAD the master can request the value of a
measured variable from the slave. This is called polling. This is the simplest case
of a measurement: send the measured value of a measured variable at the
time when the SHORT_UPLOAD command has been received and executed.
Figure 20 Address information of the parameter "Triangle" from the A2L file
Page 29
The address (0x1BDDDE, Address Extension: 0) is found in the CAN frame as
an address with five bytes: one byte for the address extension and four bytes
for the actual address. and four bytes for the actual address.
The XCP specification specifies for polling that the value of each measured
variable is queried individually. Two frames must be transmitted for each value
to be measured via polling: the request from the master to the slave and the
response from the slave to the master. The data rate is also low with this
transmission because the maximum number of user data is not transmitted.
Besides this additional bus load there is another disadvantage of the polling
method: When polling several data, the user normally attaches importance to
the data correlating with each other. However, several values that are
measured one after the other with polling do not have to correlate with each
other. There is no information about which calculation cycles the values come
from. Polling is therefore only suitable for measurement to a limited extent,
since it produces an unnecessarily large amount of data traffic and does not
take the measurement data into account in relation to the processes in the
ECU.
This task is taken over by the DAQ procedure. DAQ stands for Data Acquisition
and is used via the sending of DTOs (Data Transfer Objects) from the slave to
the master.
Page 30
measured values are only recorded and transmitted when the event
occurs. This ensures that all data match each other.
> To reduce the bus load, the measuring process is divided into two phases:
In a configuration phase, the master informs the slave which values it is
interested in, and in the second phase, only the transmission of the
slave's measurement data to the master takes place. During the
transmission, the measurement data are summarized as compactly as
possible in the packets.
How can the acquisition of measured values be linked to events in the control
unit? In Figure 22 Events in the ECU the connection between the calculation
cycles in the ECU and the value development of the variables X and Y is shown
again slightly modified.
An event is not necessarily a cyclic event equidistant in time, but can also be
angularly synchronous, e.g. in the case of an combustion engine ECU. Thus, the
time interval between two events depends on the engine speed. A singular
event, such as the actuation of a button by the driver, is also an event that is
not equidistant in time in any way.
The selection of the measurement object and the associated event is made by
the user. The events are described in the A2L file.
Page 31
Figure 23 Examples of event definitions
However, the assignment of the measured variables to the events in the ECU
can of course be changed directly by the user.
Page 32
After configuring the measured variables, the user starts the measurement.
The XCP master summarizes the desired measured variables in so-called DAQ
lists. The measurement signals are assigned to the selected events. This
configuration information is sent to the slave before the actual start of the
measurement. The slave then knows which addresses it should read out and
transmit when which event is reached. This division of the measurement into a
configuration and a measuring phase was already mentioned at the very
beginning of the chapter.
This solves both problems that occur during polling: both the optimized use of
bandwidth, since the master no longer must request each value individually
during the measurement, and the correlation of the measurement data.
So far, the selection of the measured variables by their name and the
assignment to a measurement event have been described. But how exactly is
the configuration transferred to the XCP slave?
Let's look at the problem from the side of the memory structure in the
controller: The user has selected signals and wants to measure them. In order
not to have to use a complete frame for sending a signal value, the slave packs
as many values as possible into one frame. The slave does not create the
definition of the composition by itself, otherwise the master could not interpret
the data when receiving the frame. Therefore, the master sends the
instructions to the slave how to distribute the values to the frames.
Page 33
The assignment is made via so-called Object Description Tables (ODTs). To
identify a measured variable unambiguously, the address and the object length
are important. Thus, one receives with an ODT the assignment of the RAM
contents from the slave to the structure of a frame on the bus. According to
the communication model the transfer is done as DAQ DTO (Data Transfer
Object).
More precisely, an entry in an ODT list references a memory area in RAM by the
address and length of the object.
In the XCP protocol, the ODTs are combined into DAQ lists. Each DAQ list
contains a number of ODTs and is assigned to an event.
Page 34
Figure 28 DAQ list with three ODTs
If, for example, the user uses two measuring grids (= two different events in
the ECU), two DAQ lists are also used. One DAQ list is required for each event
used. Each DAQ list contains the entries concerning the ODTs and each ODT
contains the references to the values in the RAM cells.
DAQ lists come in three different forms: Static, Predefined and Dynamic.
Static DAQ-lists:
If the DAQ lists and ODT tables are permanently defined in the control unit, as
known from CCP, they are called static DAQ lists. Here it is not defined which
measured variables are in the ODT lists. A static DAQ list defines the frame
which can be filled (in contrast to this see predefined DAQ lists).
Page 35
For static DAQ lists, the definitions are defined in the ECU code and described
in the A2L. Figure 30 Static DAQ lists shows a section of an A2L in which static
DAQ lists are defined:
In the example above, there is a DAQ list with the number 0, which is associated
with a 10ms event and can carry a maximum of five ODTs. The DAQ list
numbered 1 has three ODTs and is associated with the 1ms event.
With the download of the application into the ECU, in the case of static DAQ
lists, the number of DAQ lists and the respective ODT lists contained therein
are fixed. If the user now tries to measure more signals with an event than fit
into the assigned DAQ list, the slave in the ECU will not be able to fulfill the
requirements and the configuration attempt will be aborted with an error. The
fact that the other DAQ list is still completely available and therefore
transmission capacity is still free is irrelevant.
Predefined DAQ-lists:
Completely predefined DAQ lists can also be determined in the ECU. However,
this procedure is practically not used in ECUs due to the lack of flexibility of the
user. The situation is different for analog measurement systems that transfer
their data via XCP: Here, the flexibility is not necessary because the physical
structure of the measurement system remains the same over its lifetime.
Dynamic DAQ-lists:
Dynamic DAQ lists are mostly used in ECU development. It is not the absolute
sizes of the DAQ and ODT lists that are permanently defined in the ECU code,
but only the size of the memory area that can be used for the DAQ lists. The
advantage is that the measurement tool has more leeway when combining the
DAQ lists and can manage the structure of the DAQ lists dynamically.
Page 36
Figure 31 Dynamic DAQ lists
When compiling the DAQ lists, the master must be able to distinguish whether
dynamic or static DAQ lists are used, what the sizes and structures of the DAQ
lists are, etc.
With version 1.5 of the XCP standard, the so-called "Packed Mode" was
defined. The mode enables the transmission of several measured values of a
signal in one ODT.
Figure 32 Transmission of five measured values of signals S1 and S2 in one ODT each
With this form of transmission, only one timestamp is transmitted per DAQ
list. The XCP master calculates the timestamps of the individual measured
values by an offset calculation on the transmitted timestamp. The sampling
rate is defined in the A2L.
A typical application is the measurement of physical quantities. For example,
the voltage values at an inverter in the electric vehicle are sampled at one
megahertz. The measurement system summarizes the data and transmits it
via XCP on Ethernet. A defined number of measured values is transmitted in
an ODT. The XCP master calculates the timestamps of the individual measured
Page 37
values by incrementing the timestamp by one microsecond for each measured
value.
The XCP calibration procedure has already been presented in the chapter on
the exchange of CTOs. This type of calibration is available in every XCP driver
and forms the basis for adjusting objects in the ECU. However, there is no
synchronization between the sending of an calibration command and an event
in the ECU.
In contrast, the use of STIM is not based on the exchange of CTOs, but on the
use of DTOs with communication synchronized to an event in the slave. The
master must therefore know which events in the slave it can synchronize to at
all. This information must also be available in the A2L.
The basic task of the STIM method is to provide data to the control unit. For
example, when working with radar sensors, you always need an environment
that reflects the radar beams. For a laboratory setup, this is unfavorable. The
solution via XCP looks like this: In the vehicle, raw radar data is recorded by the
sensor. In the laboratory, these recordings can then be transferred back to the
sensor via XCP STIM.
The addressing of XCP packets was already introduced at the beginning of the
chapter. Now that the terms DAQ, ODT and STIM have been introduced, XCP
packet addressing is presented in more detail.
While the use of a PID is completely sufficient for the transmission of CTOs to
uniquely identify a packet, this is no longer sufficient for the transmission of
DAQ and STIM data. The following figure gives an overview of the possible
addressing that can be used for DTOs:
Page 38
Figure 34 Structure of XCP package for DTO transmissions
"Absolute" means that during the entire communication - i.e. across all DAQ
lists - the ODT numbers are unique. In this respect, the use of absolute ODT
numbers requires a transformation step in which a so-called "FIRST_PID for
the DAQ list" is used.
If a DAQ list starts with PID j, the PID of the first packet has the value j, the
second packet PID j + 1, the third packet PID j + 2 and so on. Of course, the
slave has to take care that the sum of FIRST_PID + relative ODT number stays
below the PID of the next DAQ list.
Transmission type "relative ODT numbers and absolute DAQ list numbers".
In this case, both the DAQ list number and the ODT number are transmitted in
the identification field. The ODT number is transmitted with one byte, the DAQ
number with one or two bytes.
Page 39
Figure 36 ID field with relative ODT and absolute DAQ numbers (two bytes)
If a transmission with three bytes is out of the question, four bytes can also be
used with the aid of a fill byte:
Figure 37 ID field with relative ODT and absolute DAQ numbers as well as fill byte (total four
bytes)
How does the XCP master find out which method the slave uses? On the one
hand by the entry in the A2L and on the other hand by the query to the slave,
which communication variant is implemented.
Bypassing can be implemented by sharing DAQ and STIM (see Figure 6 XCP
communication model with CTO and DTO) and represents a special form of
rapid prototyping solution. However, further details are required for a deeper
understanding, so this procedure will not be explained until the Bypassing
chapter.
Page 40
1.5. Time correlation and synchronization
1.5.1. Introduction
Since the first version of the XCP specification a time correlation between
master and slave is available, which is based on the GET_DAQ_CLOCK
command. The XCP master sends the GET_DAQ_CLOCK command to the
slave. When the command is received, the XCP slave records its time and sends
it back as a response. Since the XCP master knows the time at which it sent
the request, the XCP master can calculate a time offset between the master
clock and the slave clock.
The achievable accuracy of the time correlation is limited with this method.
Currently, synchronization accuracies in the single-digit microsecond range or
even below are required, which cannot be achieved with this method.
Page 41
Syntonized means that one second is the same for all clocks. But the clocks do
not have to show the same time.
Initial situation: Several clocks are connected to each other via a network.
To synchronize them with each other, the clock that has the highest accuracy
is first searched for. The clock that is best suited for this is selected cyclically
via the "Best Master Clock Algorithm (BMCA)". It is called the "Grandmaster
Clock". It serves as a synchronization source for all other clocks in the network.
A clock that synchronizes to the Grandmaster Clock is called Slave Clock. Just
as with XCP, in the PTP environment we also speak of master and slave.
However, an XCP slave can be the master clock in the network.
For time synchronization the slave clocks and the Grandmaster Clock exchange
Ethernet packets with each other. Time differences are calculated via the
transmission times of the packets, which are used to synchronize the clocks.
The ability to precisely time-stamp the send and receive time of Ethernet
packets is a basic requirement for time synchronization.
If the clocks are connected via routers and switches, these must also support
the PTP protocol. A PTP capable Ethernet Switch represents itself to a
connected Grandmaster Clock as Slave Clock. Other slave clocks, which are
connected to the Ethernet switch, see the Ethernet switch as master clock.
Page 42
Figure 38 First stage of time synchronization
In the picture above the calculation results in 1041µs-944µs = 97µs. The slave
adds this time difference to its own time. So, the synchronism between both
clocks is already pretty good, but due to the signal propagation time there is
still a time difference of 2µs in this example. This synchronization runs cyclically.
For example once per second.
The reverse path also runs cyclically. With a DelayRequest the slave clock sends
a packet to the master clock. The slave clock remembers the time of sending
TS3 (1050µs).
Page 43
The master clock receives the packet at time TM3. The master clock sends back
the time TM3 (1054µs) to the slave clock. The slave calculates its new time from
this. The time difference between TM3 and TS3 is 4µs. If we now assume that
the runtime of the Ethernet packets is the same in both directions, we only
have to divide by 2 to calculate the runtime difference. In this example it
amounts to 2µs. The slave adds this difference again to its current time. Thus,
the time of the slave clock is identical with the time of the master clock.
Several scenarios are presented in this chapter. They differ in whether and how
the XCP slave is synchronized with a master clock. Not all scenarios are
relevant in practice. Anyone who takes the trouble to provide a PTP master in
the overall system will certainly also ensure that the XCP slave can synchronize.
An XCP slave can know several clocks. Each clock has a unique UUID identifier.
The XCP slave communicates the identifier of the Grandmaster Clock to the
XCP master. This gives the XCP master an overview of all clocks in the system.
If the XCP slave is not able to synchronize its time with the Grandmaster Clock,
the following procedure can be used: The XCP slave sends timestamp tuples to
the XCP master. One is the local timestamp, and the other is the timestamp
of the globally synchronized clock that was valid when the local timestamp was
read. Thus, the XCP master knows the relation between the clocks and can
perform a precise clock correlation within the XCP master.
Page 44
both commands are meant. In a PTP network the clocks of the participants are
synchronized anyway.
Command TIME_CORRELATION_PROPERTIES
With this command the XCP master queries the general information about the
synchronization status of the clocks available in the XCP slave as well as their
properties. The command is also used to configure the behavior of the XCP
slave with regard to time correlation.
Page 45
Figure 40 Free-running clock in XCP slave
Page 46
Figure 42 Slave clock syntonized with Grandmaster Clock
1.5.4.4. Scenario 4.a: XCP slave with two clocks: Free-running clock combined
with a synchronized clock
Initial situation: The XCP slave cannot synchronize its own free-running clock
with the Grandmaster Clock. However, there is another clock available in the
XCP slave that is synchronized with a Grandmaster Clock. For example in the
Ethernet PHY. If the timestamps of both clocks are available to the XCP
master, it can perform the correlation of both clocks.
Scenario 4b:
The prerequisite for the scenario just described is that both clocks can be read
at any time. However, this may not be possible. For example, several resources
access the Ethernet PHY. If the synchronized clock is located there, immediate
processing of the GET_DAQ_MULTICAST request may be delayed by another
access.
Mostly, however, these devices offer the possibility to generate a trigger
periodically, e.g., one pulse per second. This trigger can be used to detect the
clock of the XCP slave. Since the time of the synchronized clock is known when
the trigger occurs, the XCP slave can transmit both timestamps via
EV_TIME_SYNC.
Page 47
Figure 44 Two clocks with triggered EV_TIME_SYNC shipping
A main requirement for the design of the XCP protocol was to support
different transport layers. The following layers are defined at the time of
writing this document: XCP on CAN, XCP on FlexRay, XCP on Ethernet, XCP on
SxI and XCP on USB. The CAN and FlexRay bus systems are explained on the
Vector E-Learning platform.
Page 48
1.6.1. CAN
The frame with the ID 0x12 is sent by CAN node A and all other nodes on the
bus receive this frame. CAN nodes C and D conclude during the acceptance
check that they do not need this frame and discard it. CAN node B, on the other
hand, determines that the layers further up the bus need the frame's
information and makes it available via the receive buffer. The CAN nodes are
linked as follows:
Page 49
Figure 46 Representation of a CAN network
The XCP frames are not described in the communication matrix! If, for example
with the help of XCP, measurement data is sent from the slave via dynamic
DAQ lists, the composition of the frames is carried out by the user depending
on the selected signals. If the signal composition changes, the frame content
also changes.
CAN identifiers are required to transmit XCP data via CAN. To occupy as few
CAN identifiers as possible, XCP communication is limited to the use of only
two CAN identifiers that are not used in the DBC for "normal" communication.
One identifier is needed to send information from the master to the slave, the
other is used by the slave to reply to the master.
The excerpt from the CANape Trace window shows the CAN identifiers used
under the "ID" column. In this example, two identifiers are used: ID 554 for the
frames from the master to the slave (Dir Tx) and ID 555 for sending the frames
of the slave to the master (Dir Rx).
Page 50
Figure 47 Example of XCP on CAN communication
The CAN bus transmits a maximum of eight data bytes per frame. In the case
of XCP, however, information about the command used or the response sent
is required. The first byte of the CAN data bytes is used for this purpose. Thus,
seven bytes are available for the transport of user data per CAN frame.
In CANape you will find several XCP on CAN sample configurations with the
virtual ECU XCPsim. For more details about the standard, see the ASAM XCP
on CAN Transport Layer specification.
1.6.2. CAN FD
CAN FD (FD: Flexible Data rate) is an extension of the CAN protocol. The main
differences to CAN are the extension of the user data from 8 to up to 64 bytes.
In addition, CAN FD offers the possibility to send the user data with an
increased data rate. Thus, the data bytes can be sent with a higher
transmission rate after the arbitration phase than during the arbitration
phase.
Starting with the XCP specification 1.2, XCP on CAN FD is supported. The
information about the two different transmission rates must be reflected in
the A2L. Therefore, a CAN FD transport layer block is needed in the A2L file. It
is not possible to use CAN and CAN FD frames on the same physical bus at the
same time.
Page 51
Figure 48 Representation of a CAN FD frame
Frames in the CAN FD format can be distinguished from the standard CAN
format by means of a recessive EDL bit (High Level), since they are identified
by a dominant EDL bit (Low Level). Similarly, a recessive BRS bit switches to
the higher bit rate when sending the data field. The ESI bit is used to identify
the error state of a CAN FD node. In addition, another four bits form the so-
called Data Length Code (DLC), which maps the extended user data length as
possible values of 12, 16, 20, 24, 32, 48 and 64 bytes.
1.6.3. FlexRay
Page 52
Figure 49 Nodes K and L are redundantly connected to each other
In the first communication cycle, node K sends the frame a in slot 1. Scheduling
is also stored in the software of nodes L and M. The frame a is then sent to the
higher communication layers. Therefore, the content of frame a is passed on
to the respective higher communication layers.
Page 53
Figure 51 Representation of a FlexRay communication matrix
Due to further characteristics of the FlexRay bus, the specification of the slot
number alone is not sufficient as a reference to the content. For example,
multiplexing is supported: If a cycle repeats, the same content does not have
to be sent each time. Multiplexing can be used, for example, to specify that
information is only ever sent every second time the slot is passed through.
Instead of the pure slot number, the so-called "FlexRay Data Link Layer
Protocol Data Unit Identifier" (FLX_LPDU_ID) are used, which can be thought
of as a kind of generalized slot ID. In order to describe such an LPDU, four
specifications are required:
Page 54
Figure 52 Representation of the FlexRay LPDUs
Scheduling also has an impact on the use of XCP on FlexRay, since it defines
exactly what is sent. With XCP, this cannot be defined easily. The user
determines which measurement data is sent by compiling the signals only at
runtime of the measurement. So, it can only be controlled which aspect of the
XCP communication can be used in which LPDU: CTO or DTO from master to
slave or from slave to master.
The following example explains the process: In slot n the XCP master may send
a command (CMD) and in slot n + 2 slave A answers with the response (RES).
XCP on FlexRay frames are always defined with the aid of LPDUs.
The A2L description file, in which the objects with the corresponding address in
the ECU are defined, is required for access to ECU-internal variables. In
addition, the FIBEX file is required so that the XCP master knows with which
LPDUs it may send and on which LPDUs the XCP slaves send their responses.
Only in combination, i.e. the establishment of the reference of an A2L file to a
FIBEX file, the communication between XCP master and XCP slave(s) can
work.
Here "XCPsim.xml" is the reference from the A2L to the FIBEX file.
Page 55
Figure 53 Assignment of XCP communication to LPDUs
Further details on XCP on FlexRay can be found, for example, in the CANape
help. CANape comes with a so-called FIBEX Viewer that allows convenient
viewing of the scheduling. The XCP frames are conveniently assigned to the
LPDUs via the driver settings of the XCP on FlexRay device in CANape.
The protocol is explained in detail in the ASAM XCP on FlexRay Transport Layer
specification. An XCP on FlexRay sample configuration with the XCPsim virtual
ECU can be found in CANape. The sample configuration assumes real Vector
FlexRay hardware.
1.6.4. Ethernet
XCP on Ethernet can be operated either with TCP/IP or with UDP/IP. TCP is a
secured transport protocol on Ethernet in which the loss of a packet is detected
by means of the handshake procedure. TCP organizes the retransmission of
the packet in case of packet loss. UDP does not provide this security
mechanism. If a packet is lost here, UDP does not provide any mechanisms for
resending the lost packet at this protocol level.
XCP on Ethernet can be used not only with real ECUs, but also to measure and
calibrate virtual ECUs. A virtual ECU is the use of the code that otherwise runs
in the ECU as an executable program (e.g. DLL) on the computer. Other
resources are available there than in an ECU (CPU, memory ...).
But first to the actual protocol. IP packets always contain the address of the
sender and the recipient. The simplest way to think of an IP packet is as a kind
of letter on which the addresses of the recipient and the sender are written.
The addresses of the individual subscribers must always be unique. A unique
address includes IP address and port number.
Page 56
Figure 54 XCP packet with TCP/IP or UDP/IP
The header consists of a control field with two words in Intel format (= four
bytes). They contain the length (LEN) and a counter (CTR). LEN specifies the
number of bytes of the XCP packet. The CTR is used to identify a packet loss.
UDP/IP is not a secure protocol. If a packet loss occurs, it is not intercepted by
the protocol layer. The control is done by the counter information. When the
master sends the packet to the slave, it generates a counter number that is
incremented each time a packet is sent. The slave responds with the same
pattern: it increments its own counter with each packet it sends. The counter
of the slave and the counter of the master work independently. It depends on
the measuring task whether UDP or TCP is to be used.
For XCP on Ethernet (TCP/IP and UDP/IP) the end consists of a control field
with 0,1,2 or 3 FILL bytes.
An Ethernet packet can carry multiple XCP packets, but an XCP packet must
never exceed the limits of a UDP/IP packet.
With the enhancements through version 1.3 of the XCP standard, an extension
for XCP slave detection was defined specifically for XCP on Ethernet.
The master can detect XCP slaves via the GET_SLAVE_ID command. The
master sends out a multicast packet (IPv4) with the IP address 239.255.0.0 on
port 5556. Regardless of whether an XCP slave already has a connection to a
master or not, the slave must process the request and send back a response.
Page 57
For more information on the protocol, see the ASAM XCP on Ethernet
Transport Layer specification. In CANape you will also find an XCP on Ethernet
sample configuration with the virtual ECU XCPsim or with virtual ECUs in the
form of DLLs implemented using Simulink models and the Simulink Coder.
1.6.5. SxI
SxI is the collective name for SPI or SCI. Since this is not a data bus but a
controller interface that is only suitable for point-to-point connections, there
is no addressing for this transmission. The communication between both
participants is either synchronous or asynchronous.
The XCP header consists of a control field with two pieces of information: the
length LEN and the counter. The length of these quantities can be byte or word
(Intel format). LEN indicates the number of bytes of the XCP packet. The CTR
is used to identify packet loss. The control is done in the same way as for XCP
on Ethernet via the counter information. Under certain circumstances it may
be necessary to add padding bytes to the packet, for example if SPI is used in
WORD or DWORD mode or if the minimum packet length would be undershot.
These fill bytes are appended in the control field.
For more information about the protocol, see the ASAM XCP on SxI Transport
Layer specification.
1.6.6. USB
Page 58
1.6.7. LIN
This chapter lists and explains further services that can be implemented via
XCP. They are all based on the mechanisms of communication using CTOs and
DTOs already described. Some XCP services have already been explained, e.g.
synchronous data acquisition/stimulation or read/write access to the device
memory.
Although the XCP specification clearly defines the different services, it also
states whether the service must be implemented in any case or whether it is
optional. For example, an XCP slave must support a "Connect" for the master
to establish a connection. However, flashing via XCP is not mandatory, the XCP
slave does not have to support it. It simply depends on the project and software
requirements. All services listed in this chapter are optional.
To better understand the XCP commands for page switching, the terms sector,
segment and page should be explained at this point.
Page 59
Figure 56 Memory representation
From the XCP point of view, the memory of a slave consists of a continuous
memory that is addressed with a 40-bit width. The physical structure of a
memory is in sectors. Knowledge of the Flash sectors is mandatory for flashing
because the Flash memories can only be erased block by block.
The logical structure takes place in so-called segments, which describe where
calibration data is located in the memory. The start address and the size of a
segment do not have to be oriented to the start addresses and sizes of the
physical sectors. Each segment can be divided into several pages. The pages of
a segment describe the same parameters on the same addresses. The values
of these parameters and the write/read rights can be regulated individually for
each page.
Page 60
The slave must initialize all pages for all segments. The master uses the
GET_CAL_PAGE command to ask the slave which page is currently active for
ECU access and which for XCP access. It can happen that a mutual locking is
necessary for the accesses. For example, the XCP slave may not access a page
if this page is currently active for the ECU. As I said, there can be a dependency
- but there doesn't have to be. It is a question of how the slave implementation
is realized.
Flashing means writing data to an area of the flash memory. To do this, it must
be known exactly how the memory is structured. A Flash memory is divided into
several sectors (physical sections), which are written with a start address and
a length. To distinguish them, they are given a consecutive identification
number. One byte is available for this purpose, so that the maximum number
of sectors is 255.
Page 61
The information about the flash sectors is also part of the A2L data.
Flashing via XCP roughly divides the entire flash process into three areas:
> Preparation (e.g. for version control and thus to check whether the new
content can be flashed at all)
> Execution (the new content is sent to the control unit)
> Follow-up (e.g. checksum control etc.)
In the XCP standard, the main focus is on the actual execution of flashing. If
you compare this process with flashing via diagnostic protocols, you will see
that the process-specific elements, such as serial number handling with
metadata, are supported rather sparsely in XCP. Flashing in the development
phase was clearly the focus of the definition, not complex process steps that
are necessary at the end of the line.
Page 62
In the preparation phase, it is therefore essentially a matter of determining
whether the new content fits the ECU at all. There are no special commands
for version control. Rather, the practice has established itself that project-
specific definitions are made as to which commands are supported.
Page 63
1.7.4. Automatic detection of the slave
By reading the A2L file, the master knows the details of the slave. However,
the XCP protocol also allows the master to query the slave about its protocol-
specific properties. A number of commands are available for this purpose:
GET_COMM_MODE_INFO
The response to this command provides the master with information about
various communication options of the slave, e.g., whether block transfer or
interleaved mode is supported and which minimum time intervals between
requests in these modes must be observed by the master.
GET_STATUS
The response to this query provides all status information of the slave. Which
resources (CAL/PAG, DAQ, STIM, PGM and DBG) are generally available and
which of these resources are currently active (e.g., memory activities).
GET_DAQ_PROCESSOR_INFO
The master receives the general information it needs to know about the
restrictions of the slave: E.g., number of predefined DAQ lists, available DAQ
lists and events.
GET_DAQ_RESOLUTION_INFO
Further information about the DAQ capabilities of the slave is exchanged via
this command: maximum size of an ODT for DAQ and for STIM, granularity of
the ODT entries, number of bytes for timestamp transmission.
GET_DAQ_EVENT_INFO
If this command is used, the call is made once per event of the control unit.
Information is requested about whether the event can be used for DAQ, STIM
or DAQ/STIM, whether the event occurs cyclically and, if so, what the cycle time
is.
The master learns whether the slave supports the method by means of the
GET_COMM_MODE_INFO query.
Page 64
1.7.6. Saving a DAQ configuration and direct data transfer on power-up
Before a DAQ measurement can be made via XCP, the DAQ configuration
must be present in the slave. XCP provides a mechanism to load the DAQ
configuration in the slave into a non-volatile memory, so that the configuration
is already available when the slave is started. This is called RESUME mode..
On the one hand, this allows the so-called cold start measurement and, on the
other hand, it saves configuration time in case of repeated, unchanged use of
a measurement configuration.
Normally, the algorithm is available in the master as a DLL. So if a user has the
"seed-and-key" DLL and the A2L file, there is nothing to prevent access to the
resources in the ECU. As the ECU approaches production startup, the XCP
Page 65
driver is often disabled. To restore XCP access to the ECU, an individual
sequence of diagnostic commands is usually used. Thus, the XCP driver is still
available in production vehicles for the most part but is normally deactivated
to protect against manipulation of the ECU.
Page 66
2. ECU description file A2L
One reason why an A2L file is needed has already been mentioned: the
assignment of symbolic names to addresses. For example, if the software
developer has implemented a PID controller in his application and has given the
names P1, I1 and D1 to the variables proportional, integral, and differential
components, the application developer should be able to access these variables
by their names. Let's take the following picture as an example:
By using the symbolic names, the user can conveniently access the desired
values. Another example provides the consideration of signal quantities
measured from the control unit:
In the legend the user can read the logical names of the signals. On which
address the variables once stood in the control unit is irrelevant for offline
viewing of the values. The correct address is necessary for the request for the
values in the control unit, but the address itself is irrelevant for the user. He
uses the logical name for selection and visualization. The user selects the object
based on the name and the XCP master looks up the associated address and
data type in the A2L.
Page 67
As a further attribute of a parameter, for example, a minimum and a maximum
value can be defined. The value of the object must be within these limits. The
limits are intended to prevent a user from using a value beyond the limits and
causing damage.
Rules for the conversion between physical and raw values are also defined in
the A2L. A sensor that supplies an 8-bit value serves as a simple example. The
numerical values supplied by the sensor are therefore between 0 and 255, but
the value of the sensor is to be displayed as a percentage. The mapping of the
sensor value [0 ... 255] into [0 ... 100 %] is done by a conversion rule, which again
is stored in the A2L. If the raw value of a variable is measured, the
measurement and calibration tool use the stored formula and displays the
physical value.
In addition to scalar quantities, there are also characteristic curves and maps.
Example for the use of a characteristic curve: A Hall sensor can be used for
distance measurement. The distance is determined via the strength of a
magnetic field. The relationship between magnetic field and distance is non-
linear. This non-linearity makes the calculation of the distance difficult. With
the help of a characteristic curve, the output value of the Hall sensor can first
be linearized before the values are calculated as input variables in the
algorithm.
Maps are often used instead of complex calculations. If, for example, there is a
relationship y = f(x) and the function f can only be determined with a great deal
of computational effort, it is often easier to calculate the values over the
possible range of x and to store the results in the form of a table. If the value x
is now fixed in the controller, the value y does not have to be calculated at
runtime of the controller, but the map supplies the result y to the input variable
x. The result y is then stored in a table. It may still be necessary to interpolate
between two values, but that would be all.
How is this characteristic curve stored in the memory? Do all x-values come
first and then all y-values? Or is the storage done according to the scheme: x1,
y1; x2, y2; x3, y3 ...? Since here different possibilities can be used in the code,
the way of the memory storage is described over a storage scheme in the A2L.
The convenience for the user results from the symbolic handling of the
quantities, the direct view of the physical values and the access to complex
elements such as maps without having to worry about complex storage
schemes.
Page 68
2.1. Structure of an A2L file
The A2L file is an ASCII readable file that uses keywords to describe the various
aspects:
Page 69
/begin AXIS_DESCR
FIX_AXIS NO_INPUT_QUANTITY BitSlice.CONVERSION 8 0 7
EXTENDED_LIMITS 0 7
READ_ONLY
BYTE_ORDER MSB_LAST
FORMAT "%.0
FIX_AXIS_PAR_DIST 0 1 8
/end AXIS_DESCR
/begin AXIS_DESCR
FIX_AXIS NO_INPUT_QUANTITY BitSlice.CONVERSION 8 0 7
EXTENDED_LIMITS 0 7
READ_ONLY
BYTE_ORDER MSB_LAST
FORMAT "%.0
FIX_AXIS_PAR_DIST 0 1 8
/end AXIS_DESCR
/begin IF_DATA CANAPE_EXT
100
LINK_MAP "map3_8_8_uc" 0xE0338 0x0 0 0x0 1 0x87 0x0
DISPLAY 0 0 255
/end IF_DATA
FORMAT "%.3
/end CHARACTERISTIC
The ASCII text is readable, but you need a deep understanding of all the
keywords to understand it. A description of the structure can be found in the
ASAM XCP Protocol Layer Specification. As a user of a tool like CANape,
however, you don't have to be familiar with it. You work on the CANape GUI
with the measurement and calibration variables. The way in which the objects
are described in the A2L is completely transparent to you.
The A2L essentially describes the contents of the memory of the XCP slave.
This in turn depends on the application located in it, which was developed as
C/C++ code. After the compiler/linker run of the application code, important
elements of an A2L file are already present in the linker MAP file: the name of
the objects, the data types, and the addresses in memory.
However, the linker map file lacks information such as the communication
parameters between the XCP master and slave. The minimum and maximum
Page 70
values of the parameters, the conversion rules between raw and physical
values and the storage schemes for characteristic curves and maps are also
missing.
Let's start by creating an empty A2L and the communication parameters: For
example, if you want to create an A2L that describes an ECU with XCP on CAN
interface, create a new device in CANape and select XCP on CAN as the
interface. Then you can add further communication-specific information (e.g.
CAN identifier). After saving, you have an A2L that contains the entire
communication part of the A2L. Now the definitions of the measurement and
calibration variables is still missing.
After a code change with compile and link, a new linker MAP file is present. The
addresses of the objects will have changed with a probability bordering on
certainty. Newly added objects can be integrated into the A2L again. In any
case, however, an address update in the A2L is necessary. This is done via
CANape or the ASAP2 Studio by mouse click. Using the name of the A2L object,
the corresponding entry is searched for in the linker MAP file, the address is
read out and updated in the A2L.
If your application changes very dynamically, objects are renamed, data types
are adjusted, parameters are deleted and others are added, then the manual
workflow is not practical. To generate an A2L from your code, other tools are
available for an automatic flow.
On the Vector homepage you can find information about the "ASAP2 Tool-
Set", with the help of which you can automatically generate A2Ls from the
source code in a batch process.
Page 71
2.3. A2L content versus ECU implementation
If an XCP master reads in an A2L file that does not completely match the ECU,
misunderstandings may occur in the communication. For example, the A2L file
may contain a different value for the timestamp resolution than the one
implemented in the ECU. If this is the case, the problem must be recognized
and solved. The user receives support from the master, which can ask the slave
via the protocol what was implemented in the slave.
XCP provides a set of functions designed for the automatic detection of the
slave. This assumes that automatic detection is implemented in the slave. If
the master asks the slave and the answers from the slave do not match the
data in the A2L description file, the master must decide which settings it will
use. With CANape, the information read from the slave has a higher priority
than the information from the A2L file.
Page 72
3. Calibration concepts
ECU parameters are constant variables that are adjusted and optimized
during the development of the ECU or an ECU variant. This is an iterative
process in which the optimum value of a parameter is found through repeated
calibrations and measurements.
The calibration concept answers the question of how parameters in the ECU
can be changed during the development and calibration phase of the ECU.
There is not only one calibration concept, but several. Which concept comes
into question usually depends strongly on the possibilities and resources of the
microcontroller used.
Normally, parameters are stored in the flash memory of the series ECU. The
underlying program variables are defined as constants in the software. To
make parameters changeable at runtime during development of the ECU,
additional RAM memory is required.
A calibration concept deals with the following questions, among others: How
do the parameters initially get from the Flash to the RAM? How is the
microcontroller's access to the RAM redirected? What is the solution if there
are more parameters than can be accommodated in the RAM at the same
time? How do the parameters get back to the Flash? Are changes to the
parameters persistent, i.e., are they retained when the ECU is turned off?
A distinction is made between transparent and non-transparent calibration
concepts. Transparent means that the calibration tool does not have to take
care of the above issues, since all necessary mechanisms are realized by the
ECU implementation. In the following, some procedures are briefly presented.
C code example:
The parameter "factor" represents a constant with the value 0.5. When
compiling and linking the code, a place in the Flash is provided for "factor". The
object is therefore assigned to an address that is in the data area of the Flash
memory. The value 0.5 is located at the corresponding address in the hex file.
In the linker MAP file there is the information name (factor), address and data
type.
Page 73
value change can only be made in the code and results in a compiler/linker run
with subsequent flashing. Alternatively, only the value in the hex file can be
modified and this can then be flashed again. CANape can do this. This is called
"offline calibration" of the hex file.
C code example:
Some ECUs have the option of storing data in a so-called EEPROM memory.
In contrast to Flash memories, EEPROM memories can erase and program
each memory cell individually. The available EEPROM memory is usually limited
to a few kilobytes. An EEPROM memory is often used, for example, to store
programmable parameters in the workshop or to implement a persistence
mechanism in the ECU, such as for the mileage. Online calibration would be
conceivable here, but it is rarely used because access to EEPROM cells is
relatively slow and EEPROM parameters are usually copied to RAM memory
during booting, where they can be accessed directly.
ECUs that do not have a physical EEPROM memory often implement a so-
called EEPROM emulation. Here, several small flash sectors are used
alternately to record parameter changes so that the last valid value can always
be determined. This would also make online calibration conceivable.
In both cases, the memory accesses concerned would then be intercepted in
the software component of the XCP driver and implemented with the software
routines of the EEPROM or the EEPROM emulation.
Page 74
3.2. Parameters in RAM
C code example:
Here it is specified that the parameter "factor" is a RAM variable with the
initial value 0.5. When compiling and linking the code, a place in RAM will be
allocated for the "factor" object and the corresponding RAM address will
appear in the linker MAP file. The initial value 0.5 is stored in flash memory.
During booting of the ECU all RAM variables are initialized once with their
initial values from the flash memory. This is mostly already performed in the
start-up code of the compiler manufacturer; the application programmer does
not have to take care of this. The application uses the values of the parameters
that are in RAM, and these can be modified via normal XCP memory accesses.
Calibration parameters in RAM are still immutable from the point of view of
the ECU software, i.e. the application itself does not change them. Many
compilers discover this fact by code analysis and simply optimize away the
required RAM memory space. Normally it is therefore also necessary here to
prevent the compiler from optimizing with the "volatile" attribute.
The RAM area where the parameters are located is called Calibration RAM
from the point of view of the calibration tool.
The Calibration RAM does not have to consist of a completely contiguous RAM
area. It can also be distributed over several areas or even arbitrarily. However,
it offers significant advantages to arrange the parameters in a few contiguous
RAM areas and to separate them from other RAM quantities, such as state
variables and intermediate results that can be changed by the application
software. This is especially important if an offline calibration of the Calibration
Page 75
RAM with a hex file should be possible. At the user's request, the calibration
tool must be able to load the variables changed offline into the ECU during the
transition from offline to online calibration.
This case occurs very often. For example, when an applicator reconnects to the
control unit on the next working day, he wants to continue working at the point
where he left off the previous evening. However, by booting the control unit,
the flashed content has been copied to the RAM as initial data. In order for the
user to continue working from the previous day, he must load his parameter
set file saved the previous evening into the RAM of the control unit. This loading
process can be optimized in terms of time by keeping the number of necessary
transfers to a minimum. For this purpose, it is advantageous if the tool can
quickly and reliably determine whether differences exist by checksum
formation over larger contiguous ranges. If there are no differences between
the calibration RAM contents in the ECU and the file modified by the tool, this
area does not have to be transferred. If the memory area containing the
calibration variables is not clearly defined, or if it contains variables that are
modified by the ECU software, checksumming always results in a difference
and the parameter values are transferred, either from the ECU to the XCP
master or in the opposite direction. Depending on the transfer speed and the
amount of data, the transfer takes several minutes.
The calibration tool can then either create flashable hex files of this range itself
or it directly relies on the original hex files of the linker to change the initial
values of the parameters in the hex file.
Page 76
mechanisms that serve exactly this purpose, many things are possible. In this
case, the parameters are created as parameters in the flash, as in calibration
concept 1. This method has enormous advantages over the described
calibration concept 2 "Parameters in RAM":
> Flash and RAM addresses are not differentiated. The A2L file, the hex
file and the linker MAP file always contain the flash addresses. This
provides clear relations, the Hex file is directly flashable and the A2L file
fits directly to it.
> The overlay can be switched on and off as a whole, which makes it
possible to switch between the values in Flash and those in RAM at
lightning speed. This is referred to as the RAM page and the Flash page
of a memory area (segment). XCP supports the control of memory page
switching with its own commands.
> If necessary, the memory pages can be switched separately for XCP
access and ECU access, i.e. XCP can access one memory page while the
ECU software works with the other. This allows, for example, the offline
calibration data to be downloaded to RAM while the ECU is still working
with the flash data, and avoids possible inconsistencies that can be
problematic with a running ECU.
> The overlay with RAM does not have to be complete and can be adapted
to the application. It is possible to operate with less RAM than with flash.
But more about this later.
A typical procedure for establishing the connection from the calibration tool to
the control unit with the subsequent download of offline calibrated values is as
follows:
If a difference has been detected during the checksum calculation via the RAM,
there is normally first a query to the user as to how to proceed. Should the
content of the ECU RAM be sent to the master or the content of a file on the
master side to the RAM of the ECU? If the user decides to write the offline
changes to the ECU, the further procedure is as follows:
Finally, the memory page is always switched to RAM so that parameters can
be changed. However, the user can also explicitly determine which memory
page should be active in the control unit. For example, the behavior of the RAM
Page 77
parameter set can be compared with the flash parameter set or, in an
emergency, it is possible to switch back to a tried and tested parameter set in
flash in a flash.
In this case, it is a good idea to carry out the overlaying of flash with RAM
dynamically and only overlay the affected flash memory area with RAM when
a parameter is actually written to. This process can take place with a certain
granularity and - depending on the implementation - is transparent for the
calibration tool from the XCP point of view. When the XCP driver in the ECU
detects a write access to the flash that would result in a change, part of the
calibration RAM is used to recopy the corresponding part of the flash and
activate the overlay mechanism for this part. For this purpose, the RAM is
allocated, i.e. permanently assigned and marked as occupied. However, the
resources of the calibration RAM are limited. During the calibration process, a
RAM area that has been allocated once is not released again, so that the
available calibration RAM runs out with further requests. If the RAM resource
is used up and a new allocation is requested, the user is notified of the
exhausted RAM resource. He is then offered the option of flashing or saving
the changes made so far. This frees up the allocated RAM area again and the
user can calibrate again. The variant that the control unit automatically flashes
the previously changed parameters is usually ruled out for the reasons already
mentioned in the calibration concept "Parameters in flash".
In some cases it may happen that the download of a parameter set created
offline is infeasible due to insufficient RAM resources. In this case, the only
option is to flash it. The user can undo the changes from the tool at any time,
freeing up the allocated RAM blocks.
Page switching between RAM and Flash Page is also possible with this concept
without any restrictions.
The parameters should be arranged in the flash in a functionally related
manner so that the available RAM blocks are used as efficiently as possible.
The software developer then determines that the variables that belong
together thematically are also located in a contiguous memory area. After
copying into RAM, the parameters necessary for tuning this function are
completely available.
Page 78
3.5. RAM pointer-based calibration concept according to AUTOSAR
The concept does not necessarily require the use of an AUTOSAR operating
system; it can also be used in a different environment - e.g. without an
operating system. The concept has a basic similarity to the previous one. The
main difference is that the replacement of flash with RAM is not realized by
hardware mechanisms, but by software mechanisms. The calibration
parameters are always referenced by the ECU software via pointers. Flash or
RAM contents are accessed by changing these pointers. The flash parameters
to be changed are copied into a specified block of free RAM. This procedure,
just like the previous ones, can be implemented completely transparently from
the XCP point of view. Alternatively, the user of the calibration tool explicitly
selects the quantities to be changed, for example by preselecting the desired
parameters. This has the advantage that the resource allocation and
utilization is visible to the user and he is not surprised in the middle of the work
by the situation that memory space is missing.
The pointer table is in the RAM. When booting the control unit, all pointers
point to the parameter values in the flash. The position and size of the
calibration RAM is known, but there are no parameter values in it after booting.
The application initially works completely from the flash.
If a user selects a parameter from the A2L file for the first time after booting
and wants write access to it, this first triggers a copy operation within the
controller. The XCP slave determines that the address to which access is to be
made is in the flash area and copies the value of the parameter to the
calibration RAM. To ensure that the application does not continue to fetch the
parameter value from the flash area but from the RAM area, an additional
change is made in the pointer table:
Page 79
Figure 62 Pointer change and copy to RAM
The application still gets the value of the parameter via the pointer table.
However, since the pointer now points to the RAM address, the value is fetched
from there. Thus, the user can change the value of the parameter via XCP and
observe the effect of the change via the measurement. The disadvantage of
this procedure is that an entry in a pointer table must be available for each
parameter, and this in turn is associated with a considerable additional RAM
memory requirement for the pointer table.
The next figure illustrates the problem. Three parameters of a PID controller
(P, I and D) are contained in the flash area of an ECU. The pointer table already
contains the RAM addresses and the parameter values in the RAM are also
changed.
Page 80
Example:
The calibration RAM should have a size of 400 bytes. Four structures with the
following sizes are defined in the software:
If the user selects a parameter from structure A, the 250 bytes are copied from
the flash to the calibration RAM and the user has access to all parameters
located in structure A via XCP. If the calibration task is limited to the
parameters of this structure, the calibration RAM is completely sufficient. If
the user now selects another parameter, but this is located in structure C,
these 120 bytes must also be copied to the calibration RAM. Since the 400
bytes in the calibration RAM are sufficient, the user can access all parameters
of structures A and C simultaneously.
One disadvantage of the single pointer concept is that memory page switching
is not easy to implement. Although the calibration tool could simply write the
pointer table completely for page switching, this is not feasible in an arbitrarily
short time, so that temporary inconsistencies and side effects can result. A
tool-transparent implementation would double the memory requirements for
the pointer table, since a copy of the previous pointer table with the RAM
pointers would have to be created when the memory page is switched to flash
memory.
Figure 60 Initial RAM data represents the pointer table. It is located in the RAM.
As already mentioned, this table must be copied from the flash to the RAM. So
this table is in the flash memory. If you now use another pointer (a table
pointer) that points either to the pointer table in RAM or in flash, you arrive at
the double pointer solution.
Page 81
Figure 64 Double pointer concept
The parameter values are initially accessed via the table pointer. If the table
pointer points to the pointer table in RAM, the application finally accesses the
actual parameters via the contents of the RAM pointer table. The low access
speed and the creation of more program code are the disadvantages of this
solution.
This method was patented a few years ago by ZF Friedrichshafen under the
name "InCircuit2" and has strong similarities with the pointer-based concept
according to AUTOSAR. Here, too, the ECU application accesses the
parameter data with the help of a pointer table. However, this pointer table is
not located in RAM, but in Flash. Changes to the pointer table can therefore
only be made by flash programming. A tool transparent implementation is not
possible. The advantage is the saved RAM memory for the pointer table. The
patent has been revoked in the meantime.
Page 82
4. Areas of application for XCP
XCP is not only applicable in embedded systems / ECUs. It can basically be used
in any system in which the code can be implemented.
The possibility of "external XCP slaves" is explained as a further area of
application. They enable powerful access to embedded systems.
The use of debuggers via XCP on embedded systems is also explained.
If you move along the development process, you come across the most diverse
approaches to solutions for the development of electronics and software. HIL,
SIL and rapid prototyping are keywords that describe different scenarios.
These always have a controlled system and a controller in common.
Page 83
4.1. MIL: Model in the Loop
In this development environment, both the controller and the controlled system
are simulated as a model. In the example shown, both models run in Simulink
as a runtime environment. The options of the Simulink runtime environment
are available for analyzing the behavior.
This requires neither a code generation step nor instrumentation of the model.
Timestamps are also sent via the XCP. CANape completely adapts to the time
behavior of the Simulink runtime environment. Whether the model runs faster
or slower than in real time is irrelevant. If, for example, the function developer
in the model uses the Simulink debugger to step through the model, CANape
still takes the time transmitted by XCP as reference time.
Page 84
4.2. SIL: Software in the Loop
In this development step, code is generated from the model of the controller,
which is then used in a computer-based runtime environment. Of course, the
controller may have been developed without any model-based approach. The
controlled system is still simulated. XCP can be used to measure and adjust the
controller. If the controller originates from a Simulink model, a code generation
step generates C code for a DLL and the associated A2L. If the controller
development is based on handwritten code, it is embedded in a C++ project
that is delivered with CANape.
After compiling and linking, the DLL is used in the context of CANape. With
support of the XCP link, the algorithms in the DLL can be measured and
adjusted just as if the application were already integrated in an ECU.
Page 85
4.3. HIL: Hardware-in-the-loop
HIL-systems are available in various forms. The following figure shows the
rough concept:
The controller algorithm runs on an embedded platform (e.g. the control unit),
the controlled system is still simulated. The controller is connected to the HIL
system via I/Os. Since it operates in real time, the HIL platform must also run
in real time. Data from the controller algorithm and from the controlled system
can be acquired or parameters can be adjusted via XCP.
Page 86
The terms "rapid" and "prototyping" describe the task very well. The aim is to
develop a functional prototype as quickly as possible, to use it on the runtime
environment and to test it. This requires simple work steps throughout the
entire process.
In the literature, the RCP approach is often divided into two areas: Fullpassing
and bypassing.
Not only the I/Os pose a challenge, but often functional elements of the ECU
software (e.g. network management) are needed to enable functioning in a
more complex network. However, if one uses a complete ECU for rapid control
prototyping instead of a general controller platform, the complexity of the
flash process, the scope of the overall software, etc. stand in the way of the
"rapid" requirement.
4.5. Bypassing
Bypassing is based on acquiring data from the ECU, processing it outside the
ECU, and writing the result back to the ECU. Since both measuring and writing
to the ECU must be done synchronously with the ECU processes, DAQ and
STIM mechanisms are used. So at least two DAQ lists are needed: One with
the direction DAQ (from slave to master) and another with the direction STIM
(from master to slave).
In the Figure 73 Basic principle of bypassing the control unit is connected to the
controlled system. The necessary I/Os and software components are available
in the ECU. In the bypassing hardware, an algorithm A1 is running, which is
present in the ECU in the version A. A' is a new variant of the algorithm and is
now to be tested on the real controlled system.
Page 87
Figure 73 Basic principle of bypassing
The bypassing hardware and the ECU are connected to each other via XCP. On
the one hand, this involves fetching the data required for algorithm A' from the
ECU via DAQ, and on the other hand, stimulating the results of A' back into
the ECU. The following figure demonstrates the schematic flow:
A blue function block is shown in the ECU, in which algorithm A runs. In order
that A' can now be used, the data that enters algorithm A as an input variable
is measured out of the ECU by DAQ.
Step 1: In the ECU, the data is acquired and sent to the bypassing tool before
algorithm A is calculated in the ECU. Normally, the input data to function A
and function A' are identical.
Page 88
Step 3: The results of the calculation of algorithm A' are transferred to the
bypassing tool.
Step 4: The data is transferred to the ECU via STIM. During this time, the ECU
calculates algorithm A. When the stimulated results are available and the
calculation of algorithm A is finished, the values calculated in the ECU are
typically overwritten with the stimulated values of algorithm A'.
Thus, the calculation of algorithm A' and not A was used in the overall flow of
the ECU. This method allows the combination of the fast ("rapid") exchange
of the algorithms on the bypassing hardware with the use of the I/Os and the
basic software of the ECU.
The performance limits of the transport protocol naturally also have a limiting
effect on the bypass. If short bypassing cycles are required, access via DAQ and
STIM into the ECU can also be made via debugging or trace interfaces of the
controller. The Vector VX1000 measurement and calibration hardware
converts the data from the controller interface into an XCP on Ethernet data
stream.
Figure 75 Bypassing with real-time bypassing hardware and fast ECU access
In the illustration, ECU access is via XCP on Ethernet and the bypass algorithm
is calculated on a separate bypassing hardware (e.g. VN8900 family) with real-
time operating system. This means that the variance of the calculation time is
much smaller than with a calculation on a laptop, since there is no influence on
the calculation time by other applications.
Page 89
4.6. Shortening iteration cycles with virtual ECUs
In order to optimize the algorithm in the ECU with the help of XCP, stimulation
with data is necessary. The process can take place during test drives in the
ECU. However, XCP also provides another solution in which the algorithm does
not run on an ECU, but in the form of executable code on the computer or as a
model in Simulink in the form of a "virtual ECU". This virtual ECU does not have
to run in real time, since in this case there is no coupling to a real system. It can
run much faster - depending on the computing power of the PC.
After the end of the calculation, a new measurement file is available to the user
for analyzing the behavior of the control unit. The time length of the new
measurement file corresponds exactly to the length of the input measurement
file. If the duration of a test drive is one hour, for example, the algorithm on the
computer calculates the entire test drive in a few seconds. Then there is a
measurement result corresponding to a test of one hour duration. From the
analysis of the data, the user makes decisions for parameterization and the
iteration cycle starts again.
Page 90
Figure 77 Process flow with virtual control units
Page 91
The POD (Plug-on-Device) is installed in the embedded system and connected
to the debugging or trace interface of the controller. The POD serializes the
data and sends it to the remote base module.
A VX1000 base module receives the data from the POD. Via Ethernet, the base
module offers two XCP on Ethernet slaves. If an XCP master connects to one
of the XCP slaves, it has full access to the data in the controller.
In addition to measurement, all other use cases such as calibration and flashing
are also supported.
Figure 78 Integrated POD in the control unit with external XCP slave.
The VX1000 product family offers many different POD and base modules. You
can find more information here.
For these cases, the XCP standard was extended in version 1.5 to include the
topic of software debugging via XCP. This created significant added value for
the development of embedded systems:
> Uniform hardware for all application areas reduces costs and
complexity.
> Robust solution with automotive temperature range.
> The debugging configuration does not require any extension of the ECU
software.
Page 92
Figure 79 Debugger via XCP
Page 93
5. Exemplary XCP implementation
The XCP protocol layer is based on the XCP transport layer, which in turn is
based on the actual bus communication.
The software interface between the transport and protocol layers is very
simple. It includes only a few functions:
> If the slave receives an XCP frame via the bus, it first arrives in the
communication driver, which forwards the frame to the XCP transport
layer. Via the function call XcpCommand() the transport layer informs
the protocol layer about the frame.
> If the XCP protocol layer wants to send information (e.g. a response to
an XCP command from the master or a DAQ packet), the content is
forwarded to the transport layer via the ApplXcpSend() function.
> The transport layer notifies the protocol layer that the information was
successfully sent by calling the XcpSendCallBack() function.
Page 94
The interface between the application and the protocol layer can also be
implemented using only four functions:
> The application activates the XCP driver with the help of XcpInit(). This
call is made once during the startup process.
> XcpEvent(y) informs the XCP driver that event y has occurred.
> The XcpBackground() call allows the XCP driver to perform certain
activities in the background (e.g. calculating a checksum).
> Since addresses are always defined as 40-bit values in A2L files (32-bit
address, 8-bit address extension), the XCP driver uses the
ApplXcpGetPointer() function to get a pointer from an A2L-compliant
address.
Task:
Initialization of the XCP driver
Description:
With XcpInit() the application activates the XCP driver. This command must
be executed exactly once before any XCP driver function may be called.
Task:
The application informs the XCP driver which event has occurred. Each event
is assigned a unique event number.
Description:
When compiling the measurement configuration in the measurement and
calibration tool, the user selects which measurement values are to be acquired
synchronously with which event. The information about measured values and
events comes from the A2L. The desired measurement configuration is
communicated to the XCP driver in the form of DAQ lists.
Page 95
XcpEvent (8); // Event 8 is used for ignition angle synchronous
measurements.
Task:
Performs background activities of the XCP driver.
Description:
The function should be called periodically in a background or idle task. It is used
by the XCP driver for checksum calculation, for example, since the calculation
of a longer checksum in XcpCommand() could take an unacceptably long time.
With each call to XcpBackground() a partial checksum of 256 bytes is
calculated. The duration of a checksum calculation therefore depends on the
call frequency of XcpBackground(). Otherwise there are no requirements for
the call frequency and periodicity. The return value 1 indicates that a checksum
calculation is currently running.
Task:
Interpretation of an XCP command.
Description:
Each time the transport layer receives an XCP frame, this function must be
called. The parameter is a pointer to the frame.
Task:
Passing a frame to be sent to the transport layer.
Description:
The protocol layer sends the information via this call, which is then sent to the
master via the transport layer. Via the call XcpSendCallBack a handshake
procedure between protocol and transport layer is realized.
Task:
With the callback, the transport layer informs the protocol layer about the
successful sending of the last frame passed to ApplXcpSend().
Description:
The protocol layer will not call any ApplXcpSend() command until it is indicated
via XcpSendCallBack() that the previous information was sent successfully.
Page 96
XcpSendCallBack() returns the value 0 (FALSE) if the XCP driver is idle. If there
are more frames to be sent, ApplXcpSend() is called directly from
XcpSendCallBack().
Task:
Conversion of an A2L compliant address into a pointer.
Description:
The function maps the 40-bit A2L-compliant addressing (32-bit address + 8-
bit address extension) sent by the XCP master to a valid pointer. The address
extension can be used, for example, to distinguish between different address
ranges or memory types.
/* Enable calibration */
#define XCP_ENABLE_CALIBRATION
#define XCP_ENABLE_SHORT_UPLOAD
For a CAN transport layer the appropriate CTO and DTO size of eight bytes is
set. The driver must know whether it runs on a platform with Motorola or Intel
byteorder, in this case a Motorola CPU (big-endian). The remaining parameters
activate the functionalities: Measure, Adjust and Checksum Calculation. For
the checksum calculation the algorithm is set (here summation of all bytes into
a dword) and for measuring the size of the available memory is specified (here
512 bytes). The memory is mainly needed to store the DAQ lists and to buffer
Page 97
the data during the measurement. The size therefore determines the
maximum possible number of measurement signals.
Page 98
6. Overview of the protocol development
All extensions are optional. Thus, XCP 1.1 is compatible with XCP 1.0.
> Parameters in the A2L for the definition of the required ECU resources
by XCP DAQ measurement configurations (e.g. RAM consumption, CPU
execution time, required transmission bandwidth for transport via CAN
or Ethernet). XCP Master can access the parameters and calculate the
resource consumption of the measurement and warn the user if it is
exceeded, for example.
> Prioritization control by the master to transport the measurement data
via CAN. The objective here is to avoid disturbing the necessary
communication flow of the vehicle CAN as much as possible.
> Calculation of the required bandwidth and limits when transporting
data via TCP or UDP.
> Description of XCP on CAN FD.
All extensions are optional. Thus, XCP 1.2 is compatible with XCP 1.1.
> Improve time correlation of XCP slaves through multicast solutions that
are on the same network.
> Time synchronization between XCP slave timestamp and external clock
(e.g. via IEEE1588)
> Checking the bypassing data flow and error handling
Page 99
All extensions are optional. Thus, XCP 1.3 is compatible with XCP 1.2.
All extensions are optional. Thus XCP 1.4 is compatible to XCP 1.3.
Page 100
6.5. XCP Version 1.5 (2017)
> Software Debugging over XCP (DBG)
All extensions are optional. Thus XCP 1.5 is compatible to XCP 1.4.
Page 101
List of abbreviations
Page 102
Download Sending data from master to slave
Upload Send data from slave to master
Page 103
Bibliography
You can find details about the protocol and ASAM at www.asam.net.
Web addresses
Standardization bodies:
> ASAM, XCP protocol-specific documents, A2L specification,
www.asam.net
Page 104
List of Figures
Figure 1 Classic process flow when developing applications for embedded systems 6
Figure 2 Process flow when developing applications for embedded systems with the XCP standard 6
Figure 3 The interface model of ASAM 7
Figure 4 Universal access via the development process 8
Figure 5 Division of the XCP protocol into protocol and transport layers 9
Figure 6 XCP communication model with CTO and DTO 13
Figure 7 Standard CTO exchange 14
Figure 8 Master Block Transfer Mode 15
Figure 9 Slave Block Transfer Mode 15
Figure 10 Interleaved Communication Mode 16
Figure 11 XCP package 16
Figure 12 The package identification 17
Figure 13 Overview of the XCP Packet Identifier (PID) 18
Figure 14 Counter Field 18
Figure 15 Timestamp 18
Figure 16 Data field in XCP package 19
Figure 17 Overview of the structure of the CTO package 21
Figure 18 Trace representation of an adjustment process 26
Figure 19 Transfer of a parameter set file into the RAM of the control unit 28
Figure 20 Address information of the size "Triangle" from the A2L file 29
Figure 21 Polling communication in CANape's Trace Window 30
Figure 22 Events in the ECU 31
Figure 23 Examples of event definitions 32
Figure 24 Assignment of "Triangle" to the possible events in the A2L 32
Figure 25 Selection of events (Measurement mode) per measurand 32
Figure 26 Excerpt from the CANape Trace window of a DAQ measurement 33
Figure 27 Assignment of RAM addresses to ODT 34
Figure 28 DAQ list with three ODTs 35
Figure 29 Transmission of signals 1-10 with timestamp 35
Figure 30 Static DAQ lists 36
Figure 31 Dynamic DAQ lists 37
Figure 32 Transmission of five measured values of signals S1 and S2 in one ODT each 37
Figure 33 Event for DAQ and STIM 38
Figure 34 Structure of XCP package for DTO transmissions 39
Figure 35 Identification field with absolute ODT numbers 39
Figure 36 ID field with relative ODT and absolute DAQ numbers (two bytes) 40
Figure 37 ID field with relative ODT and absolute DAQ numbers as well as fill byte (total four bytes) 40
Figure 38 First stage of time synchronization 43
Figure 39 Second stage of time synchronization 43
Figure 40 Free-running clock in XCP slave 46
Figure 41 XCP Slave Clock synchronized with Grandmaster Clock 46
Figure 42 Slave clock syntonized with Grandmaster Clock 47
Figure 43 Free running clock combined with synchronized clock 47
Figure 44 Two clocks with triggered EV_TIME_SYNC shipping 48
Figure 45 Determination which bus station sends which frames 49
Figure 46 Representation of a CAN network 50
Figure 47 Example of XCP on CAN communication 51
Figure 48 Nodes K and L are redundantly connected to each other 53
Figure 49 Communication via slot definition 53
Figure 50 Representation of a FlexRay communication matrix 54
Figure 51 Representation of the FlexRay LPDUs 55
Figure 52 Assignment of XCP communication to LPDUs 56
Figure 53 XCP packet with TCP/IP or UDP/IP 57
Figure 54 XCP on SxI package 58
Figure 55 Memory representation 60
Figure 56 Illustration of the driver setting for the Flash area 62
Figure 58 Parameters in an adjustment window 67
Figure 59 Signal display over time 67
Figure 60 Initial RAM data 75
Figure 61 Initial situation after booting 79
Figure 62 Pointer change and copy to RAM 80
Figure 63 Pointer table for individual parameters 80
Figure 64 Double pointer concept 82
Figure 65 Areas of application and use cases 83
Figure 66 Controlled system (plant) and regulator (controller) 83
Figure 67 Model-in-the-loop in Simulink 84
Figure 68 CANape as a measurement and calibration tool with Simulink models 84
Figure 69 Software-in-the-loop with Simulink environment 85
Page 105
Figure 70 CANape as SIL development platform 85
Figure 71 HIL solution 86
Figure 72 RCP solution 86
Figure 73 Basic principle of bypassing 88
Figure 74 Bypassing sequence 88
Figure 75 Bypassing with real-time bypassing hardware and fast ECU access 89
Figure 76 Short calibration cycles with virtual controllers 90
Figure 77 Process flow with virtual control units 91
Figure 78 Integrated POD in the control unit with external XCP slave. 92
Figure 79 Debugger via XCP 93
Figure 80 Integration of the XCP slave in the ECU code 94
Page 106
Appendix - XCP Solutions at Vector
The XCP standard was significantly shaped by Vector. The extensive know-how
and many experiences flowed into the comprehensive XCP support:
Tools
> CANape: The XCP Master. With integrated ASAP2 Studio as A2L Editor.
> ASAP2 Tool-Set: Complete tool chain for batch-controlled generation of
A2L description files. Including ASAP2 Studio as A2L editor.
> CANoe.XCP: extends CANoe with the ability to communicate with
embedded systems via XCP for test and analysis tasks.
> VX1000: Comprehensive hardware family for implementing external
XCP slave solutions. The hardware is connected to the embedded system
via debugging and trace interfaces of the controllers and processors. In
the direction of the measurement and calibration tool, communication
takes place via XCP.
Embedded software
> XCP Basic driver for Ethernet (Windows and Linux) free for download.
> XCP Professional: ideal solution for those who want to purchase an
integrated XCP driver along with the basic Vector software.
> MICROSAR XCP - contains the functional scope of XCP Professional and
is based on the AUTOSAR specifications. Available for the Vector basic
software MICROSAR.
Services
> Consulting on the use of XCP in your projects
> Support for the integration of XCP
Trainings
> On the Vector E-Learning platform you will find a free training course on
XCP.
> The Vector Academy also offers an XCP seminar.
Page 107
Subject index
A G
A2L ............................................................................... 67 GET_CAL_PAGE ........................................................ 61
Adress Extension ..................................................... 26, 30 GET_COMM_MODE_INFO ....................................... 64
ALLOC_ODT ............................................................... 36 GET_DAQ_CLOCK_MULTICAST ............................ 45
AML ........................................................................ 21, 69 GET_DAQ_EVENT_INFO .......................................... 64
ASAP2 Tool-Set............................................................ 71 GET_DAQ_PROCESSOR_INFO ................................ 64
GET_DAQ_RESOLUTION_INFO .............................. 64
GET_STATUS.............................................................. 64
B
Bandwidth optimization ................................................ 30 H
Bypassing ................................................................ 40, 87
HIL................................................................................ 86
C
L
CAL............................................................................... 13
CAN .............................................................................. 49 LIN................................................................................ 59
CAN FD ........................................................................ 51 LPDU ............................................................................ 54
CMD ....................................................................... 13, 21
CTO............................................................................... 12
CYCLE_REPETITION ................................................. 54 M
MAX_CTO ................................................................... 17
D MAX_DTO ................................................................... 17
MIL ............................................................................... 84
DAQ .................................................................. 13, 29, 30
DAQ List Dynamic ....................................................... 36
DAQ List Predefined ..................................................... 36 O
DAQ List Static ............................................................. 35
DATA Field .................................................................. 19
OFFSET ........................................................................ 54
DBG .............................................................................. 13
DOWNLOAD ............................................................... 26
DTO .............................................................................. 12
P
E Packed Mode................................................................. 37
Page switching .............................................................. 61
Payload ......................................................................... 34
ERR ......................................................................... 13, 24
PGM.............................................................................. 13
EV13, 25
PID ................................................................................ 17
EV_TIME_SYNC ......................................................... 45
POD .............................................................................. 91
Event ............................................................................. 31
Polling ........................................................................... 29
F R
Fash memory ................................................................. 10
RAM ............................................................................. 11
Fibex ............................................................................. 53
Reboot........................................................................... 28
Flash memory .......................................................... 59, 60
RES ......................................................................... 13, 24
FLX_CHANNEL .......................................................... 54
RESUME ...................................................................... 65
FLX_LPDU_ID............................................................. 54
FLX_SLOT_ID ............................................................. 54
Fullpassing .................................................................... 87
S
Seed-and-Key................................................................ 65
SEGMENT_NUMBER................................................. 60
Page 108
SERV ...................................................................... 13, 25 TIME_CORRELATION_PROPERTIES ............... 45, 46
SET_CAL_PAGE ......................................................... 61
SET_MTA ..................................................................... 26
SHORT_UPLOAD.................................................. 27, 29 U
SIL................................................................................. 85
Status Information ......................................................... 14
UDP/IP.......................................................................... 56
STIM ................................................................. 13, 29, 38
USB .............................................................................. 58
SxI ................................................................................. 58
T V
VX1000......................................................................... 89
TCP/IP........................................................................... 56
VX1000 Base Modul .................................................... 91
Page 109
Get More Information
www.vector.com