XCP on TCP on a NUCLEO-H723ZG: measurement, stimulation and calibration maps

The Examples folder next to QInsight.exe contains two projects of this example, one for each firmware image of the QFW SDK:

ProjectFirmware imageSDK chapter
Qenex_TcpClient_XCP_NucleoH723_Maps_FreeRTOS.qprojexamples/nucleo_h723zg, preset Debug (FreeRTOS + lwIP)Integration: XCP on TCP
Qenex_TcpClient_XCP_NucleoH723_Maps_BareMetal.qprojexamples/nucleo_h723zg_baremetal, preset Debug (no RTOS, lwIP RAW API)Integration without an RTOS

The two projects have the same content — the same driver, events, variables, scripts and workspace; they differ only in the addresses of five variables that live at different places in the two images (the uwTick counter and the four matrix objects). From QInsight's point of view the board behaves the same in both cases.

Unlike the simulation examples, QInsight talks to a real device here: a NUCLEO board with an XCP slave, connected over Ethernet. One project shows every mode of the XCP on TCP protocol — DAQ, polling with writes, STIM and the transfer of Matrix variables in block mode — plus the behaviour of the TCP Client driver when the connection breaks.

The "Nucleo H723 live + maps" workspace while running — sines from the board, the ignition map, the Watch Table and the torque curveThe "Nucleo H723 live + maps" workspace while running — sines from the board, the ignition map, the Watch Table and the torque curve

What the example shows

  • DAQ measurement — the firmware generates three sines (sine1–sine3) and transmits their values by itself from the event channel demo10ms every 10 ms; QInsight sends no requests.
  • Polling of calibration parameters — the amplitudes and periods of all three sines are read every 500 ms and can be written at any time; the firmware reacts to a change immediately.
  • STIM streaming — a periodic script computes a slow sine in percent and QInsight sends it to the board as a stream of STIM packets, to the address of sine1_value, in the same event channel the board measures with.
  • The sine1_bypass switch — decides who owns the sine1_value signal: 0 = the board's internal model, 1 = the master via STIM.
  • The raw/value split — sine1_raw is the output of the internal model (computed every cycle, even during bypass), sine1_value is the published signal. Both curves sit side by side in the graph, so the bypass is visible at a glance.
  • A map read on request — the 16 × 16 ignition advance map (float, 1072 B) is bound to an On Request event: it is not read periodically; the whole block is fetched by the Read button of the Matrix control.
  • A polled curve — the eight-point torque curve (32 B) is read every 500 ms as one block.
  • A large 64 × 64 map — 16,640 B, the largest block QInsight transfers over XCP; it is read on request as a series of UPLOAD bursts.
  • Cell calibration — in Write Mode you edit cells and axis breakpoints; only the changed cells are written to the board (adjacent cells are merged into one DOWNLOAD block).
  • Feedback from the firmware — the scalar qfwDemoMapOut ("Map lookup") is computed by the firmware every 10 ms as the sum of one cell of each matrix object, so a written cell shows up in the Watch Table.

What you need

  • A NUCLEO-H723ZG board with one of the two images of the QFW SDK example firmware (table above) and the matching project. Both images contain the demo signals and the matrix objects of app/src/demo_map.c, and the slave reports block mode.
  • An Ethernet connection to the board. The project expects the address 192.168.2.20, port 5555 — adapt it in the driver settings to your network (the PC must be in the same subnet).
  • Variable addresses matching your firmware build. The addresses are absolute (address extension 0) and come from the ELF file: the tools/elf_vars_scan.py tool of the SDK package reads them with the configuration nucleo_h723zg.vars.json (or nucleo_h723zg_baremetal.vars.json) from the example folder and produces a QInsight import file (Home → Project Configuration → Variables → Import); arrays are exported as Matrix variables with the X-axis address in the description. After every firmware build refresh the addresses and overwrite them in the project — otherwise QInsight reads and stimulates the wrong places in memory. The procedure is described in Variable addresses for QInsight.

The project

The project contains one TCP Client driver with the XCP on TCP protocol, four events, seventeen variables, two scripts and the workspace Nucleo H723 live + maps with four controls.

Driver and protocol

One TCP Client driver with one instance of the XCP on TCP protocol underneath — the board is the TCP server, QInsight the client.

Driver settings:

ParameterValueMeaning
ip192.168.2.20address of the board
port5555TCP port of the XCP slave
connectionTimeoutMs1500how long to wait for the connection to be established — short on purpose: after a cable pull the first attempt usually starts while the link is still negotiating, and the next attempt follows after reconnectDelayMs
reconnectDelayMs1000delay between reconnection attempts
reconnectAttempts3after three failed attempts in a row the driver stops trying (the default -1 retries without limit)
keepAliveMs5000after 5 s without traffic TCP keepalive checks the connection — detects an unplugged cable

Protocol settings:

ParameterValueMeaning
requestTimeoutMs1000response timeout of one XCP command
requestRetries2repetitions of a command after a timeout (in addition to the first attempt)
daqTimestampsslavetime axis of DAQ samples from the board clock (µs stamps from the QFW SDK)

