Skip to content

Device API

See Add a board for implementation and registration steps.

get_device(name, *, device_options=None, serial_port=None)

Construct a board-specific device wrapper when available.

Parameters:

Name Type Description Default
name str

Device identifier.

required
device_options dict[str, Any] | None

Optional board-specific options (for example Portenta core split).

None
serial_port str | None

Serial port used for upload/measure operations.

None

Returns:

Type Description
Any

Device wrapper implementing the DeviceInterface contract.

Raises:

Type Description
ValueError

If existing validation or execution checks fail.

Exception

If existing validation or execution checks fail.

resolve_device_options(device_name, device_config)

Resolve backend-owned device options from a config subtree.

Parameters:

Name Type Description Default
device_name str

Target device identifier.

required
device_config Any

Device config subtree or namespace-like object.

required

Returns:

Type Description
dict[str, Any] | None

Normalized backend options, or None when the backend does not use explicit option fields.

Notes

Shared runtime knobs such as runtime_mode and latency_budget_ms are merged here so higher-level orchestration code can stay board-agnostic. Backend-owned fields still come from per-board config subtrees because the Portenta and STM32 wrappers expose different option schemas.

DeviceInterface

Bases: ABC

Contract for device-specific compile/upload/measure workflows.

spec abstractmethod property

Return the device specification metadata.

Returns:

Type Description
DeviceSpec

Static limits and toolchain metadata for this device.

prepare_candidate(*, request)

Prepare backend-owned build inputs and return the compile directory.

Parameters:

Name Type Description Default
request CandidatePrepareRequest

Candidate preparation payload assembled by orchestration.

required

Returns:

Type Description
Path

Directory that should be passed to the backend compile step.

Raises:

Type Description
NotImplementedError

If existing validation or execution checks fail.

cleanup_prepared_candidate(prepared_dir)

Release backend-owned candidate artifacts after one evaluation.

Parameters:

Name Type Description Default
prepared_dir Path | None

Path previously returned by prepare_candidate().

required

compile(*, sketch_path, arena_kb, window_size, num_channels, build_defines=None) abstractmethod

Compile the firmware for the target device.

Parameters:

Name Type Description Default
sketch_path Path

Path to the firmware project directory.

required
arena_kb int

Tensor arena size in KiB for this attempt.

required
window_size int

Sliding window length used by the model.

required
num_channels int

Number of sensor channels per window.

required

Returns:

Type Description
CompileResult

Parsed compile output and resource usage.

upload(*, sketch_path, build_dir, serial_port) abstractmethod

Upload compiled firmware to the device.

Parameters:

Name Type Description Default
sketch_path Path

Path to the firmware project directory.

required
build_dir Path | None

Build directory containing compiled artifacts.

required
serial_port str | None

Serial port to upload to.

required

Returns:

Type Description
UploadResult

Upload success flag and log output.

measure(*, serial_port, baud_rate, serial_timeout_s, measured_inference_runs=10, dut_ready_timeout_s=None, harness_serial_port=None, harness_fqbn=None, harness_auto_flash=None, harness_arm_pin=None, harness_trigger_pin=None, dut_arm_hold_ms=None, harness_stable_low_ms=None, harness_ready_timeout_s=None, harness_arm_timeout_s=None, harness_active_timeout_s=None, harness_done_timeout_s=None) abstractmethod

Capture latency/power metrics from the device.

Parameters:

Name Type Description Default
serial_port str | None

Serial port used for log capture.

required
baud_rate int

Serial baud rate.

required
serial_timeout_s float

Timeout for log capture.

required
dut_ready_timeout_s float | None

Time to wait for DUT READY before sending START.

None
harness_serial_port str | None

Optional serial port for the INA228 harness.

None
harness_fqbn str | None

FQBN for the harness board (Arduino CLI only).

None
harness_auto_flash str | None

Harness flashing policy (once, always, never).

None
harness_arm_pin int | None

Harness/DUT arm pin number (active-low).

None
harness_trigger_pin int | None

Harness/DUT trigger pin number.

None
dut_arm_hold_ms int | None

Arm-low hold duration before DUT sets trigger HIGH.

None
harness_stable_low_ms int | None

Stable-low window required before harness arms.

None
harness_ready_timeout_s float | None

Timeout waiting for HARNESS READY.

None
harness_arm_timeout_s float | None

Harness-side arm timeout while waiting for a valid D2 trigger after D3 active-low arming. This value is compiled into harness firmware as CREST_HARNESS_ARM_TIMEOUT_MS; set to 0 to disable it.

None
harness_active_timeout_s float | None

Maximum time to wait for a harness measurement window.

None
harness_done_timeout_s float | None

Timeout waiting for DONE response.

None

Returns:

