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 Cortex M Knowledge Patch?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/nevaberry-cortex-m-knowledge-patch-nevaberry-plugins)
---
name: cortex-m-knowledge-patch
description: Cortex-M
version: "0.7.7"
license: MIT
metadata:
author: Nevaberry
---
# Cortex-M compatibility guidance
Use this skill when updating Cortex-M firmware dependencies, resolving
critical-section linkage, configuring startup memory, using semihosting I/O,
or configuring interrupt and exception handlers and linker sections.
## Reference index
| Reference | Topics |
| --- | --- |
| [Core and critical sections](references/core-and-critical-sections.md) | Toolchain, core feature deprecation, singleton linkage, privilege, NVIC, delays, active exceptions |
| [Semihosting](references/semihosting.md) | Toolchain, I/O synchronization, feature removal, printing, host streams, disabling calls, debug output |
| [Startup and memory](references/startup-and-memory.md) | Runtime toolchain, startup hook deprecation, stack limits, data copying, stack painting, RAM initialization |
| [Handlers and linker configuration](references/handlers-and-linker.md) | Handler lint expectations, interrupt capacity, HardFault placement and trampoline, text alignment |
## Breaking changes and deprecations
### Toolchain requirements
`cortex-m` 0.7.8 and `cortex-m-rt` 0.7.6 use the Rust 2024 edition and require
Rust 1.85 or newer. `cortex-m-semihosting` 0.6.0 requires Rust 1.85.
### Remove the inline assembly feature
Remove `inline-asm` from Cargo feature lists for `cortex-m`: it has no effect
in 0.7.8 and is slated for removal in a future major release.
For `cortex-m-semihosting`, remove `inline-asm` from the crate's Cargo feature
list when upgrading. Since 0.5.0, that crate always uses inline assembly.
### Printing no longer returns an I/O result
From `cortex-m-semihosting` 0.4.0 onward, printing macros discard I/O errors
and return `()`. When upgrading from 0.3.7, where they return `Result`, remove
`?` and `.unwrap()` from their calls.
```rust
cortex_m_semihosting::hprintln!("value: {}", 42);
```
### Host stream types
`cortex-m-semihosting` 0.4.0 merged `HStdout` and `HStderr` into
`cortex_m_semihosting::hio::HostStream`. Use `HostStream` in type annotations
and function signatures for either host stream.
### Startup hook deprecation
The `#[pre_init]` startup hook is deprecated in `cortex-m-rt` 0.7.6.
Existing uses produce deprecation warnings.
## Supply a critical-section implementation
The final binary must supply a `critical-section` implementation for
`singleton!` to link. A missing implementation can produce an undefined
`_critical_section_1_0_acquire` symbol.
Enable `critical-section-single-core` on privileged single-core targets,
or choose a suitable implementation for your target, typically from its HAL,
with cross-core locking on multicore chips.
```toml
[dependencies]
cortex-m = { version = "0.7.8", features = ["critical-section-single-core"] }
```
`cortex-m-semihosting` 0.6.0 uses `critical_section::Mutex` to synchronize
semihosting I/O. Firmware using this I/O must provide a `critical-section`
implementation for its target.
## Configure startup memory
### Main stack limit
Enable `set_msplim` to initialize the Main Stack Pointer Limit register
(MSPLIM) at reset. The linker also exposes `_stack_end` since 0.7.5 for custom
stack-limit setup.
```toml
[dependencies]
cortex-m-rt = { version = "0.7.6", features = ["set_msplim"] }
```
### Data already copied by a bootloader
Enable `skip-data-copy` when the bootloader has already copied `.data` to its
runtime address and the original load address may be inaccessible after
handoff. The runtime skips that copy during reset.
```toml
[dependencies]
cortex-m-rt = { version = "0.7.6", features = ["skip-data-copy"] }
```
### Inspect stack use
Since `cortex-m-rt` 0.7.5, `paint-stack` fills the entire stack with a fixed
value at startup so you can inspect how much stack has been used.
```toml
[dependencies]
cortex-m-rt = { version = "0.7.6", features = ["paint-stack"] }
```
### Initialize RAM for hardware error detection
Enable `zero-init-ram`, introduced in `cortex-m-rt` 0.7.4, when hardware error
detection requires RAM to be initialized at startup.
```toml
[dependencies]
cortex-m-rt = { version = "0.7.6", features = ["zero-init-ram"] }
```
## Use core APIs and delays
The following behaviors apply to `cortex-m` 0.7.8.
`enter_unprivileged` switches execution to unprivileged mode using the
Process Stack Pointer (`PSP`).
The `NVIC` peripheral exposes the `ITNS` interrupt target state registers.
`cortex-m` provides delays for drivers that use `embedded-hal` 1.0.
`asm::delay(n)` consumes at least `n` CPU cycles, including on dual-issue
Cortex-M7 cores. On other cores, the same argument will likely take about
twice as many cycles as before.
`SCB::vect_active()` avoids the byte read that could fault on models that
require ICSR to be read as a word.
## Configure handlers and linker sections
Since `cortex-m-rt` 0.7.5, entry and interrupt handlers accept the Rust
`#[expect(...)]` lint attribute, and the runtime supports up to 496 interrupts
on Armv8-M targets.
Since `cortex-m-rt` 0.7.5, the user handler symbol `_HardFault` is placed in
`.HardFault.user`. Match this input section in custom linker scripts that
place the handler explicitly.
Since `cortex-m-rt` 0.7.4, use `#[exception(trampoline = false)]` to install a
HardFault handler directly. The default trampoline passes an exception frame
to the handler. See the handler reference for an example.
In `cortex-m-rt` 0.7.7, the default `_stext` meets the `.text` section's
alignment requirement. If you explicitly override `_stext`, choose an
address that meets that requirement to avoid lld's section-alignment warning.
## Control semihosting output
Enable the `no-semihosting` Cargo feature to disable all semihosting calls.
```toml
[dependencies]
cortex-m-semihosting = { version = "0.6.0", features = ["no-semihosting"] }
```
The crate's `dbg!` macro sends output to host stderr through `heprintln!`.
```rust
cortex_m_semihosting::dbg!(2 + 2);
```