XCP in the QFW SDK
The QFW SDK adds a complete XCP slave to the MCU firmware, so QInsight connects to the device with the XCP on TCP or XCP on CAN protocol:
- polling and DAQ measurement — the device samples the values in
its own cycle, with 1 µs resolution timestamps from the device clock
(QInsight with the default
daqTimestamps=slaveuses them directly for the time axis), - calibration writes from QInsight controls,
- STIM — stimulation of firmware variables streamed from the PC, applied synchronously with your application cycle,
- block mode — calibration maps, curves and value blocks (Matrix variables) transferred as one block in a burst of packets instead of hundreds of acknowledged transfers.
Transports: XCP on TCP and XCP on classic CAN
The engine compiles in one of two variants; a firmware image contains exactly one of them (the two variants collide on their symbols by design). The public header and the API are the same, only the transport codec, the glue and the receive entry differ:
| XCP on TCP (Ethernet) | XCP on classic CAN | |
|---|---|---|
| Engine variant | QFW_XCP_TRANSPORT=eth (default) | QFW_XCP_TRANSPORT=can |
| Receive entry | qfw_xcp_rx(bytes, len) — a byte stream | qfw_xcp_rx_can_frame(data, dlc) — one CAN frame |
| Glue template | glue/freertos_lwip — server task over lwIP sockets; glue/baremetal_lwip_raw — no RTOS, polled from the main loop over the lwIP RAW API | glue/freertos_can — server task over the FDCAN port |
| Port | port/clock | port/clock + port/fdcan |
| Packet size | MAX_CTO = 248 B (commands), MAX_DTO = 1024 B (DAQ/STIM packet) | 8-byte frames, MAX_CTO = MAX_DTO = 8 |
| Block mode | MAX_BS 255 packets | MAX_BS 16 frames |
| QInsight | XCP on TCP | XCP on CAN with a PEAK CAN adapter |
The ST peripheral is called FDCAN; the SDK uses it in classic CAN mode (8-byte frames, no bit-rate switching). What changes for CAN is described in XCP on classic CAN.
What the package contains
The SDK is delivered as the package qfw-xcp-sdk-1.0.0 in the SDK
subfolder of the QInsight installation folder:
| Path | Content | Ownership |
|---|---|---|
include/ | qfw_xcp.h — the only header your code needs (C11 / C++); qfw_xcp_version.h — version and git revision of the package | QENEX |
engine/src/ | the engine sources: XCP command processing, DAQ/STIM lists, calibration memory access, timestamps, transmit queue. No threads, sockets, heap, stdio or blocking calls; depends on the C library only. engine/ORIGIN.md states what the engine is derived from (Vector XCPlite, MIT) and what QENEX changed | QENEX — compile it, do not edit it |
glue/freertos_lwip/ | source template: FreeRTOS server task over lwIP sockets (XCP on TCP) with connection recovery | template — copy into your project and adapt |
glue/freertos_can/ | source template: FreeRTOS server task over the FDCAN port (XCP on classic CAN) | template |
glue/baremetal_lwip_raw/ | source template: XCP on TCP over the lwIP RAW API without an RTOS, driven from the main loop (Init + Poll) | template |
port/clock/ | source template: 64-bit microsecond clock from the Cortex-M7 DWT cycle counter | template — replace for another MCU |
port/fdcan/ | source template: STM32H7 FDCAN peripheral in classic CAN mode + the vendored ST HAL FDCAN driver (BSD-3-Clause) | template |
examples/nucleo_h723zg/ | complete CubeMX/CMake project for the NUCLEO-H723ZG (FreeRTOS + lwIP + SDK); presets Debug (Ethernet) and DebugCan (classic CAN); demo signals and matrix objects (app/src/demo_map.c) | reference — build it first, then copy from it |
examples/nucleo_h723zg_baremetal/ | the same board and the same demo content without an RTOS (lwIP NO_SYS + the bare-metal glue); preset Debug (Ethernet) | reference |
cmake/qfw_xcp.cmake | include() it from CMake: creates the target qfw::xcp from engine/src and exports the glue/port source lists | QENEX |
tools/ | elf_vars_scan.py, elf_vars_to_qinsight.py, elf_vars.template.json — variable addresses from the ELF → QInsight import file; arrays are exported as Matrix variables | QENEX |
docs/ | integration.md (the step-by-step guide this section is based on), compatibility.md, configuration.md (defaults and limits) | |
LICENSES/ | QENEX Software License Agreement, XCPlite MIT notice (Vector Informatik), ST HAL BSD-3-Clause notice | |
README.md, RELEASE-NOTES.md, MANIFEST.json | quick start, changes in this version, SHA-256 of every file |
The integration model
Three layers take part: your application, the glue (one server task, or
without an RTOS a poll from the main loop) and the engine. The engine
never calls FreeRTOS, lwIP, the HAL or printf; everything it needs from
the environment comes through the callbacks in qfw_xcp_config_t, which
the glue fills in. That is why the engine is portable and why a glue is
needed at all. The diagram below shows the FreeRTOS glue; without an
RTOS the server task is replaced by a call to QfwXcpTcpRawGlue_Poll()
on every pass of the main loop (see
Integration without an RTOS).
your application glue (one server task) engine (qfw::xcp)
───────────────── ────────────────────── ─────────────────
QfwXcpGlue_Init(&cfg) ────> fills qfw_xcp_config_t ───────────> qfw_xcp_init()
creates the server task
accept / recv ─── bytes ──────────> qfw_xcp_rx() parses commands, STIM data
every 1 ms ───────────────────────> qfw_xcp_poll() ──────> config.transmit() (glue: lwip_send)
qfw_xcp_trigger_event(id) ────────────────────────────────────> samples DAQ lists, applies STIM
engine callbacks: get_clock, crit_enter/leave, log <──── engine
From the application's point of view the integration is three calls,
placed in the CubeMX task template of freertos.c:
| Call | Where | What it does |
|---|---|---|
QfwXcpServer_Init() | once in the default task, after MX_LWIP_Init() | initializes the clock port, fills the glue configuration (identity, port or CAN identifiers, log level, clock callback), calls QfwXcpGlue_Init — which creates the recursive mutex, fills qfw_xcp_config_t, calls qfw_xcp_init and creates the server task — and creates the DAQ events with qfw_xcp_create_event |
QfwXcpServer_Tick() | periodically from one task (every 500 ms in the example) | the single writer of the 64-bit clock overflow counter |
qfw_xcp_trigger_event(id) | from your cyclic task, right after the variables were updated | the engine writes pending STIM data into memory and samples the DAQ lists bound to the event, with a timestamp |
The glue provides the engine with four callbacks — transmit (non-blocking,
false = backpressure), get_clock (monotonic microseconds, 64-bit),
crit_enter / crit_leave (a recursive mutex; the bare-metal glue
leaves them out because the engine runs in a single context) and an
optional log — plus the statically allocated transmit queue memory. The glue's server task
feeds the engine with received data (qfw_xcp_rx or
qfw_xcp_rx_can_frame), calls qfw_xcp_poll every millisecond and
signals a new connection or a bus-off with qfw_xcp_on_transport_reset.
The rules behind these calls are collected in
The engine contract.
Events created with qfw_xcp_create_event are the event channels that
DAQ and STIM events bind to in QInsight (daqId; the first event gets id
0). The variable addresses come from the ELF of the build you flash — the
tools in tools/ read them and produce a QInsight import file, see
Variable addresses for QInsight.
Block mode and Matrix variables
The engine has XCP block mode enabled (XCP_ENABLE_BLOCK_MODE;
OPTION_DISABLE_BLOCK_MODE turns it off), announced to the master in
CONNECT (SERVER_BLOCK_MODE) and in GET_COMM_MODE_INFO
(MASTER_BLOCK_MODE, MAX_BS, MIN_ST):
- Slave block mode (reads): an
UPLOADlonger than one packet is answered by the engine with a burst ofRESpackets without further requests. - Master block mode (writes): the master sends
DOWNLOAD+DOWNLOAD_NEXTblocks of at mostMAX_BSpackets, acknowledged once per block. On a wrong block counter the engine answersERR_SEQUENCEwith the expected count and ignores the rest of that block silently; the master repeats the block. MAX_BSis 255 on Ethernet and 16 on CAN,MIN_ST0; tune them withXCP_BLOCK_MAX_BS/XCP_BLOCK_MIN_ST(docs/configuration.md). On CAN the RX FIFO0 holds 32 frames and the glue polls every 1 ms — 16 frames back to back leave a margin.
QInsight uses block mode for Matrix variables
— maps, curves and value blocks up to 64 × 64 × 4 B of data: a 1 KB map
reads over TCP in a few milliseconds as one burst of five packets; on CAN
it is 147 frames in five bursts (a 16 KB map ≈ 2,340 frames, ≈ 0.6 s at
500 kbit/s). Scalars are unaffected; only an 8-byte scalar on CAN is now
answered as a 7 + 1 B burst instead of ERR_OUT_OF_RANGE. An older
master that does not negotiate block mode keeps working packet by packet
as before.
A matrix object in the firmware is one contiguous block X axis, Y
axis, data (data row-major); the address tools export it from the ELF
as a Matrix variable, see
Arrays, curves and maps.
The example ships three such objects in app/src/demo_map.c
(qfwDemoMap 16 × 16 float with axes, qfwDemoCurve 8 × uint16,
qfwDemoBigMap 64 × 64 float) and the scalar qfwDemoMapOut that
depends on their cells. The QInsight side is described under
Block mode in the protocol reference.
Requirements
| Item | Requirement |
|---|---|
| CPU / toolchain | any 32-bit target with a C11 compiler and C11 atomics; verified on Cortex-M7 (STM32H723, hard-float ABI) with GCC 14.3 from STM32CubeCLT. The engine is compiled with your flags, so there is no ABI to match. |
| C library | newlib / newlib-nano; the engine calls memcpy memset memmove memcmp strlen strnlen strcmp strncpy strrchr snprintf vsnprintf only. |
| Flash / RAM | engine ≈ 22 KB code + 11 KB static RAM, plus the transmit queue you provide (both TCP glues 9072 B, CAN glue 4632 B). |
| Clock | a monotonic 64-bit counter in microseconds (port/clock derives it from the DWT cycle counter). |
FreeRTOS (freertos_lwip and freertos_can glues) | CMSIS-RTOS v2, configSUPPORT_STATIC_ALLOCATION 1, configUSE_RECURSIVE_MUTEXES 1. The baremetal_lwip_raw glue needs no RTOS. |
| lwIP (TCP glue) | with FreeRTOS: socket API and the options listed in Integration: XCP on TCP; without an RTOS: NO_SYS 1, the RAW API and TCP_MSS / TCP_SND_BUF as in Integration without an RTOS. |
| Host tools | Python 3 with pyelftools for the variable address tools. |
Licensing
The engine has no activation key, no runtime license check and no time
limit — the SDK is the same for every QInsight license (see the
introduction). The engine version is reported
by qfw_xcp_version() as "QFW-XCP <semver> (<git>)"; quote it in every
support request. Measurement time is set by the QInsight license: Free and
Trial 30 minutes per start, Commercial unlimited. Distributing firmware
with the engine to third parties requires a Commercial license (QENEX
Software License Agreement, Annex B).
Compatibility and versions
- SDK 1.0.0 is the first release to customers; it ships inside the QInsight 1.0.0 installer and includes block mode, the bare-metal glue and the export of arrays as Matrix variables. QInsight 1.0.0 or newer is required (the variable import: Home → Project Configuration → Variables → Import; Matrix variables over XCP).
- The engine speaks standard XCP 1.4 (protocol and transport layer), so any XCP 1.4 master on TCP works for the standard feature set.
- The package is versioned as a whole (SemVer):
qfw_xcp.h, the engine sources and the glue/port templates are one version — always take all of them from the same package. A header/engine mismatch is caught byqfw_xcp_initat init. - Verified: NUCLEO-H723ZG at 550 MHz, FreeRTOS 10 (CMSIS-RTOS v2), lwIP
2.2.1 (STM32Cube FW_H7 V1.13.0), XCP on TCP port 5555, and the same
board without an RTOS (lwIP
NO_SYS, RAW API) — DAQ, STIM, maps and curves in block mode, second-connection refusal, cable-pull recovery; XCP on classic CAN via PCAN-USB at 500 kbit/s, identifiers 0x200/0x201 (block mode on CAN is covered by the regression tests, not by a live session).
Next
The step-by-step procedure for Ethernet: Integration: XCP on TCP (with FreeRTOS) and Integration without an RTOS. The QInsight side is described in the XCP protocol reference.

