Instructions for AI coding agents working in this repository. Keep answers and changes consistent with the rules below. When a rule here conflicts with the current state of the code, trust the code, flag the discrepancy, and update this file.
X-HEEP is an open-source, configurable RISC-V microcontroller described in
SystemVerilog. The RTL is generated: Python scripts (util/xheep_gen/)
expand a configuration (configs/) into Mako templates (*.tpl) that produce
the final .sv files. FuseSoC orchestrates hardware builds and simulation;
software is built with Make + CMake using a RISC-V cross-compiler.
configs/— MCU configuration (HJSON files or Python scripts). Entry point for customization.hw/— RTL:core-v-mini-mcu/(SoC top),ip/,ip_examples/,fpga/,asic/,simulation/,system/(SoC + pad ring),vendor/(vendored third-party IPs).sw/— Software: applications, drivers, SDK, linker scripts.tb/— Testbench (tb_top.sv,testharness.sv) and C++ simulation driver (tb_top.cpp).test/— Test scripts:test_apps/(app compile+sim suite),test_x_heep_gen/,verifheep/.util/— Python tooling:xheep_gen/(the generator, vendored),vendor.py,c_gen.py, Docker, profiling.scripts/— Build/simulation helper scripts.docs/— Sphinx documentation (docs/source/).build/,sw/build/— Generated build outputs.
- Never edit generated files. If a file has a
.tplsibling, it is regenerated bymake mcu-genand edits will be lost. Edit the.tplinstead. - Never edit register-generated files:
*_reg_top.sv,*_reg_pkg.sv(generated by OpenTitanregtoolfromdata/*.hjsonduring FuseSoC runs, not committed) and*_regs.h/*_structs.hinsw/device/lib/drivers/(generated from the same HJSON or mcu-gen). Edit thedata/*.hjsonor config instead. - Configuration changes go in
configs/, not in generated RTL or headers. After changing any.tpl, config, orconfigs/file, re-runmake mcu-gen— many files depend on it.
- Python deps live in a conda env named
x-heep(create once withmake conda, thenconda activate x-heep). A venv flow also exists viaMakefile.venv. RISCV_XHEEPmust point to the RISC-V toolchain directory without/bin.- There is a Docker image available:
make -C util/docker docker-pull && make -C util/docker docker-run(the container providesinit_gcc/init_clang/init_corevshell shortcuts that setCOMPILER/COMPILER_PREFIX/ARCH).
Run make help for the authoritative, up-to-date list of targets and
parameters (the Makefile is self-documenting). The essentials:
make mcu-gen # generate RTL from config; run after any .tpl/config change
make app PROJECT=hello_world # compile an app (RISC-V cross-compile via CMake)
make verilator-build # build the Verilator model (once, or after RTL changes)
make verilator-run # run sw/build/main.hex on the Verilator model
make test # synthesize verilator, compile+simulate all apps
make test TEST_FLAGS=--compile-only # fast: compile all apps only
make compare-mcu-gen # diff mcu-gen output vs main for testing config/generator changes
make verible # format SystemVerilog
make format-python # format Python (black)Useful outputs:
- Firmware:
sw/build/main.* - App UART output:
uart0.login the sim-verilator directory
- Access registers via
mmio+ generated<name>_regs.h/<name>_structs.h(never hardcode addresses); prefer the SDK layer (sw/device/lib/sdk/) in applications when available. - FuseSoC
.corefiles describe filesets/dependencies; the main one iscore-v-mini-mcu.core. Do not list generated files in.corefilesets.
Vendored code (copies of other repositories) lives in hw/vendor/, sw/vendor/,
util/xheep_gen/, hw/fpga/xheep_fpga_support/, each described by a *.vendor.hjson
file pinning the upstream URL and commit.
- For quick testing/debugging you may edit vendored files in place, but
tell the user to transfer the change upstream (or to a patch) before merging.
Then update the
revin the*.vendor.hjsonand runmake vendor-update. CI re-vendors and rejects any uncommitted in-place edits. - Small change in a repo we don't control (hard to upstream): add a patch
under
hw/vendor/patches/<org>_<repo>/and setpatch_dirin the*.vendor.hjson. - Never edit
*.lock.hjson(generated byutil/vendor.py).
- Getting started / setup:
docs/source/GettingStarted/ - Configuration (xheep_gen):
docs/source/Configuration/ - How-to guides (simulators, debugging, FPGA, flash):
docs/source/How_to/ - Extending HW/SW:
docs/source/Extending/ - Testing:
docs/source/Testing/