Type Description
MeasureResult

Parsed latency/power metrics.

evaluate(*, dirpath, arena_kb, window_size, num_channels, serial_port=None, run_hil=True, baud_rate=115200, serial_timeout_s=12.0, measured_inference_runs=10, dut_ready_timeout_s=None, harness_serial_port=None, harness_fqbn=None, harness_auto_flash=None, harness_arm_pin=None, harness_trigger_pin=None, dut_arm_hold_ms=None, harness_stable_low_ms=None, harness_ready_timeout_s=None, harness_arm_timeout_s=None, harness_active_timeout_s=None, harness_done_timeout_s=None) abstractmethod

Compile, upload, and measure a model on the target device.

Parameters:

Name Type Description Default
dirpath str | Path

Path to the sketch or project directory containing firmware sources.

required
arena_kb int

Tensor arena size in KiB for this attempt.

required
window_size int

Sliding window length used by the model.

required
num_channels int

Number of sensor channels in each window.

required
serial_port str | None

Serial port for upload and log capture.

None
run_hil bool

When False, compile only (no upload/measurement).

True
baud_rate int

Serial baud rate for log capture.

115200
serial_timeout_s float

Timeout for latency/power log capture.

12.0
dut_ready_timeout_s float | None

Time to wait for DUT READY before sending START.

None

Returns:

Type Description
DeviceMetrics

Normalized metrics for the run.

DeviceSpec dataclass

Static hardware capabilities and constraints.

Parameters:

Name Type Description Default
name str

Human-readable device identifier.

required
arena_sizes_kb Sequence[int]

Candidate tensor arena sizes in KiB.

required
max_ram_bytes int

Maximum usable RAM on the device in bytes.

required
max_flash_bytes int

Maximum usable flash on the device in bytes.

required
max_external_flash_bytes int | None

Maximum usable external flash on the device in bytes, when the backend supports separate weight storage outside the primary program image. Not used by all boards.

None
fqbn str | None

Fully qualified board name (Arduino CLI only).

None
toolchain str | None

Toolchain identifier (e.g., "arduino-cli", "stm32-cube").

None

Attributes:

Name Type Description
name str

Human-readable device identifier.

arena_sizes_kb Sequence[int]

Candidate tensor arena sizes in KiB.

max_ram_bytes int

Maximum usable RAM on the device in bytes.

max_flash_bytes int

Maximum usable flash on the device in bytes.

max_external_flash_bytes Optional[int]

Maximum usable external flash on the device in bytes, when the backend supports separate weight storage outside the primary program image. Not used by all boards.

fqbn Optional[str]

Fully qualified board name (Arduino CLI only).

toolchain Optional[str]

Toolchain identifier (e.g., "arduino-cli", "stm32-cube").

CandidatePrepareRequest dataclass

Typed request passed into backend candidate preparation.

Parameters:

Name Type Description Default
config Any

Loaded CREST configuration object.

required
model Any

Model instance to export and stage for one backend attempt.

required
model_variant str

Human-readable export variant label.

required
artifact_root Path

Root directory chosen by orchestration for backend-owned artifacts.

required
tflite_model_path Path

Explicit TFLite output path selected by orchestration.

required
calibration_split DataSplit | None

Calibration split used for representative export data when required.

required
quantization_mode str

Deployment quantization mode selected for this candidate.

required
input_shape tuple[int, ...] | None

Logical model input shape excluding the batch dimension.

required
checkpoint_path Path | str | None

Checkpoint path associated with trained export variants when one exists.

None

Attributes:

Name Type Description
config Any

Loaded CREST configuration object.

model Any

Model instance to export and stage for one backend attempt.

model_variant str

Human-readable export variant label.

artifact_root Path

Root directory chosen by orchestration for backend-owned artifacts.

tflite_model_path Path

Explicit TFLite output path selected by orchestration.

calibration_split DataSplit | None

Calibration split used for representative export data when required.

quantization_mode str

Deployment quantization mode selected for this candidate.

input_shape tuple[int, ...] | None

Logical model input shape excluding the batch dimension.

checkpoint_path Path | str | None

Checkpoint path associated with trained export variants when one exists.

CompileResult dataclass

Result of a device-specific compile step.

Parameters:

Name Type Description Default
success bool

True when compilation succeeded.

required
log str

Combined stdout/stderr from the compile step.

required
flash_bytes int | None

Parsed flash usage in bytes, if available.

required
ram_bytes int | None

Parsed RAM usage in bytes, if available.

required
overflow_kind str | None

"flash" or "ram" when an overflow is detected.

required
build_dir Path | None

Build cache directory if applicable.

None
arena_bytes int | None

Parsed activation arena size in bytes, if available.

None
heap_bytes int | None

