Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Riscv Embedded Knowledge Patch?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/nevaberry-riscv-embedded-knowledge-patch)
---
name: riscv-embedded-knowledge-patch
description: RISC-V embedded (Rust)
version: "0.16.1"
license: MIT
metadata:
author: Nevaberry
---
# RISC-V embedded Rust compatibility
Load this skill when migrating or configuring `riscv`, `riscv-rt`, or
`riscv-peripheral`: CSR access, interrupt handling, runtime startup, linker
scripts, and standard peripheral registers.
## Reference index
| Reference | Topics |
| --- | --- |
| [CSR and interrupts](references/csr-and-interrupts.md) | CSR safety, removed APIs, register proxies, typed interrupts, target configuration, trait imports, and trap-table placement |
| [Runtime startup](references/runtime-startup.md) | Entry arguments, supervisor mode, missing CSRs, initialization hooks, early assembly, hart stacks, HAL entry, and toolchain requirements |
| [Linking and traps](references/linking-and-traps.md) | Linker symbols and sections, heap access, optional scripts, fallback hooks, trap dispatch, vectored handlers, and interrupt setup |
| [Standard peripherals](references/peripherals.md) | ACLINT, CLINT, PLIC, trait contracts, instance methods, generated constructors, async HAL support, and dependencies |
## Breaking changes and deprecations
### Review CSR write safety and removed fields
CSR writes become `unsafe` by default in `riscv` 0.13.0. Review the register
and value at existing write call sites before wrapping calls in `unsafe`.
Remove calls to user-mode trap registers, user-level interrupt fields and
cause variants, and machine environment-call delegation in `medeleg` when
upgrading to `riscv` 0.11.0. FCSR register operations are also removed.
In `riscv` 0.16.1, XS and SD are read-only summaries; remove writes to them.
The `mstatus` and `sstatus` APIs gain UBE, VS, UXL, and SXL helpers, and
corrected masks preserve all legal status bits.
### Update trait imports and trap-generation features
The migration from `riscv-pac` to `riscv-types`, introduced in the yanked
`riscv` 0.16.0 release, requires updated trait imports and Rust 1.81 or later.
In `riscv` 0.16.1, only `pac_enum` is re-exported from `riscv-macros`.
Enable `rt` or `rt-v-trap` when relying on trap code generated by
`riscv::pac_enum`. This requirement also began in the yanked 0.16.0 release.
```toml
[dependencies]
riscv = { version = "0.16.1", features = ["rt"] }
```
### Replace the custom target flag
`riscv` 0.15.0 removes the build script supplying `cfg(riscv)`. Use the
built-in architecture check:
```rust
#[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))]
use riscv::register;
```
### Adjust custom linker scripts
In `riscv-rt` 0.14.0, add a second leading underscore to `_sdata`, `_edata`,
`_idata`, `_sbss`, `_ebss`, `_sheap`, `_eheap`, `_estack`, and `_sstack`.
Keep `_stext` as the configurable text start, with `__stext` at the same
address. Use `__etext`, `__srodata`, and `__erodata` for the text end and
read-only data bounds.
Use `riscv_rt::heap_start()` to initialize an allocator because `__sheap`
is private. The linker aligns `.heap` to four bytes.
From `riscv` 0.15.0, custom linker scripts need to place `.trap.vector` for
tables generated by `riscv::pac_enum(unsafe CoreInterrupt)`; these tables
previously used `.trap`. `RISCV_MTVEC_ALIGN` configures the vector-table
alignment constraint from `riscv` 0.13.0.
### Move pre-RAM hooks to assembly
Enable `pre-init` and define `__pre_init` in assembly using
`core::arch::global_asm!` to run a hook before RAM initialization.
The Rust `pre_init` attribute was deprecated in `riscv-rt` 0.15.0 because
Rust code at this stage is unsound; its re-export was removed in 0.18.0.
From `riscv-rt` 0.16.0, custom `_mp_hook` and `__pre_init` assembly must
preserve startup arguments in `s0`–`s2`, with `a2` saved in `a5` on RVE.
Early hooks must operate without a stack while RAM is uninitialized.
The runtime no longer zeroes general-purpose registers and avoids stack
access before `_start_rust`.
### Update custom trap-dispatch features
In `riscv-rt` 0.13.0 through 0.17.x, `no-exceptions` omits the default
`_dispatch_exception`, and `no-interrupts` omits the default
`_dispatch_core_interrupt`. Corresponding standard handler references are
also omitted from the linker script from 0.15.0.
`riscv-rt` 0.18.0 deprecates those feature names in favor of
`custom-exceptions` and `custom-interrupts`, respectively.
### Migrate peripheral call sites and dependencies
With `riscv-peripheral` 0.3.0, change CLINT and PLIC associated-function
calls to methods on a peripheral instance. Types generated by
`clint_codegen!` and `plic_codegen!` expose these methods through `Deref`.
`riscv-peripheral` 0.3.0 drops `embedded-hal-async` support. Use a
chip-specific async HAL crate that accounts for the chip's hart topology.
The `riscv` re-export is removed in 0.4.0; if you used it, add `riscv` as a
direct dependency and import from it.
## CSR and interrupt quick reference
### Select privilege-specific nesting
Both `riscv::interrupt::machine` and `riscv::interrupt::supervisor` expose
`nested` for handlers that need nested interrupts. `riscv::interrupt`
re-exports the machine API by default and the supervisor API with `s-mode`.
### Edit proxies and handle CSR errors
Use `Mstatus::update_*` and the `Mcounteren` update helpers for in-memory
edits before a separate CSR write. Panicking APIs gain fallible counterparts
in `riscv` 0.12.0 for callers that need to handle CSR errors.
`Mstatus::from(usize)` and `Mcause::from(usize)` construct synthetic values
for tests from 0.12.0. `Mcause::from_bits` allows all 64 bits to be set on
RV64 from 0.15.0.
### Use typed interrupt operations and atomic clearing
In `riscv` 0.15.0, `mie` and `sie` enable operations and `mip` and `sip`
pending operations gain APIs based on `riscv_pac::CoreInterruptNumber`.
`riscv::interrupt` exposes `is_interrupt_enabled`, `enable_interrupt`,
`disable_interrupt`, and `is_interrupt_pending`.
`Mip` and `Sip` fields are read-only to prevent read-modify-write updates
from clearing interrupts that arrive between the read and write. Use
`unsafe` `mip::clear_pending` or `sip::clear_pending` only when both the
chip and the interrupt source support the operation.
## Runtime configuration quick reference
### Receive startup arguments and select supervisor mode
An application's `#[entry]` can receive startup values of `a0`–`a2` from
`riscv-rt` 0.9.0. Machine-mode startup puts the hart ID in `a0` at the
beginning of the runtime from 0.16.0.
Enable `s-mode` on `riscv-rt` for supervisor-mode startup. From 0.10.0,
the caller passes the hart ID to `_mp_hook` as a `usize`; custom hooks
must accept that parameter.
### Configure targets with missing CSRs
| Feature | Runtime behavior |
| --- | --- |
| `single-hart` | Assumes hart zero and skips reading `mhartid` from `riscv-rt` 0.12.0 |
| `no-xie-xip` | Supports chips lacking XIE and XIP CSRs from `riscv-rt` 0.16.0 |
| `no-mhartid` | Loads zero into `a0` from `riscv-rt` 0.17.0 |
| `no-xtvec` | Omits interrupt-related runtime code from `riscv-rt` 0.17.0 |
### Generate vectored handlers
Enable `v-trap` for vectored interrupt handling and for
`#[riscv_rt::core_interrupt]` and `#[riscv_rt::exception]` to generate their
corresponding traps. `RISCV_RT_BASE_ISA` configures macro generation for
the base ISA, such as RV32I or RV32E, from `riscv-rt` 0.14.0; it is required
for vectored core-interrupt trap generation from 0.17.0.
### Add runtime hooks
Enable `post-init` and use `#[riscv_rt::post_init]` for the Rust
`__post_init` hook before `main` from `riscv-rt` 0.16.0.
Enable `custom-setup-interrupts` in `riscv-rt` 0.18.0 to omit the default
`_setup_interrupts` and make `#[riscv_rt::setup_interrupts]` available.
The replacement can take one `usize` argument containing the running
hart's ID.
### Include device and memory scripts
Enable `device` or `memory` to have `link.x` include `device.x` or
`memory.x`, respectively, from `riscv-rt` 0.15.0. Enable both when supplying
both scripts for inclusion.
```toml
[dependencies]
riscv-rt = { version = "0.15", features = ["device", "memory"] }
```