This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F28379D: Implementation of XCP on CAN For C2000

Part Number: TMS320F28379D

<Introduction>

XCP is a common requirement from automotive OEMs. I’ve found that Implementing XCP-on-CAN for a C2000 device is far from straightforward and there doesn’t seem to be much information publicly available so this post is to improve on that situation. The complicating factor is the C2000 Minimum Addressable Unit (MAU) of 16 bits. XCP has a setting called ADDRESS_GRANULARITY (AG) which can be set to WORD instead of the usual BYTE. The intention behind this (I think) was to make XCP adaptable to architectures where the MAU is not 8bits. The problem is that the MCD (Measurement Calibration, Diagnostic) tools I have tried do not support AG=WORD. For example, Vector CANape.

https://support.vector.com/kb?id=kb_article_view&sysparm_article=KB0012595

 

MathWorks have implemented XCP with CANape but this is only of use when your entire project is MATLAB/Simulink based such that Simulink generates the A2L file and updates its addresses from the ELF file.

https://uk.mathworks.com/help/ti-c2000/ug/calibrate-ecu-can-example.html

That’s fine for individual developers but no good for a large collaborative project consisting of auto-coded and hand coded modules with multiple toolchains.

 

There’s probably other ways to solve this but here’s how I got XCP-on-CAN to work on F2800039C, although this should be applicable to any C2000 device. Feel free to post a simpler solution or challenge any of the following.

<Implementation Background>

By default, XCP A2L address n and address n+1 differs by 8 bits (AG=BYTE). For the C2000 device, address n and n+1 differs by 16 bits (AG=WORD). The question then is how the C2000 XCP slave (AG=WORD) can emulate AG=BYTE in order to talk to the XCP master? The general solution (not my invention) is to multiply all physical device addresses by 2 such that:

  • A2L Address = Device Address x 2.
  • Device Address = A2L  Address / 2.

 

Historically CANape supports this addressing scheme through an expert setting called DSP_MODE, presumably in lieu of XCP AG=WORD mode. CANape DSP_MODE stored all addresses in its ASAP2 database as 2 x the physical device address. When CCP sent a CRO containing an address to the slave it would first divide the A2L database address by 2 before sending the CRO. The C2000 slave therefore receives a meaningful physical address which can be dereferenced without further processing. However, CANape DSP_MODE is only available for a CCP device, the setting is not there for an XCP device. Furthermore address update in CANape is only possible with the legacy COFF linker output, EABI doesn’t work.

 

So the XCP solution (Vector CANape CCP DSP_MODE emulation) described here has three practical aspects:

  1. The A2L file creation/address update stage shall double the physical addresses extracted from the CCS EABI .out file.
  2. In operation, the XCP slave shall halve the received A2L addresses to calculate a Device Address before being dereferenced.
  3. An even A2L Address shall access the lower octet of the Device Address. An odd A2L address shall access the upper octet of the Device Address.

 

The benefit of this scheme is that it is totally hidden from the XCP Master so is portable to any MCD tool with the same A2L file. I happen to be using CANape but if you want a free of charge MCD tool for basic XCP testing, I recommend checking out ASAP2Demo. https://jnachbaur.de/ASAP2Demo/ASAP2.html

 

<Example Address Mapping>

Source declarations:

 

Fullscreen
1
2
3
4
5
Uint16_t XCP_TEST_UBYTE1 = 0x0011;
Uint16_t XCP_TEST_UBYTE2 = 0x0022;
uint16_t XCP_TEST_UWORD = 0x4433;
uint32_t XCP_TEST_ULONG = 0x88776655;
uint64_t XCP_TEST_UINT64 = 0x10FFEEDDCCBBAA99;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

The example CHARACTERISTICS are being placed in GSRAM0 starting at address 0x0000C000 by the linker.

Device and A2L Address Mapping After Linking and A2L Creation:

View in CANape:

<Suggested Implementation Steps>

Step 1) Get Vector’s XCP Sample Implementation.

Step 2) Make XCP slave source modifications for halving addresses. See attached patch file.

Step 3) Integrate into your application and CAN transport layer code.

Step 4) Make your A2L file as usual but arrange for the addresses in the A2L file to be double the addresses in the linker .out file. This is the trickiest part for which I wrote a Python script.

Step 5) Use your MCD tool with a regular XCP-on-CAN device (AG=BYTE). As far as the MCD tool is concerned, the slave will behave like a device where MAU=8bits like most other ECUs.

<Detailed Steps>

 

 xcp_patch.zip

  • Integrate to your application:
    • Call XcpInit() once.
    • Call XcpEvent(x) when event x occurs.
    • Call XcpCommand() when the slave receives a CTO from CANape.
    • Implement code to send a DTO when ApplXcpSend() is called.
    • Call XcpSendCallBack() when the DTO in the previous step has been successfully transmitted.

 

  • Make your A2L file as usual but arrange for the addresses in the A2L file to be double the physical addresses in the linker .out file. Some solutions:
    • Vector CANape: I use Vector’s ASAP2 Tool-Set v15 (ASAP2Updater.exe) to update addresses. I discovered by accident that if I choose MAP_FORMAT = 131 (ELF/DWARF Extended) the addresses are doubled for me. This behaviour is controlled by option ELF_ADDRESS_MODE=WORD. Note that selecting the same MAP format (131) does not work correctly when CANape map update feature is used. Maybe it works in a later version.
    • ASAP2Demo: It has a paid for A2L/ELF synch add-on option but at the time of writing the 2 x address feature is not yet available for the C2000 parser but has been requested. I don’t know if it will ever materialise.
    • Script: Below is a Python script to apply after your regular address update tool has completed. It’s crude but works.
  • Use MCD Tool as usual. e.g. CANape.

Python Script

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# Python program to double the addresses (starting "0x") of MEASUREMENTs and CHARACTERISTICS
# in an A2L file.
# Tested with Python 3.10.
import sys
# Use Regex pattern matching.
import re
def main():
try:
in_file = open(sys.argv[1], "r")
out_file = open(sys.argv[2], "w")
# Read the input file line by line.
lines = in_file.readlines()
new_list = []
idx = 0
found_IF_DATA = False
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX