Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: check
args: --features=${{ matrix.mcu }},rtic,high --examples
args: --features=${{ matrix.mcu }},rtic1,high --examples

- uses: actions-rs/cargo@v1
with:
Expand Down
17 changes: 3 additions & 14 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,8 @@
"rust.all_targets": false,
"rust.target": "thumbv7m-none-eabi",
"rust.all_features": false,
"rust.features": [
"rtic",
"stm32f103",
"medium"
],
"rust.features": ["rtic1", "stm32f103", "medium"],
"rust-analyzer.checkOnSave.allTargets": false,
"rust-analyzer.checkOnSave.extraArgs": [
"--target",
"thumbv7m-none-eabi"
],
"rust-analyzer.cargo.features": [
"rtic",
"stm32f103",
"medium"
]
"rust-analyzer.checkOnSave.extraArgs": ["--target", "thumbv7m-none-eabi"],
"rust-analyzer.cargo.features": ["rtic1", "stm32f103", "medium"]
}
2 changes: 1 addition & 1 deletion .zed/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"rust-analyzer": {
"initialization_options": {
"cargo": {
"features": ["defmt", "rtic", "stm32f103", "medium"]
"features": ["defmt", "rtic1", "stm32f103", "medium"]
},
"check": {
"allTargets": false,
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,20 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Breaking changes

- move pin connecting to timer channels after `Pwm` initialization [#517]

### Changed

- `timer.rs` refactoring
- `rtic` feature renamed to `rtic1` [#517]

### Added

- `rtic2` feature, timer `Capture` support [#517]

[#517]: https://github.com/stm32-rs/stm32f1xx-hal/pull/517

## [v0.11.0] - 2025-09-09

Expand Down
49 changes: 41 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ readme = "README.md"
version = "0.11.0"

[package.metadata.docs.rs]
features = ["stm32f103", "rtic", "high"]
features = ["stm32f103", "rtic1", "high"]
default-target = "x86_64-unknown-linux-gnu"

[dependencies]
Expand All @@ -28,11 +28,21 @@ nb = "1.1"
embedded-dma = "0.2.0"
bxcan = "0.8.0"
void = { default-features = false, version = "1.0.2" }
fugit = "0.3.7"
fugit = "0.3.9"
fugit-timer = "0.1.3"
rtic-monotonic = { version = "1.0", optional = true }
bitflags = "1.3.2"
vcell = "0.1.3"
# rtic1
rtic-monotonic = { version = "1.0", optional = true }
systick-monotonic = { version = "1.0.1", optional = true }
cortex-m-rtic = { version = "1.1.4", features = [
"test-critical-section",
], optional = true }
# rtic2
rtic-time = { version = "2.0.1", optional = true }
embedded-hal-async = { version = "1.0", optional = true }
rtic = { version = "2.2", features = ["thumbv7-backend"], optional = true }
atomic-polyfill = { version = "1.0.3", optional = true }

[dependencies.stm32f1]
version = "0.16.0"
Expand All @@ -57,12 +67,12 @@ version = "0.8.0"
optional = true

[dev-dependencies]
defmt-rtt = "1.0"
panic-halt = "1.0.0"
panic-semihosting = "0.6.0"
panic-itm = "0.4.2"
panic-probe = "1.0"
rtt-target = "0.6.1"
cortex-m-rtic = "1.1.4"
cortex-m-semihosting = "0.5.0"
heapless = "0.9.1"
mfrc522 = { version = "0.8.0", features = ["eh02"] }
Expand Down Expand Up @@ -93,7 +103,22 @@ has-can = []
# Devices with Dac
has-dac = []

rtic = ["rtic-monotonic"]
## Support monotonic timers and other stuff that can be used by [RTICv1 framework](https://crates.io/crates/cortex-m-rtic)
rtic1 = ["dep:rtic-monotonic", "dep:systick-monotonic", "cortex-m-rtic"]

## Support monotonic timers and other stuff that can be used by [RTICv2 framework](https://crates.io/crates/rtic)
##
## Requires nightly rust compiler
rtic2 = [
"dep:rtic-time",
"dep:rtic",
"dep:atomic-polyfill",
"dep:embedded-hal-async",
]
rtic-tim2 = []
rtic-tim3 = []
rtic-tim4 = []
rtic-tim5 = []

[profile.dev]
incremental = false
Expand All @@ -114,7 +139,7 @@ required-features = ["stm32f103", "stm32-usbd"]

[[example]]
name = "usb_serial_rtic"
required-features = ["stm32f103", "stm32-usbd"]
required-features = ["stm32f103", "stm32-usbd", "rtic1"]

[[example]]
name = "blinky_timer_irq"
Expand All @@ -130,12 +155,16 @@ required-features = ["medium"]

[[example]]
name = "timer-interrupt-rtic"
required-features = ["stm32f103", "medium"]
required-features = ["stm32f103", "medium", "rtic1"]

[[example]]
name = "exti"
required-features = []

[[example]]
name = "exti_rtic"
required-features = ["rtic1"]

[[example]]
name = "can-echo"
required-features = ["has-can"]
Expand All @@ -146,7 +175,7 @@ required-features = ["has-can"]

[[example]]
name = "can-rtic"
required-features = ["has-can"]
required-features = ["has-can", "rtic1"]

[[example]]
name = "gpio_input"
Expand All @@ -155,3 +184,7 @@ required-features = ["stm32f103"]
[[example]]
name = "serial-interrupt-idle"
required-features = ["stm32f103", "medium"]

[[example]]
name = "rtic2-timer-input-capture"
required-features = ["stm32f103", "rtic2"]
81 changes: 28 additions & 53 deletions examples/pwm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,103 +9,78 @@ use panic_halt as _;

use cortex_m::asm;
use cortex_m_rt::entry;
use stm32f1xx_hal::{
pac,
prelude::*,
time::ms,
timer::{Channel, Tim2NoRemap},
};
use stm32f1xx_hal::{pac, prelude::*, time::ms};

#[entry]
fn main() -> ! {
let p = pac::Peripherals::take().unwrap();

let mut rcc = p.RCC.constrain();

let mut afio = p.AFIO.constrain(&mut rcc);

let mut gpioa = p.GPIOA.split(&mut rcc);
let gpioa = p.GPIOA.split(&mut rcc);
// let mut gpiob = p.GPIOB.split(&mut rcc);

// TIM2
let c1 = gpioa.pa0.into_alternate_push_pull(&mut gpioa.crl);
let c2 = gpioa.pa1.into_alternate_push_pull(&mut gpioa.crl);
let c3 = gpioa.pa2.into_alternate_push_pull(&mut gpioa.crl);
let c1 = gpioa.pa0;
let c2 = gpioa.pa1;
let c3 = gpioa.pa2;
// If you don't want to use all channels, just leave some out
// let c4 = gpioa.pa3.into_alternate_push_pull(&mut gpioa.crl);
let pins = (c1, c2, c3);
// let c4 = gpioa.pa3;

// TIM3
// let c1 = gpioa.pa6.into_alternate_push_pull(&mut gpioa.crl);
// let c2 = gpioa.pa7.into_alternate_push_pull(&mut gpioa.crl);
// let c3 = gpiob.pb0.into_alternate_push_pull(&mut gpiob.crl);
// let c4 = gpiob.pb1.into_alternate_push_pull(&mut gpiob.crl);
// let c1 = gpioa.pa6;
// let c2 = gpioa.pa7;
// let c3 = gpiob.pb0;
// let c4 = gpiob.pb1;

// TIM4 (Only available with the "medium" density feature)
// let c1 = gpiob.pb6.into_alternate_push_pull(&mut gpiob.crl);
// let c2 = gpiob.pb7.into_alternate_push_pull(&mut gpiob.crl);
// let c3 = gpiob.pb8.into_alternate_push_pull(&mut gpiob.crh);
// let c4 = gpiob.pb9.into_alternate_push_pull(&mut gpiob.crh);
// let c1 = gpiob.pb6;
// let c2 = gpiob.pb7;
// let c3 = gpiob.pb8;
// let c4 = gpiob.pb9;

//let mut pwm =
// Timer::new(p.TIM2, &mut rcc).pwm_hz::<Tim2NoRemap, _, _>(pins, &mut afio.mapr, 1.kHz());
// Timer::new(p.TIM2, &mut rcc).pwm_hz(pins, 1.kHz());
// or
let mut pwm = p
.TIM2
.pwm_hz::<Tim2NoRemap, _, _>(pins, &mut afio.mapr, 1.kHz(), &mut rcc);
let (mut pwm_mgr, (pwm_c1, pwm_c2, pwm_c3, ..)) = p.TIM2.pwm_hz(1.kHz(), &mut rcc);

// Enable clock on each of the channels
pwm.enable(Channel::C1);
pwm.enable(Channel::C2);
pwm.enable(Channel::C3);
let mut c1 = pwm_c1.with(c1);
c1.enable();
let mut c2 = pwm_c2.with(c2);
c2.enable();
let mut c3 = pwm_c3.with(c3);
c3.enable();

//// Operations affecting all defined channels on the Timer

// Adjust period to 0.5 seconds
pwm.set_period(ms(500).into_rate());
pwm_mgr.set_period(ms(500).into_rate());

asm::bkpt();

// Return to the original frequency
pwm.set_period(1.kHz());
pwm_mgr.set_period(1.kHz());

asm::bkpt();

let max = pwm.get_max_duty();
let max = pwm_mgr.get_max_duty();

//// Operations affecting single channels can be accessed through
//// the Pwm object or via dereferencing to the pin.

// Use the Pwm object to set C3 to full strength
pwm.set_duty(Channel::C3, max);
c3.set_duty(max);

asm::bkpt();

// Use the Pwm object to set C3 to be dim
pwm.set_duty(Channel::C3, max / 4);
c3.set_duty(max / 4);

asm::bkpt();

// Use the Pwm object to set C3 to be zero
pwm.set_duty(Channel::C3, 0);

asm::bkpt();

// Extract the PwmChannel for C3
let mut pwm_channel = pwm.split().2;

// Use the PwmChannel object to set C3 to be full strength
pwm_channel.set_duty(max);

asm::bkpt();

// Use the PwmChannel object to set C3 to be dim
pwm_channel.set_duty(max / 4);

asm::bkpt();

// Use the PwmChannel object to set C3 to be zero
pwm_channel.set_duty(0);
c3.set_duty(0);

asm::bkpt();

Expand Down
21 changes: 11 additions & 10 deletions examples/pwm_custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use panic_halt as _;

use cortex_m::asm;
use stm32f1xx_hal::{pac, prelude::*, timer::Timer};
use stm32f1xx_hal::{pac, prelude::*};

use cortex_m_rt::entry;

Expand All @@ -27,30 +27,31 @@ fn main() -> ! {
let p0 = pb4.into_alternate_push_pull(&mut gpiob.crl);
let p1 = gpiob.pb5.into_alternate_push_pull(&mut gpiob.crl);

let pwm = Timer::new(p.TIM3, &mut rcc).pwm_hz((p0, p1), &mut afio.mapr, 1.kHz());
let (pwm, pwm_channels) = p.TIM3.remap(&mut afio.mapr).pwm_hz(1.kHz(), &mut rcc);

let max = pwm.get_max_duty();

let mut pwm_channels = pwm.split();
let mut c1 = pwm_channels.0.with(p0);
let mut c2 = pwm_channels.1.with(p1);

// Enable the individual channels
pwm_channels.0.enable();
pwm_channels.1.enable();
c1.enable();
c2.enable();

// full
pwm_channels.0.set_duty(max);
pwm_channels.1.set_duty(max);
c1.set_duty(max);
c2.set_duty(max);

asm::bkpt();

// dim
pwm_channels.1.set_duty(max / 4);
c2.set_duty(max / 4);

asm::bkpt();

// zero
pwm_channels.0.set_duty(0);
pwm_channels.1.set_duty(0);
c1.set_duty(0);
c2.set_duty(0);

asm::bkpt();

Expand Down
Loading
Loading