Skip to content
Back to skills

Stm32 Rust Knowledge Patch

ASecurity

STM32 (Rust)

  • 25 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added December 1, 2026
developmentrustgoapi

Works with

  • api

Security analysis

A100/100

Pro scans all 7 files and shows the line behind each finding

Scanned December 1, 2026

npx -y skills add Nevaberry/nevaberry-plugins --skill stm32-rust-knowledge-patch --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Stm32 Rust Knowledge Patch?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Stm32 Rust Knowledge Patch
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/nevaberry-stm32-rust-knowledge-patch-nevaberry-plugins/badge)](https://www.skillsdirectory.com/skills/nevaberry-stm32-rust-knowledge-patch-nevaberry-plugins)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: stm32-rust-knowledge-patch
description: STM32 (Rust)
version: "0.23.0"
license: MIT
metadata:
  author: Nevaberry
---


# STM32 Rust compatibility guidance

Load this skill when selecting STM32 PAC device features, migrating register
access, or updating F1/F4 HAL peripheral, pin, clock, ADC, timer, and RTC code.

## Reference index

| Reference | Topics |
| --- | --- |
| [PAC setup and device support](references/pac-setup-and-device-support.md) | Dependencies, generation tools, device features, family and peripheral coverage |
| [PAC register access](references/pac-register-access.md) | Access widths, arrays, clusters, field enums, flag semantics |
| [PAC names and interrupts](references/pac-names-and-interrupts.md) | Register and field renames, peripheral removals, interrupt migrations |
| [HAL peripherals and pins](references/hal-peripherals-and-pins.md) | PAC dependencies, device selection, remapping, SPI, I2C, serial, QEI, DAC |
| [HAL clocks, ADC, and timers](references/hal-clocks-adc-and-timers.md) | RCC ownership, clock configuration, ADC control, PWM updates, input capture, RTC |

## HAL dependency and type migrations

### PAC compatibility and device selection

- The F1 HAL uses `stm32f1` 0.16.0. Align direct PAC dependencies with that
  version when passing PAC peripheral types to the HAL.
- The F1 HAL checks at build time that a device feature is selected.
- The F4 HAL switches from `stm32f4-staging` back to `stm32f4`. Use a compatible
  `stm32f4` dependency when passing PAC peripheral types to the HAL.
- Generic PAC `Periph` types now implement `Ptr` and `Steal` for use in F4 HAL
  code with those trait bounds.

### RCC ownership and mutable access

- In the F1 HAL, `Rcc` contains `Clocks`; `freeze` accepts `Config` or `RawConfig`.
- F1 peripheral APIs use `&mut Rcc` or `&mut RCC` where supported. Clock arguments
  that previously took `Clocks` by value now take `&Clocks`.
- F4 peripheral enable and reset require mutable access to the PAC RCC.
  Pass `&mut rcc` to `PER::enable` and `PER::reset`.

### Pin types and remapping

- F1 constructors for `Serial`, `I2c`, `Spi`, `Can`, `Qei`, and `PwmInput` accept
  pin enums through `RInto` conversions.
- The F1 peripheral `remap` API and `Rmp` wrapper replace `RemapStruct` types.
  CAN1 and CAN2 remapping is also corrected.
- In the F4 HAL, replace `ErasedPin` with `AnyPin` in imports and type annotations.
- F4 optional peripheral pins use `Option` in place of `NoPin`: use `None` for
  an unused pin and `Some(pin)` for a connected pin.

### F1 SPI roles and optional signals

- Use `Spi` for master mode and `SpiSlave` for slave mode. They replace the `OP`
  generic that distinguished the roles.
- SPI takes `Option<PIN>` for each of SCK, MISO, and MOSI. Use `Some(pin)` for
  a connected signal and a peripheral-specific helper such as `SPIx::NoSck`
  for an unused signal.

### F1 ADC construction and QEI imports

- `Adc::new` replaces the peripheral-specific `Adc::adcX` constructors.
  The HAL also adds the `AdcExt` trait.
- The `qei` module moves under `pwm_input`, and QEI gets a `Direction` re-export.

## PAC access migrations

### Register widths

Affected IWDG, WWDG, USART/UART, SPI, and I2C registers now use 16-bit definitions.
SPI also exposes the byte-width `DR8` view of the data register.

For QUADSPI, choose `dr8()`, `dr16()`, or `dr()` on the register block for
8-, 16-, or 32-bit data access, respectively.

```rust
let byte: u8 = qspi.dr8().read().bits();
```

### Indexed fields, arrays, and channel clusters

- Affected ADC, GPIO, CAN, DSI, EXTI, SAI, DMA, and TIM fields use indexed field
  arrays, including ADC field arrays on C0, G0, and WL.
- DAC channels, RTC alarms, and DMAMUX registers use arrays, as do F4 SDIO
  response registers. H5 GPIO and H5/U5 GTZC also gain register arrays.
- On C0, G0, H5, and U0, access `CHEP0R` through `CHEP7R` through the USB endpoint
  register array by endpoint index.
- HPDMA uses `CH` and `CH2D` channel clusters. H5 and U5 GPDMA also groups
  registers into per-channel clusters.

### G0 writes and channel selection

- DMA `IFCR` is write-only. Use a write to clear flags.
- USB interrupt flags in `ISTR` are write-zero-to-clear. Endpoint flags in
  `CHEPR` use write-zero-to-clear or write-one-to-toggle, depending on the flag.
- `ADC.CHSELR1` exposes separate one-bit channel fields instead of combined `CHSEL`.
- Use `Div4` in place of `Div3` for the corrected `HSIDIV` variant.

### Peripheral and field names

- F101 and F102 drop CAN. F103 drops `CAN2` and renames `CAN1` to `CAN`.
- G0 removes its own Cortex-M0+ core peripheral definitions. Use `cortex-m`
  to access those core peripherals.
- Timer `TS` and `SMS` field names are corrected. C0, G0, and H5 also have
  corrected `CCMR1_Output` field names; `IWDG_KR` `KEY` variants have new names.
- HRTIM drops timer-block suffixes from register and field names and defines
  timer events per block. It adds H7/G4 enums; H7 drops the `DLL` definition.
- MP1 removes prefixes from generated peripheral names. U5 strips prefixes
  from generated register names and groups MDF registers into clusters.

Device-specific DMA interrupt names, peripheral moves, removed registers,
and H7 RCC/FLASH naming are detailed in
[PAC names and interrupts](references/pac-names-and-interrupts.md).

## PAC setup and field values

PAC crates use Rust edition 2021, depend on `defmt` 1.0, and support atomic
register operations. If no device feature is selected, the build lists the
available features; use that list to choose the target feature in Cargo.

PAC generation uses `svd2rust` 0.36.1, `svdtools` 0.4.6, and `form` 0.13.0.
The `svd2rust.toml` configuration sets custom identifier suffixes for generated code.

USART and TIM gain field enums. Other additions include ADC on L4/L5/G0/H5/WB,
SPI on G4/U5/H7+, and RCC and SYSCFG on G0/WB. The full peripheral enum list is in
[PAC register access](references/pac-register-access.md).

C0, N6, U0, and H7R/S gain initial support. UCPD definitions are available on
G0x1, G4, H5, H7R/S, L5, and U5. Device-specific additions are in
[PAC setup and device support](references/pac-setup-and-device-support.md).

## Communication interfaces

### F1 SPI and I2C

SPI exposes `spi::FrameSize` for frame typing. The F1 HAL introduces initial
`embedded-hal` 1.0 support, including SPI trait implementations.

The F1 HAL adopts the F4 HAL's I2C implementation. Both `I2c` and the blocking
I2C interface expose reset methods.

### F4 I2C

`I2cMasterDma` implements `embedded_hal::i2c::I2c`, so drivers requiring the
blocking `embedded-hal` I2C trait can accept it. FMPI2C timing setup accounts
for the APB clock when setting the bus rate.

### F1 serial and DAC

`Serial` supports UART4 and UART5 on devices that provide them.
The F1 HAL also supports the DAC on devices that provide it.

## ADC, timer, and clock behavior

### ADC control and calibration

F1 ADC methods let callers control the internal temperature sensor and voltage
reference. Explicit control can reduce the time spent reading these channels.
ADC methods can also enable and disable end-of-conversion (EOC) interrupts.

In the F4 HAL, ADC2 and ADC3 satisfy the `Calibrate` trait bound with no-op
implementations.

### PWM and input capture

The F1 PWM timer preloads its auto-reload value. Period changes take effect at
a timer update event. The F4 HAL supports timer input capture for recording
timer counts at input edges.

### F1 RTC and external clock configuration

Use `Rtc::restore_or_new` to initialize the RTC while preserving an RTC that
is already running. `Rtc::select_frequency` now selects the correct frequency
for LSI and HSE clock sources.

Enable HSE bypass in the RCC clock configuration when supplying an external
clock signal on `OSC_IN`. The RCC clock configuration also has an option to
allow overclocking.

Files in this skill

  • SKILL.md7.7 KB
  • coverage.json539 B
  • references/hal-clocks-adc-and-timers.md2.1 KB
  • references/hal-peripherals-and-pins.md2.6 KB
  • references/pac-names-and-interrupts.md2.8 KB
  • references/pac-register-access.md2.3 KB
  • references/pac-setup-and-device-support.md2.5 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.