fupsrl

fupsrl/CM-STACK-Simulink-Compiler

The definitive way to compile Simulink models for Raspberry with XCP measurement and calibration integrated

C 0 stars Updated 3 hours ago

CM-STACK Simulink Compiler with XCP-on-TCP

One MATLAB entry point builds a Simulink model for Raspberry Pi, glues it to Vector XCPlite, extends the stack with XCP programming, deploys the executable, and generates the INCA/CANape artifacts:

  • <model>.a2l
  • <model>.hex
  • <model>_XCP_Flash_ProF/
  • <model>_XCP_Flash_ProF.zip

The MATLAB workflow implementation is shipped as protected P-code. The C glue templates remain visible because they are compiled into the target application.

XCPlite Dependency

XCPlite is not vendored in this repository. On demand, the workflow clones or updates Vector's upstream repository:

https://github.com/vectorgrp/XCPlite.git

By default it resolves XcpliteRef = 'latest-release', currently V2.1.5 on Vector's GitHub releases page, and checks it out under external/XCPlite. That folder is ignored by Git.

Quick Start

Run from MATLAB with the Raspberry Pi connection passed as name/value options:

cd("path/to/CM-STACK-Simulink-Compiler")
addpath("workflow")

cfg = xcpWorkflow( ...
    'Model', 'xcpMultiRateTest', ...
    'PiHost', '192.168.0.101', ...
    'PiUser', 'alberto', ...
    'PiPassword', '<password>', ...
    'PiAppDir', '/home/alberto/xcp_app', ...
    'PiHostKey', 'ssh-ed25519 255 SHA256:<fingerprint>', ...
    'ModelCores', [2 3], ...
    'XcpCores', 1, ...
    'Deploy', true);

Set 'Deploy', false in the same call to build only: Simulink code generation, remote compilation, A2L, HEX and ProF are produced, but the target service is not swapped/restarted.

What The Workflow Does

  1. Generates Simulink C code with Embedded Coder.
  2. Fetches Vector XCPlite latest stable release if needed.
  3. Stages model code, XCPlite, and generated glue sources.
  4. Patches the staged XCPlite copy for XCP PGM support.
  5. Builds the executable on the Raspberry Pi and fetches the ELF.
  6. Generates an INCA-safe A2L and one complete HEX for dataset import and flash.
  7. Generates an installable INCA ProF flash configuration.
  8. Optionally deploys and restarts the Raspberry Pi systemd service.

Runtime Features

  • XCP on Ethernet TCP, default port 5555
  • measurement DAQ with one raster per Simulink task
  • online calibration via XCPlite calibration pages
  • calibration freeze/persistence
  • INCA/CANape flashing via XCP PGM to a virtual application sector
  • atomic executable swap and rollback backup on the Raspberry Pi
  • per-core CPU usage, CPU temperature, cycle count, execution time and overrun diagnostics
  • clean INCA display names without generated <model>_P., <model>_DW., etc. prefixes

Files

workflow/
  xcpWorkflow.p              entry point
  matlab/*.p                 protected MATLAB workflow implementation
  templates/*.template       generated build/systemd config templates
  templates/xcp_main.template.c
  templates/xcp_flash.c/.h
  templates/xcp_pgm_handlers.inc

xcpMultiRateTest.slx         multirate example model
testSimulinkRaspberry.slx    basic example model
modelParams.m                example parameters

More details are in workflow/README.md and INCASetup.md.

Requirements

  • MATLAB/Simulink R2024b tested
  • Embedded Coder
  • PuTTY tools (plink.exe and pscp.exe) available on the Windows host
  • Raspberry Pi 64-bit target with SSH access
  • Git available on the Windows host, for automatic XCPlite checkout
  • INCA or CANape for measurement/calibration import

License

See LICENSE.txt.

Releases

  1. Tested Latest 3 hours ago

    V1.0

    First public release Tested on Raspberry Pi 4 - Matlab R2024a - XCPLite V2.0.5

Recent commits main

  1. Update README.md
    fupsrl · 3 months ago b3af6cd
  2. Update README.md
    fupsrl · 3 months ago 229c980
  3. Initial release
    fupsrl · 3 months ago 77f58b1