|
Sound Byte Libs 0.5.1-340-gab5b79a
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
|
Sound Byte Libs uses a declarative hardware configuration system that separates MCU drivers from board definitions, enabling portable firmware across different hardware targets.
sbl/hw/config/*.hpp and shim.json into the build directory and, with -DSBL_LOCK=ON, records the resolution in locks/<target>.lock.sbl::hw::gpio::status_led, sbl::hw::adc::knob_1) and, when the hardware has components, the generated Board.CMake runs sloth on every configure.
targets/<name>.sbl.json, with sbl-hardware checked out beside the app:| Level | Manifest | Description | Example |
|---|---|---|---|
| MCU | mcu/<arch>/<name>/mcu.json | Silicon: pins and their functions, capabilities, SDK, driver | stm32h750, linux-arm-host |
| Main module | modules/<name>/hardware.json | The board with the MCU (FPU required): boot config, board-level claims, exposed pins | daisy-patch-sm, daisy-seed |
| Attached module | modules/<name>/hardware.json | Claims pins the main module exposes, declares components | patch-init, daisy-pod |
| Device | devices/<name>/device.json | A deployable target: one main module plus attached modules | patch-init, virtual-patch-init |
| Component | components/<name>.json or components/<name>/component.json | Reusable part a module references: front-panel controls, ICs with drivers | pot, button, pcm3060 |
One per hardware target; sbl.json in the project root is the single-target form. It declares hardware sources, the device, and the target's system config:
Sources can be:
{ "name": "local", "path": "./hardware" } - relative to the target file{ "name": "sbl", "github": "owner/repo", "ref": "main" } - cloned into the build's cache; "ssh": true clones over SSHTarget uses source:path format: sbl:devices/patch-init.
A target file may also carry app_config overrides and a board section; see the sloth README for those and for app.sbl.json, the app's own declarations shared by every target.
Defines the silicon, abridged from mcu/arm/stm32h750/mcu.json:
The board with the MCU: "main": true and a system section naming the MCU. It claims what the board itself uses and exposes the rest under logical names. Abridged from modules/daisy-patch-sm:
uses binds an IC component (here the codec) to the board's buses; sloth adds the component's driver directory to the build.
Claims pins by the main module's logical names, never MCU pins, and declares the components on them. It names no parent, so one attached module can sit on a real and a virtual main module. Abridged from modules/patch-init:
Names the main module and the attached modules that make up one target. A device is app-agnostic, and it may carry a board section binding board roles to its own types (see the sloth README).
A front-panel component gives a type and its pin slots (components/button.json):
An IC component is a directory with component.json and a driver/; its claims are bound by the module that uses it.
The resolver checks each claim against the layer below it:
Attached module -> main module -> MCU -> generated code, with validation at each step.
Resolution steps:
b7 with function gpiob7 as MCU pin PB8 -> the requested function must be in its functionsPB8 -> the pin must not already be claimedPin conflicts are detected at resolution time. If the same MCU pin is claimed twice (even through different exposed names), the resolver fails with a conflict error.
sloth writes into <build>/generated/sbl/hw/config/:
| File | Contents |
|---|---|
gpio.hpp | GPIO handles (sbl::hw::gpio::) |
adc.hpp | ADC handles, if any ADC claims |
uart.hpp | UART handles, if any UART claims |
i2c.hpp | I2C handles, if any I2C claims |
electrical.hpp | Port electrics (jack-to-ADC circuit) and idle codes |
mcu.hpp | MCU metadata (sbl::hw::mcu::) |
target.hpp | Target config (sbl::hw::target::) |
board.hpp | The Board, if the hardware declares components |
app.hpp | App config (sbl::app::), if the app declares any |
shim.json | The SHIM: the app's ports, their electrics and the audio shape, for a host |
meta.hpp (build metadata) goes one level up, in sbl/hw/.
Example gpio.hpp:
Example mcu.hpp:
The <sbl/hw/hw.hpp> umbrella header includes the MCU drivers and every generated config header that exists.
With -DSBL_LOCK=ON, CMake writes the resolved hardware to locks/<target>.lock beside the app (locks/patch-init.lock for targets/patch-init.sbl.json) and rewrites it only when the resolution changes. It is off by default, so a build leaves no lock. With -DSBL_LOCKED=ON, CMake verifies the lock instead and fails if it is missing or stale. Abridged:
Paths in the lock are relative to it, so the lock does not change between checkouts.
Create one target file per hardware target under targets/:
Build with:
SBL_CONFIG is relative to the app's source directory. A CMakePresets.json with one preset per target sets it.
| Directory | Contents |
|---|---|
mcu/arm/<name>/ | ARM Cortex-M MCUs (FPU required): mcu.json, driver/, reg/ (cecrops-generated registers), startup and linker script |
mcu/linux-arm-host/ | The Linux host MCU for the workbench and host builds |
modules/<name>/ | Main and attached modules (hardware.json) |
devices/<name>/ | Devices (device.json) |
components/ | Component definitions; IC components are directories with a driver |
The Pydantic models in sbl-schema/sbl_schema/models/ are the source of truth. sbl-schema generate writes the JSON schemas to sbl-schema/sbl_schema/schemas/:
| Schema | Purpose |
|---|---|
sbl.schema.json | Target files (and a single-target sbl.json) |
mcu.schema.json | MCU manifests |
module.schema.json | Attached module manifests |
mainboard.schema.json | The mainboard format; sloth validates main modules in it after reshaping them |
shim.schema.json | The SHIM |
Device manifests are validated by their model when sloth loads them, and sloth checks app.sbl.json as it reads it. Devices, app.sbl.json and component files have no generated schema file. For detailed documentation, see the Hardware Schema Documentation.
CMake runs sloth with SBL_PYTHON if set, else the Python in a .venv beside sound-byte-libs or in tools/, else the system Python.
The sloth README (tools/sloth/README.md) lists the commands and their options from --help.
sloth uses template packs to decouple code generation from the core tool. This allows non-SBL projects to use sloth with their own output formats.
A template pack is a directory containing:
manifest.json - Defines outputs and template pathsDiscovery order:
-t/--templates CLI flag (highest priority)SLOTH_TEMPLATES environment variabletools/sloth/sloth/templates_sbl/)Example manifest.json:
Using custom templates:
Two resolution methods:
resolve_to_ir() - Returns frozen ResolutionResult with flat access (preferred for generation)resolve() - Returns mutable Resolution with manifest access (for debugging/introspection)Key principles:
SBL provides optional CMake hooks that simplify SDK integration. See the examples for usage patterns.
Three-phase lifecycle with SDK plugin branching. A user hook runs first in its phase and replaces the SDK step unless SBL_EXTEND_SDK_HOOKS is set.
Usage in CMakeLists.txt:
The hooks use a plugin system to support different SDKs. Plugins live in tools/cmake/sdk/:
| Plugin | When Used | What It Does |
|---|---|---|
none.cmake | STM32, bare-metal, the Linux host | Configures the toolchain from the MCU manifest's sdk.toolchain, generates the sdk.outputs formats (BIN/HEX; none for a native build) |
The plugin is selected by the MCU manifest's sdk.type, which CMake reads as SBL_EXT_SDK.
Define any of these before sbl_pre_project() to customize a phase. By default a user hook replaces the SDK hook for that phase:
Set SBL_EXTEND_SDK_HOOKS to run the user hook and then the SDK hook. SBL_SKIP_SDK_HOOKS, SBL_SKIP_PRE_PROJECT, SBL_SKIP_POST_PROJECT and SBL_SKIP_FINALIZE skip SDK hooks entirely.
SBL_PROFILING (default OFF) is read when an app is configured. With it on, sbl_finalize() defines SBL_PROFILING_ENABLED for the app's target, which compiles in the code the library gates behind it: AudioBudget, SectionProfile, Counter, the registry they register in and the #PROF reporter in sbl/system/profiling/, the NaN counter in sbl/dsp/types/convert.hpp, the correction count in sbl/dsp/oscillators/blep_corrector.hpp and the profiling line of the boot banner. With it off, that code compiles to nothing.
The option is the same for every target. The app starts the cycle counter with sbl::system::profiling::init() at startup; audio_budget.hpp has the usage. What an app registers is in one table at the symbol sbl_profiling_registry; registry.hpp documents its layout and how a tool reads it over SWD while the core runs.
After sbl_pre_project(), these CMake variables are available:
| Variable | Example | Description |
|---|---|---|
SBL_MCU_NAME | stm32h750 | MCU identifier |
SBL_MCU_DRIVER_PATH | /path/to/driver | Path to driver sources |
SBL_MCU_USB | tinyusb | USB stack the driver provides (tinyusb, stub or empty) |
SBL_MCU_FILESYSTEM | sdmmc-fatfs | Filesystem the driver provides (sdmmc-fatfs, posix or empty) |
SBL_EXT_SDK | none | External SDK name; none is the only plugin today |
SBL_DRIVER_LIB | sbl_stm32h750_driver | Driver library target name |
SBL_GENERATED_DIR | build/generated | Generated headers directory |
SBL_COMPONENT_DRIVER_PATHS | IC component driver directories | |
SBL_BOARD_ROLE_INCLUDE_DIRS | Include roots of the board role bindings the target uses |
sbl_post_project() adds the MCU's driver directory and aliases its library as sbl::driver, which carries the include paths for the library, the generated headers and the board role bindings.