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 Stm32 Rust Knowledge Patch?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/nevaberry-stm32-rust-knowledge-patch)
---
name: stm32-rust-knowledge-patch
description: STM32 (Rust)
version: "0.23.0"
license: MIT
metadata:
author: Nevaberry
---
# STM32 Rust Compatibility
Use this skill when updating STM32 PAC register access or code using the F1
and F4 HALs. Apply each item within its stated device family or HAL scope.
## Reference index
| Reference | Topics |
| --- | --- |
| [PAC generation and device coverage](references/pac-generation-and-device-coverage.md) | Dependencies, device features, generator configuration, supported devices and peripherals |
| [PAC register access](references/pac-register-access.md) | Access widths, indexed fields and registers, channel clusters, field enums, flag semantics |
| [PAC names and interrupts](references/pac-names-and-interrupts.md) | Renamed and removed definitions, interrupt ownership and mapping, core peripheral access |
| [HAL types and clocks](references/hal-types-and-clocks.md) | PAC compatibility, pin conversions, remapping, GPIO types, RCC ownership and clock configuration |
| [HAL peripheral APIs](references/hal-peripherals.md) | SPI, I2C, ADC, PWM, QEI, RTC, serial, DAC and input capture |
## Breaking API and type changes
### Align PAC types with the HAL
`stm32f1xx-hal` uses `stm32f1` 0.16.0. Align direct PAC dependencies with that
version when passing PAC peripheral types to the F1 HAL.
The F4 HAL switches from `stm32f4-staging` back to `stm32f4`. Use a compatible
`stm32f4` dependency if passing PAC peripheral types to the HAL.
### Update F4 erased and optional pin types
Replace `ErasedPin` with `AnyPin` in F4 HAL imports and type annotations.
For F4 peripherals with optional pins, `Option` replaces `NoPin`: use `None`
for an unused pin and `Some(pin)` for a connected pin.
### Update F1 pin conversion and remapping
F1 `Serial`, `I2c`, `Spi`, `Can`, `Qei`, and `PwmInput` constructors accept pin
enums through `RInto` conversions.
The peripheral `remap` API and `Rmp` wrapper replace `RemapStruct` types.
CAN1 and CAN2 remapping is also corrected.
### Follow F1 RCC ownership
`Rcc` contains `Clocks`; `freeze` accepts `Config` or `RawConfig`.
Peripheral APIs use `&mut Rcc` or `&mut RCC` where supported.
Clock arguments that previously took `Clocks` by value now take `&Clocks`.
### Pass mutable RCC access in F4
F4 peripheral enable and reset require mutable access to the PAC RCC.
Pass `&mut rcc` to `PER::enable` and `PER::reset`.
### Update F1 SPI role and pin types
Use `Spi` for master mode and `SpiSlave` for slave mode. These replace the
`OP` generic that distinguished the roles.
F1 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.
### Update F1 ADC construction and QEI imports
`Adc::new` replaces peripheral-specific `Adc::adcX` constructors, and the
F1 HAL adds `AdcExt`.
The F1 `qei` module moves under `pwm_input` and gains a `Direction` re-export.
## PAC access changes
### Match the data access width
On the QUADSPI register block, choose `dr8()`, `dr16()`, or `dr()` for an
8-, 16-, or 32-bit data access, respectively.
```rust
let byte: u8 = qspi.dr8().read().bits();
```
Affected IWDG, WWDG, USART/UART, SPI, and I2C registers use 16-bit definitions.
SPI also exposes the byte-width `DR8` view of its data register.
### Use indexed definitions where provided
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` using the USB endpoint
register array by endpoint index.
HPDMA groups channel registers into `CH` and `CH2D` clusters. H5 and U5
GPDMA also groups registers into per-channel clusters.
### Preserve G0 flag semantics
DMA `IFCR` is write-only; use a write to clear flags.
USB `ISTR` interrupt flags are write-zero-to-clear. Endpoint flags in
`CHEPR` use write-zero-to-clear or write-one-to-toggle semantics, depending
on the flag.
### Update G0 core access and channel selection
Use `cortex-m` for G0 Cortex-M0+ core peripherals; G0 PACs removed their own
core peripheral definitions.
G0 `ADC.CHSELR1` exposes separate one-bit channel fields in place of the
combined `CHSEL` field. For the corrected `HSIDIV` variant, use `Div4` in
place of `Div3`.
### Check renamed and removed peripheral definitions
F101 and F102 drop CAN. F103 drops `CAN2` and renames `CAN1` to `CAN`.
G030/G031/G041 and G070/G071/G081 rename `DMA` to `DMA1`; their DMA interrupt
names also change. The names-and-interrupts reference gives the exact
device-specific replacements, including G050/G051/G061 and G0B0.
Timer `TS` and `SMS` names are corrected. C0, G0, and H5 have corrected field
names in `CCMR1_Output`, and `IWDG_KR` has renamed `KEY` variants.
HRTIM drops timer-block suffixes from register and field names, defines timer
events per block, and adds H7 and G4 enums. H7 drops the `DLL` definition.
## Build and configuration
### Select a device feature
The PAC build lists available device features when none is selected; use
that list to choose the target feature in Cargo.
The F1 HAL checks at build time that a device feature is selected.
### Account for PAC dependencies
The PAC crates use Rust edition 2021 and depend on `defmt` 1.0.
They support atomic register operations.
Generator tool versions, `svd2rust.toml` identifier suffix configuration,
and device coverage are in the PAC generation reference.
### Configure an F1 external HSE clock
Enable HSE bypass in the RCC clock configuration when supplying an external
clock signal on `OSC_IN`.
The F1 RCC clock configuration also has an option to allow overclocking.
## Peripheral capabilities and behavior
### SPI and I2C traits
F1 SPI exposes `spi::FrameSize` for frame typing. The F1 HAL introduces
initial `embedded-hal` 1.0 support, including SPI trait implementations.
F4 `I2cMasterDma` implements `embedded_hal::i2c::I2c`, so drivers requiring
the blocking `embedded-hal` I2C trait can accept it.
F1 adopts the F4 HAL's I2C implementation. Both F1 `I2c` and the blocking
I2C interface expose reset methods.
### ADC controls and calibration
F1 ADC methods 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.
F4 ADC2 and ADC3 satisfy `Calibrate` with no-op implementations.
### Timer and RTC behavior
F1 PWM preloads its auto-reload value; period changes take effect at a timer
update event. F4 timer input capture records timer counts at input edges.
Use F1 `Rtc::restore_or_new` to initialize the RTC while preserving an RTC
that is already running. `Rtc::select_frequency` selects the correct
frequency for LSI and HSE clock sources.
### Additional peripheral support
F1 `Serial` supports UART4 and UART5 on devices that provide them.
The F1 HAL also supports DAC on devices that provide it.
F4 generic PAC `Periph` types implement `Ptr` and `Steal` for HAL code with
those bounds. F4 FMPI2C timing setup accounts for the APB clock when setting
the bus rate.