The protocol timeouts concern only the command/response exchange; establishing and recovering the TCP connection is the driver's job.

Block mode is not configured — the protocol detects it at connect and logs it, e.g. XCP: block mode — slave yes, master yes (MAX_BS 255, MIN_ST 0 × 100 µs). On TCP (MAX_CTO 248) a 1 KB map is one UPLOAD burst of five packets.

Events

Four events decide the mode of every variable:

EventTypeExtra ParamsUsed for
Daq_demo10msPeriodic 10 msdirection="DAQ";daqId="0"DAQ — the board transmits the sines by itself from the demo10ms channel
Stim_demo10msPeriodic 10 msdirection="STIM";daqId="0"STIM — the master streams sine1_stim into the same channel every 10 ms
Poll500msPeriodic 500 ms—polling of the parameters, the bypass switch, the uwTick counter, the curve and qfwDemoMapOut
OnRequestOnRequest—maps read by the Read button

DAQ and STIM target one and the same firmware event channel (daqId 0). The board stores received STIM packets and writes them into memory inside the event trigger — at the same moment it samples DAQ. For the DAQ event the period controls nothing (it only documents the channel cycle; QInsight compares it with the board's figure); for the STIM event it is the real transmit interval.

Scalar variables

Thirteen scalar variables; all float except uwTick (uint) and sine1_bypass (byte). Address extension is 0 everywhere. The addresses inside the gDemoSignals block are the same in both images; only uwTick differs:

VariableAddressDirectionEventPresentation (conversion)
sine1_value0x2400005CreadDaq_demo10msSine value −10…10 (PassThrough)
sine1_raw0x24000058readDaq_demo10msSine value (PassThrough)
sine2_value0x24000074readDaq_demo10msSine value (PassThrough)
sine3_value0x2400008CreadDaq_demo10msSine value (PassThrough)
sine1_amplitude0x24000050readWritePoll500msAmplitude 0…10 (PassThrough)
sine1_period0x24000054readWritePoll500msPeriod 0.05…60 s (PassThrough)
sine2_amplitude0x24000068readWritePoll500msAmplitude (PassThrough)
sine2_period0x2400006CreadWritePoll500msPeriod (PassThrough)
sine3_amplitude0x24000080readWritePoll500msAmplitude (PassThrough)
sine3_period0x24000084readWritePoll500msPeriod (PassThrough)
sine1_bypass0x24000060readWritePoll500msBypass 0/1 (PassThrough)
sine1_stim0x2400005CwriteStim_demo10msStim level 0…100 % (StimPercent)
uwTickFreeRTOS 0x24000124 / bare metal 0x2400011CreadPoll500msHAL tick, ms (PassThrough)

Worth noticing:

  • sine1_stim and sine1_value have the same address — the stimulation writes straight into the location the board publishes; only the direction and the event differ.
  • The StimPercent conversion (multiplier=5, offset=50) maps the raw range ±10 to 0–100 %: an entered 75 % gives raw 5.0, 50 % is zero. The write is entered as an engineering value and QInsight inverts it before sending (see Conversion and presentation).
  • uwTick is the millisecond HAL tick counter of the STM32 — it lies outside the gDemoSignals block and proves that any global variable from the ELF is reachable over XCP.
  • Firmware defaults of the sines: sine 1 amplitude 1.0 / period 1 s, sine 2 amplitude 5.0 / 3 s, sine 3 amplitude 0.5 / 10 s. A period below 0.05 s is clamped by the firmware.

Matrix variables

Four calibration-data variables, all little-endian, address extension 0:

Variable (Label)Shape and typesSizeAddress FreeRTOSAddress bare metalDirectionEvent
qfwDemoMap (Ignition map)16 × 16 float map; X axis ushort (rpm), Y axis byte (load)1072 B0x240142800x24008FC0readWriteOnRequest
qfwDemoCurve (Torque curve)8-point ushort curve, X axis ushort (rpm)32 B0x240146B00x240093F0readWritePoll500ms
qfwDemoBigMap (Injection map 64x64)64 × 64 float map; X and Y axes ushort16,640 B0x240146D00x24009410readWriteOnRequest
qfwDemoMapOut (Map lookup)float scalar4 B0x240187D00x2400D510readPoll500ms

A matrix address points to the start of the block, i.e. to the X axis; the Y axis and the data row by row follow in memory (see Matrix variables over XCP).

Presentations of the axes and data:

PresentationRangeUnitUsed for
RpmAxisPres0–8000rpmX axis of all three matrices
LoadAxisPres0–100%Y axis of qfwDemoMap
LoadTenthAxisPres0–100%Y axis of qfwDemoBigMap — conversion LoadTenth (×0.1), raw is in tenths of a percent
AdvancePres0–40degdata of qfwDemoMap
TorquePres0–300Nmdata of qfwDemoCurve
InjectionPres0–1100mgdata of qfwDemoBigMap
MapOutPres0–2500—qfwDemoMapOut

Firmware defaults: the ignition map has an X axis of 800–6800 rpm and a Y axis of 0–90 %, the curve an X axis of 1000–6600 rpm and values of 120–225 Nm, the large map an X axis of 500–6800 rpm.

Scripts

init.py in Startup mode prepares the generator state — time, amplitude and frequency of the stimulation sine:

import math
t = 0
a = 40
f = 1/5

script.py in Periodic mode (period=20;unit=ms) advances the time by 20 ms and writes a new value in percent:

t += 0.02
sine1_stim.EngValue = 50 + a * math.sin(2 * math.pi * f * t)

The result is a 10–90 % sine with a period of 5 s, i.e. raw ±8. The script writes EngValue; QInsight performs the inverse conversion and the STIM list then streams the last raw value every 10 ms — the script runs slower than the stream, so the board receives every value twice. Both scripts are runtime-only, not for replay (see Accessing variables). The scripts share one namespace, so a and f from init.py can be changed at runtime in the Python Interpreter window.

Workspace

The Nucleo H723 live + maps workspace has four controls:

  • Graph — sine1_value (red), sine1_raw (orange), sine2_value (blue) and sine3_value (green); auto-scaled axes.
  • Watch Table (250 ms refresh) — all scalar variables except sine1_raw, including qfwDemoMapOut, with the Write column for row-by-row writes.
  • XY Graph — sine1_value on the X axis against sine3_value on the Y axis, 10 s trace.
  • Matrix with three tabs: the qfwDemoMap map (with a Read button, since it is on an On Request event; colour scale enabled, 0–32.5), the qfwDemoCurve curve (no Read button — it is refreshed by polling) and the large map qfwDemoBigMap (with a Read button). Thanks to the virtualised table even a 64 × 64 map displays and scrolls smoothly.

The layout also opens both scripts and the Python Interpreter next to the workspace.

What you will see and what to try

  1. Connect. The driver connects, the protocol establishes the XCP session, detects block mode, sets up the DAQ and STIM lists and the graph starts: three sines from the board plus sine1_raw identical to sine1_value. The Watch Table and the torque curve fill within 500 ms; the ignition map table stays empty — it is on the On Request event. STIM streams from the start — while the bypass is 0 the board ignores it.
  2. Read. Press Read on the ignition map tab — the whole 1072 B block is fetched (one SET_MTA and an UPLOAD burst) and shown as a heat map.
  3. Write Mode. Turn on Write Mode in the map's context menu, edit a few cells (Tab moves to the next cell) and press Write. Only the changed cells are written. The control shows the new value after the next Read — it displays only what the board returns.
  4. Map lookup. After writing a cell the firmware sums, the Map lookup value in the Watch Table changes.
  5. The curve. Write a point of the torque curve (Write Mode on its tab) — the next poll within 500 ms confirms the new value.
  6. The large map. Press Read on the Injection map 64x64 tab: 16,640 B are fetched as a series of 255 B UPLOAD bursts. Turn on the colour scale (Color scale) in the control settings and look at the map as a heat map.
  7. Bypass on. In the table tick Write for sine1_bypass, enter 1 and confirm with Enter. At that moment sine1_value stops copying sine1_raw and starts following sine1_stim — the slow ±8 sine from the script. The orange sine1_raw curve carries on: the internal model keeps running, it is just not published. The XY graph changes because the X axis got a different signal.
  8. Manual stimulation. The script overwrites sine1_stim every 20 ms, so a manual value would last only a moment. Set a = 0 in the Python Interpreter (or, before the next Connect, untick Runtime for script.py in Home → Project Configuration → Scripts), turn the bypass on and write 75 % into sine1_stim — sine1_value shows 5.0; 50 % is zero, 0 % is −10. The written value is sent to the board repeatedly until a new write replaces it.
  9. Bypass off. Write sine1_bypass = 0 — sine1_value returns to the internal model and merges with sine1_raw again.
  10. Calibration. Write e.g. sine2_amplitude = 8 or sine3_period = 2 — the curve changes immediately and the poll confirms the new value back in the table within 500 ms.
  11. A second QInsight instance. Open the project a second time (or point any other client at port 5555) and press Connect: the board refuses the new connection at once (forcibly closed by the remote host in Logs) and the running measurement of the first instance continues undisturbed. The second driver retries every second and connects as soon as you end the first session.
  12. Connection loss. Unplug the Ethernet cable from the board. For a few seconds nothing changes, then keepalive ends the connection and the driver goes Faulted: Logs fill with warnings … failed (attempt N/3) …. After three failed attempts the driver reports gave up after 3 reconnect attempt(s), stops its protocol and ends up Stopped — the runtime and any other drivers (logging, simulation) keep running. Plug the cable back in, click the driver in the Solution Explorer and press Start in the Properties window: the driver connects, the protocol establishes a new XCP session and the measurement continues without stopping the runtime (see Driver states and the Start button). If you plug the cable back in before the attempt limit is exhausted, the connection recovers by itself and the attempt counter resets. The board drops the connection itself as soon as its own link goes down (the cable pulled at the board), so the reconnect is accepted at once — with these settings the measurement is back about 3.5 s after the cable is plugged in. A master lost beyond the board's link (cable pulled at a switch, PC frozen) is detected by the board's keepalive within ~5 s — until then it refuses a new connection just like a second instance.