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:
| Project | Firmware image | SDK chapter |
|---|---|---|
Qenex_TcpClient_XCP_NucleoH723_Maps_FreeRTOS.qproj | examples/nucleo_h723zg, preset Debug (FreeRTOS + lwIP) | Integration: XCP on TCP |
Qenex_TcpClient_XCP_NucleoH723_Maps_BareMetal.qproj | examples/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.


What the example shows
- DAQ measurement — the firmware generates three sines
(
sine1–sine3) and transmits their values by itself from the event channeldemo10msevery 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_bypassswitch — decides who owns thesine1_valuesignal:0= the board's internal model,1= the master via STIM. - The raw/value split —
sine1_rawis the output of the internal model (computed every cycle, even during bypass),sine1_valueis 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
UPLOADbursts. - 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
DOWNLOADblock). - 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, port5555— 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.pytool of the SDK package reads them with the configurationnucleo_h723zg.vars.json(ornucleo_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:
| Parameter | Value | Meaning |
|---|---|---|
ip | 192.168.2.20 | address of the board |
port | 5555 | TCP port of the XCP slave |
connectionTimeoutMs | 1500 | how 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 |
reconnectDelayMs | 1000 | delay between reconnection attempts |
reconnectAttempts | 3 | after three failed attempts in a row the driver stops trying (the default -1 retries without limit) |
keepAliveMs | 5000 | after 5 s without traffic TCP keepalive checks the connection — detects an unplugged cable |
Protocol settings:
| Parameter | Value | Meaning |
|---|---|---|
requestTimeoutMs | 1000 | response timeout of one XCP command |
requestRetries | 2 | repetitions of a command after a timeout (in addition to the first attempt) |
daqTimestamps | slave | time 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:
| Event | Type | Extra Params | Used for |
|---|---|---|---|
Daq_demo10ms | Periodic 10 ms | direction="DAQ";daqId="0" | DAQ — the board transmits the sines by itself from the demo10ms channel |
Stim_demo10ms | Periodic 10 ms | direction="STIM";daqId="0" | STIM — the master streams sine1_stim into the same channel every 10 ms |
Poll500ms | Periodic 500 ms | — | polling of the parameters, the bypass switch, the uwTick counter, the curve and qfwDemoMapOut |
OnRequest | OnRequest | — | 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:
| Variable | Address | Direction | Event | Presentation (conversion) |
|---|---|---|---|---|
sine1_value | 0x2400005C | read | Daq_demo10ms | Sine value −10…10 (PassThrough) |
sine1_raw | 0x24000058 | read | Daq_demo10ms | Sine value (PassThrough) |
sine2_value | 0x24000074 | read | Daq_demo10ms | Sine value (PassThrough) |
sine3_value | 0x2400008C | read | Daq_demo10ms | Sine value (PassThrough) |
sine1_amplitude | 0x24000050 | readWrite | Poll500ms | Amplitude 0…10 (PassThrough) |
sine1_period | 0x24000054 | readWrite | Poll500ms | Period 0.05…60 s (PassThrough) |
sine2_amplitude | 0x24000068 | readWrite | Poll500ms | Amplitude (PassThrough) |
sine2_period | 0x2400006C | readWrite | Poll500ms | Period (PassThrough) |
sine3_amplitude | 0x24000080 | readWrite | Poll500ms | Amplitude (PassThrough) |
sine3_period | 0x24000084 | readWrite | Poll500ms | Period (PassThrough) |
sine1_bypass | 0x24000060 | readWrite | Poll500ms | Bypass 0/1 (PassThrough) |
sine1_stim | 0x2400005C | write | Stim_demo10ms | Stim level 0…100 % (StimPercent) |
uwTick | FreeRTOS 0x24000124 / bare metal 0x2400011C | read | Poll500ms | HAL tick, ms (PassThrough) |
Worth noticing:
sine1_stimandsine1_valuehave the same address — the stimulation writes straight into the location the board publishes; only the direction and the event differ.- The
StimPercentconversion (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). uwTickis the millisecond HAL tick counter of the STM32 — it lies outside thegDemoSignalsblock 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 types | Size | Address FreeRTOS | Address bare metal | Direction | Event |
|---|---|---|---|---|---|---|
qfwDemoMap (Ignition map) | 16 × 16 float map; X axis ushort (rpm), Y axis byte (load) | 1072 B | 0x24014280 | 0x24008FC0 | readWrite | OnRequest |
qfwDemoCurve (Torque curve) | 8-point ushort curve, X axis ushort (rpm) | 32 B | 0x240146B0 | 0x240093F0 | readWrite | Poll500ms |
qfwDemoBigMap (Injection map 64x64) | 64 × 64 float map; X and Y axes ushort | 16,640 B | 0x240146D0 | 0x24009410 | readWrite | OnRequest |
qfwDemoMapOut (Map lookup) | float scalar | 4 B | 0x240187D0 | 0x2400D510 | read | Poll500ms |
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:
| Presentation | Range | Unit | Used for |
|---|---|---|---|
RpmAxisPres | 0–8000 | rpm | X axis of all three matrices |
LoadAxisPres | 0–100 | % | Y axis of qfwDemoMap |
LoadTenthAxisPres | 0–100 | % | Y axis of qfwDemoBigMap — conversion LoadTenth (×0.1), raw is in tenths of a percent |
AdvancePres | 0–40 | deg | data of qfwDemoMap |
TorquePres | 0–300 | Nm | data of qfwDemoCurve |
InjectionPres | 0–1100 | mg | data of qfwDemoBigMap |
MapOutPres | 0–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) andsine3_value(green); auto-scaled axes. - Watch Table (250 ms refresh)
— all scalar variables except
sine1_raw, includingqfwDemoMapOut, with the Write column for row-by-row writes. - XY Graph —
sine1_valueon the X axis againstsine3_valueon the Y axis, 10 s trace. - Matrix with three tabs: the
qfwDemoMapmap (with a Read button, since it is on an On Request event; colour scale enabled, 0–32.5), theqfwDemoCurvecurve (no Read button — it is refreshed by polling) and the large mapqfwDemoBigMap(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
- 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_rawidentical tosine1_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 is0the board ignores it. - Read. Press Read on the ignition map tab — the whole 1072 B
block is fetched (one
SET_MTAand anUPLOADburst) and shown as a heat map. - 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.
- Map lookup. After writing a cell the firmware sums, the
Map lookupvalue in the Watch Table changes. - The curve. Write a point of the torque curve (Write Mode on its tab) — the next poll within 500 ms confirms the new value.
- The large map. Press Read on the
Injection map 64x64tab: 16,640 B are fetched as a series of 255 BUPLOADbursts. Turn on the colour scale (Color scale) in the control settings and look at the map as a heat map. - Bypass on. In the table tick Write for
sine1_bypass, enter1and confirm with Enter. At that momentsine1_valuestops copyingsine1_rawand starts followingsine1_stim— the slow ±8 sine from the script. The orangesine1_rawcurve carries on: the internal model keeps running, it is just not published. The XY graph changes because the X axis got a different signal. - Manual stimulation. The script overwrites
sine1_stimevery 20 ms, so a manual value would last only a moment. Seta = 0in the Python Interpreter (or, before the next Connect, untick Runtime forscript.pyin Home → Project Configuration → Scripts), turn the bypass on and write 75 % intosine1_stim—sine1_valueshows 5.0;50 %is zero,0 %is −10. The written value is sent to the board repeatedly until a new write replaces it. - Bypass off. Write
sine1_bypass = 0—sine1_valuereturns to the internal model and merges withsine1_rawagain. - Calibration. Write e.g.
sine2_amplitude = 8orsine3_period = 2— the curve changes immediately and the poll confirms the new value back in the table within 500 ms. - 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 hostin 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. - 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 reportsgave 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.
Related chapters
- XCP on TCP, XCP polling, DAQ, and STIM, Matrix variables over XCP and Block mode — protocol settings, Comm params, DAQ/STIM events and diagnostics.
- TCP Client and Reconnection — driver parameters and the behaviour after an outage.
- Matrix variable and Matrix control — matrix layout, the table, Write Mode, the clipboard and the colour scale.
- Events — Extra Params for DAQ and STIM, the On Request event.
- Writing values to the device — writing from the Watch Table in engineering units.
- Start and stop — driver states and the Start button.
- XCP in the QFW SDK — the firmware side: event channels, timestamps, block mode; Integration: XCP on TCP and Integration without an RTOS — how the two example images are built step by step.
- Calibration maps over XCP on CAN — the same example over the CAN bus.
- Two ECUs at once — the same firmware on two boards at the same time, each with its own driver.
- Troubleshooting — XCP and DAQ.