Linker-reserved heap bytes, if available.

None
stack_bytes int | None

Linker-reserved stack bytes, if available.

None
external_flash_bytes int | None

External flash bytes consumed by staged weight blobs when the backend uses separate weight storage. Not used by all boards.

None
boot_build_dir Path | None

STM32-only Boot-project build directory when the backend produces separate boot and application artifacts.

None
boot_elf_path Path | None

STM32-only Boot-project ELF path used for debug loading.

None
app_build_dir Path | None

STM32-only App-project build directory when the backend produces separate boot and application artifacts.

None
app_elf_path Path | None

STM32-only App-project ELF path.

None
signed_app_bin_path Path | None

STM32-only trusted application image path emitted after signing.

None
fsbl_copy_window_bytes int | None

STM32 LRUN copy-window size compiled into the bootloader.

None

Attributes:

Name Type Description
success bool

True when compilation succeeded.

log str

Combined stdout/stderr from the compile step.

flash_bytes Optional[int]

Parsed flash usage in bytes, if available.

ram_bytes Optional[int]

Parsed RAM usage in bytes, if available.

overflow_kind Optional[str]

"flash" or "ram" when an overflow is detected.

build_dir Optional[Path]

Build cache directory if applicable.

arena_bytes Optional[int]

Parsed activation arena size in bytes, if available.

heap_bytes Optional[int]

Linker-reserved heap bytes, if available.

stack_bytes Optional[int]

Linker-reserved stack bytes, if available.

external_flash_bytes Optional[int]

External flash bytes consumed by staged weight blobs when the backend uses separate weight storage. Not used by all boards.

boot_build_dir Optional[Path]

STM32-only Boot-project build directory when the backend produces separate boot and application artifacts.

boot_elf_path Optional[Path]

STM32-only Boot-project ELF path used for debug loading.

app_build_dir Optional[Path]

STM32-only App-project build directory when the backend produces separate boot and application artifacts.

app_elf_path Optional[Path]

STM32-only App-project ELF path.

signed_app_bin_path Optional[Path]

STM32-only trusted application image path emitted after signing.

fsbl_copy_window_bytes Optional[int]

STM32 LRUN copy-window size compiled into the bootloader.

UploadResult dataclass

Result of a device-specific upload step.

Parameters:

Name Type Description Default
success bool

True when upload succeeded.

required
log str

Combined stdout/stderr from the upload step.

required

Attributes:

Name Type Description
success bool

True when upload succeeded.

log str

Combined stdout/stderr from the upload step.

MeasureResult dataclass

Parsed telemetry from a device measurement pass.

Parameters:

Name Type Description Default
latency_s float | None

Inference latency in seconds, if available.

required
arena_error_line str | None

First arena allocation error line, if found.

required
serial_log list[str]

Decoded serial log captured during measurement.

required
power_metrics dict[str, float | None] | None

Parsed power metrics fields, if present.

required

Attributes:

Name Type Description
latency_s Optional[float]

Inference latency in seconds, if available.

arena_error_line Optional[str]

First arena allocation error line, if found.

serial_log list[str]

Decoded serial log captured during measurement.

power_metrics Optional[Dict[str, Optional[float]]]

Parsed power metrics fields, if present.

DeviceMetrics dataclass

Standardized telemetry captured after a HIL or proxy run.

Parameters:

Name Type Description Default
ram_bytes int

RAM usage in bytes (or -1 if unavailable).

required
flash_bytes int

Flash usage in bytes (or -1 if unavailable).

required
latency_s float

Inference latency in seconds (or -1.0 if unavailable).

required
arena_bytes int

Tensor arena size used in bytes.

required
error_code int

Error code emitted by the device evaluation.

required
power_metrics dict[str, Any] | None

Optional raw power metrics parsed from the serial log.

None
external_flash_bytes int | None

External flash bytes consumed by staged weight blobs when the backend uses separate weight storage. Not used by Arduino boards.

None
retry_hint_bytes int | None

Suggested arena size in bytes for the next attempt, when available.

None

Attributes:

Name Type Description
ram_bytes int

RAM usage in bytes (or -1 if unavailable).

flash_bytes int

Flash usage in bytes (or -1 if unavailable).

latency_s float

Inference latency in seconds (or -1.0 if unavailable).

arena_bytes int

Tensor arena size used in bytes.

error_code int

Error code emitted by the device evaluation.

power_metrics Optional[Dict[str, Any]]

Optional raw power metrics parsed from the serial log.

external_flash_bytes Optional[int]

External flash bytes consumed by staged weight blobs when the backend uses separate weight storage. Not used by Arduino boards.

retry_hint_bytes Optional[int]

Suggested arena size in bytes for the next attempt, when available.